use of org.maxkey.authz.oauth2.provider.OAuth2Authentication in project JBM by numen06.
the class JbmClusterHelper method updateOpenClientAuthorities.
/**
* 更新客户端权限
* @param tokenStore
* @param clientId
* @param authorities
*/
public static void updateOpenClientAuthorities(TokenStore tokenStore, String clientId, Collection<? extends GrantedAuthority> authorities) {
if (authorities == null) {
return;
}
// 动态更新客户端生成的token
Collection<OAuth2AccessToken> accessTokens = tokenStore.findTokensByClientId(clientId);
if (accessTokens != null && !accessTokens.isEmpty()) {
Iterator<OAuth2AccessToken> iterator = accessTokens.iterator();
while (iterator.hasNext()) {
OAuth2AccessToken token = iterator.next();
OAuth2Authentication oAuth2Authentication = tokenStore.readAuthentication(token);
if (oAuth2Authentication != null && oAuth2Authentication.isClientOnly()) {
// 只更新客户端权限
// 由于没有set方法,使用反射机制强制赋值
BeanUtil.setFieldValue(oAuth2Authentication, "authorities", authorities);
// 重新保存
tokenStore.storeAccessToken(token, oAuth2Authentication);
}
}
}
}
use of org.maxkey.authz.oauth2.provider.OAuth2Authentication in project JBM by numen06.
the class JbmRedisTokenStore method removeAccessToken.
public void removeAccessToken(String tokenValue) {
OAuth2AccessToken removed = (OAuth2AccessToken) redisTemplate.opsForValue().get(ACCESS + tokenValue);
// caller to do that
OAuth2Authentication authentication = (OAuth2Authentication) this.redisTemplate.opsForValue().get(AUTH + tokenValue);
this.redisTemplate.delete(AUTH + tokenValue);
redisTemplate.delete(ACCESS + tokenValue);
this.redisTemplate.delete(ACCESS_TO_REFRESH + tokenValue);
if (authentication != null) {
this.redisTemplate.delete(AUTH_TO_ACCESS + authenticationKeyGenerator.extractKey(authentication));
String clientId = authentication.getOAuth2Request().getClientId();
redisTemplate.opsForList().leftPop(UNAME_TO_ACCESS + getApprovalKey(clientId, authentication.getName()));
redisTemplate.opsForList().leftPop(CLIENT_ID_TO_ACCESS + clientId);
this.redisTemplate.delete(AUTH_TO_ACCESS + authenticationKeyGenerator.extractKey(authentication));
}
}
use of org.maxkey.authz.oauth2.provider.OAuth2Authentication in project conformance-suite by openid-certification.
the class OIDCAuthenticationFacade method getPrincipal.
@Override
public ImmutableMap<String, String> getPrincipal() {
OIDCAuthenticationToken token = getOIDC();
OAuth2Authentication auth = getOAuth();
if (token != null) {
@SuppressWarnings("unchecked") ImmutableMap<String, String> prinicipal = (ImmutableMap<String, String>) token.getPrincipal();
return prinicipal;
} else if (auth != null) {
// TODO: we might be able to build this off of other properties instead
@SuppressWarnings("unchecked") ImmutableMap<String, String> prinicipal = (ImmutableMap<String, String>) auth.getPrincipal();
return prinicipal;
}
return null;
}
use of org.maxkey.authz.oauth2.provider.OAuth2Authentication in project conformance-suite by openid-certification.
the class OIDCAuthenticationFacade method getDisplayName.
@Override
public String getDisplayName() {
OIDCAuthenticationToken token = getOIDC();
OAuth2Authentication auth = getOAuth();
if (token != null) {
Map<String, String> principal = getPrincipal();
if (principal != null) {
String displayName = principal.toString();
UserInfo userInfo = getUserInfo();
if (userInfo != null) {
if (!Strings.isNullOrEmpty(userInfo.getEmail())) {
displayName = userInfo.getEmail();
} else if (!Strings.isNullOrEmpty(userInfo.getPreferredUsername())) {
displayName = userInfo.getPreferredUsername();
} else if (!Strings.isNullOrEmpty(userInfo.getName())) {
displayName = userInfo.getName();
}
return displayName;
}
return displayName;
}
} else if (auth != null) {
return auth.getName();
}
return "";
}
use of org.maxkey.authz.oauth2.provider.OAuth2Authentication in project conformance-suite by openid-certification.
the class ApiTokenService method checkToken.
@SuppressWarnings("rawtypes")
private TokenInfo checkToken(String accessToken) {
Map tokenInfoMap = tokenService.findToken(accessToken);
if (tokenInfoMap == null) {
return null;
}
JsonObject tokenInfoObj = (JsonObject) new Gson().toJsonTree(tokenInfoMap);
OAuth2AccessToken token = new LocalOAuth2AccessToken(tokenInfoObj);
OAuth2Request request = new OAuth2Request(Collections.emptyMap(), "", null, !token.isExpired(), Collections.emptySet(), null, null, null, null);
OAuth2Authentication auth = new OAuth2Authentication(request, createAuth(tokenInfoObj));
return new TokenInfo(token, auth);
}
Aggregations