Java教程

SpringBoot Https 修改状态码

本文主要是介绍SpringBoot Https 修改状态码,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
    @Bean
    public ServletWebServerFactory servletContainer() {
        TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
            @Override
            protected void postProcessContext(Context context) {
                SecurityConstraint constraint = new SecurityConstraint();
                constraint.setUserConstraint("CONFIDENTIAL");
                SecurityCollection collection = new SecurityCollection();
                collection.addPattern("/*");
                constraint.addCollection(collection);
                context.addConstraint(constraint);
            }
        };

        tomcat.addAdditionalTomcatConnectors(createStandardConnector());
        // 这里是最重要的,加上这个就OK了
        tomcat.addContextCustomizers( context -> {
            RealmBase realmBase = new RealmBase() {
                @Override
                protected String getPassword(String username) {
                    return null;
                }
                @Override
                protected Principal getPrincipal(String username) {
                    return null;
                }
            };
            realmBase.setTransportGuaranteeRedirectStatus(301);
            context.setRealm(realmBase);
        });
        return tomcat;
    }

https://ttcxy.net/blog/61b5bdbde4b09915014efb14

这篇关于SpringBoot Https 修改状态码的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!