【问题标题】:How to exclude Angular component when using PCF SSO service with EnableOAuth2Sso annotation?使用带有 EnableOAuth2Sso 注释的 PCF SSO 服务时如何排除 Angular 组件?
【发布时间】:2019-04-02 21:14:56
【问题描述】:

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

@SpringBootApplication
@Controller

public class AptSsoAppApplication {

public static void main(String[] args) {
        if ("true".equals(System.getenv("SKIP_SSL_VALIDATION"))) {
            SSLValidationDisabler.disableSSLValidation();
        }
        SpringApplication.run(AptSsoAppApplication.class, args);
    }
@EnableOAuth2Sso
    @Configuration
    protected static class SecurityConfiguration extends WebSecurityConfigurerAdapter {
      @Override
      protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
            .antMatchers("/health").permitAll()
            .anyRequest().authenticated().and()
          .csrf()
            .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());
      }
    }

Angular 项目包含组件。其中一个组件是为健康检查而设计的。 SpringBoot 应该忽略健康组件的 SSO。

我遵循了这个例子:https://spring.io/guides/tutorials/spring-security-and-angular-js/

对于所有 Angular 路由,都显示 SSO 身份验证页面。 有人可以告诉我我的代码有什么问题吗?

【问题讨论】:

  • 您是否在 Spring 项目中封装了 Angular 代码?也许在 src/main/resources 或类似的东西下?
  • 是的。我将我的角度代码包装在 SpringBoot 项目中。

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


【解决方案1】:

问题在于您的静态资源(角度代码)受到保护。您必须首先允许访问您的 Angular 应用程序。本质上 index.html 需要渲染到浏览器——它会加载底层的角度依赖。

完成后,您可以让应用程序的部分安全和不安全(进行健康检查、允许用户登录等)。

实际实施将基于您在 Spring 中设置应用的方式。

更多信息:Serving static web resources in Spring Boot & Spring Security application

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-01
    • 2017-06-18
    • 1970-01-01
    • 1970-01-01
    • 2017-01-04
    • 2023-04-08
    • 2020-05-27
    相关资源
    最近更新 更多