Search in sources :

Example 1 with IdentityProviderDataMarshaller

use of org.keycloak.broker.provider.IdentityProviderDataMarshaller 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 2 with IdentityProviderDataMarshaller

use of org.keycloak.broker.provider.IdentityProviderDataMarshaller in project keycloak by keycloak.

the class SerializedBrokeredIdentityContext method serialize.

public static SerializedBrokeredIdentityContext serialize(BrokeredIdentityContext context) {
    SerializedBrokeredIdentityContext ctx = new SerializedBrokeredIdentityContext();
    ctx.setId(context.getId());
    ctx.setBrokerUsername(context.getUsername());
    ctx.setModelUsername(context.getModelUsername());
    ctx.setEmail(context.getEmail());
    ctx.setFirstName(context.getFirstName());
    ctx.setLastName(context.getLastName());
    ctx.setBrokerSessionId(context.getBrokerSessionId());
    ctx.setBrokerUserId(context.getBrokerUserId());
    ctx.setToken(context.getToken());
    ctx.setIdentityProviderId(context.getIdpConfig().getAlias());
    ctx.emailAsUsername = context.getAuthenticationSession().getRealm().isRegistrationEmailAsUsername();
    IdentityProviderDataMarshaller serializer = context.getIdp().getMarshaller();
    for (Map.Entry<String, Object> entry : context.getContextData().entrySet()) {
        Object value = entry.getValue();
        String serializedValue = serializer.serialize(value);
        ContextDataEntry ctxEntry = ContextDataEntry.create(value.getClass().getName(), serializedValue);
        ctx.getContextData().put(entry.getKey(), ctxEntry);
    }
    return ctx;
}
Also used : IdentityProviderDataMarshaller(org.keycloak.broker.provider.IdentityProviderDataMarshaller) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

HashMap (java.util.HashMap)2 Map (java.util.Map)2 IdentityProviderDataMarshaller (org.keycloak.broker.provider.IdentityProviderDataMarshaller)2 IOException (java.io.IOException)1 BrokeredIdentityContext (org.keycloak.broker.provider.BrokeredIdentityContext)1 IdentityProvider (org.keycloak.broker.provider.IdentityProvider)1 IdentityProviderModel (org.keycloak.models.IdentityProviderModel)1 ModelException (org.keycloak.models.ModelException)1 RealmModel (org.keycloak.models.RealmModel)1