【问题标题】:Spring Security: exclude an URL from SiteMinderSpring Security:从 SiteMinder 中排除 URL
【发布时间】:2016-03-16 05:20:29
【问题描述】:

我有一个关于 Spring Security 和 SiteMinder 的问题。

通常我对所有页面的所有请求都使用 SM_USER 标头,但这次我需要排除一个 URL:它将发送一个没有 SM_USER 标头的请求。

我使用 Java 配置:

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {

    // for class CustomUserDetailsService I configured how I get the list of 
    // user authorities with the content of SM_USER header

    userDetailsService = new CustomUserDetailsService();
    UserDetailsByNameServiceWrapper<PreAuthenticatedAuthenticationToken> wrapper = new UserDetailsByNameServiceWrapper<PreAuthenticatedAuthenticationToken>(
            userDetailsService);

    preAuthenticatedProvider = new PreAuthenticatedAuthenticationProvider();
    preAuthenticatedProvider.setPreAuthenticatedUserDetailsService(wrapper);
    auth.authenticationProvider(preAuthenticatedProvider);


    log.debug("global security configuration was successfull");
}

然后我为不同的 URL 添加权限:

@Override
protected void configure(HttpSecurity http) throws Exception {      

    RequestHeaderAuthenticationFilter siteMinderFilter = new RequestHeaderAuthenticationFilter();
    siteMinderFilter.setPrincipalRequestHeader("SM_USER");
    siteMinderFilter.setAuthenticationManager(authenticationManager());   
    http.addFilter(siteMinderFilter);
    ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry = http.authorizeRequests();
//adding an authority to URL containing SM_USEr_URL
    registry.antMatchers(HttpMethod.GET, "**/SM_USER_URL/**").hasAuthority("authority1"); 

//here I try to exclude the URL from Siteminder.
    registry.antMatchers(HttpMethod.GET, "**/ExcludedPage/**").permitAll();
}

我的问题是,对于 ExcludedPage URL 的请求,除了异常之外,我什么也没得到:

    org.springframework.security.web.authentication.preauth.PreAuthenticatedCredentialsNotFoundException: SM_USER header not found in request.

我不知道如何真正为这个页面设置过滤器,它根本不需要任何 SM_USER 标头。

提前谢谢你。

【问题讨论】:

    标签: java spring spring-mvc spring-security siteminder


    【解决方案1】:

    对于应该接受站点管理员添加的每个 URL

    http.antMatcher(SM_USER_URL).addFilter(siteMinderFilter); 
    

    【讨论】:

      【解决方案2】:

      您缺少的是RequestHeaderAuthenticationFilter 的正确行为。像这样尝试setExceptionIfHeaderMissing 为假:

      @Override
      protected void configure(HttpSecurity http) throws Exception {      
      
          RequestHeaderAuthenticationFilter siteMinderFilter = new RequestHeaderAuthenticationFilter();
          siteMinderFilter.setPrincipalRequestHeader("SM_USER");
          siteMinderFilter.setAuthenticationManager(authenticationManager()); 
        ->siteMinderFilter.setExceptionIfHeaderMissing(false);
          ...
      

      【讨论】:

        猜你喜欢
        • 2022-10-19
        • 2015-02-16
        • 2023-03-11
        • 2014-05-22
        • 2014-05-15
        • 2016-07-17
        • 2014-01-19
        • 2020-12-27
        • 1970-01-01
        相关资源
        最近更新 更多