Search in sources :

Example 1 with MeResourceManager

use of org.wso2.charon3.core.protocol.endpoints.MeResourceManager in project charon by wso2.

the class MeResourceManagerTest method setUp.

@BeforeMethod
public void setUp() {
    meResourceManager = new MeResourceManager();
    abstractResourceManager = Mockito.mockStatic(AbstractResourceManager.class);
    userManager = mock(UserManager.class);
    abstractResourceManager.when(AbstractResourceManager::getEncoder).thenReturn(new JSONEncoder());
    abstractResourceManager.when(AbstractResourceManager::getDecoder).thenReturn(new JSONDecoder());
}
Also used : JSONDecoder(org.wso2.charon3.core.encoder.JSONDecoder) UserManager(org.wso2.charon3.core.extensions.UserManager) JSONEncoder(org.wso2.charon3.core.encoder.JSONEncoder) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with MeResourceManager

use of org.wso2.charon3.core.protocol.endpoints.MeResourceManager in project identity-inbound-provisioning-scim2 by wso2-extensions.

the class MeResource method patchUser.

@PATCH
public Response patchUser(@HeaderParam(SCIMProviderConstants.CONTENT_TYPE) String inputFormat, @HeaderParam(SCIMProviderConstants.ACCEPT_HEADER) String outputFormat, @QueryParam(SCIMProviderConstants.ATTRIBUTES) String attribute, @QueryParam(SCIMProviderConstants.EXCLUDE_ATTRIBUTES) String excludedAttributes, String resourceString) {
    String userId = SupportUtils.getAuthenticatedUserId();
    try {
        // content-type header is compulsory in post request.
        if (inputFormat == null) {
            String error = SCIMProviderConstants.CONTENT_TYPE + " not present in the request header";
            throw new FormatNotSupportedException(error);
        }
        if (!isValidInputFormat(inputFormat)) {
            String error = inputFormat + " is not supported.";
            throw new FormatNotSupportedException(error);
        }
        if (!isValidOutputFormat(outputFormat)) {
            String error = outputFormat + " is not supported.";
            throw new FormatNotSupportedException(error);
        }
        // obtain the user store manager
        UserManager userManager = IdentitySCIMManager.getInstance().getUserManager();
        // Build Custom schema
        buildCustomSchema(userManager, getTenantId());
        // create charon-SCIM me resource manager and hand-over the request.
        MeResourceManager meResourceManager = new MeResourceManager();
        SCIMResponse response = meResourceManager.updateWithPATCH(userId, resourceString, userManager, attribute, excludedAttributes);
        return SupportUtils.buildResponse(response);
    } catch (CharonException e) {
        return handleCharonException(e);
    } catch (FormatNotSupportedException e) {
        return handleFormatNotSupportedException(e);
    }
}
Also used : FormatNotSupportedException(org.wso2.charon3.core.exceptions.FormatNotSupportedException) UserManager(org.wso2.charon3.core.extensions.UserManager) CharonException(org.wso2.charon3.core.exceptions.CharonException) SCIMResponse(org.wso2.charon3.core.protocol.SCIMResponse) MeResourceManager(org.wso2.charon3.core.protocol.endpoints.MeResourceManager) PATCH(org.wso2.carbon.identity.jaxrs.designator.PATCH)

Example 3 with MeResourceManager

use of org.wso2.charon3.core.protocol.endpoints.MeResourceManager in project identity-inbound-provisioning-scim2 by wso2-extensions.

the class MeResource method deleteUser.

@DELETE
public Response deleteUser(@HeaderParam(SCIMProviderConstants.ACCEPT_HEADER) String format) {
    String userId = SupportUtils.getAuthenticatedUserId();
    try {
        // defaults to application/scim+json.
        if (format == null) {
            format = SCIMProviderConstants.APPLICATION_SCIM_JSON;
        }
        if (!isValidOutputFormat(format)) {
            String error = format + " is not supported.";
            throw new FormatNotSupportedException(error);
        }
        // obtain the user store manager
        UserManager userManager = IdentitySCIMManager.getInstance().getUserManager();
        // create charon-SCIM me resource manager and hand-over the request.
        MeResourceManager meResourceManager = new MeResourceManager();
        SCIMResponse scimResponse = meResourceManager.delete(userId, userManager);
        // appropriately.
        return SupportUtils.buildResponse(scimResponse);
    } catch (CharonException e) {
        return handleCharonException(e);
    } catch (FormatNotSupportedException e) {
        return handleFormatNotSupportedException(e);
    }
}
Also used : FormatNotSupportedException(org.wso2.charon3.core.exceptions.FormatNotSupportedException) UserManager(org.wso2.charon3.core.extensions.UserManager) CharonException(org.wso2.charon3.core.exceptions.CharonException) SCIMResponse(org.wso2.charon3.core.protocol.SCIMResponse) MeResourceManager(org.wso2.charon3.core.protocol.endpoints.MeResourceManager)

