Search in sources :

Example 31 with IdentityProviderModel

use of org.keycloak.models.IdentityProviderModel in project keycloak by keycloak.

the class SerializedBrokeredIdentityContext method deserialize.

public BrokeredIdentityContext deserialize(KeycloakSession session, AuthenticationSessionModel authSession) {
    BrokeredIdentityContext ctx = new BrokeredIdentityContext(getId());
    ctx.setUsername(getBrokerUsername());
    ctx.setModelUsername(getModelUsername());
    ctx.setEmail(getEmail());
    ctx.setFirstName(getFirstName());
    ctx.setLastName(getLastName());
    ctx.setBrokerSessionId(getBrokerSessionId());
    ctx.setBrokerUserId(getBrokerUserId());
    ctx.setToken(getToken());
    RealmModel realm = authSession.getRealm();
    IdentityProviderModel idpConfig = realm.getIdentityProviderByAlias(getIdentityProviderId());
    if (idpConfig == null) {
        throw new ModelException("Can't find identity provider with ID " + getIdentityProviderId() + " in realm " + realm.getName());
    }
    IdentityProvider idp = IdentityBrokerService.getIdentityProvider(session, realm, idpConfig.getAlias());
    ctx.setIdpConfig(idpConfig);
    ctx.setIdp(idp);
    IdentityProviderDataMarshaller serializer = idp.getMarshaller();
    for (Map.Entry<String, ContextDataEntry> entry : getContextData().entrySet()) {
        try {
            ContextDataEntry value = entry.getValue();
            Class<?> clazz = Reflections.classForName(value.getClazz(), this.getClass().getClassLoader());
            Object deserialized = serializer.deserialize(value.getData(), clazz);
            ctx.getContextData().put(entry.getKey(), deserialized);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    ctx.setAuthenticationSession(authSession);
    return ctx;
}
Also used : ModelException(org.keycloak.models.ModelException) IdentityProvider(org.keycloak.broker.provider.IdentityProvider) IdentityProviderModel(org.keycloak.models.IdentityProviderModel) BrokeredIdentityContext(org.keycloak.broker.provider.BrokeredIdentityContext) IOException(java.io.IOException) ModelException(org.keycloak.models.ModelException) RealmModel(org.keycloak.models.RealmModel) IdentityProviderDataMarshaller(org.keycloak.broker.provider.IdentityProviderDataMarshaller) HashMap(java.util.HashMap) Map(java.util.Map)

Example 32 with IdentityProviderModel

use of org.keycloak.models.IdentityProviderModel in project keycloak by keycloak.

the class MapIdentityProviderEntity method toModel.

static IdentityProviderModel toModel(MapIdentityProviderEntity entity) {
    if (entity == null)
        return null;
    IdentityProviderModel model = new IdentityProviderModel();
    model.setInternalId(entity.getId());
    model.setAlias(entity.getAlias());
    model.setDisplayName(entity.getDisplayName());
    model.setProviderId(entity.getProviderId());
    model.setFirstBrokerLoginFlowId(entity.getFirstBrokerLoginFlowId());
    model.setPostBrokerLoginFlowId(entity.getPostBrokerLoginFlowId());
    Boolean enabled = entity.isEnabled();
    model.setEnabled(enabled == null ? false : enabled);
    Boolean trustEmail = entity.isTrustEmail();
    model.setTrustEmail(trustEmail == null ? false : trustEmail);
    Boolean storeToken = entity.isStoreToken();
    model.setStoreToken(storeToken == null ? false : storeToken);
    Boolean linkOnly = entity.isLinkOnly();
    model.setLinkOnly(linkOnly == null ? false : linkOnly);
    Boolean addReadTokenRoleOnCreate = entity.isAddReadTokenRoleOnCreate();
    model.setAddReadTokenRoleOnCreate(addReadTokenRoleOnCreate == null ? false : addReadTokenRoleOnCreate);
    Boolean authenticateByDefault = entity.isAuthenticateByDefault();
    model.setAuthenticateByDefault(authenticateByDefault == null ? false : authenticateByDefault);
    model.setConfig(entity.getConfig() == null ? null : new HashMap<>(entity.getConfig()));
    return model;
}
Also used : HashMap(java.util.HashMap) IdentityProviderModel(org.keycloak.models.IdentityProviderModel)

Aggregations

IdentityProviderModel (org.keycloak.models.IdentityProviderModel)32 RealmModel (org.keycloak.models.RealmModel)10 Response (javax.ws.rs.core.Response)8 IdentityProvider (org.keycloak.broker.provider.IdentityProvider)8 KeycloakSession (org.keycloak.models.KeycloakSession)6 UserModel (org.keycloak.models.UserModel)6 NotFoundException (javax.ws.rs.NotFoundException)5 Path (javax.ws.rs.Path)5 Test (org.junit.Test)5 AuthenticationSessionModel (org.keycloak.sessions.AuthenticationSessionModel)5 IOException (java.io.IOException)4 Map (java.util.Map)4 OAuthErrorException (org.keycloak.OAuthErrorException)4 IdentityBrokerException (org.keycloak.broker.provider.IdentityBrokerException)4 IdentityProviderFactory (org.keycloak.broker.provider.IdentityProviderFactory)4 SocialIdentityProvider (org.keycloak.broker.social.SocialIdentityProvider)4 ClientModel (org.keycloak.models.ClientModel)4 FederatedIdentityModel (org.keycloak.models.FederatedIdentityModel)4 ErrorResponse (org.keycloak.services.ErrorResponse)4 URI (java.net.URI)3