Search in sources :

Example 1 with UmaResource

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");
}
Also used : Scope(org.oxauth.persistence.model.Scope) EntryPersistenceException(org.gluu.persist.exception.EntryPersistenceException) UmaResource(org.gluu.oxauth.model.uma.persistence.UmaResource)

Example 2 with UmaResource

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;
}
Also used : Filter(org.gluu.search.filter.Filter) UmaResource(org.gluu.oxauth.model.uma.persistence.UmaResource)

Example 3 with UmaResource

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;
}
Also used : BasePersistenceException(org.gluu.persist.exception.BasePersistenceException) OxAuthClient(org.gluu.oxtrust.model.OxAuthClient) UmaResource(org.gluu.oxauth.model.uma.persistence.UmaResource)

Example 4 with UmaResource

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;
}
Also used : OxAuthClient(org.gluu.oxtrust.model.OxAuthClient) DisplayNameEntry(org.gluu.model.DisplayNameEntry) UmaResource(org.gluu.oxauth.model.uma.persistence.UmaResource)

Example 5 with UmaResource

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();
    }
}
Also used : Scope(org.oxauth.persistence.model.Scope) ArrayList(java.util.ArrayList) UmaResource(org.gluu.oxauth.model.uma.persistence.UmaResource) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi) Operation(io.swagger.v3.oas.annotations.Operation)

Aggregations

UmaResource (org.gluu.oxauth.model.uma.persistence.UmaResource)13 Operation (io.swagger.v3.oas.annotations.Operation)6 ArrayList (java.util.ArrayList)6 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)6 OxAuthClient (org.gluu.oxtrust.model.OxAuthClient)5 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)4 Scope (org.oxauth.persistence.model.Scope)4 BaseComponentTest (org.gluu.oxauth.BaseComponentTest)2 Client (org.gluu.oxauth.model.registration.Client)2 Test (org.testng.annotations.Test)2 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 DisplayNameEntry (org.gluu.model.DisplayNameEntry)1 BasePersistenceException (org.gluu.persist.exception.BasePersistenceException)1 EntryPersistenceException (org.gluu.persist.exception.EntryPersistenceException)1 Filter (org.gluu.search.filter.Filter)1