Search in sources :

Example 81 with ComponentRepresentation

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

the class GeneratedRsaKeyProviderTest method createRep.

protected ComponentRepresentation createRep(String name, String providerId) {
    ComponentRepresentation rep = new ComponentRepresentation();
    rep.setName(name);
    rep.setParentId("test");
    rep.setProviderId(providerId);
    rep.setProviderType(KeyProvider.class.getName());
    rep.setConfig(new MultivaluedHashMap<>());
    return rep;
}
Also used : ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation) KeyProvider(org.keycloak.keys.KeyProvider)

Example 82 with ComponentRepresentation

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

the class JavaKeystoreKeyProviderTest method invalidKeystore.

@Test
public void invalidKeystore() throws Exception {
    ComponentRepresentation rep = createRep("valid", System.currentTimeMillis());
    rep.getConfig().putSingle("keystore", "/nosuchfile");
    Response response = adminClient.realm("test").components().add(rep);
    assertErrror(response, "Failed to load keys. File not found on server.");
}
Also used : ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation) Response(javax.ws.rs.core.Response) Test(org.junit.Test) AbstractKeycloakTest(org.keycloak.testsuite.AbstractKeycloakTest)

Example 83 with ComponentRepresentation

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

the class JavaKeystoreKeyProviderTest method invalidKeyAlias.

@Test
@AuthServerContainerExclude(AuthServer.REMOTE)
public void invalidKeyAlias() throws Exception {
    ComponentRepresentation rep = createRep("valid", System.currentTimeMillis());
    rep.getConfig().putSingle("keyAlias", "invalid");
    Response response = adminClient.realm("test").components().add(rep);
    assertErrror(response, "Failed to load keys. Error creating X509v1Certificate.");
}
Also used : ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation) Response(javax.ws.rs.core.Response) AuthServerContainerExclude(org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude) Test(org.junit.Test) AbstractKeycloakTest(org.keycloak.testsuite.AbstractKeycloakTest)

Example 84 with ComponentRepresentation

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

the class FallbackKeyProviderTest method differentAlgorithms.

@Test
public void differentAlgorithms() {
    String realmId = realmsResouce().realm("test").toRepresentation().getId();
    String[] algorithmsToTest = new String[] { Algorithm.RS384, Algorithm.RS512, Algorithm.PS256, Algorithm.PS384, Algorithm.PS512, Algorithm.ES256, Algorithm.ES384, Algorithm.ES512 };
    oauth.doLogin("test-user@localhost", "password");
    for (String algorithm : algorithmsToTest) {
        RealmRepresentation rep = realmsResouce().realm("test").toRepresentation();
        rep.setDefaultSignatureAlgorithm(algorithm);
        realmsResouce().realm("test").update(rep);
        oauth.openLoginForm();
        String code = oauth.getCurrentQuery().get(OAuth2Constants.CODE);
        OAuthClient.AccessTokenResponse response = oauth.doAccessTokenRequest(code, "password");
        assertNotNull(response.getAccessToken());
    }
    List<ComponentRepresentation> providers = realmsResouce().realm("test").components().query(realmId, "org.keycloak.keys.KeyProvider");
    List<String> expected = new LinkedList<>();
    expected.add("rsa");
    expected.add("hmac-generated");
    expected.add("aes-generated");
    for (String a : algorithmsToTest) {
        expected.add("fallback-" + a);
    }
    assertProviders(providers, expected.toArray(new String[providers.size()]));
}
Also used : ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation) OAuthClient(org.keycloak.testsuite.util.OAuthClient) RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) LinkedList(java.util.LinkedList) Test(org.junit.Test) AbstractKeycloakTest(org.keycloak.testsuite.AbstractKeycloakTest)

Example 85 with ComponentRepresentation

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

the class GeneratedHmacKeyProviderTest method updateKeysize.

@Test
public void updateKeysize() throws Exception {
    long priority = System.currentTimeMillis();
    ComponentRepresentation rep = createRep("valid", GeneratedHmacKeyProviderFactory.ID);
    rep.setConfig(new MultivaluedHashMap<>());
    rep.getConfig().putSingle("priority", Long.toString(priority));
    Response response = adminClient.realm("test").components().add(rep);
    String id = ApiUtil.getCreatedId(response);
    response.close();
    ComponentRepresentation component = testingClient.server("test").fetch(RunHelpers.internalComponent(id));
    assertEquals(64, Base64Url.decode(component.getConfig().getFirst("secret")).length);
    ComponentRepresentation createdRep = adminClient.realm("test").components().component(id).toRepresentation();
    createdRep.getConfig().putSingle("secretSize", "512");
    adminClient.realm("test").components().component(id).update(createdRep);
    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) 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