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