Search in sources :

Example 41 with CharonException

use of org.wso2.charon3.core.exceptions.CharonException in project charon by wso2.

the class Group method setMemberCommon.

/*
     * set member to the group
     * @param userId
     * @param userName
     * @return
     * @throws BadRequestException
     * @throws CharonException
     */
private ComplexAttribute setMemberCommon(String userId, String userName) throws BadRequestException, CharonException {
    ComplexAttribute complexAttribute = new ComplexAttribute();
    complexAttribute.setName(SCIMConstants.GroupSchemaConstants.MEMBERS + "_" + userId + SCIMConstants.DEFAULT);
    SimpleAttribute valueSimpleAttribute = new SimpleAttribute(SCIMConstants.CommonSchemaConstants.VALUE, userId);
    DefaultAttributeFactory.createAttribute(SCIMSchemaDefinitions.SCIMGroupSchemaDefinition.VALUE, valueSimpleAttribute);
    SimpleAttribute displaySimpleAttribute = new SimpleAttribute(SCIMConstants.GroupSchemaConstants.DISPLAY, userName);
    DefaultAttributeFactory.createAttribute(SCIMSchemaDefinitions.SCIMGroupSchemaDefinition.DISPLAY, displaySimpleAttribute);
    complexAttribute.setSubAttribute(valueSimpleAttribute);
    complexAttribute.setSubAttribute(displaySimpleAttribute);
    DefaultAttributeFactory.createAttribute(SCIMSchemaDefinitions.SCIMGroupSchemaDefinition.MEMBERS, complexAttribute);
    return complexAttribute;
}
Also used : SimpleAttribute(org.wso2.charon3.core.attributes.SimpleAttribute) ComplexAttribute(org.wso2.charon3.core.attributes.ComplexAttribute)

Example 42 with CharonException

use of org.wso2.charon3.core.exceptions.CharonException in project charon by wso2.

the class Group method setMember.

/*
     * set a member to the group
     * @param userId
     * @param userName
     * @throws BadRequestException
     * @throws CharonException
     */
public void setMember(String userId, String userName) throws BadRequestException, CharonException {
    if (this.isAttributeExist(SCIMConstants.GroupSchemaConstants.MEMBERS)) {
        MultiValuedAttribute members = (MultiValuedAttribute) this.attributeList.get(SCIMConstants.GroupSchemaConstants.MEMBERS);
        ComplexAttribute complexAttribute = setMemberCommon(userId, userName);
        members.setAttributeValue(complexAttribute);
    } else {
        MultiValuedAttribute members = new MultiValuedAttribute(SCIMConstants.GroupSchemaConstants.MEMBERS);
        DefaultAttributeFactory.createAttribute(SCIMSchemaDefinitions.SCIMGroupSchemaDefinition.MEMBERS, members);
        ComplexAttribute complexAttribute = setMemberCommon(userId, userName);
        members.setAttributeValue(complexAttribute);
        this.setAttribute(members);
    }
}
Also used : ComplexAttribute(org.wso2.charon3.core.attributes.ComplexAttribute) MultiValuedAttribute(org.wso2.charon3.core.attributes.MultiValuedAttribute)

Example 43 with CharonException

use of org.wso2.charon3.core.exceptions.CharonException in project charon by wso2.

the class GroupResource method getGroupsByPost.

@POST
@Path("/.search")
@Produces({ "application/json", "application/scim+json" })
@Consumes("application/scim+json")
@ApiOperation(value = "Return groups according to the filter, sort and pagination parameters", notes = "Returns HTTP 404 if the groups are not found.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Valid groups are found"), @ApiResponse(code = 404, message = "Valid groups are not found") })
public Response getGroupsByPost(String resourceString) throws FormatNotSupportedException, CharonException {
    try {
        // obtain the user store manager
        UserManager userManager = DefaultCharonManager.getInstance().getUserManager();
        // create charon-SCIM group endpoint and hand-over the request.
        GroupResourceManager groupResourceManager = new GroupResourceManager();
        SCIMResponse scimResponse = groupResourceManager.listWithPOST(resourceString, userManager);
        return buildResponse(scimResponse);
    } catch (CharonException e) {
        throw new CharonException(e.getDetail(), e);
    }
}
Also used : UserManager(org.wso2.charon3.core.extensions.UserManager) GroupResourceManager(org.wso2.charon3.core.protocol.endpoints.GroupResourceManager) CharonException(org.wso2.charon3.core.exceptions.CharonException) SCIMResponse(org.wso2.charon3.core.protocol.SCIMResponse) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 44 with CharonException

use of org.wso2.charon3.core.exceptions.CharonException in project charon by wso2.

the class GroupResource method deleteGroup.

