Search in sources :

Example 6 with ComponentRepresentation

use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.

the class ClientRegistrationPoliciesTest method setTrustedHost.

private void setTrustedHost(String hostname) {
    ComponentRepresentation trustedHostRep = findPolicyByProviderAndAuth(TrustedHostClientRegistrationPolicyFactory.PROVIDER_ID, getPolicyAnon());
    trustedHostRep.getConfig().putSingle(TrustedHostClientRegistrationPolicyFactory.TRUSTED_HOSTS, hostname);
    realmResource().components().component(trustedHostRep.getId()).update(trustedHostRep);
}
Also used : ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation)

Example 7 with ComponentRepresentation

use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.

the class UserStorageRestTest method testValidateAndCreateLdapProviderEditMode.

@Test
public void testValidateAndCreateLdapProviderEditMode() {
    // Test provider without editMode should fail
    ComponentRepresentation ldapRep = createBasicLDAPProviderRep();
    ldapRep.getConfig().remove(LDAPConstants.EDIT_MODE);
    Response resp = realm.components().add(ldapRep);
    Assert.assertEquals(400, resp.getStatus());
    resp.close();
    // Test provider with READ_ONLY edit mode and validatePasswordPolicy will fail
    ldapRep = createBasicLDAPProviderRep();
    ldapRep.getConfig().putSingle(LDAPConstants.EDIT_MODE, UserStorageProvider.EditMode.READ_ONLY.name());
    ldapRep.getConfig().putSingle(LDAPConstants.VALIDATE_PASSWORD_POLICY, "true");
    resp = realm.components().add(ldapRep);
    Assert.assertEquals(400, resp.getStatus());
    resp.close();
    // Test provider with UNSYNCED edit mode and validatePasswordPolicy will fail
    ldapRep.getConfig().putSingle(LDAPConstants.EDIT_MODE, UserStorageProvider.EditMode.UNSYNCED.name());
    ldapRep.getConfig().putSingle(LDAPConstants.VALIDATE_PASSWORD_POLICY, "true");
    resp = realm.components().add(ldapRep);
    Assert.assertEquals(400, resp.getStatus());
    resp.close();
    // Test provider with WRITABLE edit mode and validatePasswordPolicy will fail
    ldapRep.getConfig().putSingle(LDAPConstants.EDIT_MODE, UserStorageProvider.EditMode.WRITABLE.name());
    ldapRep.getConfig().putSingle(LDAPConstants.SYNC_REGISTRATIONS, "true");
    String id1 = createComponent(ldapRep);
    // Cleanup
    removeComponent(id1);
}
Also used : ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation) Response(javax.ws.rs.core.Response) Test(org.junit.Test) AbstractAuthenticationTest(org.keycloak.testsuite.admin.authentication.AbstractAuthenticationTest)

Example 8 with ComponentRepresentation

use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.

the class UserStorageRestTest method testLDAPMapperProviderConfigurationForVendorOther.

// KEYCLOAK-12934
@Test
public void testLDAPMapperProviderConfigurationForVendorOther() {
    ComponentRepresentation ldapRep = createBasicLDAPProviderRep();
    ldapRep.getConfig().putSingle(LDAPConstants.VENDOR, LDAPConstants.VENDOR_OTHER);
    String ldapModelId = createComponent(ldapRep);
    ComponentTypeRepresentation groupLDAPMapperType = findMapperTypeConfiguration(ldapModelId, GroupLDAPStorageMapperFactory.PROVIDER_ID);
    ConfigPropertyRepresentation groupRetrieverConfigProperty = getUserRolesRetrieveStrategyConfigProperty(groupLDAPMapperType, CommonLDAPGroupMapperConfig.USER_ROLES_RETRIEVE_STRATEGY);
    // LOAD_GROUPS_BY_MEMBER_ATTRIBUTE_RECURSIVELY is expected to be present just for the active directory
    List<String> options = groupRetrieverConfigProperty.getOptions();
    Assert.assertNames(options, GroupMapperConfig.LOAD_GROUPS_BY_MEMBER_ATTRIBUTE, GroupMapperConfig.GET_GROUPS_FROM_USER_MEMBEROF_ATTRIBUTE);
    Assert.assertFalse(groupRetrieverConfigProperty.getHelpText().contains("LOAD_GROUPS_BY_MEMBER_ATTRIBUTE_RECURSIVELY"));
    ComponentTypeRepresentation roleLDAPMapperType = findMapperTypeConfiguration(ldapModelId, RoleLDAPStorageMapperFactory.PROVIDER_ID);
    ConfigPropertyRepresentation roleRetrieverConfigProperty = getUserRolesRetrieveStrategyConfigProperty(roleLDAPMapperType, CommonLDAPGroupMapperConfig.USER_ROLES_RETRIEVE_STRATEGY);
    // LOAD_ROLES_BY_MEMBER_ATTRIBUTE_RECURSIVELY is expected to be present just for the active directory
    options = roleRetrieverConfigProperty.getOptions();
    Assert.assertNames(options, RoleMapperConfig.LOAD_ROLES_BY_MEMBER_ATTRIBUTE, RoleMapperConfig.GET_ROLES_FROM_USER_MEMBEROF_ATTRIBUTE);
    Assert.assertFalse(roleRetrieverConfigProperty.getHelpText().contains("LOAD_ROLES_BY_MEMBER_ATTRIBUTE_RECURSIVELY"));
    // Cleanup including mappers
    removeComponent(ldapModelId);
}
Also used : ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation) ComponentTypeRepresentation(org.keycloak.representations.idm.ComponentTypeRepresentation) ConfigPropertyRepresentation(org.keycloak.representations.idm.ConfigPropertyRepresentation) Test(org.junit.Test) AbstractAuthenticationTest(org.keycloak.testsuite.admin.authentication.AbstractAuthenticationTest)

