Search in sources :

Example 21 with IdentityProviderRepresentation

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

the class AccountBrokerTest method displayEnabledIdentityProviders.

@Test
public void displayEnabledIdentityProviders() {
    identityPage.realm(KcOidcBrokerConfiguration.INSTANCE.consumerRealmName());
    identityPage.open();
    loginPage.login("accountbrokertest", "password");
    Assert.assertTrue(identityPage.isCurrent());
    List<AccountFederatedIdentityPage.FederatedIdentity> identities = identityPage.getIdentities();
    Assert.assertEquals(1, identities.size());
    // Disable the identity provider
    RealmResource realm = adminClient.realm(bc.consumerRealmName());
    IdentityProviderResource providerResource = realm.identityProviders().get(bc.getIDPAlias());
    IdentityProviderRepresentation provider = providerResource.toRepresentation();
    provider.setEnabled(false);
    providerResource.update(provider);
    // Reload federated identities page
    identityPage.open();
    Assert.assertTrue(identityPage.isCurrent());
    identities = identityPage.getIdentities();
    Assert.assertEquals(0, identities.size());
}
Also used : IdentityProviderResource(org.keycloak.admin.client.resource.IdentityProviderResource) RealmResource(org.keycloak.admin.client.resource.RealmResource) IdentityProviderRepresentation(org.keycloak.representations.idm.IdentityProviderRepresentation) Test(org.junit.Test) AbstractBaseBrokerTest(org.keycloak.testsuite.broker.AbstractBaseBrokerTest)

Example 22 with IdentityProviderRepresentation

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

the class AbstractUiTest method createIdentityProviderRepresentation.

protected IdentityProviderRepresentation createIdentityProviderRepresentation(String alias, String providerId) {
    IdentityProviderRepresentation idpRep = new IdentityProviderRepresentation();
    idpRep.setProviderId(providerId);
    idpRep.setAlias(alias);
    idpRep.setConfig(new HashMap<>());
    return idpRep;
}
Also used : IdentityProviderRepresentation(org.keycloak.representations.idm.IdentityProviderRepresentation)

Example 23 with IdentityProviderRepresentation

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

the class LinkedAccountsTest method addTestRealms.

@Override
public void addTestRealms(List<RealmRepresentation> testRealms) {
    super.addTestRealms(testRealms);
    RealmRepresentation realm1 = testRealms.get(0);
    realm1.addIdentityProvider(createIdentityProviderRepresentation(SOCIAL_IDP_ALIAS, GoogleIdentityProviderFactory.PROVIDER_ID));
    String oidcRoot = getAuthServerRoot() + "realms/" + REALM2_NAME + "/protocol/openid-connect/";
    IdentityProviderRepresentation systemIdp = createIdentityProviderRepresentation(SYSTEM_IDP_ALIAS, OIDCIdentityProviderFactory.PROVIDER_ID);
    systemIdp.getConfig().put("clientId", CLIENT_ID);
    systemIdp.getConfig().put("clientSecret", CLIENT_SECRET);
    systemIdp.getConfig().put("clientAuthMethod", OIDCLoginProtocol.CLIENT_SECRET_POST);
    systemIdp.getConfig().put("authorizationUrl", oidcRoot + "auth");
    systemIdp.getConfig().put("tokenUrl", oidcRoot + "token");
    realm1.addIdentityProvider(systemIdp);
    ClientRepresentation client = ClientBuilder.create().clientId(CLIENT_ID).secret(CLIENT_SECRET).redirectUris(getAuthServerRoot() + "realms/" + TEST + "/broker/" + SYSTEM_IDP_ALIAS + "/endpoint").build();
    // using REALM2 as an identity provider
    RealmRepresentation realm2 = new RealmRepresentation();
    realm2.setId(REALM2_NAME);
    realm2.setRealm(REALM2_NAME);
    realm2.setEnabled(true);
    realm2.setClients(Collections.singletonList(client));
    realm2.setUsers(Collections.singletonList(homerUser));
    testRealms.add(realm2);
}
Also used : RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) IdentityProviderRepresentation(org.keycloak.representations.idm.IdentityProviderRepresentation) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation)

Example 24 with IdentityProviderRepresentation

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

the class IdentityProviderResource method getIdentityProvider.

/**
 * Get the identity provider
 *
 * @return
 */
@GET
@NoCache
@Produces(MediaType.APPLICATION_JSON)
public IdentityProviderRepresentation getIdentityProvider() {
    this.auth.realm().requireViewIdentityProviders();
    if (identityProviderModel == null) {
        throw new javax.ws.rs.NotFoundException();
    }
    IdentityProviderRepresentation rep = ModelToRepresentation.toRepresentation(realm, this.identityProviderModel);
    return StripSecretsUtils.strip(rep);
}
Also used : IdentityProviderRepresentation(org.keycloak.representations.idm.IdentityProviderRepresentation) NotFoundException(javax.ws.rs.NotFoundException) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Example 25 with IdentityProviderRepresentation

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

the class IdentityProviderTest method testSamlExportSignatureOn.

@Test
public void testSamlExportSignatureOn() throws URISyntaxException, IOException, ConfigurationException, ParsingException, ProcessingException {
    // 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.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.xml");
    Map<String, String> result = realm.identityProviders().importFrom(form);
    // Explicitly enable SP Metadata Signature
    result.put(SAMLIdentityProviderConfig.SIGN_SP_METADATA, "true");
    // Create new SAML identity provider using configuration retrieved from import-config
    IdentityProviderRepresentation idpRep = createRep("saml", "saml", true, result);
    create(idpRep);
    // 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();
    Document document = DocumentUtil.getDocument(body);
    Element signatureElement = DocumentUtil.getDirectChildElement(document.getDocumentElement(), XMLDSIG_NSURI.get(), "Signature");
    Assert.assertNotNull(signatureElement);
}
Also used : Response(javax.ws.rs.core.Response) Element(org.w3c.dom.Element) IdentityProviderRepresentation(org.keycloak.representations.idm.IdentityProviderRepresentation) Matchers.containsString(org.hamcrest.Matchers.containsString) Document(org.w3c.dom.Document) URL(java.net.URL) MultipartFormDataOutput(org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataOutput) Test(org.junit.Test)

Aggregations

IdentityProviderRepresentation (org.keycloak.representations.idm.IdentityProviderRepresentation)91 Test (org.junit.Test)45 IdentityProviderResource (org.keycloak.admin.client.resource.IdentityProviderResource)23 RealmResource (org.keycloak.admin.client.resource.RealmResource)22 UserRepresentation (org.keycloak.representations.idm.UserRepresentation)17 ClientRepresentation (org.keycloak.representations.idm.ClientRepresentation)16 Response (javax.ws.rs.core.Response)15 Matchers.containsString (org.hamcrest.Matchers.containsString)10 List (java.util.List)9 MultipartFormDataOutput (org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataOutput)8 URL (java.net.URL)7 IdentityProviderMapperRepresentation (org.keycloak.representations.idm.IdentityProviderMapperRepresentation)7 OAuthClient (org.keycloak.testsuite.util.OAuthClient)7 IOException (java.io.IOException)6 URI (java.net.URI)6 Map (java.util.Map)6 Matchers.hasSize (org.hamcrest.Matchers.hasSize)6 Matchers.is (org.hamcrest.Matchers.is)6 SAMLIdentityProviderConfig (org.keycloak.broker.saml.SAMLIdentityProviderConfig)6 AttributeType (org.keycloak.dom.saml.v2.assertion.AttributeType)6