【发布时间】: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