【发布时间】:2016-07-18 11:38:39
【问题描述】:
我有两个 Spring 应用程序:一个 Authentication Service 和一个 Business Service。
当一个 web 服务用户在 Authentication Service 进行身份验证时,他会得到一个 access_token 和一个 refresh_token。他可以通过将refresh_token 发送到服务来刷新他的access_token。服务实现AuthenticationProvider,这里设置了认证的细节:
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
UsernamePasswordAuthenticationToken newAuthentication = ...;
LinkedHashMap<String, Object> detailsMap = (LinkedHashMap<String, Object>) authentication.getDetails();
detailsMap.put(...);
newAuthentication.setDetails(detailsMap);
return newAuthentication;
}
Business Service 由Oauth2 保护。它的控制器包含
@Secured({ SOME_ROLE })
@RequestMapping(...)
public ResponseEntity<?> doSomething(OAuth2Authentication authentication) {
LinkedHashMap<String, String> detailsMap = (LinkedHashMap<String, String>) authentication
.getUserAuthentication().getDetails();
如果 web 服务用户在 Authentication Service 进行身份验证并调用 Business Service,detailsMap 将包含在 authenticate() 中设置的信息。但如果他刷新令牌并再次调用业务服务,detailsMap 将是null。
我希望在刷新令牌后保留 detailsMap。我怎样才能做到这一点?
【问题讨论】:
标签: java spring spring-security spring-security-oauth2