Search in sources :

Example 46 with GluuAttribute

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

Example 47 with GluuAttribute

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);
    }
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) HttpEntity(org.apache.http.HttpEntity) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) ParseException(org.apache.http.ParseException) IOException(java.io.IOException) GluuAttribute(org.gluu.model.GluuAttribute) Test(org.junit.Test)

Example 48 with GluuAttribute

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);
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HttpEntity(org.apache.http.HttpEntity) ByteArrayEntity(org.apache.http.entity.ByteArrayEntity) HttpResponse(org.apache.http.HttpResponse) ParseException(org.apache.http.ParseException) IOException(java.io.IOException) GluuAttribute(org.gluu.model.GluuAttribute) Test(org.junit.Test)

Example 49 with GluuAttribute

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);
    }
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) HttpEntity(org.apache.http.HttpEntity) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) ParseException(org.apache.http.ParseException) IOException(java.io.IOException) GluuAttribute(org.gluu.model.GluuAttribute) Test(org.junit.Test)

Example 50 with GluuAttribute

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);
    }
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) HttpEntity(org.apache.http.HttpEntity) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) ParseException(org.apache.http.ParseException) IOException(java.io.IOException) GluuAttribute(org.gluu.model.GluuAttribute) Test(org.junit.Test)

Aggregations

GluuAttribute (org.gluu.model.GluuAttribute)68 ArrayList (java.util.ArrayList)21 GluuCustomAttribute (org.gluu.oxtrust.model.GluuCustomAttribute)10 IOException (java.io.IOException)8 Scope (org.oxauth.persistence.model.Scope)8 HttpEntity (org.apache.http.HttpEntity)7 HttpResponse (org.apache.http.HttpResponse)7 ParseException (org.apache.http.ParseException)7 Test (org.junit.Test)7 HttpGet (org.apache.http.client.methods.HttpGet)6 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)6 Filter (org.gluu.search.filter.Filter)5 JSONObject (org.json.JSONObject)4 Operation (io.swagger.v3.oas.annotations.Operation)3 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 FacesMessage (javax.faces.application.FacesMessage)3 UIInput (javax.faces.component.UIInput)3 AttributeValidation (org.gluu.model.attribute.AttributeValidation)3