use of org.keycloak.models.ModelDuplicateException in project keycloak by keycloak.
the class MapRealmAdapter method importComponentModel.
@Override
public ComponentModel importComponentModel(ComponentModel model) {
try {
ComponentFactory componentFactory = ComponentUtil.getComponentFactory(session, model);
if (componentFactory == null && System.getProperty(COMPONENT_PROVIDER_EXISTS_DISABLED) == null) {
throw new IllegalArgumentException("Invalid component type");
}
componentFactory.validateConfiguration(session, this, model);
} catch (IllegalArgumentException | ComponentValidationException e) {
if (System.getProperty(COMPONENT_PROVIDER_EXISTS_DISABLED) == null) {
throw e;
}
}
if (entity.getComponent(model.getId()).isPresent()) {
throw new ModelDuplicateException("A Component with given id already exists");
}
MapComponentEntity component = MapComponentEntity.fromModel(model);
if (model.getParentId() == null) {
component.setParentId(getId());
}
entity.addComponent(component);
return MapComponentEntity.toModel(component);
}
use of org.keycloak.models.ModelDuplicateException in project keycloak by keycloak.
the class MapRealmAdapter method addIdentityProviderMapper.
@Override
public IdentityProviderMapperModel addIdentityProviderMapper(IdentityProviderMapperModel model) {
MapIdentityProviderMapperEntity identityProviderMapper = MapIdentityProviderMapperEntity.fromModel(model);
if (entity.getIdentityProviderMapper(model.getId()).isPresent()) {
throw new ModelDuplicateException("An IdentityProviderMapper with given id already exists");
}
entity.addIdentityProviderMapper(identityProviderMapper);
return MapIdentityProviderMapperEntity.toModel(identityProviderMapper);
}
use of org.keycloak.models.ModelDuplicateException in project keycloak by keycloak.
the class MapRealmAdapter method addAuthenticationFlow.
@Override
public AuthenticationFlowModel addAuthenticationFlow(AuthenticationFlowModel model) {
if (entity.getAuthenticationFlow(model.getId()).isPresent()) {
throw new ModelDuplicateException("An AuthenticationFlow with given id already exists");
}
MapAuthenticationFlowEntity authenticationFlowEntity = MapAuthenticationFlowEntity.fromModel(model);
entity.addAuthenticationFlow(authenticationFlowEntity);
return MapAuthenticationFlowEntity.toModel(authenticationFlowEntity);
}
use of org.keycloak.models.ModelDuplicateException in project keycloak by keycloak.
the class MapResourceStore method create.
@Override
public Resource create(String id, String name, ResourceServer resourceServer, String owner) {
LOG.tracef("create(%s, %s, %s, %s)%s", id, name, resourceServer, owner, getShortStackTrace());
// @UniqueConstraint(columnNames = {"NAME", "RESOURCE_SERVER_ID", "OWNER"})
DefaultModelCriteria<Resource> mcb = forResourceServer(resourceServer.getId()).compare(SearchableFields.NAME, Operator.EQ, name).compare(SearchableFields.OWNER, Operator.EQ, owner);
if (tx.getCount(withCriteria(mcb)) > 0) {
throw new ModelDuplicateException("Resource with name '" + name + "' for " + resourceServer.getId() + " already exists for request owner " + owner);
}
MapResourceEntity entity = new MapResourceEntityImpl();
entity.setId(id);
entity.setName(name);
entity.setResourceServerId(resourceServer.getId());
entity.setOwner(owner);
entity = tx.create(entity);
return entityToAdapter(entity);
}
use of org.keycloak.models.ModelDuplicateException in project keycloak by keycloak.
the class MapResourceServerStore method create.
@Override
public ResourceServer create(ClientModel client) {
String clientId = client.getId();
LOG.tracef("create(%s)%s", clientId, getShortStackTrace());
if (clientId == null)
return null;
if (!StorageId.isLocalStorage(clientId)) {
throw new ModelException("Creating resource server from federated ClientModel not supported");
}
if (tx.read(clientId) != null) {
throw new ModelDuplicateException("Resource server already exists: " + clientId);
}
MapResourceServerEntity entity = new MapResourceServerEntityImpl();
entity.setId(clientId);
return entityToAdapter(tx.create(entity));
}
Aggregations