小编Jim*_*m.R的帖子

使用Spring Boot 1.3.2(没有spring-cloud-security)和@ EnableOAuth2Sso配置AuthenticationSuccessHandler

我们有一个Spring Boot 1.3.2/Webflow网络应用程序,我们正在转换为使用SSO.我按照"从Spring Boot 1.2到1.3迁移OAuth2应用程序"博客中的步骤,让应用程序切换到我们的Auth服务器进行身份验证,并使用令牌正确填充其安全上下文的Web应用程序.

唯一不起作用的是自定义身份验证成功处理程序,它们在用户会话继续登录页面之前配置几个位.

目前在我们的安全配置中配置如下,它扩展了WebSecurityConfigurerAdapter

@Override
protected void configure(HttpSecurity http) throws Exception {
    // These are all the unprotected endpoints.
    http.authorizeRequests()
            .antMatchers(new String[] { "/", "/login", "/error",
                    "/loginFailed", "/static/**" })
            .permitAll();

    // Protect all the other endpoints with a login page.
    http.authorizeRequests().anyRequest()
            .hasAnyAuthority("USER", "ADMIN").and().formLogin().loginPage("/login").failureUrl("/loginFailed")
            .successHandler(customAuthenticationSuccessHandler()).and().logout()
            .logoutRequestMatcher(new AntPathRequestMatcher("/logout"));
    http.exceptionHandling().accessDeniedHandler(new AccessDeniedHandler() {

        @Override
        public void handle(HttpServletRequest request, HttpServletResponse response,
                AccessDeniedException accessDeniedException) throws IOException, ServletException {
            if (accessDeniedException instanceof CsrfException) {
                response.sendRedirect(request.getContextPath() + "/logout");
            }
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

我可以看到在启动期间配置了处理程序,但是一旦用户成功登录就不会调用它.我在主题上找到的所有问题都是指使用OAuth2SsoConfigurerAdapter,但是因为我们不再使用spring- cloud-security这个类不可用.

更新:我发现使用BeanPostProcessor可以实现这一点: …

java spring-boot spring-security-oauth2

7
推荐指数
1
解决办法
9806
查看次数

标签 统计

java ×1

spring-boot ×1

spring-security-oauth2 ×1