Search in sources :

Example 11 with IdentityProviderResource

use of org.keycloak.admin.client.resource.IdentityProviderResource in project keycloak by keycloak.

the class IdentityProviderTest method testCreateWithBasicAuth.

@Test
public void testCreateWithBasicAuth() {
    IdentityProviderRepresentation newIdentityProvider = createRep("new-identity-provider", "oidc");
    newIdentityProvider.getConfig().put(IdentityProviderModel.SYNC_MODE, "IMPORT");
    newIdentityProvider.getConfig().put("clientId", "clientId");
    newIdentityProvider.getConfig().put("clientSecret", "some secret value");
    newIdentityProvider.getConfig().put("clientAuthMethod", OIDCLoginProtocol.CLIENT_SECRET_BASIC);
    create(newIdentityProvider);
    IdentityProviderResource identityProviderResource = realm.identityProviders().get("new-identity-provider");
    assertNotNull(identityProviderResource);
    IdentityProviderRepresentation representation = identityProviderResource.toRepresentation();
    assertNotNull(representation);
    assertNotNull(representation.getInternalId());
    assertEquals("new-identity-provider", representation.getAlias());
    assertEquals("oidc", representation.getProviderId());
    assertEquals("IMPORT", representation.getConfig().get(IdentityProviderMapperModel.SYNC_MODE));
    assertEquals("clientId", representation.getConfig().get("clientId"));
    assertEquals(ComponentRepresentation.SECRET_VALUE, representation.getConfig().get("clientSecret"));
    assertEquals(OIDCLoginProtocol.CLIENT_SECRET_BASIC, representation.getConfig().get("clientAuthMethod"));
    assertTrue(representation.isEnabled());
    assertFalse(representation.isStoreToken());
    assertFalse(representation.isTrustEmail());
    assertEquals("some secret value", testingClient.testing("admin-client-test").getIdentityProviderConfig("new-identity-provider").get("clientSecret"));
    IdentityProviderRepresentation rep = realm.identityProviders().findAll().stream().filter(i -> i.getAlias().equals("new-identity-provider")).findFirst().get();
    assertEquals(ComponentRepresentation.SECRET_VALUE, rep.getConfig().get("clientSecret"));
}
Also used : IdentityProviderResource(org.keycloak.admin.client.resource.IdentityProviderResource) IdentityProviderRepresentation(org.keycloak.representations.idm.IdentityProviderRepresentation) Test(org.junit.Test)

Example 12 with IdentityProviderResource

use of org.keycloak.admin.client.resource.IdentityProviderResource in project keycloak by keycloak.

the class IdentityProviderTest method testCreate.

@Test
public void testCreate() {
    IdentityProviderRepresentation newIdentityProvider = createRep("new-identity-provider", "oidc");
    newIdentityProvider.getConfig().put(IdentityProviderModel.SYNC_MODE, "IMPORT");
    newIdentityProvider.getConfig().put("clientId", "clientId");
    newIdentityProvider.getConfig().put("clientSecret", "some secret value");
    create(newIdentityProvider);
    IdentityProviderResource identityProviderResource = realm.identityProviders().get("new-identity-provider");
    assertNotNull(identityProviderResource);
    IdentityProviderRepresentation representation = identityProviderResource.toRepresentation();
    assertNotNull(representation);
    assertNotNull(representation.getInternalId());
    assertEquals("new-identity-provider", representation.getAlias());
    assertEquals("oidc", representation.getProviderId());
    assertEquals("IMPORT", representation.getConfig().get(IdentityProviderMapperModel.SYNC_MODE));
    assertEquals("clientId", representation.getConfig().get("clientId"));
    assertEquals(ComponentRepresentation.SECRET_VALUE, representation.getConfig().get("clientSecret"));
    assertTrue(representation.isEnabled());
    assertFalse(representation.isStoreToken());
    assertFalse(representation.isTrustEmail());
    assertEquals("some secret value", testingClient.testing("admin-client-test").getIdentityProviderConfig("new-identity-provider").get("clientSecret"));
    IdentityProviderRepresentation rep = realm.identityProviders().findAll().stream().filter(i -> i.getAlias().equals("new-identity-provider")).findFirst().get();
    assertEquals(ComponentRepresentation.SECRET_VALUE, rep.getConfig().get("clientSecret"));
}
Also used : IdentityProviderResource(org.keycloak.admin.client.resource.IdentityProviderResource) IdentityProviderRepresentation(org.keycloak.representations.idm.IdentityProviderRepresentation) Test(org.junit.Test)

