protected void setPlainAttribute(Map<String, Object> attributes, ProtocolMapperModel mappingModel, Object attributeValue) { String protocolClaim = mappingModel.getConfig().get(OIDCAttributeMapperHelper.TOKEN_CLAIM_NAME); if (protocolClaim == null || attributeValue == null) { return; } attributes.put(protocolClaim, attributeValue); } }
public static boolean useFullPath(ProtocolMapperModel mappingModel) { return "true".equals(mappingModel.getConfig().get(FULL_PATH)); }
public static ProtocolMapperModel create(String clientId, String clientRolePrefix, String name, String tokenClaimName) { ProtocolMapperModel mapper = CASAttributeMapperHelper.createClaimMapper(name, tokenClaimName, "String", PROVIDER_ID); mapper.getConfig().put(ProtocolMapperUtils.USER_MODEL_CLIENT_ROLE_MAPPING_CLIENT_ID, clientId); mapper.getConfig().put(ProtocolMapperUtils.USER_MODEL_CLIENT_ROLE_MAPPING_ROLE_PREFIX, clientRolePrefix); return mapper; } }
public static ProtocolMapperModel create(String name, String userAttribute, String tokenClaimName, String claimType, boolean multivalued, boolean aggregateAttrs) { ProtocolMapperModel mapper = CASAttributeMapperHelper.createClaimMapper(name, tokenClaimName, claimType, PROVIDER_ID); mapper.getConfig().put(ProtocolMapperUtils.USER_ATTRIBUTE, userAttribute); if (multivalued) { mapper.getConfig().put(ProtocolMapperUtils.MULTIVALUED, "true"); } if (aggregateAttrs) { mapper.getConfig().put(ProtocolMapperUtils.AGGREGATE_ATTRS, "true"); } return mapper; } }
public static ProtocolMapperModel create(String realmRolePrefix, String name, String tokenClaimName) { ProtocolMapperModel mapper = CASAttributeMapperHelper.createClaimMapper(name, tokenClaimName, "String", PROVIDER_ID); mapper.getConfig().put(ProtocolMapperUtils.USER_MODEL_REALM_ROLE_MAPPING_ROLE_PREFIX, realmRolePrefix); return mapper; } }
public static ProtocolMapperModel create(String name, String userAttribute, String tokenClaimName, String claimType) { ProtocolMapperModel mapper = CASAttributeMapperHelper.createClaimMapper(name, tokenClaimName, claimType, PROVIDER_ID); mapper.getConfig().put(ProtocolMapperUtils.USER_ATTRIBUTE, userAttribute); return mapper; } }
@Override public void setAttribute(Map<String, Object> attributes, ProtocolMapperModel mappingModel, UserSessionModel userSession, KeycloakSession session, ClientSessionContext clientSessionCt) { setMappedAttribute(attributes, mappingModel, mappingModel.getConfig().get(CLAIM_VALUE)); }
public static ProtocolMapperModel create(String name, String userSessionNote, String tokenClaimName, String jsonType) { ProtocolMapperModel mapper = CASAttributeMapperHelper.createClaimMapper(name, tokenClaimName, jsonType, PROVIDER_ID); mapper.getConfig().put(ProtocolMapperUtils.USER_SESSION_NOTE, userSessionNote); return mapper; } }
public static ProtocolMapperModel create(String name, String tokenClaimName, boolean fullPath) { ProtocolMapperModel mapper = CASAttributeMapperHelper.createClaimMapper(name, tokenClaimName, "String", PROVIDER_ID); mapper.getConfig().put(FULL_PATH, Boolean.toString(fullPath)); return mapper; } }
@Override public void setAttribute(Map<String, Object> attributes, ProtocolMapperModel mappingModel, UserSessionModel userSession, KeycloakSession session, ClientSessionContext clientSessionCt) { UserModel user = userSession.getUser(); String attributeName = mappingModel.getConfig().get(ProtocolMapperUtils.USER_ATTRIBUTE); boolean aggregateAttrs = Boolean.valueOf(mappingModel.getConfig().get(ProtocolMapperUtils.AGGREGATE_ATTRS)); Collection<String> attributeValue = KeycloakModelUtils.resolveAttribute(user, attributeName, aggregateAttrs); setMappedAttribute(attributes, mappingModel, attributeValue); }
@Override public void setAttribute(Map<String, Object> attributes, ProtocolMapperModel mappingModel, UserSessionModel userSession, KeycloakSession session, ClientSessionContext clientSessionCt) { String noteName = mappingModel.getConfig().get(ProtocolMapperUtils.USER_SESSION_NOTE); String noteValue = userSession.getNote(noteName); if (noteValue == null) return; setMappedAttribute(attributes, mappingModel, noteValue); }
@Override public void setAttribute(Map<String, Object> attributes, ProtocolMapperModel mappingModel, UserSessionModel userSession, KeycloakSession session, ClientSessionContext clientSessionCtx) { String rolePrefix = mappingModel.getConfig().get(ProtocolMapperUtils.USER_MODEL_REALM_ROLE_MAPPING_ROLE_PREFIX); AccessToken.Access access = RoleResolveUtil.getResolvedRealmRoles(session, clientSessionCtx, false); if (access == null) { return; } setAttribute(attributes, mappingModel, access.getRoles(), rolePrefix); }
@Override public void setAttribute(Map<String, Object> attributes, ProtocolMapperModel mappingModel, UserSessionModel userSession, KeycloakSession session, ClientSessionContext clientSessionCt) { UserModel user = userSession.getUser(); String propertyName = mappingModel.getConfig().get(ProtocolMapperUtils.USER_ATTRIBUTE); String propertyValue = ProtocolMapperUtils.getUserModelValue(user, propertyName); setMappedAttribute(attributes, mappingModel, propertyValue); }
@Override public void updateProtocolMapper(ProtocolMapperModel mapping) { ProtocolMapperEntity entity = getProtocolMapperEntity(mapping.getId()); entity.setProtocolMapper(mapping.getProtocolMapper()); if (entity.getConfig() == null) { entity.setConfig(mapping.getConfig()); } else { entity.getConfig().clear(); entity.getConfig().putAll(mapping.getConfig()); } em.flush(); }
@Override public void updateProtocolMapper(ProtocolMapperModel mapping) { ProtocolMapperEntity entity = getProtocolMapperEntity(mapping.getId()); entity.setProtocolMapper(mapping.getProtocolMapper()); if (entity.getConfig() == null) { entity.setConfig(mapping.getConfig()); } else { entity.getConfig().clear(); entity.getConfig().putAll(mapping.getConfig()); } em.flush(); }
@Override public void updateProtocolMapper(ProtocolMapperModel mapping) { ProtocolMapperEntity entity = getProtocolMapperyEntityById(mapping.getId()); entity.setProtocolMapper(mapping.getProtocolMapper()); entity.setConsentRequired(mapping.isConsentRequired()); entity.setConsentText(mapping.getConsentText()); if (entity.getConfig() != null) { entity.getConfig().clear(); entity.getConfig().putAll(mapping.getConfig()); } else { entity.setConfig(mapping.getConfig()); } updateMongoEntity(); }
@Override public void updateProtocolMapper(ProtocolMapperModel mapping) { ProtocolMapperEntity entity = getProtocolMapperyEntityById(mapping.getId()); entity.setProtocolMapper(mapping.getProtocolMapper()); entity.setConsentRequired(mapping.isConsentRequired()); entity.setConsentText(mapping.getConsentText()); if (entity.getConfig() != null) { entity.getConfig().clear(); entity.getConfig().putAll(mapping.getConfig()); } else { entity.setConfig(mapping.getConfig()); } updateMongoEntity(); }
public static ProtocolMapperRepresentation toRepresentation(ProtocolMapperModel model) { ProtocolMapperRepresentation rep = new ProtocolMapperRepresentation(); rep.setId(model.getId()); rep.setProtocol(model.getProtocol()); Map<String, String> config = new HashMap<String, String>(); config.putAll(model.getConfig()); rep.setConfig(config); rep.setName(model.getName()); rep.setProtocolMapper(model.getProtocolMapper()); rep.setConsentText(model.getConsentText()); rep.setConsentRequired(model.isConsentRequired()); return rep; }
@Override public ProtocolMapperModel addProtocolMapper(ProtocolMapperModel model) { if (getProtocolMapperByName(model.getProtocol(), model.getName()) != null) { throw new ModelDuplicateException("Protocol mapper name must be unique per protocol"); } String id = model.getId() != null ? model.getId() : KeycloakModelUtils.generateId(); ProtocolMapperEntity entity = new ProtocolMapperEntity(); entity.setId(id); entity.setName(model.getName()); entity.setProtocol(model.getProtocol()); entity.setProtocolMapper(model.getProtocolMapper()); entity.setClient(this.entity); entity.setConfig(model.getConfig()); em.persist(entity); this.entity.getProtocolMappers().add(entity); return entityToModel(entity); }
@Override public ProtocolMapperModel addProtocolMapper(ProtocolMapperModel model) { if (getProtocolMapperByName(model.getProtocol(), model.getName()) != null) { throw new ModelDuplicateException("Protocol mapper name must be unique per protocol"); } ProtocolMapperEntity entity = new ProtocolMapperEntity(); String id = model.getId() != null ? model.getId() : KeycloakModelUtils.generateId(); entity.setId(id); entity.setProtocol(model.getProtocol()); entity.setName(model.getName()); entity.setProtocolMapper(model.getProtocolMapper()); entity.setConfig(model.getConfig()); entity.setConsentRequired(model.isConsentRequired()); entity.setConsentText(model.getConsentText()); getMongoEntity().getProtocolMappers().add(entity); updateMongoEntity(); return entityToModel(entity); }