use of org.wso2.carbon.apimgt.rest.api.util.exception.ConflictException in project charon by wso2.
the class GroupResourceManager method create.
/*
* Create group in the service provider given the submitted payload that contains the SCIM group
* resource, format and the handler to usermanager.
*
* @param scimObjectString - Payload of HTTP request, which contains the SCIM object.
* @param usermanager
* @param attributes
* @param excludeAttributes
* @return
*/
@Override
public SCIMResponse create(String scimObjectString, UserManager userManager, String attributes, String excludeAttributes) {
JSONEncoder encoder = null;
JSONDecoder decoder = null;
try {
// obtain the json encoder
encoder = getEncoder();
// obtain the json decoder
decoder = getDecoder();
// returns core-group schema
SCIMResourceTypeSchema schema = SCIMResourceSchemaManager.getInstance().getGroupResourceSchema();
// get the URIs of required attributes which must be given a value
Map<String, Boolean> requiredAttributes = ResourceManagerUtil.getOnlyRequiredAttributesURIs((SCIMResourceTypeSchema) CopyUtil.deepCopy(schema), attributes, excludeAttributes);
// decode the SCIM group object, encoded in the submitted payload.
Group group = (Group) decoder.decodeResource(scimObjectString, schema, new Group());
// validate decoded group
ServerSideValidator.validateCreatedSCIMObject(group, SCIMSchemaDefinitions.SCIM_GROUP_SCHEMA);
// handover the SCIM User object to the group usermanager provided by the SP.
Group createdGroup;
// need to send back the newly created group in the response payload
createdGroup = ((UserManager) userManager).createGroup(group, requiredAttributes);
// encode the newly created SCIM group object and add id attribute to Location header.
String encodedGroup;
Map<String, String> httpHeaders = new HashMap<String, String>();
if (createdGroup != null) {
encodedGroup = encoder.encodeSCIMObject(createdGroup);
// add location header
httpHeaders.put(SCIMConstants.LOCATION_HEADER, getResourceEndpointURL(SCIMConstants.GROUP_ENDPOINT) + "/" + createdGroup.getId());
httpHeaders.put(SCIMConstants.CONTENT_TYPE_HEADER, SCIMConstants.APPLICATION_JSON);
} else {
String message = "Newly created Group resource is null..";
throw new InternalErrorException(message);
}
// put the uri of the Group object in the response header parameter.
return new SCIMResponse(ResponseCodeConstants.CODE_CREATED, encodedGroup, httpHeaders);
} catch (InternalErrorException e) {
return encodeSCIMException(e);
} catch (BadRequestException e) {
return encodeSCIMException(e);
} catch (ConflictException e) {
return encodeSCIMException(e);
} catch (CharonException e) {
return encodeSCIMException(e);
} catch (NotFoundException e) {
return encodeSCIMException(e);
} catch (NotImplementedException e) {
return encodeSCIMException(e);
}
}
use of org.wso2.carbon.apimgt.rest.api.util.exception.ConflictException in project carbon-apimgt by wso2.
the class RestApiUtil method handleConflict.
/**
* Logs the error, builds a ConflictException with specified details and throws it
*
* @param description description of the error
* @param log Log instance
* @throws ConflictException
*/
public static void handleConflict(String description, Log log) throws ConflictException {
ConflictException conflictException = buildConflictException(RestApiConstants.STATUS_CONFLICT_MESSAGE_DEFAULT, description);
log.error(description);
throw conflictException;
}
use of org.wso2.carbon.apimgt.rest.api.util.exception.ConflictException in project carbon-apimgt by wso2.
the class RestApiUtil method handleResourceAlreadyExistsError.
/**
* Logs the error, builds a ConflictException with specified details and throws it
*
* @param description description of the error
* @param log Log instance
* @throws ConflictException
*/
public static void handleResourceAlreadyExistsError(String description, Log log) throws ConflictException {
ConflictException conflictException = buildConflictException(RestApiConstants.STATUS_CONFLICT_MESSAGE_RESOURCE_ALREADY_EXISTS, description);
log.error(description);
throw conflictException;
}
use of org.wso2.carbon.apimgt.rest.api.util.exception.ConflictException in project carbon-apimgt by wso2.
the class RestApiUtil method handleResourceAlreadyExistsError.
/**
* Logs the error, builds a ConflictException with specified details and throws it
*
* @param description description of the error
* @param t Throwable instance
* @param log Log instance
* @throws ConflictException
*/
public static void handleResourceAlreadyExistsError(String description, Throwable t, Log log) throws ConflictException {
ConflictException conflictException = buildConflictException(RestApiConstants.STATUS_CONFLICT_MESSAGE_RESOURCE_ALREADY_EXISTS, description);
log.error(description, t);
throw conflictException;
}
use of org.wso2.carbon.apimgt.rest.api.util.exception.ConflictException in project charon by wso2.
the class MeResourceManager method create.
@Override
public SCIMResponse create(String scimObjectString, UserManager userManager, String attributes, String excludeAttributes) {
JSONEncoder encoder = null;
try {
// obtain the json encoder
encoder = getEncoder();
// obtain the json decoder
JSONDecoder decoder = getDecoder();
// obtain the schema corresponding to user
// unless configured returns core-user schema or else returns extended user schema)
SCIMResourceTypeSchema schema = SCIMResourceSchemaManager.getInstance().getUserResourceSchema();
// get the URIs of required attributes which must be given a value
Map<String, Boolean> requiredAttributes = ResourceManagerUtil.getOnlyRequiredAttributesURIs((SCIMResourceTypeSchema) CopyUtil.deepCopy(schema), attributes, excludeAttributes);
// decode the SCIM User object, encoded in the submitted payload.
User user = (User) decoder.decodeResource(scimObjectString, schema, new User());
// validate the created user.
ServerSideValidator.validateCreatedSCIMObject(user, schema);
User createdUser;
if (userManager != null) {
/*handover the SCIM User object to the user usermanager provided by the SP.
need to send back the newly created user in the response payload*/
createdUser = userManager.createMe(user, requiredAttributes);
} else {
String error = "Provided user manager handler is null.";
// throw internal server error.
throw new InternalErrorException(error);
}
// encode the newly created SCIM user object and add id attribute to Location header.
String encodedUser;
Map<String, String> responseHeaders = new HashMap<String, String>();
if (createdUser != null) {
// create a deep copy of the user object since we are going to change it.
User copiedUser = (User) CopyUtil.deepCopy(createdUser);
// need to remove password before returning
ServerSideValidator.validateReturnedAttributes(copiedUser, attributes, excludeAttributes);
encodedUser = encoder.encodeSCIMObject(copiedUser);
// add location header
responseHeaders.put(SCIMConstants.LOCATION_HEADER, getResourceEndpointURL(SCIMConstants.USER_ENDPOINT) + "/" + createdUser.getId());
responseHeaders.put(SCIMConstants.CONTENT_TYPE_HEADER, SCIMConstants.APPLICATION_JSON);
} else {
String error = "Newly created User resource is null.";
throw new InternalErrorException(error);
}
// put the uri of the User object in the response header parameter.
return new SCIMResponse(ResponseCodeConstants.CODE_CREATED, encodedUser, responseHeaders);
} catch (CharonException e) {
return encodeSCIMException(e);
} catch (BadRequestException e) {
return encodeSCIMException(e);
} catch (ConflictException e) {
return encodeSCIMException(e);
} catch (InternalErrorException e) {
return encodeSCIMException(e);
} catch (NotFoundException e) {
return encodeSCIMException(e);
}
}
Aggregations