Search in sources :

Example 21 with ComponentRepresentation

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

the class AbstractMigrationTest method testLdapKerberosMigration_2_5_0.

protected void testLdapKerberosMigration_2_5_0() {
    log.info("testing ldap kerberos migration");
    RealmRepresentation realmRep = migrationRealm2.toRepresentation();
    List<ComponentRepresentation> components = migrationRealm2.components().query(realmRep.getId(), UserStorageProvider.class.getName());
    assertEquals(2, components.size());
    boolean testedLdap = false;
    boolean testedKerberos = false;
    for (ComponentRepresentation component : components) {
        if (component.getName().equals("ldap-provider")) {
            assertEquals("2", component.getConfig().getFirst(PrioritizedComponentModel.PRIORITY));
            assertEquals("READ_ONLY", component.getConfig().getFirst(LDAPConstants.EDIT_MODE));
            assertEquals("true", component.getConfig().getFirst(LDAPConstants.SYNC_REGISTRATIONS));
            assertEquals(LDAPConstants.VENDOR_RHDS, component.getConfig().getFirst(LDAPConstants.VENDOR));
            assertEquals("uid", component.getConfig().getFirst(LDAPConstants.USERNAME_LDAP_ATTRIBUTE));
            assertEquals("uid", component.getConfig().getFirst(LDAPConstants.RDN_LDAP_ATTRIBUTE));
            assertEquals("nsuniqueid", component.getConfig().getFirst(LDAPConstants.UUID_LDAP_ATTRIBUTE));
            assertEquals("inetOrgPerson, organizationalPerson", component.getConfig().getFirst(LDAPConstants.USER_OBJECT_CLASSES));
            assertEquals("http://localhost", component.getConfig().getFirst(LDAPConstants.CONNECTION_URL));
            assertEquals("dn", component.getConfig().getFirst(LDAPConstants.USERS_DN));
            assertEquals(LDAPConstants.AUTH_TYPE_NONE, component.getConfig().getFirst(LDAPConstants.AUTH_TYPE));
            assertEquals("true", component.getConfig().getFirst(KerberosConstants.ALLOW_KERBEROS_AUTHENTICATION));
            assertEquals("realm", component.getConfig().getFirst(KerberosConstants.KERBEROS_REALM));
            assertEquals("principal", component.getConfig().getFirst(KerberosConstants.SERVER_PRINCIPAL));
            assertEquals("keytab", component.getConfig().getFirst(KerberosConstants.KEYTAB));
            testedLdap = true;
        } else if (component.getName().equals("kerberos-provider")) {
            assertEquals("3", component.getConfig().getFirst(PrioritizedComponentModel.PRIORITY));
            assertEquals("realm", component.getConfig().getFirst(KerberosConstants.KERBEROS_REALM));
            assertEquals("principal", component.getConfig().getFirst(KerberosConstants.SERVER_PRINCIPAL));
            assertEquals("keytab", component.getConfig().getFirst(KerberosConstants.KEYTAB));
        }
    }
}
Also used : ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation) UserStorageProvider(org.keycloak.storage.UserStorageProvider) RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation)

Example 22 with ComponentRepresentation

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

the class GeneratedEcdsaKeyProviderTest method supportedEc.

private String supportedEc(String ecInNistRep) {
    long priority = System.currentTimeMillis();
    ComponentRepresentation rep = createRep("valid", GeneratedEcdsaKeyProviderFactory.ID);
    rep.setConfig(new MultivaluedHashMap<>());
    rep.getConfig().putSingle("priority", Long.toString(priority));
    if (ecInNistRep != null) {
        rep.getConfig().putSingle(ECDSA_ELLIPTIC_CURVE_KEY, ecInNistRep);
    } else {
        ecInNistRep = DEFAULT_EC;
    }
    Response response = adminClient.realm(TEST_REALM_NAME).components().add(rep);
    String id = ApiUtil.getCreatedId(response);
    getCleanup().addComponentId(id);
    response.close();
    ComponentRepresentation createdRep = adminClient.realm(TEST_REALM_NAME).components().component(id).toRepresentation();
    // stands for the number of properties in the key provider config
    assertEquals(2, createdRep.getConfig().size());
    assertEquals(Long.toString(priority), createdRep.getConfig().getFirst("priority"));
    assertEquals(ecInNistRep, createdRep.getConfig().getFirst(ECDSA_ELLIPTIC_CURVE_KEY));
    KeysMetadataRepresentation keys = adminClient.realm(TEST_REALM_NAME).keys().getKeyMetadata();
    KeysMetadataRepresentation.KeyMetadataRepresentation key = null;
    for (KeyMetadataRepresentation k : keys.getKeys()) {
        if (KeyType.EC.equals(k.getType()) && id.equals(k.getProviderId())) {
            key = k;
            break;
        }
    }
    assertNotNull(key);
    assertEquals(id, key.getProviderId());
    assertEquals(KeyType.EC, key.getType());
    assertEquals(priority, key.getProviderPriority());
    // created key's component id
    return id;
}
Also used : ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation) Response(javax.ws.rs.core.Response) KeysMetadataRepresentation(org.keycloak.representations.idm.KeysMetadataRepresentation) KeyMetadataRepresentation(org.keycloak.representations.idm.KeysMetadataRepresentation.KeyMetadataRepresentation) KeyMetadataRepresentation(org.keycloak.representations.idm.KeysMetadataRepresentation.KeyMetadataRepresentation)

