Search in sources :

Example 16 with ComponentModel

use of org.keycloak.component.ComponentModel in project keycloak by keycloak.

the class LDAPMappersComparatorTest method testCompareWithCNUsername.

@Test
public void testCompareWithCNUsername() {
    MultivaluedHashMap<String, String> cfg = new MultivaluedHashMap<>();
    cfg.add(LDAPConstants.USERNAME_LDAP_ATTRIBUTE, LDAPConstants.CN);
    LDAPMappersComparator ldapMappersComparator = new LDAPMappersComparator(new LDAPConfig(cfg));
    List<ComponentModel> mappers = getMappers();
    Collections.sort(mappers, ldapMappersComparator.sortAsc());
    assertOrder(mappers, "username-cn", "sAMAccountName", "first name", "full name");
    Collections.sort(mappers, ldapMappersComparator.sortDesc());
    assertOrder(mappers, "full name", "first name", "sAMAccountName", "username-cn");
}
Also used : MultivaluedHashMap(org.keycloak.common.util.MultivaluedHashMap) LDAPMappersComparator(org.keycloak.storage.ldap.mappers.LDAPMappersComparator) LDAPConfig(org.keycloak.storage.ldap.LDAPConfig) ComponentModel(org.keycloak.component.ComponentModel) Test(org.junit.Test)

Example 17 with ComponentModel

use of org.keycloak.component.ComponentModel in project keycloak by keycloak.

the class RealmAdapter method updateComponent.

@Override
public void updateComponent(ComponentModel component) {
    ComponentUtil.getComponentFactory(session, component).validateConfiguration(session, this, component);
    ComponentEntity c = getComponentEntity(component.getId());
    if (c == null)
        return;
    ComponentModel old = entityToModel(c);
    c.setName(component.getName());
    c.setProviderId(component.getProviderId());
    c.setProviderType(component.getProviderType());
    c.setParentId(component.getParentId());
    c.setSubType(component.getSubType());
    setConfig(component, c);
    ComponentUtil.notifyUpdated(session, this, old, component);
}
Also used : ComponentModel(org.keycloak.component.ComponentModel)

Example 18 with ComponentModel

use of org.keycloak.component.ComponentModel in project keycloak by keycloak.

the class RealmAdapter method entityToModel.

protected ComponentModel entityToModel(ComponentEntity c) {
    ComponentModel model = new ComponentModel();
    model.setId(c.getId());
    model.setName(c.getName());
    model.setProviderType(c.getProviderType());
    model.setProviderId(c.getProviderId());
    model.setSubType(c.getSubType());
    model.setParentId(c.getParentId());
    MultivaluedHashMap<String, String> config = new MultivaluedHashMap<>();
    for (ComponentConfigEntity configEntity : c.getComponentConfigs()) {
        config.add(configEntity.getName(), configEntity.getValue());
    }
    model.setConfig(config);
    return model;
}
Also used : MultivaluedHashMap(org.keycloak.common.util.MultivaluedHashMap) ComponentModel(org.keycloak.component.ComponentModel)

Example 19 with ComponentModel

use of org.keycloak.component.ComponentModel in project keycloak by keycloak.

the class DeclarativeUserProfileProvider method setConfiguration.

@Override
public void setConfiguration(String configuration) {
    ComponentModel component = getComponentModel();
    removeConfigJsonFromComponentModel(component);
    RealmModel realm = session.getContext().getRealm();
    if (!isBlank(configuration)) {
        // store new parts
        List<String> parts = UPConfigUtils.getChunks(configuration, 3800);
        MultivaluedHashMap<String, String> config = component.getConfig();
        config.putSingle(UP_PIECES_COUNT_COMPONENT_CONFIG_KEY, "" + parts.size());
        int i = 0;
        for (String part : parts) {
            config.putSingle(UP_PIECE_COMPONENT_CONFIG_KEY_BASE + (i++), part);
        }
        realm.updateComponent(component);
    } else {
        realm.removeComponent(component);
    }
}
Also used : RealmModel(org.keycloak.models.RealmModel) ComponentModel(org.keycloak.component.ComponentModel)

Example 20 with ComponentModel

use of org.keycloak.component.ComponentModel in project keycloak by keycloak.

the class TestLDAPResource method prepareRolesLDAPTest.

/**
 * Prepare groups LDAP tests. Creates some LDAP mappers as well as some built-in GRoups and users in LDAP
 */
