Search in sources :

Example 1 with MapPermissionTicketEntityImpl

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

the class MapPermissionTicketStore method create.

@Override
public PermissionTicket create(String resourceId, String scopeId, String requester, ResourceServer resourceServer) {
    LOG.tracef("create(%s, %s, %s, %s)%s", resourceId, scopeId, requester, resourceServer, getShortStackTrace());
    String owner = authorizationProvider.getStoreFactory().getResourceStore().findById(resourceId, resourceServer.getId()).getOwner();
    // @UniqueConstraint(columnNames = {"OWNER", "REQUESTER", "RESOURCE_SERVER_ID", "RESOURCE_ID", "SCOPE_ID"})
    DefaultModelCriteria<PermissionTicket> mcb = forResourceServer(resourceServer.getId()).compare(SearchableFields.OWNER, Operator.EQ, owner).compare(SearchableFields.RESOURCE_ID, Operator.EQ, resourceId).compare(SearchableFields.REQUESTER, Operator.EQ, requester);
    if (scopeId != null) {
        mcb = mcb.compare(SearchableFields.SCOPE_ID, Operator.EQ, scopeId);
    }
    if (tx.getCount(withCriteria(mcb)) > 0) {
        throw new ModelDuplicateException("Permission ticket for resource server: '" + resourceServer.getId() + ", Resource: " + resourceId + ", owner: " + owner + ", scopeId: " + scopeId + " already exists.");
    }
    MapPermissionTicketEntity entity = new MapPermissionTicketEntityImpl();
    entity.setResourceId(resourceId);
    entity.setRequester(requester);
    entity.setCreatedTimestamp(System.currentTimeMillis());
    if (scopeId != null) {
        entity.setScopeId(scopeId);
    }
    entity.setOwner(owner);
    entity.setResourceServerId(resourceServer.getId());
    entity = tx.create(entity);
    return entityToAdapter(entity);
}
Also used : PermissionTicket(org.keycloak.authorization.model.PermissionTicket) ModelDuplicateException(org.keycloak.models.ModelDuplicateException) MapPermissionTicketEntityImpl(org.keycloak.models.map.authorization.entity.MapPermissionTicketEntityImpl) MapPermissionTicketEntity(org.keycloak.models.map.authorization.entity.MapPermissionTicketEntity)

Aggregations

PermissionTicket (org.keycloak.authorization.model.PermissionTicket)1 ModelDuplicateException (org.keycloak.models.ModelDuplicateException)1 MapPermissionTicketEntity (org.keycloak.models.map.authorization.entity.MapPermissionTicketEntity)1 MapPermissionTicketEntityImpl (org.keycloak.models.map.authorization.entity.MapPermissionTicketEntityImpl)1