use of org.wso2.balana.xacml3.Attributes in project charon by wso2.
the class JSONDecoder method decodeSearchRequestBody.
/*
* decode the raw string and create a search object
* @param scimResourceString
* @return
* @throws BadRequestException
*/
public SearchRequest decodeSearchRequestBody(String scimResourceString, SCIMResourceTypeSchema schema) throws BadRequestException {
FilterTreeManager filterTreeManager = null;
Node rootNode = null;
// decode the string and create search object
try {
JSONObject decodedJsonObj = new JSONObject(new JSONTokener(scimResourceString));
SearchRequest searchRequest = new SearchRequest();
ArrayList<String> attributes = new ArrayList<>();
ArrayList<String> excludedAttributes = new ArrayList<>();
JSONArray attributesValues = (JSONArray) decodedJsonObj.opt(SCIMConstants.OperationalConstants.ATTRIBUTES);
JSONArray excludedAttributesValues = (JSONArray) decodedJsonObj.opt(SCIMConstants.OperationalConstants.EXCLUDED_ATTRIBUTES);
JSONArray schemas = (JSONArray) decodedJsonObj.opt(SCIMConstants.CommonSchemaConstants.SCHEMAS);
if (schemas.length() != 1) {
throw new BadRequestException("Schema is invalid", ResponseCodeConstants.INVALID_VALUE);
}
if (attributesValues != null) {
for (int i = 0; i < attributesValues.length(); i++) {
attributes.add((String) attributesValues.get(i));
}
}
if (excludedAttributesValues != null) {
for (int i = 0; i < excludedAttributesValues.length(); i++) {
excludedAttributes.add((String) excludedAttributesValues.get(i));
}
}
if (decodedJsonObj.opt(SCIMConstants.OperationalConstants.FILTER) != null) {
filterTreeManager = new FilterTreeManager((String) decodedJsonObj.opt(SCIMConstants.OperationalConstants.FILTER), schema);
rootNode = filterTreeManager.buildTree();
}
searchRequest.setAttributes(attributes);
searchRequest.setExcludedAttributes(excludedAttributes);
searchRequest.setSchema((String) schemas.get(0));
searchRequest.setCountStr(decodedJsonObj.optString(SCIMConstants.OperationalConstants.COUNT));
searchRequest.setStartIndexStr(decodedJsonObj.optString(SCIMConstants.OperationalConstants.START_INDEX));
searchRequest.setDomainName(decodedJsonObj.optString(SCIMConstants.OperationalConstants.DOMAIN));
searchRequest.setFilter(rootNode);
if (!decodedJsonObj.optString(SCIMConstants.OperationalConstants.SORT_BY).equals("")) {
searchRequest.setSortBy(decodedJsonObj.optString(SCIMConstants.OperationalConstants.SORT_BY));
}
if (!decodedJsonObj.optString(SCIMConstants.OperationalConstants.SORT_ORDER).equals("")) {
searchRequest.setSortOder(decodedJsonObj.optString(SCIMConstants.OperationalConstants.SORT_ORDER));
}
return searchRequest;
} catch (JSONException | IOException e) {
logger.error("Error while decoding the resource string");
throw new BadRequestException(ResponseCodeConstants.INVALID_SYNTAX);
}
}
use of org.wso2.balana.xacml3.Attributes in project charon by wso2.
the class GroupResourceManagerTest method testCreateGroupNotImplementedException.
@Test(dataProvider = "dataForTestCreateGroupNotImplementedException")
public void testCreateGroupNotImplementedException(String scimObjectString, String attributes, String excludeAttributes) throws ConflictException, NotImplementedException, BadRequestException, CharonException {
abstractResourceManager.when(() -> AbstractResourceManager.getResourceEndpointURL(SCIMConstants.USER_ENDPOINT)).thenReturn(SCIM2_GROUP_ENDPOINT);
abstractResourceManager.when(() -> AbstractResourceManager.encodeSCIMException(any(NotImplementedException.class))).thenReturn(getEncodeSCIMExceptionObject(new NotImplementedException()));
Mockito.when(userManager.createGroup(any(Group.class), anyMap())).thenThrow(NotImplementedException.class);
SCIMResponse scimResponse = groupResourceManager.create(scimObjectString, userManager, attributes, excludeAttributes);
Assert.assertEquals(scimResponse.getResponseStatus(), ResponseCodeConstants.CODE_NOT_IMPLEMENTED);
}
use of org.wso2.balana.xacml3.Attributes in project charon by wso2.
the class GroupResourceManagerTest method testListWithGET.
@Test(dataProvider = "dataForListWithGET")
public void testListWithGET(String filter, Integer startIndexInt, Integer countInt, String sortBy, String sortOrder, String domainName, String attributes, String excludeAttributes) {
SCIMResponse scimResponse = groupResourceManager.listWithGET(userManager, filter, startIndexInt, countInt, sortBy, sortOrder, domainName, attributes, excludeAttributes);
Assert.assertEquals(scimResponse.getResponseStatus(), ResponseCodeConstants.CODE_OK);
}
use of org.wso2.balana.xacml3.Attributes in project charon by wso2.
the class GroupResourceManagerTest method testUpdateGroupWithPUTProvidedUserManagerHandlerIsNull.
@Test(dataProvider = "dataForTestUpdateGroupWithPUTProvidedUserManagerHandlerIsNull")
public void testUpdateGroupWithPUTProvidedUserManagerHandlerIsNull(String id, String scimObjectString, String attributes, String excludeAttributes, Object scimNewGroupObject, Object scimOldGroupObject) throws BadRequestException, CharonException, NotImplementedException, NotFoundException {
Group groupNew = (Group) scimNewGroupObject;
Group groupOld = (Group) scimOldGroupObject;
SCIMResourceTypeSchema schema = SCIMResourceSchemaManager.getInstance().getGroupResourceSchema();
abstractResourceManager.when(() -> AbstractResourceManager.getResourceEndpointURL(SCIMConstants.USER_ENDPOINT)).thenReturn(SCIM2_GROUP_ENDPOINT + "/" + GROUP_ID);
abstractResourceManager.when(() -> AbstractResourceManager.encodeSCIMException(any(InternalErrorException.class))).thenReturn(getEncodeSCIMExceptionObject(new InternalErrorException()));
Mockito.when(userManager.getGroup(id, ResourceManagerUtil.getAllAttributeURIs(schema))).thenReturn(groupOld);
Group validatedGroup = (Group) ServerSideValidator.validateUpdatedSCIMObject(groupOld, groupNew, schema);
Mockito.when(userManager.updateGroup(any(Group.class), any(Group.class), anyMap())).thenReturn(validatedGroup);
SCIMResponse scimResponse = groupResourceManager.updateWithPUT(id, scimObjectString, null, attributes, excludeAttributes);
Assert.assertEquals(scimResponse.getResponseStatus(), ResponseCodeConstants.CODE_INTERNAL_ERROR);
}
use of org.wso2.balana.xacml3.Attributes in project charon by wso2.
the class GroupResourceManagerTest method testUpdateGroupWithPUTNoUserExistsWithTheGivenUserName.
@Test(dataProvider = "dataForTestUpdateGroupWithPUTNotFoundException")
public void testUpdateGroupWithPUTNoUserExistsWithTheGivenUserName(String id, String scimObjectString, String attributes, String excludeAttributes, Object scimNewGroupObject, Object scimOldGroupObject) throws BadRequestException, CharonException, NotImplementedException, NotFoundException {
Group groupNew = (Group) scimNewGroupObject;
Group groupOld = (Group) scimOldGroupObject;
SCIMResourceTypeSchema schema = SCIMResourceSchemaManager.getInstance().getGroupResourceSchema();
abstractResourceManager.when(() -> AbstractResourceManager.getResourceEndpointURL(SCIMConstants.USER_ENDPOINT)).thenReturn(SCIM2_GROUP_ENDPOINT + "/" + GROUP_ID);
abstractResourceManager.when(() -> AbstractResourceManager.encodeSCIMException(any(NotFoundException.class))).thenReturn(getEncodeSCIMExceptionObject(new NotFoundException()));
Mockito.when(userManager.getGroup(id, ResourceManagerUtil.getAllAttributeURIs(schema))).thenReturn(null);
Group validatedGroup = (Group) ServerSideValidator.validateUpdatedSCIMObject(groupOld, groupNew, schema);
Mockito.when(userManager.updateGroup(any(Group.class), any(Group.class), anyMap())).thenReturn(validatedGroup);
SCIMResponse scimResponse = groupResourceManager.updateWithPUT(id, scimObjectString, userManager, attributes, excludeAttributes);
Assert.assertEquals(scimResponse.getResponseStatus(), ResponseCodeConstants.CODE_RESOURCE_NOT_FOUND);
}
Aggregations