@POST
@Path("/configure-roles")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public void prepareRolesLDAPTest() {
    ComponentModel ldapModel = LDAPTestUtils.getLdapProviderModel(realm);
    LDAPStorageProvider ldapFedProvider = LDAPTestUtils.getLdapProvider(session, ldapModel);
    // Add role mapper
    LDAPTestUtils.addOrUpdateRoleMapper(realm, ldapModel, LDAPGroupMapperMode.LDAP_ONLY);
    // Remove all LDAP groups and users
    LDAPTestUtils.removeAllLDAPGroups(session, realm, ldapModel, "rolesMapper");
    LDAPTestUtils.removeAllLDAPUsers(ldapFedProvider, realm);
    // Add some LDAP users for testing
    LDAPObject john = LDAPTestUtils.addLDAPUser(ldapFedProvider, realm, "johnkeycloak", "John", "Doe", "john@email.org", null, "1234");
    LDAPTestUtils.updateLDAPPassword(ldapFedProvider, john, "Password1");
    LDAPObject mary = LDAPTestUtils.addLDAPUser(ldapFedProvider, realm, "marykeycloak", "Mary", "Kelly", "mary@email.org", null, "5678");
    LDAPTestUtils.updateLDAPPassword(ldapFedProvider, mary, "Password1");
    LDAPObject rob = LDAPTestUtils.addLDAPUser(ldapFedProvider, realm, "robkeycloak", "Rob", "Brown", "rob@email.org", null, "8910");
    LDAPTestUtils.updateLDAPPassword(ldapFedProvider, rob, "Password1");
    LDAPObject james = LDAPTestUtils.addLDAPUser(ldapFedProvider, realm, "jameskeycloak", "James", "Brown", "james@email.org", null, "8910");
    LDAPTestUtils.updateLDAPPassword(ldapFedProvider, james, "Password1");
    // Add some groups for testing
    LDAPObject group1 = LDAPTestUtils.createLDAPGroup("rolesMapper", session, realm, ldapModel, "group1");
    LDAPObject group2 = LDAPTestUtils.createLDAPGroup("rolesMapper", session, realm, ldapModel, "group2");
    LDAPObject group3 = LDAPTestUtils.createLDAPGroup("rolesMapper", session, realm, ldapModel, "group3");
    // add the users to the groups
    LDAPUtils.addMember(ldapFedProvider, MembershipType.DN, LDAPConstants.MEMBER, "not-used", group1, john);
    LDAPUtils.addMember(ldapFedProvider, MembershipType.DN, LDAPConstants.MEMBER, "not-used", group1, mary);
    LDAPUtils.addMember(ldapFedProvider, MembershipType.DN, LDAPConstants.MEMBER, "not-used", group1, rob);
    LDAPUtils.addMember(ldapFedProvider, MembershipType.DN, LDAPConstants.MEMBER, "not-used", group2, john);
    LDAPUtils.addMember(ldapFedProvider, MembershipType.DN, LDAPConstants.MEMBER, "not-used", group2, mary);
    // Sync LDAP groups to Keycloak DB roles
    ComponentModel mapperModel = LDAPTestUtils.getSubcomponentByName(realm, ldapModel, "rolesMapper");
    new RoleLDAPStorageMapperFactory().create(session, mapperModel).syncDataFromFederationProviderToKeycloak(realm);
}
Also used : RoleLDAPStorageMapperFactory(org.keycloak.storage.ldap.mappers.membership.role.RoleLDAPStorageMapperFactory) ComponentModel(org.keycloak.component.ComponentModel) LDAPStorageProvider(org.keycloak.storage.ldap.LDAPStorageProvider) LDAPObject(org.keycloak.storage.ldap.idm.model.LDAPObject) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Aggregations

ComponentModel (org.keycloak.component.ComponentModel)155 RealmModel (org.keycloak.models.RealmModel)74 Test (org.junit.Test)52 LDAPStorageProvider (org.keycloak.storage.ldap.LDAPStorageProvider)46 LDAPObject (org.keycloak.storage.ldap.idm.model.LDAPObject)34 UserModel (org.keycloak.models.UserModel)29 HashMap (java.util.HashMap)22 UserStorageProviderModel (org.keycloak.storage.UserStorageProviderModel)22 GroupModel (org.keycloak.models.GroupModel)21 MultivaluedHashMap (org.keycloak.common.util.MultivaluedHashMap)18 SynchronizationResult (org.keycloak.storage.user.SynchronizationResult)18 ComponentValidationException (org.keycloak.component.ComponentValidationException)16 UserStorageProvider (org.keycloak.storage.UserStorageProvider)16 LDAPStorageMapper (org.keycloak.storage.ldap.mappers.LDAPStorageMapper)15 GroupLDAPStorageMapper (org.keycloak.storage.ldap.mappers.membership.group.GroupLDAPStorageMapper)15 Path (javax.ws.rs.Path)14 DeclarativeUserProfileProvider (org.keycloak.userprofile.DeclarativeUserProfileProvider)13 ModelException (org.keycloak.models.ModelException)11 UPAttribute (org.keycloak.userprofile.config.UPAttribute)11 UPConfig (org.keycloak.userprofile.config.UPConfig)11