Search in sources :

Example 81 with BadRequestException

use of org.wso2.carbon.apimgt.rest.api.util.exception.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 82 with BadRequestException

use of org.wso2.carbon.apimgt.rest.api.util.exception.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 83 with BadRequestException

use of org.wso2.carbon.apimgt.rest.api.util.exception.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)

Example 84 with BadRequestException

use of org.wso2.carbon.apimgt.rest.api.util.exception.BadRequestException in project charon by wso2.

the class ServerSideValidator method validateUpdatedSCIMObject.

/*
     * Perform validation on SCIM Object update on service provider side
     *
     * @param oldObject
     * @param newObject
     * @param resourceSchema
     * @return
     * @throws CharonException
     */
public static AbstractSCIMObject validateUpdatedSCIMObject(AbstractSCIMObject oldObject, AbstractSCIMObject newObject, SCIMResourceTypeSchema resourceSchema) throws CharonException, BadRequestException {
    AbstractSCIMObject validatedObject = null;
    if (newObject instanceof User) {
        // set display names for complex multivalued attributes
        setDisplayNameInComplexMultiValuedAttributes(newObject, resourceSchema);
    }
    // check for read only and immutable attributes
    validatedObject = checkIfReadOnlyAndImmutableAttributesModified(oldObject, newObject, resourceSchema);
    // copy meta attribute from old to new
    validatedObject.setAttribute(oldObject.getAttribute(SCIMConstants.CommonSchemaConstants.META));
    // copy id attribute to new group object
    validatedObject.setAttribute(oldObject.getAttribute(SCIMConstants.CommonSchemaConstants.ID));
    // edit last modified date
    Date date = new Date();
    validatedObject.setLastModified(date);
    // check for required attributes.
    validateSCIMObjectForRequiredAttributes(newObject, resourceSchema);
    // check for schema list
    validateSchemaList(validatedObject, resourceSchema);
    return validatedObject;
}
Also used : AbstractSCIMObject(org.wso2.charon3.core.objects.AbstractSCIMObject) User(org.wso2.charon3.core.objects.User) Date(java.util.Date)

Example 85 with BadRequestException

use of org.wso2.carbon.apimgt.rest.api.util.exception.BadRequestException in project charon by wso2.

the class AttributeUtil method getAttributeURI.

/*
     * Will iterate through <code>{@code SCIMAttributeSchema}</code> objects
     *
     * @param attributeName
     * @return
     */
public static String getAttributeURI(String attributeName, SCIMResourceTypeSchema schema) throws BadRequestException {
    Iterator<AttributeSchema> attributeSchemas = schema.getAttributesList().iterator();
    while (attributeSchemas.hasNext()) {
        AttributeSchema attributeSchema = attributeSchemas.next();
        if (attributeSchema.getName().equals(attributeName) || attributeSchema.getURI().equals(attributeName)) {
            return attributeSchema.getURI();
        }
        // check in sub attributes
        String subAttributeURI = checkSCIMSubAttributeURIs(((SCIMAttributeSchema) attributeSchema).getSubAttributeSchemas(), attributeSchema, attributeName);
        if (subAttributeURI != null) {
            return subAttributeURI;
        }
    }
    String error = "Not a valid attribute name/uri";
    throw new BadRequestException(error, ResponseCodeConstants.INVALID_VALUE);
}
Also used : AttributeSchema(org.wso2.charon3.core.schema.AttributeSchema) SCIMAttributeSchema(org.wso2.charon3.core.schema.SCIMAttributeSchema) BadRequestException(org.wso2.charon3.core.exceptions.BadRequestException)

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 MultiValuedAttribute (org.wso2.charon3.core.attributes.MultiValuedAttribute)23 HashMap (java.util.HashMap)22 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 JSONObject (org.json.JSONObject)16 AbstractSCIMObject (org.wso2.charon3.core.objects.AbstractSCIMObject)16 JSONException (org.json.JSONException)15 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 BadRequestException (org.wso2.carbon.apimgt.rest.api.util.exception.BadRequestException)10