Search in sources :

Example 96 with Attribute

use of org.wso2.carbon.identity.configuration.mgt.core.model.Attribute in project identity-inbound-provisioning-scim2 by wso2-extensions.

the class UserResource method getUser.

@GET
@Path("{id}")
@Produces({ MediaType.APPLICATION_JSON, SCIMProviderConstants.APPLICATION_SCIM_JSON })
public Response getUser(@PathParam(SCIMConstants.CommonSchemaConstants.ID) String id, @HeaderParam(SCIMProviderConstants.ACCEPT_HEADER) String outputFormat, @QueryParam(SCIMProviderConstants.ATTRIBUTES) String attribute, @QueryParam(SCIMProviderConstants.EXCLUDE_ATTRIBUTES) String excludedAttributes) {
    try {
        if (!isValidOutputFormat(outputFormat)) {
            String error = outputFormat + " is not supported.";
            throw new FormatNotSupportedException(error);
        }
        // obtain the user store manager
        UserManager userManager = IdentitySCIMManager.getInstance().getUserManager();
        // create charon-SCIM user endpoint and hand-over the request.
        UserResourceManager userResourceManager = new UserResourceManager();
        // Build Custom schema
        buildCustomSchema(userManager, getTenantId());
        SCIMResponse scimResponse = userResourceManager.get(id, 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) UserResourceManager(org.wso2.charon3.core.protocol.endpoints.UserResourceManager) SCIMResponse(org.wso2.charon3.core.protocol.SCIMResponse)

Example 97 with Attribute

use of org.wso2.carbon.identity.configuration.mgt.core.model.Attribute in project identity-inbound-provisioning-scim2 by wso2-extensions.

the class GroupResource method patchPermissionForGroup.

@PATCH
@Path("{id}/permissions")
@Produces({ MediaType.APPLICATION_JSON, SCIMProviderConstants.APPLICATION_SCIM_JSON })
public Response patchPermissionForGroup(@PathParam(SCIMConstants.CommonSchemaConstants.ID) String id, @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) {
    // content-type header is compulsory in post request.
    if (inputFormat == null) {
        return handleFormatNotSupportedException(new FormatNotSupportedException("Content type: " + SCIMProviderConstants.CONTENT_TYPE + "  not present in the request header"));
    }
    if (!isValidInputFormat(inputFormat)) {
        return handleFormatNotSupportedException(new FormatNotSupportedException("Input format: " + inputFormat + " is not supported."));
    }
    if (!isValidOutputFormat(outputFormat)) {
        return handleFormatNotSupportedException(new FormatNotSupportedException("Output format: " + outputFormat + " is not supported."));
    }
    Map<String, String> requestAttributes = new HashMap<>();
    requestAttributes.put(SCIMProviderConstants.ID, id);
    requestAttributes.put(SCIMProviderConstants.HTTP_VERB, PATCH.class.getSimpleName());
    requestAttributes.put(SCIMProviderConstants.RESOURCE_STRING, resourceString);
    requestAttributes.put(SCIMProviderConstants.ATTRIBUTES, PERMISSIONS);
    requestAttributes.put(SCIMProviderConstants.EXCLUDE_ATTRIBUTES, excludedAttributes);
    return processRequest(requestAttributes);
}
Also used : FormatNotSupportedException(org.wso2.charon3.core.exceptions.FormatNotSupportedException) HashMap(java.util.HashMap) PATCH(org.wso2.carbon.identity.jaxrs.designator.PATCH) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PATCH(org.wso2.carbon.identity.jaxrs.designator.PATCH)

Example 98 with Attribute

use of org.wso2.carbon.identity.configuration.mgt.core.model.Attribute 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)

Example 99 with Attribute

use of org.wso2.carbon.identity.configuration.mgt.core.model.Attribute in project identity-inbound-provisioning-scim2 by wso2-extensions.

the class MeResource method updateUser.

@PUT
public Response updateUser(@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.updateWithPUT(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)

Example 100 with Attribute

use of org.wso2.carbon.identity.configuration.mgt.core.model.Attribute in project identity-inbound-provisioning-scim2 by wso2-extensions.

the class SupportUtils method buildCustomSchema.

/**
 * This builds the custom schema for tenants.
 * @param userManager
 * @param tenantId
 * @throws CharonException
 */
public static void buildCustomSchema(UserManager userManager, int tenantId) throws CharonException {
    if (log.isDebugEnabled()) {
        log.debug("Building scim2 custom attribute schema for tenant with Id: " + tenantId);
    }
    if (!SCIMCommonUtils.isCustomSchemaEnabled()) {
        return;
    }
    try {
        if (userManager.getCustomUserSchemaExtension() != null) {
            if (log.isDebugEnabled()) {
                log.debug("Scim2 custom attribute schema is found in the UserManager for tenant with Id: " + tenantId + ". Hence skip building the Extension Builder");
            }
            return;
        }
        try {
            SCIMCustomSchemaProcessor scimCustomSchemaProcessor = new SCIMCustomSchemaProcessor();
            List<SCIMCustomAttribute> attributes = scimCustomSchemaProcessor.getCustomAttributes(IdentityTenantUtil.getTenantDomain(tenantId), getCustomSchemaURI());
            AttributeSchema attributeSchema = SCIMCustomSchemaExtensionBuilder.getInstance().buildUserCustomSchemaExtension(attributes);
            SCIMCustomAttributeSchemaCache.getInstance().addSCIMCustomAttributeSchema(tenantId, attributeSchema);
        } catch (InternalErrorException e) {
            throw new CharonException("Error while building scim custom schema", e);
        }
    } catch (NotImplementedException | BadRequestException | IdentitySCIMException e) {
        throw new CharonException("Error while building scim custom schema", e);
    }
}
Also used : NotImplementedException(org.wso2.charon3.core.exceptions.NotImplementedException) SCIMCustomSchemaProcessor(org.wso2.carbon.identity.scim2.common.utils.SCIMCustomSchemaProcessor) AttributeSchema(org.wso2.charon3.core.schema.AttributeSchema) BadRequestException(org.wso2.charon3.core.exceptions.BadRequestException) InternalErrorException(org.wso2.charon3.core.exceptions.InternalErrorException) CharonException(org.wso2.charon3.core.exceptions.CharonException) SCIMCustomAttribute(org.wso2.charon3.core.attributes.SCIMCustomAttribute) IdentitySCIMException(org.wso2.carbon.identity.scim2.common.exceptions.IdentitySCIMException)

Aggregations

Test (org.testng.annotations.Test)152 ArrayList (java.util.ArrayList)137 HashMap (java.util.HashMap)112 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)103 SimpleAttribute (org.wso2.charon3.core.attributes.SimpleAttribute)99 ComplexAttribute (org.wso2.charon3.core.attributes.ComplexAttribute)94 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)89 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)89 Event (org.wso2.siddhi.core.event.Event)85 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)83 SiddhiApp (org.wso2.siddhi.query.api.SiddhiApp)83 Query (org.wso2.siddhi.query.api.execution.query.Query)83 MultiValuedAttribute (org.wso2.charon3.core.attributes.MultiValuedAttribute)82 Attribute (org.wso2.charon3.core.attributes.Attribute)73 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)73 CharonException (org.wso2.charon3.core.exceptions.CharonException)68 Map (java.util.Map)66 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)62 OMAttribute (org.apache.axiom.om.OMAttribute)51 OMElement (org.apache.axiom.om.OMElement)51