Example 23 with ComponentRepresentation

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

the class FallbackKeyProviderTest method fallbackAfterDeletingAllKeysInRealm.

@Test
public void fallbackAfterDeletingAllKeysInRealm() {
    String realmId = realmsResouce().realm("test").toRepresentation().getId();
    List<ComponentRepresentation> providers = realmsResouce().realm("test").components().query(realmId, "org.keycloak.keys.KeyProvider");
    assertEquals(3, providers.size());
    for (ComponentRepresentation p : providers) {
        realmsResouce().realm("test").components().component(p.getId()).remove();
    }
    providers = realmsResouce().realm("test").components().query(realmId, "org.keycloak.keys.KeyProvider");
    assertEquals(0, providers.size());
    oauth.doLogin("test-user@localhost", "password");
    String code = oauth.getCurrentQuery().get(OAuth2Constants.CODE);
    OAuthClient.AccessTokenResponse response = oauth.doAccessTokenRequest(code, "password");
    assertNotNull(response.getAccessToken());
    Assert.assertEquals(AppPage.RequestType.AUTH_RESPONSE, appPage.getRequestType());
    providers = realmsResouce().realm("test").components().query(realmId, "org.keycloak.keys.KeyProvider");
    assertProviders(providers, "fallback-RS256", "fallback-HS256");
}
Also used : ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation) OAuthClient(org.keycloak.testsuite.util.OAuthClient) Test(org.junit.Test) AbstractKeycloakTest(org.keycloak.testsuite.AbstractKeycloakTest)

Example 24 with ComponentRepresentation

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

the class FallbackKeyProviderTest method assertProviders.

private void assertProviders(List<ComponentRepresentation> providers, String... expected) {
    List<String> names = new LinkedList<>();
    for (ComponentRepresentation p : providers) {
        names.add(p.getName());
    }
    assertThat(names, hasSize(expected.length));
    assertThat(names, containsInAnyOrder(expected));
}
Also used : ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation) LinkedList(java.util.LinkedList)

Example 25 with ComponentRepresentation

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

the class GeneratedHmacKeyProviderTest method largeKeysize.

@Test
public void largeKeysize() {
    long priority = System.currentTimeMillis();
    ComponentRepresentation rep = createRep("valid", GeneratedHmacKeyProviderFactory.ID);
    rep.setConfig(new MultivaluedHashMap<>());
    rep.getConfig().putSingle("priority", Long.toString(priority));
    rep.getConfig().putSingle("secretSize", "512");
    Response response = adminClient.realm("test").components().add(rep);
    String id = ApiUtil.getCreatedId(response);
    response.close();
    ComponentRepresentation createdRep = adminClient.realm("test").components().component(id).toRepresentation();
    assertEquals(2, createdRep.getConfig().size());
    assertEquals("512", createdRep.getConfig().getFirst("secretSize"));
    KeysMetadataRepresentation keys = adminClient.realm("test").keys().getKeyMetadata();
    KeysMetadataRepresentation.KeyMetadataRepresentation key = null;
    for (KeysMetadataRepresentation.KeyMetadataRepresentation k : keys.getKeys()) {
        if (k.getAlgorithm().equals(Algorithm.HS256)) {
            key = k;
            break;
        }
    }
    assertEquals(id, key.getProviderId());
    assertEquals(KeyType.OCT, key.getType());
    assertEquals(priority, key.getProviderPriority());
    ComponentRepresentation component = testingClient.server("test").fetch(RunHelpers.internalComponent(id));
    assertEquals(512, Base64Url.decode(component.getConfig().getFirst("secret")).length);
}
Also used : ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation) Response(javax.ws.rs.core.Response) KeysMetadataRepresentation(org.keycloak.representations.idm.KeysMetadataRepresentation) Test(org.junit.Test) AbstractKeycloakTest(org.keycloak.testsuite.AbstractKeycloakTest)

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