Search in sources :

Example 76 with BadRequestException

use of org.wso2.carbon.apimgt.rest.api.util.exception.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);
    }
}
Also used : SimpleAttribute(org.wso2.charon3.core.attributes.SimpleAttribute) ComplexAttribute(org.wso2.charon3.core.attributes.ComplexAttribute) CharonException(org.wso2.charon3.core.exceptions.CharonException)

Example 77 with BadRequestException

use of org.wso2.carbon.apimgt.rest.api.util.exception.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);
    }
}
Also used : SimpleAttribute(org.wso2.charon3.core.attributes.SimpleAttribute) CharonException(org.wso2.charon3.core.exceptions.CharonException)

Example 78 with BadRequestException

use of org.wso2.carbon.apimgt.rest.api.util.exception.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);
    }
}
Also used : SimpleAttribute(org.wso2.charon3.core.attributes.SimpleAttribute)

Example 79 with BadRequestException

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

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

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