Search in sources :

Example 26 with Scope

use of org.oxauth.persistence.model.Scope in project oxTrust by GluuFederation.

the class ClientWebResourceTest method getClientScopesTest.

@Test
public void getClientScopesTest() {
    String inum = "800-b526-43a0-b5e5-e39c7a970386";
    HttpUriRequest request = new HttpGet(BASE_URL + ApiConstants.BASE_API_URL + ApiConstants.CLIENTS + "/" + inum + ApiConstants.SCOPES);
    HttpResponse response = handle(request);
    Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
    HttpEntity entity = response.getEntity();
    try {
        Scope[] scopes = mapper.readValue(EntityUtils.toString(entity), Scope[].class);
        Assert.assertNotNull(scopes);
        Assert.assertTrue(scopes.length >= 0);
    } catch (ParseException | IOException e) {
        e.printStackTrace();
        Assert.assertTrue(false);
    }
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) HttpEntity(org.apache.http.HttpEntity) Scope(org.oxauth.persistence.model.Scope) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) ParseException(org.apache.http.ParseException) IOException(java.io.IOException) Test(org.junit.Test)

Example 27 with Scope

use of org.oxauth.persistence.model.Scope 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)

Example 28 with Scope

use of org.oxauth.persistence.model.Scope in project oxTrust by GluuFederation.

the class UmaResourceWebResource method addScopeToUmaResource.

@POST
@Operation(summary = "Add UMA resource scope", description = "add scope to uma resource")
@ApiResponses(value = { @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = UmaResource.class)), description = "Success"), @ApiResponse(responseCode = "500", description = "Server error") })
@Path(ApiConstants.ID_PARAM_PATH + ApiConstants.SCOPES + ApiConstants.INUM_PARAM_PATH)
@ProtectedApi(scopes = { WRITE_ACCESS })
public Response addScopeToUmaResource(@PathParam(ApiConstants.ID) @NotNull String id, @PathParam(ApiConstants.INUM) @NotNull String scopeInum) {
    log(logger, "Add scope " + scopeInum + " to uma resource " + id);
    try {
        Objects.requireNonNull(id, "Uma id should not be null");
        Objects.requireNonNull(scopeInum, "scope inum should not be null");
        List<UmaResource> resources = umaResourcesService.findResourcesById(id);
        Scope umaScope = scopeDescriptionService.getUmaScopeByInum(scopeInum);
        if (resources != null && !resources.isEmpty() && umaScope != null) {
            UmaResource umaResource = resources.get(0);
            List<String> scopesDn = new ArrayList<String>();
            if (umaResource.getScopes() != null) {
                scopesDn.addAll(umaResource.getScopes());
            }
            scopesDn.add(scopeDescriptionService.getDnForScope(scopeInum));
            umaResource.setScopes(scopesDn);
            umaResourcesService.updateResource(umaResource);
            return Response.ok(umaResourcesService.findResourcesById(id).get(0)).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) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 29 with Scope

use of org.oxauth.persistence.model.Scope in project oxTrust by GluuFederation.

the class UpdateClientAction method searchAvailableScopes.

public void searchAvailableScopes() {
    if (this.availableScopes != null) {
        selectAddedScopes();
        return;
    }
    List<SelectableEntity<Scope>> tmpAvailableScopes = new ArrayList<SelectableEntity<Scope>>();
    List<Scope> scopes = new ArrayList<Scope>();
    try {
        scopes = scopeService.getAllScopesList(1000);
    } catch (Exception e) {
        e.printStackTrace();
    }
    for (Scope scope : scopes) {
        tmpAvailableScopes.add(new SelectableEntity<Scope>(scope));
    }
    this.availableScopes = tmpAvailableScopes;
    selectAddedScopes();
}
Also used : Scope(org.oxauth.persistence.model.Scope) SelectableEntity(org.gluu.model.SelectableEntity) ArrayList(java.util.ArrayList) EncryptionException(org.gluu.util.security.StringEncrypter.EncryptionException) BasePersistenceException(org.gluu.persist.exception.BasePersistenceException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) JSONException(org.codehaus.jettison.json.JSONException)

Example 30 with Scope

use of org.oxauth.persistence.model.Scope in project oxTrust by GluuFederation.

the class UpdateScopeAction method add.

public String add() throws Exception {
    if (this.scope != null) {
        return OxTrustConstants.RESULT_SUCCESS;
    }
    this.update = false;
    this.scope = new Scope();
    this.scope.setScopeType(ScopeType.OAUTH);
    try {
        if (this.scope.getOxAuthClaims() != null && this.scope.getOxAuthClaims().size() > 0) {
            this.claims = getClaimDisplayNameEntiries();
        } else {
            this.claims = new ArrayList<DisplayNameEntry>();
        }
    } catch (BasePersistenceException ex) {
        log.error("Failed to load scopes", ex);
        facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to add new scope");
        conversationService.endConversation();
        return OxTrustConstants.RESULT_FAILURE;
    }
    this.dynamicScripts = getInitialDynamicScripts();
    fillAvailableDynScript();
    this.oxAttributesJson = getScopeAttributesJson();
    return OxTrustConstants.RESULT_SUCCESS;
}
Also used : Scope(org.oxauth.persistence.model.Scope) BasePersistenceException(org.gluu.persist.exception.BasePersistenceException) DisplayNameEntry(org.gluu.model.DisplayNameEntry)

Aggregations

Scope (org.oxauth.persistence.model.Scope)63 ArrayList (java.util.ArrayList)15 IOException (java.io.IOException)12 Operation (io.swagger.v3.oas.annotations.Operation)10 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)10 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)9 HttpEntity (org.apache.http.HttpEntity)8 HttpResponse (org.apache.http.HttpResponse)8 ParseException (org.apache.http.ParseException)8 GluuAttribute (org.gluu.model.GluuAttribute)8 Test (org.junit.Test)8 User (org.gluu.oxauth.model.common.User)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 Test (org.testng.annotations.Test)7 BasePersistenceException (org.gluu.persist.exception.BasePersistenceException)5 HttpGet (org.apache.http.client.methods.HttpGet)4 HttpPost (org.apache.http.client.methods.HttpPost)4 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)4 ByteArrayEntity (org.apache.http.entity.ByteArrayEntity)4 Filter (org.gluu.search.filter.Filter)4