Search in sources :

Example 1 with ConflictException

use of org.wso2.carbon.identity.user.endpoint.exceptions.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;
}
Also used : ConflictException(org.wso2.carbon.apimgt.rest.api.util.exception.ConflictException)

Example 2 with ConflictException

use of org.wso2.carbon.identity.user.endpoint.exceptions.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;
}
Also used : ConflictException(org.wso2.carbon.apimgt.rest.api.util.exception.ConflictException)

Example 3 with ConflictException

use of org.wso2.carbon.identity.user.endpoint.exceptions.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;
}
Also used : ConflictException(org.wso2.carbon.apimgt.rest.api.util.exception.ConflictException)

Example 4 with ConflictException

use of org.wso2.carbon.identity.user.endpoint.exceptions.ConflictException in project charon by wso2.

the class RoleResourceManager method updateWithPUTRole.

@Override
public SCIMResponse updateWithPUTRole(String id, String putRequest, RoleManager roleManager) {
    try {
        if (roleManager == null) {
            String error = "Provided role manager is null.";
            throw new InternalErrorException(error);
        }
        JSONEncoder encoder = getEncoder();
        JSONDecoder decoder = getDecoder();
        SCIMResourceTypeSchema schema = SCIMResourceSchemaManager.getInstance().getRoleResourceSchema();
        Map<String, Boolean> requestAttributes = ResourceManagerUtil.getAllAttributeURIs(schema);
        Role role = decoder.decodeResource(putRequest, schema, new Role());
        Role updatedRole;
        // Retrieve the old object.
        Role oldRole = roleManager.getRole(id, requestAttributes);
        if (oldRole != null) {
            Role newRole = (Role) ServerSideValidator.validateUpdatedSCIMObject(oldRole, role, schema);
            updatedRole = roleManager.updateRole(oldRole, newRole);
        } else {
            String error = "No role exists with the given id: " + id;
            throw new NotFoundException(error);
        }
        return getScimResponse(encoder, updatedRole);
    } catch (NotFoundException | BadRequestException | CharonException | ConflictException | InternalErrorException | NotImplementedException e) {
        return encodeSCIMException(e);
    }
}
Also used : ConflictException(org.wso2.charon3.core.exceptions.ConflictException) NotImplementedException(org.wso2.charon3.core.exceptions.NotImplementedException) NotFoundException(org.wso2.charon3.core.exceptions.NotFoundException) InternalErrorException(org.wso2.charon3.core.exceptions.InternalErrorException) Role(org.wso2.charon3.core.objects.Role) JSONDecoder(org.wso2.charon3.core.encoder.JSONDecoder) BadRequestException(org.wso2.charon3.core.exceptions.BadRequestException) JSONEncoder(org.wso2.charon3.core.encoder.JSONEncoder) SCIMResourceTypeSchema(org.wso2.charon3.core.schema.SCIMResourceTypeSchema) CharonException(org.wso2.charon3.core.exceptions.CharonException)

Example 5 with ConflictException

use of org.wso2.carbon.identity.user.endpoint.exceptions.ConflictException in project charon by wso2.

the class RoleResourceManager method createRole.

@Override
public SCIMResponse createRole(String postRequest, RoleManager roleManager) {
    try {
        if (roleManager == null) {
            String error = "Provided role manager is null.";
            throw new InternalErrorException(error);
        }
        JSONEncoder encoder = getEncoder();
        JSONDecoder decoder = getDecoder();
        SCIMResourceTypeSchema schema = SCIMResourceSchemaManager.getInstance().getRoleResourceSchema();
        Role role = decoder.decodeResource(postRequest, schema, new Role());
        ServerSideValidator.validateCreatedSCIMObject(role, SCIMSchemaDefinitions.SCIM_ROLE_SCHEMA);
        Role createdRole = roleManager.createRole(role);
        String encodedRole;
        Map<String, String> httpHeaders = new HashMap<>();
        if (createdRole != null) {
            encodedRole = encoder.encodeSCIMObject(createdRole);
            httpHeaders.put(SCIMConstants.LOCATION_HEADER, getResourceEndpointURL(SCIMConstants.ROLE_ENDPOINT) + "/" + createdRole.getId());
            httpHeaders.put(SCIMConstants.CONTENT_TYPE_HEADER, SCIMConstants.APPLICATION_JSON);
        } else {
            String message = "Newly created Role resource is null.";
            throw new InternalErrorException(message);
        }
        return new SCIMResponse(ResponseCodeConstants.CODE_CREATED, encodedRole, httpHeaders);
    } catch (InternalErrorException | BadRequestException | ConflictException | CharonException | NotFoundException | NotImplementedException e) {
        return encodeSCIMException(e);
    }
}
Also used : HashMap(java.util.HashMap) ConflictException(org.wso2.charon3.core.exceptions.ConflictException) NotImplementedException(org.wso2.charon3.core.exceptions.NotImplementedException) NotFoundException(org.wso2.charon3.core.exceptions.NotFoundException) InternalErrorException(org.wso2.charon3.core.exceptions.InternalErrorException) Role(org.wso2.charon3.core.objects.Role) JSONDecoder(org.wso2.charon3.core.encoder.JSONDecoder) BadRequestException(org.wso2.charon3.core.exceptions.BadRequestException) JSONEncoder(org.wso2.charon3.core.encoder.JSONEncoder) SCIMResourceTypeSchema(org.wso2.charon3.core.schema.SCIMResourceTypeSchema) CharonException(org.wso2.charon3.core.exceptions.CharonException) SCIMResponse(org.wso2.charon3.core.protocol.SCIMResponse)

Aggregations

Test (org.testng.annotations.Test)26 SCIMResponse (org.wso2.charon3.core.protocol.SCIMResponse)20 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)13 ConflictException (org.wso2.charon3.core.exceptions.ConflictException)13 User (org.wso2.charon3.core.objects.User)13 CharonException (org.wso2.charon3.core.exceptions.CharonException)11 InternalErrorException (org.wso2.charon3.core.exceptions.InternalErrorException)11 Role (org.wso2.charon3.core.objects.Role)11 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 NotImplementedException (org.wso2.charon3.core.exceptions.NotImplementedException)8 Matchers.anyString (org.mockito.Matchers.anyString)7 NotFoundException (org.wso2.charon3.core.exceptions.NotFoundException)7 Group (org.wso2.charon3.core.objects.Group)7 RoleBasicInfo (org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo)6 JSONEncoder (org.wso2.charon3.core.encoder.JSONEncoder)6 SCIMResourceTypeSchema (org.wso2.charon3.core.schema.SCIMResourceTypeSchema)6 ConflictException (org.wso2.carbon.apimgt.rest.api.util.exception.ConflictException)5 JSONDecoder (org.wso2.charon3.core.encoder.JSONDecoder)5 HashMap (java.util.HashMap)4 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)3