【发布时间】:2018-09-20 00:29:47
【问题描述】:
如果我们设置了授权权限,Spring security 允许我们使用hasAnyAuthority()、hasAnyRole()、hasRole() 授权 URL。如果我创建了一个自定义令牌增强器,我可以在我的令牌中添加附加信息,有没有办法使用附加信息进行授权?
自定义令牌增强器:
public final class CustomTokenEnhancer implements TokenEnhancer {
@Override
public OAuth2AccessToken enhance(
OAuth2AccessToken accessToken,
OAuth2Authentication authentication) {
Map<String, Object> additionalInfo = new HashMap<>();
additionalInfo.put("company", "authorizeAPIsWithCompany");
((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(additionalInfo);
return accessToken;
}
}
是否可以根据上述附加信息键、值授权 API?如果没有,我应该如何处理这个想法?
例如:
@Override
public void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/authorizedURL").hasCompany("authorizeAPIsWithCompany")
.....
}
【问题讨论】:
标签: spring spring-boot spring-security spring-security-oauth2 spring-oauth2