Search in sources :

Example 96 with Attributes

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);
    }
}
Also used : SearchRequest(org.wso2.charon3.core.utils.codeutils.SearchRequest) Node(org.wso2.charon3.core.utils.codeutils.Node) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) IOException(java.io.IOException) FilterTreeManager(org.wso2.charon3.core.utils.codeutils.FilterTreeManager) JSONTokener(org.json.JSONTokener) JSONObject(org.json.JSONObject) BadRequestException(org.wso2.charon3.core.exceptions.BadRequestException)

Example 97 with Attributes

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);
}
Also used : Group(org.wso2.charon3.core.objects.Group) NotImplementedException(org.wso2.charon3.core.exceptions.NotImplementedException) SCIMResponse(org.wso2.charon3.core.protocol.SCIMResponse) Test(org.testng.annotations.Test)

Example 98 with Attributes

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);
}
Also used : SCIMResponse(org.wso2.charon3.core.protocol.SCIMResponse) Test(org.testng.annotations.Test)

Example 99 with Attributes

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);
}
Also used : Group(org.wso2.charon3.core.objects.Group) SCIMResourceTypeSchema(org.wso2.charon3.core.schema.SCIMResourceTypeSchema) InternalErrorException(org.wso2.charon3.core.exceptions.InternalErrorException) SCIMResponse(org.wso2.charon3.core.protocol.SCIMResponse) Test(org.testng.annotations.Test)

Example 100 with Attributes

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);
}
Also used : Group(org.wso2.charon3.core.objects.Group) NotFoundException(org.wso2.charon3.core.exceptions.NotFoundException) SCIMResourceTypeSchema(org.wso2.charon3.core.schema.SCIMResourceTypeSchema) SCIMResponse(org.wso2.charon3.core.protocol.SCIMResponse) Test(org.testng.annotations.Test)

Aggregations

ArrayList (java.util.ArrayList)111 HashMap (java.util.HashMap)111 Test (org.testng.annotations.Test)106 SCIMResponse (org.wso2.charon3.core.protocol.SCIMResponse)83 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)76 SCIMResourceTypeSchema (org.wso2.charon3.core.schema.SCIMResourceTypeSchema)64 Map (java.util.Map)56 CharonException (org.wso2.charon3.core.exceptions.CharonException)54 User (org.wso2.charon3.core.objects.User)53 ComplexAttribute (org.wso2.charon3.core.attributes.ComplexAttribute)43 MultiValuedAttribute (org.wso2.charon3.core.attributes.MultiValuedAttribute)39 SimpleAttribute (org.wso2.charon3.core.attributes.SimpleAttribute)39 List (java.util.List)35 Group (org.wso2.charon3.core.objects.Group)33 JSONObject (org.json.JSONObject)32 Attribute (org.wso2.charon3.core.attributes.Attribute)32 InternalErrorException (org.wso2.charon3.core.exceptions.InternalErrorException)32 NotFoundException (org.wso2.charon3.core.exceptions.NotFoundException)30 UserStoreException (org.wso2.carbon.user.api.UserStoreException)27 NotImplementedException (org.wso2.charon3.core.exceptions.NotImplementedException)26