de.adorsys.sts.tokenauth.KeycloakTokenRolesParser Maven / Gradle / Ivy
package de.adorsys.sts.tokenauth;
import com.nimbusds.jwt.JWTClaimsSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.ParseException;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/**
* Parses keycloak roles and render them as scope strings.
*
* @author fpo
*
*/
public class KeycloakTokenRolesParser {
private final Logger logger = LoggerFactory.getLogger(KeycloakTokenRolesParser.class);
public void parseRoles(JWTClaimsSet claimSet, final List result){
// Realm roles
Map objectClaim = readClaim(claimSet, "realm_access");
if(objectClaim!=null){
Object roles = objectClaim.get("roles");
addRoles(roles, result);
}
// Resource roles
objectClaim = readClaim(claimSet, "resource_access");
if(objectClaim!=null){
Collection