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