Example 13 with IdentityProviderResource

use of org.keycloak.admin.client.resource.IdentityProviderResource in project keycloak by keycloak.

the class IdentityProviderTest method testCreateWithJWT.

@Test
public void testCreateWithJWT() {
    IdentityProviderRepresentation newIdentityProvider = createRep("new-identity-provider", "oidc");
    newIdentityProvider.getConfig().put(IdentityProviderModel.SYNC_MODE, "IMPORT");
    newIdentityProvider.getConfig().put("clientId", "clientId");
    newIdentityProvider.getConfig().put("clientAuthMethod", OIDCLoginProtocol.PRIVATE_KEY_JWT);
    create(newIdentityProvider);
    IdentityProviderResource identityProviderResource = realm.identityProviders().get("new-identity-provider");
    assertNotNull(identityProviderResource);
    IdentityProviderRepresentation representation = identityProviderResource.toRepresentation();
    assertNotNull(representation);
    assertNotNull(representation.getInternalId());
    assertEquals("new-identity-provider", representation.getAlias());
    assertEquals("oidc", representation.getProviderId());
    assertEquals("IMPORT", representation.getConfig().get(IdentityProviderMapperModel.SYNC_MODE));
    assertEquals("clientId", representation.getConfig().get("clientId"));
    assertNull(representation.getConfig().get("clientSecret"));
    assertEquals(OIDCLoginProtocol.PRIVATE_KEY_JWT, representation.getConfig().get("clientAuthMethod"));
    assertTrue(representation.isEnabled());
    assertFalse(representation.isStoreToken());
    assertFalse(representation.isTrustEmail());
}
Also used : IdentityProviderResource(org.keycloak.admin.client.resource.IdentityProviderResource) IdentityProviderRepresentation(org.keycloak.representations.idm.IdentityProviderRepresentation) Test(org.junit.Test)

Example 14 with IdentityProviderResource

use of org.keycloak.admin.client.resource.IdentityProviderResource in project keycloak by keycloak.

the class IdentityProviderTest method testSamlImportAndExportMultipleSigningKeys.

@Test
public void testSamlImportAndExportMultipleSigningKeys() throws URISyntaxException, IOException, ParsingException {
    // Use import-config to convert IDPSSODescriptor file into key value pairs
    // to use when creating a SAML Identity Provider
    MultipartFormDataOutput form = new MultipartFormDataOutput();
    form.addFormData("providerId", "saml", MediaType.TEXT_PLAIN_TYPE);
    URL idpMeta = getClass().getClassLoader().getResource("admin-test/saml-idp-metadata-two-signing-certs.xml");
    byte[] content = Files.readAllBytes(Paths.get(idpMeta.toURI()));
    String body = new String(content, Charset.forName("utf-8"));
    form.addFormData("file", body, MediaType.APPLICATION_XML_TYPE, "saml-idp-metadata-two-signing-certs");
    Map<String, String> result = realm.identityProviders().importFrom(form);
    assertSamlImport(result, SIGNING_CERT_1 + "," + SIGNING_CERT_2, true);
    // Create new SAML identity provider using configuration retrieved from import-config
    create(createRep("saml", "saml", true, result));
    IdentityProviderResource provider = realm.identityProviders().get("saml");
    IdentityProviderRepresentation rep = provider.toRepresentation();
    assertCreatedSamlIdp(rep, true);
    // Now list the providers - we should see the one just created
    List<IdentityProviderRepresentation> providers = realm.identityProviders().findAll();
    Assert.assertNotNull("identityProviders not null", providers);
    Assert.assertEquals("identityProviders instance count", 1, providers.size());
    assertEqual(rep, providers.get(0));
    // Perform export, and make sure some of the values are like they're supposed to be
    Response response = realm.identityProviders().get("saml").export("xml");
    Assert.assertEquals(200, response.getStatus());
    body = response.readEntity(String.class);
    response.close();
    assertSamlExport(body);
}
Also used : Response(javax.ws.rs.core.Response) IdentityProviderResource(org.keycloak.admin.client.resource.IdentityProviderResource) IdentityProviderRepresentation(org.keycloak.representations.idm.IdentityProviderRepresentation) Matchers.containsString(org.hamcrest.Matchers.containsString) URL(java.net.URL) MultipartFormDataOutput(org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataOutput) Test(org.junit.Test)

