Search in sources :

Example 81 with BadRequestException

use of org.wso2.charon3.core.exceptions.BadRequestException in project charon by wso2.

the class User method setSimpleAttribute.

/*
     * set simple attribute in the scim object
     * @param attributeName
     * @param attributeSchema
     * @param value
     * @throws CharonException
     * @throws BadRequestException
     */
private void setSimpleAttribute(String attributeName, AttributeSchema attributeSchema, Object value) throws CharonException, BadRequestException {
    if (this.isAttributeExist(attributeName)) {
        ((SimpleAttribute) this.attributeList.get(attributeName)).updateValue(value);
    } else {
        SimpleAttribute simpleAttribute = new SimpleAttribute(attributeName, value);
        simpleAttribute = (SimpleAttribute) DefaultAttributeFactory.createAttribute(attributeSchema, simpleAttribute);
        this.attributeList.put(attributeName, simpleAttribute);
    }
}
Also used : SimpleAttribute(org.wso2.charon3.core.attributes.SimpleAttribute)

Example 82 with BadRequestException

use of org.wso2.charon3.core.exceptions.BadRequestException in project charon by wso2.

the class User method setGroup.

/*
     * set the associated groups of the user
     * @param type
     * @param value
     * @param display
     * @throws CharonException
     * @throws BadRequestException
     */
public void setGroup(String type, String value, String display) throws CharonException, BadRequestException {
    SimpleAttribute typeSimpleAttribute = null;
    SimpleAttribute valueSimpleAttribute = null;
    SimpleAttribute displaySimpleAttribute = null;
    ComplexAttribute complexAttribute = new ComplexAttribute();
    if (type != null) {
        typeSimpleAttribute = new SimpleAttribute(SCIMConstants.CommonSchemaConstants.TYPE, type);
        typeSimpleAttribute = (SimpleAttribute) DefaultAttributeFactory.createAttribute(SCIMSchemaDefinitions.SCIMUserSchemaDefinition.GROUP_TYPE, typeSimpleAttribute);
        complexAttribute.setSubAttribute(typeSimpleAttribute);
    }
    if (value != null) {
        valueSimpleAttribute = new SimpleAttribute(SCIMConstants.CommonSchemaConstants.VALUE, value);
        valueSimpleAttribute = (SimpleAttribute) DefaultAttributeFactory.createAttribute(SCIMSchemaDefinitions.SCIMUserSchemaDefinition.GROUP_VALUE, valueSimpleAttribute);
        complexAttribute.setSubAttribute(valueSimpleAttribute);
    }
    if (display != null) {
        displaySimpleAttribute = new SimpleAttribute(SCIMConstants.CommonSchemaConstants.DISPLAY, display);
        displaySimpleAttribute = (SimpleAttribute) DefaultAttributeFactory.createAttribute(SCIMSchemaDefinitions.SCIMUserSchemaDefinition.GROUP_DISPLAY, displaySimpleAttribute);
        complexAttribute.setSubAttribute(displaySimpleAttribute);
    }
    if (complexAttribute.getSubAttributesList().size() != 0) {
        Object typeVal = SCIMConstants.DEFAULT;
        Object valueVal = SCIMConstants.DEFAULT;
        if (typeSimpleAttribute != null && typeSimpleAttribute.getValue() != null) {
            typeVal = typeSimpleAttribute.getValue();
        }
        if (valueSimpleAttribute != null && valueSimpleAttribute.getValue() != null) {
            valueVal = valueSimpleAttribute.getValue();
        }
        String complexAttributeName = SCIMConstants.UserSchemaConstants.GROUPS + "_" + valueVal + "_" + typeVal;
        complexAttribute.setName(complexAttributeName);
        DefaultAttributeFactory.createAttribute(SCIMSchemaDefinitions.SCIMUserSchemaDefinition.GROUPS, complexAttribute);
        setGroup(complexAttribute);
    }
}
Also used : SimpleAttribute(org.wso2.charon3.core.attributes.SimpleAttribute) ComplexAttribute(org.wso2.charon3.core.attributes.ComplexAttribute)

Example 83 with BadRequestException

use of org.wso2.charon3.core.exceptions.BadRequestException in project charon by wso2.

the class User method setGroup.

private void setGroup(ComplexAttribute groupPropertiesAttribute) throws CharonException, BadRequestException {
    MultiValuedAttribute groupsAttribute;
    if (this.attributeList.containsKey(SCIMConstants.UserSchemaConstants.GROUPS)) {
        groupsAttribute = (MultiValuedAttribute) this.attributeList.get(SCIMConstants.UserSchemaConstants.GROUPS);
        groupsAttribute.setAttributeValue(groupPropertiesAttribute);
    } else {
        groupsAttribute = new MultiValuedAttribute(SCIMConstants.UserSchemaConstants.GROUPS);
        groupsAttribute.setAttributeValue(groupPropertiesAttribute);
        groupsAttribute = (MultiValuedAttribute) DefaultAttributeFactory.createAttribute(SCIMSchemaDefinitions.SCIMUserSchemaDefinition.GROUPS, groupsAttribute);
        this.attributeList.put(SCIMConstants.UserSchemaConstants.GROUPS, groupsAttribute);
    }
}
Also used : MultiValuedAttribute(org.wso2.charon3.core.attributes.MultiValuedAttribute)

