Search in sources :

Example 1 with LinkedAccountRepresentation

use of org.keycloak.representations.account.LinkedAccountRepresentation in project keycloak by keycloak.

the class LinkedAccountsRestServiceTest method testGetLinkedAccounts.

@Test
public void testGetLinkedAccounts() throws IOException {
    SortedSet<LinkedAccountRepresentation> details = linkedAccountsRep();
    assertEquals(3, details.size());
    int order = 0;
    for (LinkedAccountRepresentation account : details) {
        if (account.getProviderAlias().equals("github")) {
            assertTrue(account.isConnected());
        } else {
            assertFalse(account.isConnected());
        }
        // test that accounts were sorted by guiOrder
        if (order == 0)
            assertEquals("mysaml", account.getDisplayName());
        if (order == 1)
            assertEquals("MyOIDC", account.getDisplayName());
        if (order == 2)
            assertEquals("GitHub", account.getDisplayName());
        order++;
    }
}
Also used : LinkedAccountRepresentation(org.keycloak.representations.account.LinkedAccountRepresentation) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest)

Example 2 with LinkedAccountRepresentation

use of org.keycloak.representations.account.LinkedAccountRepresentation in project keycloak by keycloak.

the class LinkedAccountsResource method toLinkedAccountRepresentation.

private LinkedAccountRepresentation toLinkedAccountRepresentation(IdentityProviderModel provider, Set<String> socialIds, Stream<FederatedIdentityModel> identities) {
    String providerId = provider.getAlias();
    FederatedIdentityModel identity = getIdentity(identities, providerId);
    String displayName = KeycloakModelUtils.getIdentityProviderDisplayName(session, provider);
    String guiOrder = provider.getConfig() != null ? provider.getConfig().get("guiOrder") : null;
    LinkedAccountRepresentation rep = new LinkedAccountRepresentation();
    rep.setConnected(identity != null);
    rep.setSocial(socialIds.contains(provider.getProviderId()));
    rep.setProviderAlias(providerId);
    rep.setDisplayName(displayName);
    rep.setGuiOrder(guiOrder);
    rep.setProviderName(provider.getAlias());
    if (identity != null) {
        rep.setLinkedUsername(identity.getUserName());
    }
    return rep;
}
Also used : FederatedIdentityModel(org.keycloak.models.FederatedIdentityModel) LinkedAccountRepresentation(org.keycloak.representations.account.LinkedAccountRepresentation)

Aggregations

LinkedAccountRepresentation (org.keycloak.representations.account.LinkedAccountRepresentation)2 Test (org.junit.Test)1 FederatedIdentityModel (org.keycloak.models.FederatedIdentityModel)1 AbstractTestRealmKeycloakTest (org.keycloak.testsuite.AbstractTestRealmKeycloakTest)1