Example 15 with IdentityProviderResource

use of org.keycloak.admin.client.resource.IdentityProviderResource in project keycloak by keycloak.

the class IdentityProviderTest method testDeleteProtocolMappersAfterDeleteIdentityProvider.

// KEYCLOAK-7872
@Test
public void testDeleteProtocolMappersAfterDeleteIdentityProvider() {
    create(createRep("google3", "google"));
    IdentityProviderResource provider = realm.identityProviders().get("google3");
    IdentityProviderMapperRepresentation mapper = new IdentityProviderMapperRepresentation();
    mapper.setIdentityProviderAlias("google3");
    mapper.setName("my_mapper");
    mapper.setIdentityProviderMapper("oidc-hardcoded-role-idp-mapper");
    Map<String, String> config = new HashMap<>();
    config.put(IdentityProviderMapperModel.SYNC_MODE, IdentityProviderMapperSyncMode.INHERIT.toString());
    config.put("role", "offline_access");
    mapper.setConfig(config);
    Response response = provider.addMapper(mapper);
    List<IdentityProviderMapperRepresentation> mappers = provider.getMappers();
    assertThat(mappers, hasSize(1));
    assertAdminEvents.clear();
    provider.remove();
    assertAdminEvents.assertEvent(realmId, OperationType.DELETE, AdminEventPaths.identityProviderPath("google3"), ResourceType.IDENTITY_PROVIDER);
    create(createRep("google3", "google"));
    IdentityProviderResource newProvider = realm.identityProviders().get("google3");
    assertThat(newProvider.getMappers(), empty());
}
Also used : Response(javax.ws.rs.core.Response) IdentityProviderMapperRepresentation(org.keycloak.representations.idm.IdentityProviderMapperRepresentation) IdentityProviderResource(org.keycloak.admin.client.resource.IdentityProviderResource) HashMap(java.util.HashMap) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Aggregations

IdentityProviderResource (org.keycloak.admin.client.resource.IdentityProviderResource)47 IdentityProviderMapperRepresentation (org.keycloak.representations.idm.IdentityProviderMapperRepresentation)26 IdentityProviderRepresentation (org.keycloak.representations.idm.IdentityProviderRepresentation)22 Test (org.junit.Test)20 Response (javax.ws.rs.core.Response)11 Matchers.containsString (org.hamcrest.Matchers.containsString)10 RealmResource (org.keycloak.admin.client.resource.RealmResource)9 Before (org.junit.Before)6 URL (java.net.URL)4 HashMap (java.util.HashMap)4 MultipartFormDataOutput (org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataOutput)4 ClientsResource (org.keycloak.admin.client.resource.ClientsResource)4 UsersResource (org.keycloak.admin.client.resource.UsersResource)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 IOException (java.io.IOException)3 URI (java.net.URI)3 List (java.util.List)3 Map (java.util.Map)3 Set (java.util.Set)3 NotFoundException (javax.ws.rs.NotFoundException)3