【问题标题】:How to exclude a URL when usinf PCF SSO service with EnableOAuth2Sso annotation?使用带有 EnableOAuth2Sso 注释的 PCF SSO 服务时如何排除 URL?
【发布时间】:2016-12-06 23:59:52
【问题描述】:

我正在使用 Angular 和 Spring Boot 来构建一个带有 Rest API 的单页应用程序。这是我的配置:

@SpringBootApplication
@EnableOAuth2Sso
public class AppConfig extends SpringBootServletInitializer implements ApplicationContextAware  {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(AppConfig.class);
    }

    public static void main(String[] args) {
        ApplicationContext appContext = SpringApplication.run(AppConfig.class);
        context = appContext;
    }

    @Configuration
    protected static class SecurityConfig extends WebSecurityConfigurerAdapter {
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http.authorizeRequests()
                    .antMatchers("/healthcheck", "/").permitAll()
                    .antMatchers("/api/**").authenticated()
                    .anyRequest().authenticated();
        }
    }

}

我使用的 SSO 服务由 Pivotal Cloud Foundry[PCF] 提供。在我加入之前一切都很好

安全配置

类。加载应用程序后,用户将立即重定向到 SSO 登录页面,然后重定向回应用程序。但我需要从身份验证中排除“健康检查”URL。这就是我包含 SecurityConfig 类的原因。但是现在 SSO 身份验证根本不起作用。我只能到达 /healthcheck。

我按照这个例子https://spring.io/guides/tutorials/spring-boot-oauth2/

有人可以告诉我我的代码有什么问题吗?

谢谢。

【问题讨论】:

    标签: spring-boot spring-security single-sign-on cloud-foundry


    【解决方案1】:

    我想通了。我不得不将我的 EnableOAuth2Sso 移动到 WebSecurityConfigurerAdapter。像这样:

    @SpringBootApplication
    public class AppConfig extends SpringBootServletInitializer implements ApplicationContextAware  {
    
        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
            return application.sources(AppConfig.class);
        }
    
        public static void main(String[] args) {
            ApplicationContext appContext = SpringApplication.run(AppConfig.class);
            context = appContext;
        }
    
        @Configuration
        @EnableOAuth2Sso
        protected static class SecurityConfig extends WebSecurityConfigurerAdapter {
            @Override
            protected void configure(HttpSecurity http) throws Exception {
                http.authorizeRequests()
                        .antMatchers("/healthcheck", "/").permitAll()
                        .antMatchers("/api/**").authenticated()
                        .anyRequest().authenticated();
            }
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 2019-04-02
      • 1970-01-01
      • 2017-05-01
      • 1970-01-01
      • 2020-05-27
      • 2015-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多