use of org.gluu.model.GluuAttribute in project oxTrust by GluuFederation.
the class ScopeWebResource method getScopeClaims.
@GET
@Path(ApiConstants.INUM_PARAM_PATH + ApiConstants.CLAIMS)
@Operation(summary = "Get scope claims", description = "List all claims of a scope")
@ApiResponses(value = { @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = GluuAttribute[].class)), description = "Success"), @ApiResponse(responseCode = "500", description = "Server error") })
@ProtectedApi(scopes = { WRITE_ACCESS })
public Response getScopeClaims(@PathParam(ApiConstants.INUM) @NotNull String inum) {
log(logger, "List all claims of scope ==> " + inum);
try {
Objects.requireNonNull(inum, "inum should not be null");
Scope oxAuthScope = scopeService.getScopeByInum(inum);
List<String> claimsDn = new ArrayList<String>();
List<GluuAttribute> attributes = new ArrayList<GluuAttribute>();
if (oxAuthScope != null) {
claimsDn.addAll(oxAuthScope.getOxAuthClaims());
for (String claimDn : claimsDn) {
attributes.add(attributeService.getAttributeByDn(claimDn));
}
return Response.ok(attributes).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.gluu.model.GluuAttribute in project oxTrust by GluuFederation.
the class AttributeWebResourceTest method getAllAttributesTest.
@Test
public void getAllAttributesTest() {
HttpUriRequest request = new HttpGet(BASE_URL + ApiConstants.BASE_API_URL + ApiConstants.ATTRIBUTES);
HttpResponse response = handle(request);
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
HttpEntity entity = response.getEntity();
try {
String content = EntityUtils.toString(entity);
GluuAttribute[] gluuAttributes = mapper.readValue(content, GluuAttribute[].class);
Assert.assertTrue(gluuAttributes.length > 10);
} catch (ParseException | IOException e) {
e.printStackTrace();
Assert.assertTrue(false);
}
}
use of org.gluu.model.GluuAttribute in project oxTrust by GluuFederation.
the class AttributeWebResourceTest method createAttributeTest.
@Test
public void createAttributeTest() {
mapper.setSerializationInclusion(Include.NON_NULL);
mapper.setSerializationInclusion(Include.NON_EMPTY);
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
String name = "customTest";
GluuAttribute attribute = getGluuAtrribute(name);
HttpPost request = new HttpPost(BASE_URL + ApiConstants.BASE_API_URL + ApiConstants.ATTRIBUTES);
try {
String json = mapper.writeValueAsString(attribute);
HttpEntity entity = new ByteArrayEntity(json.toString().getBytes("UTF-8"), ContentType.APPLICATION_FORM_URLENCODED);
request.setEntity(entity);
request.setHeader("Content-Type", MediaType.APPLICATION_JSON);
HttpResponse response = handle(request);
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
HttpEntity result = response.getEntity();
GluuAttribute gluuAttribute = mapper.readValue(EntityUtils.toString(result), GluuAttribute.class);
Assert.assertEquals(gluuAttribute.getName(), name);
Assert.assertEquals(gluuAttribute.getDisplayName(), name);
} catch (ParseException | IOException e) {
e.printStackTrace();
Assert.assertTrue(false);
}
}
use of org.gluu.model.GluuAttribute in project oxTrust by GluuFederation.
the class AttributeWebResourceTest method getActiveAttributesTest.
@Test
public void getActiveAttributesTest() {
HttpUriRequest request = new HttpGet(BASE_URL + ApiConstants.BASE_API_URL + ApiConstants.ATTRIBUTES + ApiConstants.ACTIVE);
HttpResponse response = handle(request);
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
HttpEntity entity = response.getEntity();
try {
String content = EntityUtils.toString(entity);
GluuAttribute[] gluuAttributes = mapper.readValue(content, GluuAttribute[].class);
Assert.assertTrue(gluuAttributes.length > 10);
for (GluuAttribute gluuAttribute : gluuAttributes) {
Assert.assertTrue(gluuAttribute.getStatus().getValue().equalsIgnoreCase("active"));
}
} catch (ParseException | IOException e) {
e.printStackTrace();
Assert.assertTrue(false);
}
}
use of org.gluu.model.GluuAttribute in project oxTrust by GluuFederation.
the class AttributeWebResourceTest method getAttributeByInumTest.
@Test
public void getAttributeByInumTest() {
String inum = "CAE3";
HttpUriRequest request = new HttpGet(BASE_URL + ApiConstants.BASE_API_URL + ApiConstants.ATTRIBUTES + "/" + inum);
HttpResponse response = handle(request);
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
HttpEntity entity = response.getEntity();
try {
String content = EntityUtils.toString(entity);
System.out.println("Content:" + content);
GluuAttribute gluuAttribute = mapper.readValue(content, GluuAttribute.class);
Assert.assertNotNull(gluuAttribute);
Assert.assertTrue(gluuAttribute.getInum().equalsIgnoreCase(inum));
System.out.println("Name:" + gluuAttribute.getDisplayName());
} catch (ParseException | IOException e) {
e.printStackTrace();
Assert.assertTrue(false);
}
}
Aggregations