Search in sources :

Example 1 with OxAuthSectorIdentifier

use of org.gluu.oxtrust.model.OxAuthSectorIdentifier in project oxTrust by GluuFederation.

the class SectorIdentifierService method generateIdForNewSectorIdentifier.

/**
 * Generate new oxId for sector identifier
 *
 * @return New oxId for sector identifier
 * @throws Exception
 */
public String generateIdForNewSectorIdentifier() {
    OxAuthSectorIdentifier sectorIdentifier = new OxAuthSectorIdentifier();
    String newId = null;
    do {
        newId = generateIdForNewSectorIdentifierImpl();
        String newDn = getDnForSectorIdentifier(newId);
        sectorIdentifier.setDn(newDn);
    } while (ldapEntryManager.contains(sectorIdentifier));
    return newId;
}
Also used : OxAuthSectorIdentifier(org.gluu.oxtrust.model.OxAuthSectorIdentifier)

Example 2 with OxAuthSectorIdentifier

use of org.gluu.oxtrust.model.OxAuthSectorIdentifier in project oxTrust by GluuFederation.

the class SectorIdentifierService method searchSectorIdentifiers.

/**
 * Search sector identifiers by pattern
 *
 * @param pattern   Pattern
 * @param sizeLimit Maximum count of results
 * @return List of sector identifiers
 */
public List<OxAuthSectorIdentifier> searchSectorIdentifiers(String pattern, int sizeLimit) {
    String[] targetArray = new String[] { pattern };
    Filter searchFilter = Filter.createSubstringFilter(OxTrustConstants.oxId, null, targetArray, null);
    List<OxAuthSectorIdentifier> result = ldapEntryManager.findEntries(getDnForSectorIdentifier(null), OxAuthSectorIdentifier.class, searchFilter, sizeLimit);
    return result;
}
Also used : OxAuthSectorIdentifier(org.gluu.oxtrust.model.OxAuthSectorIdentifier) Filter(org.gluu.search.filter.Filter)

Example 3 with OxAuthSectorIdentifier

use of org.gluu.oxtrust.model.OxAuthSectorIdentifier in project oxTrust by GluuFederation.

the class SectorIdentifierWebResourceTest method createSectorIdentifierTest.

@Test
public void createSectorIdentifierTest() {
    String name = "ApiSector";
    OxAuthSectorIdentifier sector = getSector(name);
    HttpPost request = new HttpPost(BASE_URL + ApiConstants.BASE_API_URL + ApiConstants.SECTORS);
    try {
        String json = mapper.writeValueAsString(sector);
        HttpEntity entity = new ByteArrayEntity(json.toString().getBytes("UTF-8"), ContentType.APPLICATION_FORM_URLENCODED);
        request.setEntity(entity);
        String CONTENT_TYPE = "Content-Type";
        request.setHeader(CONTENT_TYPE, MediaType.APPLICATION_JSON);
        HttpResponse response = handle(request);
        Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
        HttpEntity result = response.getEntity();
        OxAuthSectorIdentifier mySector = mapper.readValue(EntityUtils.toString(result), OxAuthSectorIdentifier.class);
        Assert.assertNotNull(mySector);
        Assert.assertEquals(mySector.getDescription(), name);
    } catch (ParseException | IOException e) {
        e.printStackTrace();
        Assert.assertTrue(false);
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) OxAuthSectorIdentifier(org.gluu.oxtrust.model.OxAuthSectorIdentifier) 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) Test(org.junit.Test)

Example 4 with OxAuthSectorIdentifier

use of org.gluu.oxtrust.model.OxAuthSectorIdentifier in project oxTrust by GluuFederation.

the class SectorIdentifierWebResourceTest method getAllSectorIdentifiersTest.

@Test
public void getAllSectorIdentifiersTest() {
    HttpUriRequest request = new HttpGet(BASE_URL + ApiConstants.BASE_API_URL + ApiConstants.SECTORS);
    HttpResponse response = handle(request);
    Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
    HttpEntity entity = response.getEntity();
    try {
        OxAuthSectorIdentifier[] sectors = mapper.readValue(EntityUtils.toString(entity), OxAuthSectorIdentifier[].class);
        Assert.assertNotNull(sectors);
        Assert.assertTrue(sectors.length >= 0);
    } catch (ParseException | IOException e) {
        e.printStackTrace();
        Assert.assertTrue(false);
    }
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) OxAuthSectorIdentifier(org.gluu.oxtrust.model.OxAuthSectorIdentifier) 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) Test(org.junit.Test)

Example 5 with OxAuthSectorIdentifier

use of org.gluu.oxtrust.model.OxAuthSectorIdentifier in project oxTrust by GluuFederation.

the class SectorIdentifierWebResourceTest method updateUmaResourceTest.

@Test
public void updateUmaResourceTest() {
    String name = "ApiSectorUpdate";
    OxAuthSectorIdentifier scope = getSector(name);
    HttpPost request = new HttpPost(BASE_URL + ApiConstants.BASE_API_URL + ApiConstants.SECTORS);
    try {
        String json = mapper.writeValueAsString(scope);
        HttpEntity entity = new ByteArrayEntity(json.toString().getBytes("UTF-8"), ContentType.APPLICATION_FORM_URLENCODED);
        request.setEntity(entity);
        String CONTENT_TYPE = "Content-Type";
        request.setHeader(CONTENT_TYPE, MediaType.APPLICATION_JSON);
        HttpResponse response = handle(request);
        Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
        HttpEntity result = response.getEntity();
        OxAuthSectorIdentifier mySector = mapper.readValue(EntityUtils.toString(result), OxAuthSectorIdentifier.class);
        Assert.assertEquals(mySector.getDescription(), name);
        mySector.setDescription(mySector.getDescription() + " Updated");
        HttpPut second = new HttpPut(BASE_URL + ApiConstants.BASE_API_URL + ApiConstants.SECTORS);
        json = mapper.writeValueAsString(mySector);
        entity = new ByteArrayEntity(json.toString().getBytes("UTF-8"), ContentType.APPLICATION_FORM_URLENCODED);
        second.setEntity(entity);
        second.setHeader(CONTENT_TYPE, MediaType.APPLICATION_JSON);
        response = handle(second);
        Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
    } catch (ParseException | IOException e) {
        e.printStackTrace();
        Assert.assertTrue(false);
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) OxAuthSectorIdentifier(org.gluu.oxtrust.model.OxAuthSectorIdentifier) 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) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Aggregations

OxAuthSectorIdentifier (org.gluu.oxtrust.model.OxAuthSectorIdentifier)11 IOException (java.io.IOException)4 HttpEntity (org.apache.http.HttpEntity)4 HttpResponse (org.apache.http.HttpResponse)4 ParseException (org.apache.http.ParseException)4 Test (org.junit.Test)4 HttpGet (org.apache.http.client.methods.HttpGet)2 HttpPost (org.apache.http.client.methods.HttpPost)2 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)2 ByteArrayEntity (org.apache.http.entity.ByteArrayEntity)2 Filter (org.gluu.search.filter.Filter)2 HttpPut (org.apache.http.client.methods.HttpPut)1 BaseMappingException (org.gluu.persist.exception.mapping.BaseMappingException)1