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