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++;
}
}
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;
}
Aggregations