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