Java Code Examples for org.keycloak.models.utils.KeycloakModelUtils#getIdentityProviderDisplayName()

The following examples show how to use org.keycloak.models.utils.KeycloakModelUtils#getIdentityProviderDisplayName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IdentityProviderBean.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private void addIdentityProvider(List<IdentityProvider> orderedSet, RealmModel realm, URI baseURI, IdentityProviderModel identityProvider) {
    String loginUrl = Urls.identityProviderAuthnRequest(baseURI, identityProvider.getAlias(), realm.getName()).toString();
    String displayName = KeycloakModelUtils.getIdentityProviderDisplayName(session, identityProvider);
    Map<String, String> config = identityProvider.getConfig();
    boolean hideOnLoginPage = config != null && Boolean.parseBoolean(config.get("hideOnLoginPage"));
    if (!hideOnLoginPage) {
        orderedSet.add(new IdentityProvider(identityProvider.getAlias(),
                displayName, identityProvider.getProviderId(), loginUrl,
                config != null ? config.get("guiOrder") : null));
    }
}
 
Example 2
Source File: AccountFederatedIdentityBean.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public AccountFederatedIdentityBean(KeycloakSession session, RealmModel realm, UserModel user, URI baseUri, String stateChecker) {
    this.session = session;

    List<IdentityProviderModel> identityProviders = realm.getIdentityProviders();
    Set<FederatedIdentityModel> identities = session.users().getFederatedIdentities(user, realm);

    int availableIdentities = 0;
    if (identityProviders != null && !identityProviders.isEmpty()) {
        for (IdentityProviderModel provider : identityProviders) {
            if (!provider.isEnabled()) {
                continue;
            }
            String providerId = provider.getAlias();

            FederatedIdentityModel identity = getIdentity(identities, providerId);

            if (identity != null) {
                availableIdentities++;
            }

            String displayName = KeycloakModelUtils.getIdentityProviderDisplayName(session, provider);
            FederatedIdentityEntry entry = new FederatedIdentityEntry(identity, displayName, provider.getAlias(), provider.getAlias(),
            		  															provider.getConfig() != null ? provider.getConfig().get("guiOrder") : null);
            this.identities.add(entry);
        }
    }
    
    this.identities.sort(IDP_COMPARATOR_INSTANCE);

    // Removing last social provider is not possible if you don't have other possibility to authenticate
    this.removeLinkPossible = availableIdentities > 1 || user.getFederationLink() != null || AccountFormService.isPasswordSet(session, realm, user);
}
 
Example 3
Source File: LinkedAccountsResource.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public SortedSet<LinkedAccountRepresentation> getLinkedAccounts(KeycloakSession session, RealmModel realm, UserModel user) {
    List<IdentityProviderModel> identityProviders = realm.getIdentityProviders();
    SortedSet<LinkedAccountRepresentation> linkedAccounts = new TreeSet<>();
    
    if (identityProviders == null || identityProviders.isEmpty()) return linkedAccounts;
    
    Set<String> socialIds = findSocialIds();
    Set<FederatedIdentityModel> identities = session.users().getFederatedIdentities(user, realm);
    for (IdentityProviderModel provider : identityProviders) {
        if (!provider.isEnabled()) {
            continue;
        }
        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());
        }
        linkedAccounts.add(rep);
    }
    
    return linkedAccounts;
}