Example 4 with MeResourceManager

use of org.wso2.charon3.core.protocol.endpoints.MeResourceManager in project identity-inbound-provisioning-scim2 by wso2-extensions.

the class MeResource method createUser.

@POST
public Response createUser(@HeaderParam(SCIMProviderConstants.CONTENT_TYPE) String inputFormat, @HeaderParam(SCIMProviderConstants.ACCEPT_HEADER) String outputFormat, @QueryParam(SCIMProviderConstants.ATTRIBUTES) String attribute, @QueryParam(SCIMProviderConstants.EXCLUDE_ATTRIBUTES) String excludedAttributes, String resourceString) {
    try {
        // content-type header is compulsory in post request.
        if (inputFormat == null) {
            String error = SCIMProviderConstants.CONTENT_TYPE + " not present in the request header";
            throw new FormatNotSupportedException(error);
        }
        if (!isValidInputFormat(inputFormat)) {
            String error = inputFormat + " is not supported.";
            throw new FormatNotSupportedException(error);
        }
        if (!isValidOutputFormat(outputFormat)) {
            String error = outputFormat + " is not supported.";
            throw new FormatNotSupportedException(error);
        }
        // create charon-SCIM user endpoint and hand-over the request.
        MeResourceManager meResourceManager = new MeResourceManager();
        // obtain the user store manager
        UserManager userManager = IdentitySCIMManager.getInstance().getUserManager();
        // Build Custom schema
        buildCustomSchema(userManager, getTenantId());
        SCIMResponse response = meResourceManager.create(resourceString, userManager, attribute, excludedAttributes);
        return SupportUtils.buildResponse(response);
    } catch (CharonException e) {
        return handleCharonException(e);
    } catch (FormatNotSupportedException e) {
        return handleFormatNotSupportedException(e);
    }
}
Also used : FormatNotSupportedException(org.wso2.charon3.core.exceptions.FormatNotSupportedException) UserManager(org.wso2.charon3.core.extensions.UserManager) CharonException(org.wso2.charon3.core.exceptions.CharonException) SCIMResponse(org.wso2.charon3.core.protocol.SCIMResponse) MeResourceManager(org.wso2.charon3.core.protocol.endpoints.MeResourceManager)

Example 5 with MeResourceManager

use of org.wso2.charon3.core.protocol.endpoints.MeResourceManager in project identity-inbound-provisioning-scim2 by wso2-extensions.

the class MeResource method getUser.

@GET
@Produces({ MediaType.APPLICATION_JSON, SCIMProviderConstants.APPLICATION_SCIM_JSON })
public Response getUser(@HeaderParam(SCIMProviderConstants.ACCEPT_HEADER) String outputFormat, @QueryParam(SCIMProviderConstants.ATTRIBUTES) String attribute, @QueryParam(SCIMProviderConstants.EXCLUDE_ATTRIBUTES) String excludedAttributes) {
    String userId = SupportUtils.getAuthenticatedUserId();
    try {
        if (!isValidOutputFormat(outputFormat)) {
            String error = outputFormat + " is not supported.";
            throw new FormatNotSupportedException(error);
        }
        // obtain the user store manager
        UserManager userManager = IdentitySCIMManager.getInstance().getUserManager();
        // Build Custom schema
        buildCustomSchema(userManager, getTenantId());
        // create charon-SCIM me endpoint and hand-over the request.
        MeResourceManager meResourceManager = new MeResourceManager();
        SCIMResponse scimResponse = meResourceManager.get(userId, userManager, attribute, excludedAttributes);
        // appropriately.
        return SupportUtils.buildResponse(scimResponse);
    } catch (CharonException e) {
        return handleCharonException(e);
    } catch (FormatNotSupportedException e) {
        return handleFormatNotSupportedException(e);
    }
}
Also used : FormatNotSupportedException(org.wso2.charon3.core.exceptions.FormatNotSupportedException) UserManager(org.wso2.charon3.core.extensions.UserManager) CharonException(org.wso2.charon3.core.exceptions.CharonException) SCIMResponse(org.wso2.charon3.core.protocol.SCIMResponse) MeResourceManager(org.wso2.charon3.core.protocol.endpoints.MeResourceManager)

Aggregations

UserManager (org.wso2.charon3.core.extensions.UserManager)6 CharonException (org.wso2.charon3.core.exceptions.CharonException)5 FormatNotSupportedException (org.wso2.charon3.core.exceptions.FormatNotSupportedException)5 SCIMResponse (org.wso2.charon3.core.protocol.SCIMResponse)5 MeResourceManager (org.wso2.charon3.core.protocol.endpoints.MeResourceManager)5 BeforeMethod (org.testng.annotations.BeforeMethod)1 PATCH (org.wso2.carbon.identity.jaxrs.designator.PATCH)1 JSONDecoder (org.wso2.charon3.core.encoder.JSONDecoder)1 JSONEncoder (org.wso2.charon3.core.encoder.JSONEncoder)1