Search in sources :

Example 1 with MapResourceEntity

use of org.keycloak.models.map.authorization.entity.MapResourceEntity 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)

Aggregations

Resource (org.keycloak.authorization.model.Resource)1 ModelDuplicateException (org.keycloak.models.ModelDuplicateException)1 MapResourceEntity (org.keycloak.models.map.authorization.entity.MapResourceEntity)1 MapResourceEntityImpl (org.keycloak.models.map.authorization.entity.MapResourceEntityImpl)1