我希望在 spring security 中设置 ForwardedHeaderFilter ,这样我就可以让 spring 知道登录后要使用哪个协议。我在负载均衡器后面有几个应用程序服务器(使用 ssl 终止),并且 spring security 使用 http (而不是 https)重定向用户。因此,我的用户现在收到了一条烦人的警告消息。我可以在网上找到的唯一示例是使用 spring boot,但我没有实现。
我想在我的安全配置中使用“addFilterBefore()”方法,但从未调用过滤器。
有任何想法吗?
// Apply sameOrigin policy for iframe embeddings
http.headers().frameOptions().sameOrigin();
// ********* Add filter here? *******
http.addFilterBefore(new ForwardedHeaderFilter(), ChannelProcessingFilter.class);
// Authorization filters
http.authorizeRequests().antMatchers("/sysAdmin/**", "/monitoring/**").access("isFullyAuthenticated() and hasRole('GOD')");
http.authorizeRequests().antMatchers("/app/**").authenticated();
http.authorizeRequests().antMatchers("/**").permitAll();
http.formLogin()
.loginPage("/public/login.jsp")
.loginProcessingUrl("/login")
.usernameParameter("username")
.passwordParameter("password")
.defaultSuccessUrl("/app/Dashboard.action", false)
.failureHandler(customAuthenticationFailureHandler());
// Disable so that logout "get" url works (otherwise you have to do a html form)
http.csrf().disable();
http.logout().logoutSuccessUrl("/public/login.jsp");
http.sessionManagement()
.invalidSessionUrl("/public/expiredSession.jsp?expiredId=2")
.maximumSessions(2)
.sessionRegistry(sessionRegistry())
.expiredUrl("/public/expiredSession.jsp?expiredId=3");
Run Code Online (Sandbox Code Playgroud)