Search in sources :

Example 11 with ModelDuplicateException

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);
}
Also used : ComponentValidationException(org.keycloak.component.ComponentValidationException) MapComponentEntity(org.keycloak.models.map.realm.entity.MapComponentEntity) ComponentFactory(org.keycloak.component.ComponentFactory) ModelDuplicateException(org.keycloak.models.ModelDuplicateException)

Example 12 with ModelDuplicateException

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);
}
Also used : ModelDuplicateException(org.keycloak.models.ModelDuplicateException) MapIdentityProviderMapperEntity(org.keycloak.models.map.realm.entity.MapIdentityProviderMapperEntity)

Example 13 with ModelDuplicateException

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);
}
Also used : MapAuthenticationFlowEntity(org.keycloak.models.map.realm.entity.MapAuthenticationFlowEntity) ModelDuplicateException(org.keycloak.models.ModelDuplicateException)

Example 14 with ModelDuplicateException

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);
}
Also used : Resource(org.keycloak.authorization.model.Resource) ModelDuplicateException(org.keycloak.models.ModelDuplicateException) MapResourceEntity(org.keycloak.models.map.authorization.entity.MapResourceEntity) MapResourceEntityImpl(org.keycloak.models.map.authorization.entity.MapResourceEntityImpl)

Example 15 with ModelDuplicateException

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));
}
Also used : MapResourceServerEntityImpl(org.keycloak.models.map.authorization.entity.MapResourceServerEntityImpl) ModelException(org.keycloak.models.ModelException) ModelDuplicateException(org.keycloak.models.ModelDuplicateException) MapResourceServerEntity(org.keycloak.models.map.authorization.entity.MapResourceServerEntity)

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