Example 84 with BadRequestException

use of org.wso2.charon3.core.exceptions.BadRequestException in project charon by wso2.

the class BulkRequestProcessor method getBulkResponseContent.

private BulkResponseContent getBulkResponseContent(BulkRequestContent bulkRequestContent, ResourceManager resourceManager) throws BadRequestException {
    BulkResponseContent bulkResponseContent = null;
    SCIMResponse response;
    if (bulkRequestContent.getMethod().equals(SCIMConstants.OperationalConstants.POST)) {
        response = resourceManager.create(bulkRequestContent.getData(), userManager, null, null);
        bulkResponseContent = createBulkResponseContent(response, SCIMConstants.OperationalConstants.POST, bulkRequestContent);
        errorsCheck(response);
    } else if (bulkRequestContent.getMethod().equals(SCIMConstants.OperationalConstants.PUT)) {
        String resourceId = extractIDFromPath(bulkRequestContent.getPath());
        response = resourceManager.updateWithPUT(resourceId, bulkRequestContent.getData(), userManager, null, null);
        bulkResponseContent = createBulkResponseContent(response, SCIMConstants.OperationalConstants.PUT, bulkRequestContent);
        errorsCheck(response);
    } else if (bulkRequestContent.getMethod().equals(SCIMConstants.OperationalConstants.PATCH)) {
        String resourceId = extractIDFromPath(bulkRequestContent.getPath());
        response = resourceManager.updateWithPATCH(resourceId, bulkRequestContent.getData(), userManager, null, null);
        bulkResponseContent = createBulkResponseContent(response, SCIMConstants.OperationalConstants.PATCH, bulkRequestContent);
        errorsCheck(response);
    } else if (bulkRequestContent.getMethod().equals(SCIMConstants.OperationalConstants.DELETE)) {
        String resourceId = extractIDFromPath(bulkRequestContent.getPath());
        response = resourceManager.delete(resourceId, userManager);
        bulkResponseContent = createBulkResponseContent(response, SCIMConstants.OperationalConstants.DELETE, bulkRequestContent);
        errorsCheck(response);
    }
    return bulkResponseContent;
}
Also used : BulkResponseContent(org.wso2.charon3.core.objects.bulk.BulkResponseContent)

Example 85 with BadRequestException

use of org.wso2.charon3.core.exceptions.BadRequestException in project charon by wso2.

the class BulkRequestProcessor method processBulkRequests.

public BulkResponseData processBulkRequests(BulkRequestData bulkRequestData) throws BadRequestException {
    BulkResponseData bulkResponseData = new BulkResponseData();
    SCIMResponse response = null;
    for (BulkRequestContent bulkRequestContent : bulkRequestData.getUserOperationRequests()) {
        if (failOnError == 0) {
            bulkResponseData.addUserOperation(getBulkResponseContent(bulkRequestContent, userResourceManager));
        } else {
            if (errors < failOnError) {
                bulkResponseData.addUserOperation(getBulkResponseContent(bulkRequestContent, userResourceManager));
            }
        }
    }
    for (BulkRequestContent bulkRequestContent : bulkRequestData.getGroupOperationRequests()) {
        if (failOnError == 0) {
            bulkResponseData.addGroupOperation(getBulkResponseContent(bulkRequestContent, groupResourceManager));
        } else {
            if (errors < failOnError) {
                bulkResponseData.addGroupOperation(getBulkResponseContent(bulkRequestContent, groupResourceManager));
            }
        }
    }
    bulkResponseData.setSchema(SCIMConstants.BULK_RESPONSE_URI);
    return bulkResponseData;
}
Also used : BulkRequestContent(org.wso2.charon3.core.objects.bulk.BulkRequestContent) BulkResponseData(org.wso2.charon3.core.objects.bulk.BulkResponseData)

Aggregations

BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)63 CharonException (org.wso2.charon3.core.exceptions.CharonException)31 SimpleAttribute (org.wso2.charon3.core.attributes.SimpleAttribute)30 ComplexAttribute (org.wso2.charon3.core.attributes.ComplexAttribute)27 HashMap (java.util.HashMap)23 MultiValuedAttribute (org.wso2.charon3.core.attributes.MultiValuedAttribute)23 Attribute (org.wso2.charon3.core.attributes.Attribute)20 InternalErrorException (org.wso2.charon3.core.exceptions.InternalErrorException)19 SCIMResponse (org.wso2.charon3.core.protocol.SCIMResponse)19 SCIMResourceTypeSchema (org.wso2.charon3.core.schema.SCIMResourceTypeSchema)19 NotFoundException (org.wso2.charon3.core.exceptions.NotFoundException)18 JSONException (org.json.JSONException)17 JSONObject (org.json.JSONObject)17 AbstractSCIMObject (org.wso2.charon3.core.objects.AbstractSCIMObject)16 JSONEncoder (org.wso2.charon3.core.encoder.JSONEncoder)15 JSONDecoder (org.wso2.charon3.core.encoder.JSONDecoder)14 NotImplementedException (org.wso2.charon3.core.exceptions.NotImplementedException)14 User (org.wso2.charon3.core.objects.User)12 JSONArray (org.json.JSONArray)11 ArrayList (java.util.ArrayList)9