Search in sources :

Example 11 with ComponentRepresentation

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

the class KerberosStandaloneTest method handleUnknownKerberosRealm.

/**
 * KEYCLOAK-4178
 *
 * Assert it's handled when kerberos realm is unreachable
 *
 * @throws Exception
 */
@Test
@UncaughtServerErrorExpected
public void handleUnknownKerberosRealm() throws Exception {
    // Switch kerberos realm to "unavailable"
    List<ComponentRepresentation> reps = testRealmResource().components().query("test", UserStorageProvider.class.getName());
    org.keycloak.testsuite.Assert.assertEquals(1, reps.size());
    ComponentRepresentation kerberosProvider = reps.get(0);
    kerberosProvider.getConfig().putSingle(KerberosConstants.KERBEROS_REALM, "unavailable");
    testRealmResource().components().component(kerberosProvider.getId()).update(kerberosProvider);
    // Try register new user and assert it failed
    UserRepresentation john = new UserRepresentation();
    john.setUsername("john");
    Response response = testRealmResource().users().create(john);
    Assert.assertEquals(500, response.getStatus());
    response.close();
}
Also used : ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation) Response(javax.ws.rs.core.Response) UserStorageProvider(org.keycloak.storage.UserStorageProvider) UserRepresentation(org.keycloak.representations.idm.UserRepresentation) Test(org.junit.Test) UncaughtServerErrorExpected(org.keycloak.testsuite.arquillian.annotation.UncaughtServerErrorExpected)

Example 12 with ComponentRepresentation

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

the class KerberosStandaloneTest method noProvider.

/**
 * KEYCLOAK-3451
 *
 * Test that if there is no User Storage Provider that can handle kerberos we can still login
 *
 * @throws Exception
 */
@Test
public void noProvider() throws Exception {
    List<ComponentRepresentation> reps = testRealmResource().components().query("test", UserStorageProvider.class.getName());
    org.keycloak.testsuite.Assert.assertEquals(1, reps.size());
    ComponentRepresentation kerberosProvider = reps.get(0);
    testRealmResource().components().component(kerberosProvider.getId()).remove();
    /*
         To do this we do a valid kerberos login.  The authenticator will obtain a valid token, but there will
         be no user storage provider that can process it.  This means we should be on the login page.
         We do this through a JAX-RS client request.  We extract the action URL from the login page, and stuff it
         into selenium then just perform a regular login.
         */
    Response spnegoResponse = spnegoLogin("hnelson", "secret");
    String context = spnegoResponse.readEntity(String.class);
    spnegoResponse.close();
    Assert.assertTrue(context.contains("Sign in to test"));
    String url = ActionURIUtils.getActionURIFromPageSource(context);
    // Follow login with HttpClient. Improve if needed
    MultivaluedMap<String, String> params = new javax.ws.rs.core.MultivaluedHashMap<>();
    params.putSingle("username", "test-user@localhost");
    params.putSingle("password", "password");
    Response response = client.target(url).request().post(Entity.form(params));
    URI redirectUri = response.getLocation();
    assertAuthenticationSuccess(redirectUri.toString());
    events.clear();
    testRealmResource().components().add(kerberosProvider);
}
Also used : ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation) Response(javax.ws.rs.core.Response) UserStorageProvider(org.keycloak.storage.UserStorageProvider) URI(java.net.URI) Test(org.junit.Test)

Example 13 with ComponentRepresentation

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

the class OpenshiftClientStorageTest method onBefore.

@Before
public void onBefore() {
    assumeFeatureEnabled(OPENSHIFT_INTEGRATION);
    ComponentRepresentation provider = new ComponentRepresentation();
    provider.setName("openshift-client-storage");
    provider.setProviderId(OpenshiftClientStorageProviderFactory.PROVIDER_ID);
    provider.setProviderType(ClientStorageProvider.class.getName());
    provider.setConfig(new MultivaluedHashMap<>());
    provider.getConfig().putSingle(OpenshiftClientStorageProviderFactory.CONFIG_PROPERTY_OPENSHIFT_URI, "http://localhost:8880");
    provider.getConfig().putSingle(OpenshiftClientStorageProviderFactory.CONFIG_PROPERTY_ACCESS_TOKEN, "token");
    provider.getConfig().putSingle(OpenshiftClientStorageProviderFactory.CONFIG_PROPERTY_DEFAULT_NAMESPACE, "default");
    provider.getConfig().putSingle(OpenshiftClientStorageProviderFactory.CONFIG_PROPERTY_REQUIRE_USER_CONSENT, "true");
    Response resp = adminClient.realm("test").components().add(provider);
    resp.close();
    clientStorageId = ApiUtil.getCreatedId(resp);
    getCleanup().addComponentId(clientStorageId);
}
Also used : ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation) Response(javax.ws.rs.core.Response) ClientStorageProvider(org.keycloak.storage.client.ClientStorageProvider) Before(org.junit.Before)

Example 14 with ComponentRepresentation

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

the class ImportedRsaKeyProviderTest 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 15 with ComponentRepresentation

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

the class ImportedRsaKeyProviderTest method invalidCertificate.

private void invalidCertificate(String providerId) throws Exception {
    KeyPair keyPair = KeyUtils.generateRsaKeyPair(2048);
    Certificate invalidCertificate = CertificateUtils.generateV1SelfSignedCertificate(KeyUtils.generateRsaKeyPair(2048), "test");
    ComponentRepresentation rep = createRep("invalid", providerId);
    rep.getConfig().putSingle(Attributes.PRIVATE_KEY_KEY, PemUtils.encodeKey(keyPair.getPrivate()));
    rep.getConfig().putSingle(Attributes.CERTIFICATE_KEY, "nonsense");
    Response response = adminClient.realm("test").components().add(rep);
    assertErrror(response, "Failed to decode certificate");
    rep.getConfig().putSingle(Attributes.CERTIFICATE_KEY, PemUtils.encodeCertificate(invalidCertificate));
    response = adminClient.realm("test").components().add(rep);
    assertErrror(response, "Certificate does not match private key");
}
Also used : ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation) Response(javax.ws.rs.core.Response) KeyPair(java.security.KeyPair) Certificate(java.security.cert.Certificate)

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