Search in sources :

Example 1 with MapPolicyEntity

use of org.keycloak.models.map.authorization.entity.MapPolicyEntity in project keycloak by keycloak.

the class MapPolicyStore method create.

@Override
public Policy create(AbstractPolicyRepresentation representation, ResourceServer resourceServer) {
    LOG.tracef("create(%s, %s, %s)%s", representation.getId(), resourceServer.getId(), resourceServer, getShortStackTrace());
    // @UniqueConstraint(columnNames = {"NAME", "RESOURCE_SERVER_ID"})
    DefaultModelCriteria<Policy> mcb = forResourceServer(resourceServer.getId()).compare(SearchableFields.NAME, Operator.EQ, representation.getName());
    if (tx.getCount(withCriteria(mcb)) > 0) {
        throw new ModelDuplicateException("Policy with name '" + representation.getName() + "' for " + resourceServer.getId() + " already exists");
    }
    String uid = representation.getId();
    MapPolicyEntity entity = new MapPolicyEntityImpl();
    entity.setId(uid);
    entity.setType(representation.getType());
    entity.setName(representation.getName());
    entity.setResourceServerId(resourceServer.getId());
    entity = tx.create(entity);
    return entityToAdapter(entity);
}
Also used : Policy(org.keycloak.authorization.model.Policy) MapPolicyEntityImpl(org.keycloak.models.map.authorization.entity.MapPolicyEntityImpl) ModelDuplicateException(org.keycloak.models.ModelDuplicateException) MapPolicyEntity(org.keycloak.models.map.authorization.entity.MapPolicyEntity)

Aggregations

Policy (org.keycloak.authorization.model.Policy)1 ModelDuplicateException (org.keycloak.models.ModelDuplicateException)1 MapPolicyEntity (org.keycloak.models.map.authorization.entity.MapPolicyEntity)1 MapPolicyEntityImpl (org.keycloak.models.map.authorization.entity.MapPolicyEntityImpl)1