Java Code Examples for org.keycloak.models.ProtocolMapperModel#setId()

The following examples show how to use org.keycloak.models.ProtocolMapperModel#setId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClientAdapter.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@Override
public Set<ProtocolMapperModel> getProtocolMappers() {
    Set<ProtocolMapperModel> mappings = new HashSet<ProtocolMapperModel>();
    for (ProtocolMapperEntity entity : this.entity.getProtocolMappers()) {
        ProtocolMapperModel mapping = new ProtocolMapperModel();
        mapping.setId(entity.getId());
        mapping.setName(entity.getName());
        mapping.setProtocol(entity.getProtocol());
        mapping.setProtocolMapper(entity.getProtocolMapper());
        Map<String, String> config = new HashMap<String, String>();
        if (entity.getConfig() != null) {
            config.putAll(entity.getConfig());
        }
        mapping.setConfig(config);
        mappings.add(mapping);
    }
    return mappings;
}
 
Example 2
Source File: ClientScopeAdapter.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@Override
public Set<ProtocolMapperModel> getProtocolMappers() {
    Set<ProtocolMapperModel> mappings = new HashSet<ProtocolMapperModel>();
    for (ProtocolMapperEntity entity : this.entity.getProtocolMappers()) {
        ProtocolMapperModel mapping = new ProtocolMapperModel();
        mapping.setId(entity.getId());
        mapping.setName(entity.getName());
        mapping.setProtocol(entity.getProtocol());
        mapping.setProtocolMapper(entity.getProtocolMapper());
        Map<String, String> config = new HashMap<String, String>();
        if (entity.getConfig() != null) {
            config.putAll(entity.getConfig());
        }
        mapping.setConfig(config);
        mappings.add(mapping);
    }
    return mappings;
}
 
Example 3
Source File: VirtualClientModelGenerator.java    From keycloak-extension-playground with Apache License 2.0 5 votes vote down vote up
private static Set<ProtocolMapperModel> createDefaultProtocolMappers() {

        Set<ProtocolMapperModel> mappers = new LinkedHashSet<>();

        ProtocolMapperModel clientIdMapper = UserSessionNoteMapper.createClaimMapper(
                ServiceAccountConstants.CLIENT_ID_PROTOCOL_MAPPER,
                ServiceAccountConstants.CLIENT_ID,
                ServiceAccountConstants.CLIENT_ID,
                "String",
                true,
                true);
        clientIdMapper.setId(KeycloakModelUtils.generateId());
        mappers.add(clientIdMapper);

        ProtocolMapperModel dynamicMapperModel = new ProtocolMapperModel();
        dynamicMapperModel.setName(DynamicClaimMapper.PROVIDER_ID);
        dynamicMapperModel.setId(KeycloakModelUtils.generateId());
        dynamicMapperModel.setProtocol(OIDCLoginProtocol.LOGIN_PROTOCOL);
        dynamicMapperModel.setProtocolMapper(DynamicClaimMapper.PROVIDER_ID);
        Map<String, String> config = new HashMap<>();
        config.put(OIDCAttributeMapperHelper.INCLUDE_IN_ACCESS_TOKEN, "true");
        config.put(OIDCAttributeMapperHelper.INCLUDE_IN_ID_TOKEN, "false");
        dynamicMapperModel.setConfig(config);
        mappers.add(dynamicMapperModel);

        return mappers;
    }
 
Example 4
Source File: RepresentationToModel.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public static void updateClientProtocolMappers(ClientRepresentation rep, ClientModel resource) {

        if (rep.getProtocolMappers() != null) {
            Map<String,ProtocolMapperModel> existingProtocolMappers = new HashMap<>();
            for (ProtocolMapperModel existingProtocolMapper : resource.getProtocolMappers()) {
                existingProtocolMappers.put(generateProtocolNameKey(existingProtocolMapper.getProtocol(), existingProtocolMapper.getName()), existingProtocolMapper);
            }

            for (ProtocolMapperRepresentation protocolMapperRepresentation : rep.getProtocolMappers()) {
                String protocolNameKey = generateProtocolNameKey(protocolMapperRepresentation.getProtocol(), protocolMapperRepresentation.getName());
                ProtocolMapperModel existingMapper = existingProtocolMappers.get(protocolNameKey);
                    if (existingMapper != null) {
                        ProtocolMapperModel updatedProtocolMapperModel = toModel(protocolMapperRepresentation);
                        updatedProtocolMapperModel.setId(existingMapper.getId());
                        resource.updateProtocolMapper(updatedProtocolMapperModel);

                        existingProtocolMappers.remove(protocolNameKey);

                } else {
                    resource.addProtocolMapper(toModel(protocolMapperRepresentation));
                }
            }

            for (Map.Entry<String, ProtocolMapperModel> entryToDelete : existingProtocolMappers.entrySet()) {
                resource.removeProtocolMapper(entryToDelete.getValue());
            }
        }
    }
 
Example 5
Source File: RepresentationToModel.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public static ProtocolMapperModel toModel(ProtocolMapperRepresentation rep) {
    ProtocolMapperModel model = new ProtocolMapperModel();
    model.setId(rep.getId());
    model.setName(rep.getName());
    model.setProtocol(rep.getProtocol());
    model.setProtocolMapper(rep.getProtocolMapper());
    model.setConfig(removeEmptyString(rep.getConfig()));
    return model;
}
 
Example 6
Source File: ClientAdapter.java    From keycloak with Apache License 2.0 5 votes vote down vote up
protected ProtocolMapperModel entityToModel(ProtocolMapperEntity entity) {
    ProtocolMapperModel mapping = new ProtocolMapperModel();
    mapping.setId(entity.getId());
    mapping.setName(entity.getName());
    mapping.setProtocol(entity.getProtocol());
    mapping.setProtocolMapper(entity.getProtocolMapper());
    Map<String, String> config = new HashMap<String, String>();
    if (entity.getConfig() != null) config.putAll(entity.getConfig());
    mapping.setConfig(config);
    return mapping;
}
 
Example 7
Source File: ClientScopeAdapter.java    From keycloak with Apache License 2.0 5 votes vote down vote up
protected ProtocolMapperModel entityToModel(ProtocolMapperEntity entity) {
    ProtocolMapperModel mapping = new ProtocolMapperModel();
    mapping.setId(entity.getId());
    mapping.setName(entity.getName());
    mapping.setProtocol(entity.getProtocol());
    mapping.setProtocolMapper(entity.getProtocolMapper());
    Map<String, String> config = new HashMap<String, String>();
    if (entity.getConfig() != null) config.putAll(entity.getConfig());
    mapping.setConfig(config);
    return mapping;
}
 
Example 8
Source File: OpenshiftSAClientAdapter.java    From keycloak with Apache License 2.0 3 votes vote down vote up
private static Set<ProtocolMapperModel> createDefaultProtocolMappers() {
    Set<ProtocolMapperModel> mappers = new HashSet<>();

    ProtocolMapperModel mapper = OIDCAttributeMapperHelper.createClaimMapper("username", "username", "preferred_username", "string", true, true, UserPropertyMapper.PROVIDER_ID);

    mapper.setId(KeycloakModelUtils.generateId());

    mappers.add(mapper);

    return mappers;
}