我用的是SpringOAuth2。我已经配置了一个 ResourceServer
如下所示。当对服务进行并发调用时,多个线程错误地共享同一主体。配置是否导致主体共享?如果不是的话,有什么想法能解释原因吗?
EnableWebSecurity
@EnableResourceServer
@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true)
@Configuration
public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
@Override
public void configure(HttpSecurity http) throws Exception {
http.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.headers()
.contentSecurityPolicy("script-src 'self'")
.and()
.frameOptions()
.deny()
.and()
.requestMatchers()
.and()
.authorizeRequests()
.antMatchers(HttpMethod.GET, PERMISSIBLE_PATHS).permitAll()
.anyRequest().authenticated();
}
@Bean
public PrincipalExtractor principalExtractor() {
return map -> map.get(USER_CLAIM);
}
@Bean
public AuthoritiesExtractor authoritiesExtractor() {
return map -> AuthorityUtils.commaSeparatedStringToAuthorityList(
((List<String>) map.get(GROUP_CLAIMS)).stream()
.map(group -> String.format("ROLE_%s", group.toUpperCase()))
.collect(Collectors.joining(",")));
}
}
暂无答案!
目前还没有任何答案,快来回答吧!