use of org.gluu.oxauth.model.uma.persistence.UmaResource in project oxAuth by GluuFederation.
the class UmaValidationService method validatePermission.
public void validatePermission(org.gluu.oxauth.model.uma.UmaPermission permission, Client client) {
String resourceId = permission.getResourceId();
if (StringHelper.isEmpty(resourceId)) {
log.error("Resource id is empty");
throw errorResponseFactory.createWebApplicationException(BAD_REQUEST, INVALID_RESOURCE_ID, "Resource id is empty");
}
try {
UmaResource resource = resourceService.getResourceById(resourceId);
if (resource == null) {
log.error("Resource isn't registered or there are two resources with same Id");
throw errorResponseFactory.createWebApplicationException(BAD_REQUEST, INVALID_RESOURCE_ID, "Resource is not registered.");
}
for (String s : permission.getScopes()) {
if (resource.getScopes().contains(s)) {
continue;
}
final Scope spontaneousScope = umaScopeService.getOrCreate(client, s, Sets.newHashSet(umaScopeService.getScopeIdsByDns(resource.getScopes())));
if (spontaneousScope == null) {
log.error("Scope isn't registered and is not allowed by spontaneous scopes. Scope: " + s);
throw errorResponseFactory.createWebApplicationException(BAD_REQUEST, INVALID_SCOPE, "At least one of the scopes isn't registered");
}
}
return;
} catch (EntryPersistenceException ex) {
log.error(ex.getMessage(), ex);
}
log.error("Resource isn't registered");
throw errorResponseFactory.createWebApplicationException(BAD_REQUEST, INVALID_RESOURCE_ID, "Resource isn't registered");
}
use of org.gluu.oxauth.model.uma.persistence.UmaResource in project oxTrust by GluuFederation.
the class ResourceSetService method findResources.
/**
* Search resources by pattern
*
* @param pattern
* Pattern
* @param sizeLimit
* Maximum count of results
* @return List of resources
*/
public List<UmaResource> findResources(String pattern, int sizeLimit) {
String[] targetArray = new String[] { pattern };
Filter oxIdFilter = Filter.createSubstringFilter("oxId", null, targetArray, null);
Filter displayNameFilter = Filter.createSubstringFilter(OxTrustConstants.displayName, null, targetArray, null);
Filter searchFilter = Filter.createORFilter(oxIdFilter, displayNameFilter);
List<UmaResource> result = persistenceEntryManager.findEntries(getDnForResource(null), UmaResource.class, searchFilter, sizeLimit);
return result;
}
use of org.gluu.oxauth.model.uma.persistence.UmaResource in project oxTrust by GluuFederation.
the class UpdateUmaScopeAction method update.
public String update() {
this.update = true;
if (this.umaScope != null) {
this.oxAttributesJson = getScopeAttributesJson();
return OxTrustConstants.RESULT_SUCCESS;
}
try {
String scopeDn = scopeDescriptionService.getDnForScope(this.scopeInum);
this.umaScope = scopeDescriptionService.getUmaScopeByDn(scopeDn);
this.oxAttributesJson = getScopeAttributesJson();
this.authorizationPolicies = getInitialAuthorizationPolicies();
List<UmaResource> umaResourceList = resourceSetService.findResourcesByScope(scopeDn);
if (umaResourceList != null) {
for (UmaResource umaResource : umaResourceList) {
List<String> list = umaResource.getClients();
if (list != null) {
clientList = new ArrayList<OxAuthClient>();
for (String clientDn : list) {
OxAuthClient oxAuthClient = clientService.getClientByDn(clientDn);
if (oxAuthClient != null) {
clientList.add(oxAuthClient);
}
}
}
}
}
} catch (BasePersistenceException ex) {
log.error("Failed to find scope description '{}'", this.scopeInum, ex);
conversationService.endConversation();
return OxTrustConstants.RESULT_FAILURE;
}
if (this.umaScope == null) {
log.error("Scope description is null");
conversationService.endConversation();
return OxTrustConstants.RESULT_FAILURE;
}
return OxTrustConstants.RESULT_SUCCESS;
}
use of org.gluu.oxauth.model.uma.persistence.UmaResource in project oxTrust by GluuFederation.
the class UpdateResourceAction method add.
private String add() {
this.resource = new UmaResource();
this.scopes = new ArrayList<DisplayNameEntry>();
this.clients = new ArrayList<DisplayNameEntry>();
this.clientList = new ArrayList<OxAuthClient>();
this.resources = new ArrayList<String>();
return OxTrustConstants.RESULT_SUCCESS;
}
use of org.gluu.oxauth.model.uma.persistence.UmaResource in project oxTrust by GluuFederation.
the class UmaResourceWebResource method getUmaResourceScopes.
@GET
@Path(ApiConstants.ID_PARAM_PATH + ApiConstants.SCOPES)
@Operation(summary = "Get UMA resource scopes", description = "Get scopes of uma resource")
@ProtectedApi(scopes = { READ_ACCESS })
public Response getUmaResourceScopes(@PathParam(ApiConstants.ID) @NotNull String id) {
try {
log(logger, "Get scopes of uma resource having id " + id);
Objects.requireNonNull(id, "id should not be null");
List<UmaResource> resources = umaResourcesService.findResourcesById(id);
if (resources != null && !resources.isEmpty()) {
UmaResource resource = resources.get(0);
List<String> scopesDn = resource.getScopes();
List<Scope> scopes = new ArrayList<Scope>();
if (scopesDn != null) {
for (String scopeDn : scopesDn) {
scopes.add(scopeDescriptionService.getUmaScopeByDn(scopeDn));
}
}
return Response.ok(scopes).build();
} else {
return Response.status(Response.Status.NOT_FOUND).build();
}
} catch (Exception e) {
log(logger, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
}
Aggregations