use of org.wso2.charon3.core.exceptions.BadRequestException in project charon by wso2.
the class AbstractValidator method validateSCIMObjectForRequiredSubAttributes.
/*
* Validate SCIMObject for required sub attributes given the object and the corresponding schema.
*
* @param attribute
* @param attributeSchema
* @throws CharonException
* @throws BadRequestException
*/
private static void validateSCIMObjectForRequiredSubAttributes(AbstractAttribute attribute, AttributeSchema attributeSchema) throws CharonException, BadRequestException {
if (attribute != null) {
List<SCIMAttributeSchema> subAttributesSchemaList = ((SCIMAttributeSchema) attributeSchema).getSubAttributeSchemas();
if (subAttributesSchemaList != null) {
for (SCIMAttributeSchema subAttributeSchema : subAttributesSchemaList) {
if (subAttributeSchema.getRequired()) {
if (attribute instanceof ComplexAttribute) {
if (attribute.getSubAttribute(subAttributeSchema.getName()) == null) {
String error = "Required sub attribute: " + subAttributeSchema.getName() + " is missing in the SCIM Attribute: " + attribute.getName();
throw new BadRequestException(error, ResponseCodeConstants.INVALID_VALUE);
}
} else if (attribute instanceof MultiValuedAttribute) {
List<Attribute> values = ((MultiValuedAttribute) attribute).getAttributeValues();
for (Attribute value : values) {
if (value instanceof ComplexAttribute) {
if (value.getSubAttribute(subAttributeSchema.getName()) == null) {
String error = "Required sub attribute: " + subAttributeSchema.getName() + ", is missing in the SCIM Attribute: " + attribute.getName();
throw new BadRequestException(error, ResponseCodeConstants.INVALID_VALUE);
}
}
}
}
}
// Following is only applicable for extension schema validation.
AbstractAttribute subAttribute = null;
if (attribute instanceof ComplexAttribute) {
subAttribute = (AbstractAttribute) ((ComplexAttribute) attribute).getSubAttribute(subAttributeSchema.getName());
} else if (attribute instanceof MultiValuedAttribute) {
List<Attribute> subAttributeList = ((MultiValuedAttribute) attribute).getAttributeValues();
for (Attribute subAttrbte : subAttributeList) {
if (subAttrbte.getName().equals(subAttributeSchema.getName())) {
subAttribute = (AbstractAttribute) subAttrbte;
}
}
}
List<SCIMAttributeSchema> subSubAttributesSchemaList = ((SCIMAttributeSchema) subAttributeSchema).getSubAttributeSchemas();
if (subSubAttributesSchemaList != null) {
validateSCIMObjectForRequiredSubAttributes(subAttribute, subAttributeSchema);
}
}
}
}
}
use of org.wso2.charon3.core.exceptions.BadRequestException in project charon by wso2.
the class AbstractValidator method checkForSameValues.
/*
* check for same values in a simple singular attributes or multivalued primitive type attributes
*
* @param oldAttributeList
* @param newAttributeList
* @param attributeSchema
* @throws BadRequestException
*/
private static void checkForSameValues(Map<String, Attribute> oldAttributeList, Map<String, Attribute> newAttributeList, AttributeSchema attributeSchema) throws BadRequestException {
Attribute newTemporyAttribute = newAttributeList.get(attributeSchema.getName());
Attribute oldTemporyAttribute = oldAttributeList.get(attributeSchema.getName());
if (newTemporyAttribute instanceof SimpleAttribute) {
if (!((((SimpleAttribute) newTemporyAttribute).getValue()).equals(((SimpleAttribute) oldTemporyAttribute).getValue()))) {
throw new BadRequestException(ResponseCodeConstants.MUTABILITY);
}
} else if (newTemporyAttribute instanceof MultiValuedAttribute && !attributeSchema.getType().equals(SCIMDefinitions.DataType.COMPLEX)) {
if (!checkListEquality(((MultiValuedAttribute) newTemporyAttribute).getAttributePrimitiveValues(), ((MultiValuedAttribute) oldTemporyAttribute).getAttributePrimitiveValues())) {
throw new BadRequestException(ResponseCodeConstants.MUTABILITY);
}
}
}
use of org.wso2.charon3.core.exceptions.BadRequestException in project charon by wso2.
the class AbstractSCIMObject method setLocation.
/*
* set the location of the meta attribute
*
* @param location
*/
public void setLocation(String location) throws CharonException, BadRequestException {
// create the location attribute as defined in schema.
SimpleAttribute locationAttribute = (SimpleAttribute) DefaultAttributeFactory.createAttribute(SCIMSchemaDefinitions.LOCATION, new SimpleAttribute(SCIMConstants.CommonSchemaConstants.LOCATION, location));
// check meta complex attribute already exist.
if (getMetaAttribute() != null) {
ComplexAttribute metaAttribute = getMetaAttribute();
// check version attribute already exist
if (metaAttribute.isSubAttributeExist(locationAttribute.getName())) {
String error = "Read only attribute is tried to modify";
throw new CharonException(error);
} else {
metaAttribute.setSubAttribute(locationAttribute);
}
} else {
// create meta attribute and set the sub attribute.
createMetaAttribute();
getMetaAttribute().setSubAttribute(locationAttribute);
}
}
use of org.wso2.charon3.core.exceptions.BadRequestException in project charon by wso2.
the class AbstractSCIMObject method setId.
/*
* Set a value for the id attribute. If attribute not already created in the resource,
* create attribute and set the value.
* Unique identifier for the SCIM Resource as defined by the Service Provider
* This is read-only. So can only set once.
*
* @param id Unique identifier for the SCIM Resource as defined by the Service Provider.
* @throws CharonException
* @throws BadRequestException
*/
public void setId(String id) throws CharonException, BadRequestException {
if (isAttributeExist(SCIMConstants.CommonSchemaConstants.ID)) {
String error = "Read only attribute is trying to be modified";
throw new CharonException(error);
} else {
SimpleAttribute idAttribute = new SimpleAttribute(SCIMConstants.CommonSchemaConstants.ID, id);
idAttribute = (SimpleAttribute) DefaultAttributeFactory.createAttribute(SCIMSchemaDefinitions.ID, idAttribute);
this.setAttribute(idAttribute);
}
}
use of org.wso2.charon3.core.exceptions.BadRequestException in project charon by wso2.
the class Group method setDisplayName.
/*
* set the display name of the group
* @param displayName
* @throws CharonException
* @throws BadRequestException
*/
public void setDisplayName(String displayName) throws CharonException, BadRequestException {
if (this.isAttributeExist(SCIMConstants.GroupSchemaConstants.DISPLAY_NAME)) {
((SimpleAttribute) this.attributeList.get(SCIMConstants.GroupSchemaConstants.DISPLAY_NAME)).updateValue(displayName);
} else {
SimpleAttribute displayAttribute = new SimpleAttribute(SCIMConstants.GroupSchemaConstants.DISPLAY_NAME, displayName);
displayAttribute = (SimpleAttribute) DefaultAttributeFactory.createAttribute(SCIMSchemaDefinitions.SCIMGroupSchemaDefinition.DISPLAY_NAME, displayAttribute);
this.attributeList.put(SCIMConstants.GroupSchemaConstants.DISPLAY_NAME, displayAttribute);
}
}
Aggregations