Example 9 with ComponentRepresentation

use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.

the class AbstractKerberosTest method updateUserStorageProvider.

/**
 * Update UserStorage provider (Kerberos provider or LDAP provider with Kerberos enabled) with specified updater and save it
 */
protected void updateUserStorageProvider(Consumer<ComponentRepresentation> updater) {
    List<ComponentRepresentation> reps = testRealmResource().components().query("test", UserStorageProvider.class.getName());
    Assert.assertEquals(1, reps.size());
    ComponentRepresentation kerberosProvider = reps.get(0);
    updater.accept(kerberosProvider);
    testRealmResource().components().component(kerberosProvider.getId()).update(kerberosProvider);
}
Also used : ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation) UserStorageProvider(org.keycloak.storage.UserStorageProvider)

Example 10 with ComponentRepresentation

use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.

the class AbstractKerberosTest method getUserStorageConfiguration.

protected ComponentRepresentation getUserStorageConfiguration(String providerName, String providerId) {
    Map<String, String> kerberosConfig = getKerberosRule().getConfig();
    MultivaluedHashMap<String, String> config = toComponentConfig(kerberosConfig);
    UserStorageProviderModel model = new UserStorageProviderModel();
    model.setLastSync(0);
    model.setChangedSyncPeriod(-1);
    model.setFullSyncPeriod(-1);
    model.setName(providerName);
    model.setPriority(0);
    model.setProviderId(providerId);
    model.setConfig(config);
    ComponentRepresentation rep = ModelToRepresentation.toRepresentationWithoutConfig(model);
    return rep;
}
Also used : ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation) UserStorageProviderModel(org.keycloak.storage.UserStorageProviderModel)

Aggregations

ComponentRepresentation (org.keycloak.representations.idm.ComponentRepresentation)120 Test (org.junit.Test)56 Response (javax.ws.rs.core.Response)44 UserStorageProvider (org.keycloak.storage.UserStorageProvider)22 KeyProvider (org.keycloak.keys.KeyProvider)17 AbstractKeycloakTest (org.keycloak.testsuite.AbstractKeycloakTest)13 Before (org.junit.Before)12 KeysMetadataRepresentation (org.keycloak.representations.idm.KeysMetadataRepresentation)12 RealmModel (org.keycloak.models.RealmModel)10 AuthServerContainerExclude (org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude)10 KeyPair (java.security.KeyPair)9 UserModel (org.keycloak.models.UserModel)9 AbstractAuthenticationTest (org.keycloak.testsuite.admin.authentication.AbstractAuthenticationTest)8 RealmResource (org.keycloak.admin.client.resource.RealmResource)7 MultivaluedHashMap (org.keycloak.common.util.MultivaluedHashMap)7 ComponentModel (org.keycloak.component.ComponentModel)7 UserRepresentation (org.keycloak.representations.idm.UserRepresentation)7 OIDCClientRepresentation (org.keycloak.representations.oidc.OIDCClientRepresentation)6 AbstractAuthTest (org.keycloak.testsuite.AbstractAuthTest)6 List (java.util.List)5