@DELETE
@Path("/{id}")
@Produces({ "application/json", "application/scim+json" })
@ApiOperation(value = "Delete the group with the given id", notes = "Returns HTTP 204 if the group is successfully deleted.")
@ApiResponses(value = { @ApiResponse(code = 204, message = "Group is deleted"), @ApiResponse(code = 404, message = "Valid group is not found") })
public Response deleteGroup(@ApiParam(value = SCIMProviderConstants.ID_DESC, required = true) @PathParam(SCIMProviderConstants.ID) String id) throws FormatNotSupportedException, CharonException {
    try {
        // obtain the user store manager
        UserManager userManager = DefaultCharonManager.getInstance().getUserManager();
        // create charon-SCIM group endpoint and hand-over the request.
        GroupResourceManager groupResourceManager = new GroupResourceManager();
        SCIMResponse scimResponse = groupResourceManager.delete(id, userManager);
        // appropriately.
        return buildResponse(scimResponse);
    } catch (CharonException e) {
        throw new CharonException(e.getDetail(), e);
    }
}
Also used : UserManager(org.wso2.charon3.core.extensions.UserManager) GroupResourceManager(org.wso2.charon3.core.protocol.endpoints.GroupResourceManager) CharonException(org.wso2.charon3.core.exceptions.CharonException) SCIMResponse(org.wso2.charon3.core.protocol.SCIMResponse) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 45 with CharonException

use of org.wso2.charon3.core.exceptions.CharonException in project charon by wso2.

the class GroupResource method updateGroup.

@PUT
@Path("{id}")
@Produces({ "application/json", "application/scim+json" })
@Consumes("application/scim+json")
@ApiOperation(value = "Return the updated group", notes = "Returns HTTP 404 if the group is not found.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Group is updated"), @ApiResponse(code = 404, message = "Valid group is not found") })
public Response updateGroup(@ApiParam(value = SCIMProviderConstants.ID_DESC, required = true) @PathParam(SCIMProviderConstants.ID) String id, @ApiParam(value = SCIMProviderConstants.ATTRIBUTES_DESC, required = false) @QueryParam(SCIMProviderConstants.ATTRIBUTES) String attribute, @ApiParam(value = SCIMProviderConstants.EXCLUDED_ATTRIBUTES_DESC, required = false) @QueryParam(SCIMProviderConstants.EXCLUDE_ATTRIBUTES) String excludedAttributes, String resourceString) throws FormatNotSupportedException, CharonException {
    try {
        // obtain the user store manager
        UserManager userManager = DefaultCharonManager.getInstance().getUserManager();
        // create charon-SCIM group endpoint and hand-over the request.
        GroupResourceManager groupResourceManager = new GroupResourceManager();
        SCIMResponse response = groupResourceManager.updateWithPUT(id, resourceString, userManager, attribute, excludedAttributes);
        return buildResponse(response);
    } catch (CharonException e) {
        throw new CharonException(e.getDetail(), e);
    }
}
Also used : UserManager(org.wso2.charon3.core.extensions.UserManager) GroupResourceManager(org.wso2.charon3.core.protocol.endpoints.GroupResourceManager) CharonException(org.wso2.charon3.core.exceptions.CharonException) SCIMResponse(org.wso2.charon3.core.protocol.SCIMResponse) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

CharonException (org.wso2.charon3.core.exceptions.CharonException)46 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)44 SimpleAttribute (org.wso2.charon3.core.attributes.SimpleAttribute)34 ComplexAttribute (org.wso2.charon3.core.attributes.ComplexAttribute)32 SCIMResponse (org.wso2.charon3.core.protocol.SCIMResponse)31 MultiValuedAttribute (org.wso2.charon3.core.attributes.MultiValuedAttribute)28 Attribute (org.wso2.charon3.core.attributes.Attribute)27 HashMap (java.util.HashMap)22 InternalErrorException (org.wso2.charon3.core.exceptions.InternalErrorException)19 SCIMResourceTypeSchema (org.wso2.charon3.core.schema.SCIMResourceTypeSchema)19 NotFoundException (org.wso2.charon3.core.exceptions.NotFoundException)18 AbstractSCIMObject (org.wso2.charon3.core.objects.AbstractSCIMObject)17 JSONEncoder (org.wso2.charon3.core.encoder.JSONEncoder)15 UserManager (org.wso2.charon3.core.extensions.UserManager)15 JSONObject (org.json.JSONObject)14 JSONDecoder (org.wso2.charon3.core.encoder.JSONDecoder)14 NotImplementedException (org.wso2.charon3.core.exceptions.NotImplementedException)14 JSONException (org.json.JSONException)13 User (org.wso2.charon3.core.objects.User)13 ApiOperation (io.swagger.annotations.ApiOperation)12