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