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