Search in sources :

Example 41 with ModelDuplicateException

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

the class MapUserSessionProvider method createUserSession.

@Override
public UserSessionModel createUserSession(String id, RealmModel realm, UserModel user, String loginUsername, String ipAddress, String authMethod, boolean rememberMe, String brokerSessionId, String brokerUserId, UserSessionModel.SessionPersistenceState persistenceState) {
    LOG.tracef("createUserSession(%s, %s, %s, %s)%s", id, realm, loginUsername, persistenceState, getShortStackTrace());
    MapUserSessionEntity entity;
    if (Objects.equals(persistenceState, TRANSIENT)) {
        if (id == null) {
            id = UUID.randomUUID().toString();
        }
        entity = new MapUserSessionEntity(id, realm, user, loginUsername, ipAddress, authMethod, rememberMe, brokerSessionId, brokerUserId, false);
        transientUserSessions.put(entity.getId(), entity);
    } else {
        if (id != null && userSessionTx.read(id) != null) {
            throw new ModelDuplicateException("User session exists: " + id);
        }
        entity = new MapUserSessionEntity(id, realm, user, loginUsername, ipAddress, authMethod, rememberMe, brokerSessionId, brokerUserId, false);
        entity = userSessionTx.create(entity);
    }
    entity.setPersistenceState(persistenceState);
    setUserSessionExpiration(entity, realm);
    UserSessionModel userSession = userEntityToAdapterFunc(realm).apply(entity);
    if (userSession != null) {
        DeviceActivityManager.attachDevice(userSession, session);
    }
    return userSession;
}
Also used : UserSessionModel(org.keycloak.models.UserSessionModel) ModelDuplicateException(org.keycloak.models.ModelDuplicateException)

Example 42 with ModelDuplicateException

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

the class MapRealmAdapter method addAuthenticatorExecution.

@Override
public AuthenticationExecutionModel addAuthenticatorExecution(AuthenticationExecutionModel model) {
    if (entity.getAuthenticationExecution(model.getId()).isPresent()) {
        throw new ModelDuplicateException("An RequiredActionProvider with given id already exists");
    }
    MapAuthenticationExecutionEntity executionEntity = MapAuthenticationExecutionEntity.fromModel(model);
    entity.addAuthenticationExecution(executionEntity);
    return MapAuthenticationExecutionEntity.toModel(executionEntity);
}
Also used : ModelDuplicateException(org.keycloak.models.ModelDuplicateException) MapAuthenticationExecutionEntity(org.keycloak.models.map.realm.entity.MapAuthenticationExecutionEntity)

Aggregations

ModelDuplicateException (org.keycloak.models.ModelDuplicateException)42 Consumes (javax.ws.rs.Consumes)12 UserModel (org.keycloak.models.UserModel)11 POST (javax.ws.rs.POST)9 Response (javax.ws.rs.core.Response)6 NotFoundException (javax.ws.rs.NotFoundException)5 ClientModel (org.keycloak.models.ClientModel)5 RealmModel (org.keycloak.models.RealmModel)5 BadRequestException (javax.ws.rs.BadRequestException)4 PUT (javax.ws.rs.PUT)4 Path (javax.ws.rs.Path)4 ModelException (org.keycloak.models.ModelException)4 X509Certificate (java.security.cert.X509Certificate)3 NoCache (org.jboss.resteasy.annotations.cache.NoCache)3 ErrorResponseException (org.keycloak.services.ErrorResponseException)3 ClientPolicyException (org.keycloak.services.clientpolicy.ClientPolicyException)3 URI (java.net.URI)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 ClientScopeModel (org.keycloak.models.ClientScopeModel)2 ProtocolMapperModel (org.keycloak.models.ProtocolMapperModel)2