本文整理汇总了Java中org.keycloak.representations.AccessToken.getRealmAccess方法的典型用法代码示例。如果您正苦于以下问题:Java AccessToken.getRealmAccess方法的具体用法?Java AccessToken.getRealmAccess怎么用?Java AccessToken.getRealmAccess使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.keycloak.representations.AccessToken
的用法示例。
在下文中一共展示了AccessToken.getRealmAccess方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: forwardAuthRoles
import org.keycloak.representations.AccessToken; //导入方法依赖的package包/类
private void forwardAuthRoles(IPolicyContext context, KeycloakOauthConfigBean config,
AccessToken parsedToken) {
if (config.getForwardRoles().getActive()) {
Access access = null;
if (config.getForwardRoles().getApplicationName() != null) {
access = parsedToken.getResourceAccess(config.getForwardRoles().getApplicationName());
} else {
access = parsedToken.getRealmAccess();
}
if (access == null || access.getRoles() == null) {
context.setAttribute(AuthorizationPolicy.AUTHENTICATED_USER_ROLES, Collections.<String>emptySet());
} else {
context.setAttribute(AuthorizationPolicy.AUTHENTICATED_USER_ROLES, access.getRoles());
}
}
}
示例2: buildRoles
import org.keycloak.representations.AccessToken; //导入方法依赖的package包/类
private static GrantedAuthority[] buildRoles(AccessToken accessToken) {
List<GrantedAuthority> roles;
roles = new ArrayList<GrantedAuthority>();
if (accessToken != null && accessToken.getRealmAccess() != null) {
for (String role : accessToken.getRealmAccess().getRoles()) {
roles.add(new GrantedAuthorityImpl(role));
}
}
roles.add(SecurityRealm.AUTHENTICATED_AUTHORITY);
return roles.toArray(new GrantedAuthority[roles.size()]);
}
示例3: buildRoles
import org.keycloak.representations.AccessToken; //导入方法依赖的package包/类
private void buildRoles(AccessToken accessToken) {
if (accessToken != null && accessToken.getRealmAccess() != null) {
for (String role : accessToken.getRealmAccess().getRoles()) {
roles.add(role);
}
}
}
示例4: authenticate
import org.keycloak.representations.AccessToken; //导入方法依赖的package包/类
@Override
public Account authenticate(AuthenticationToken authenticationToken) {
KeycloakToken keycloakToken = (KeycloakToken) authenticationToken;
Account account = new Account(keycloakToken.getUsername(), keycloakToken);
AccessToken accessToken = keycloakToken.getToken();
if (!Strings.isNullOrEmpty(accessToken.getName())) {
account.setName(accessToken.getName());
}
if (!Strings.isNullOrEmpty(accessToken.getEmail())) {
account.addEmailAddress(accessToken.getEmail());
}
Set<String> roles = new TreeSet<>();
// add realm roles
AccessToken.Access realmAccess = accessToken.getRealmAccess();
if (realmAccess != null) {
roles.addAll(Optional.fromNullable(realmAccess.getRoles()).or(Collections.emptySet()));
}
// add resource roles
for (Map.Entry<String, AccessToken.Access> entry : accessToken.getResourceAccess().entrySet()) {
AccessToken.Access resourceAccess = entry.getValue();
roles.addAll(Optional.fromNullable(resourceAccess.getRoles()).or(Collections.emptySet()));
}
// add account roles
for (String role : roles) {
if (definedRoles.containsKey(role)) {
Role definedRole = definedRoles.get(role);
account.getAuthorizations().addRole(definedRole);
} else {
account.getAuthorizations().addRole(role);
}
}
cacheAccount(account);
return account;
}