Search in sources :

Example 61 with Role

use of org.wso2.carbon.identity.role.mgt.core.Role in project charon by wso2.

the class RoleResourceManager method listWithGETRole.

@Override
public SCIMResponse listWithGETRole(RoleManager roleManager, String filter, Integer startIndexInt, Integer countInt, String sortBy, String sortOrder) {
    try {
        if (roleManager == null) {
            String error = "Provided role manager is null.";
            throw new InternalErrorException(error);
        }
        Integer count = ResourceManagerUtil.processCount(countInt);
        Integer startIndex = ResourceManagerUtil.processStartIndex(startIndexInt);
        sortOrder = resolveSortOrder(sortOrder, sortBy);
        SCIMResourceTypeSchema schema = SCIMResourceSchemaManager.getInstance().getRoleResourceSchema();
        // Build node for filtering.
        Node rootNode = buildNode(filter, schema);
        JSONEncoder encoder = getEncoder();
        List<Object> rolesList = roleManager.listRolesWithGET(rootNode, startIndex, count, sortBy, sortOrder);
        return processRoleList(rolesList, encoder, startIndex);
    } catch (CharonException | InternalErrorException | BadRequestException | NotImplementedException e) {
        return encodeSCIMException(e);
    } catch (IOException e) {
        String error = "Error in tokenization of the input filter.";
        CharonException charonException = new CharonException(error);
        return AbstractResourceManager.encodeSCIMException(charonException);
    }
}
Also used : Node(org.wso2.charon3.core.utils.codeutils.Node) NotImplementedException(org.wso2.charon3.core.exceptions.NotImplementedException) InternalErrorException(org.wso2.charon3.core.exceptions.InternalErrorException) IOException(java.io.IOException) BadRequestException(org.wso2.charon3.core.exceptions.BadRequestException) SCIMResourceTypeSchema(org.wso2.charon3.core.schema.SCIMResourceTypeSchema) JSONEncoder(org.wso2.charon3.core.encoder.JSONEncoder) CharonException(org.wso2.charon3.core.exceptions.CharonException)

Example 62 with Role

use of org.wso2.carbon.identity.role.mgt.core.Role in project charon by wso2.

the class ServerSideValidator method validateCreatedSCIMObject.

/*
     * Validate created SCIMObject according to the spec
     *
     * @param scimObject
     * @param resourceSchema
     * @throw CharonException
     * @throw BadRequestException
     * @throw NotFoundException
     */
public static void validateCreatedSCIMObject(AbstractSCIMObject scimObject, SCIMResourceTypeSchema resourceSchema) throws CharonException, BadRequestException, NotFoundException {
    if (scimObject instanceof User) {
        // set display names for complex multivalued attributes
        setDisplayNameInComplexMultiValuedAttributes(scimObject, resourceSchema);
    }
    // remove any read only attributes
    removeAnyReadOnlyAttributes(scimObject, resourceSchema);
    if (!(scimObject instanceof Role)) {
        String id = UUID.randomUUID().toString();
        scimObject.setId(id);
        Instant now = Instant.now();
        // Set the created date and time.
        scimObject.setCreatedInstant(AttributeUtil.parseDateTime(AttributeUtil.formatDateTime(now)));
        // Creates date and the last modified are the same if not updated.
        scimObject.setLastModifiedInstant(AttributeUtil.parseDateTime(AttributeUtil.formatDateTime(now)));
    }
    // set location and resourceType
    if (resourceSchema.isSchemaAvailable(SCIMConstants.USER_CORE_SCHEMA_URI)) {
        String location = createLocationHeader(AbstractResourceManager.getResourceEndpointURL(SCIMConstants.USER_ENDPOINT), scimObject.getId());
        scimObject.setLocation(location);
        scimObject.setResourceType(SCIMConstants.USER);
    } else if (resourceSchema.isSchemaAvailable(SCIMConstants.GROUP_CORE_SCHEMA_URI)) {
        String location = createLocationHeader(AbstractResourceManager.getResourceEndpointURL(SCIMConstants.GROUP_ENDPOINT), scimObject.getId());
        scimObject.setLocation(location);
        scimObject.setResourceType(SCIMConstants.GROUP);
    } else if (resourceSchema.isSchemaAvailable(SCIMConstants.ROLE_SCHEMA_URI)) {
        scimObject.setResourceType(SCIMConstants.ROLE);
    }
    // check for required attributes
    validateSCIMObjectForRequiredAttributes(scimObject, resourceSchema);
    validateSchemaList(scimObject, resourceSchema);
}
Also used : Role(org.wso2.charon3.core.objects.Role) User(org.wso2.charon3.core.objects.User) Instant(java.time.Instant)

Example 63 with Role

use of org.wso2.carbon.identity.role.mgt.core.Role in project charon by wso2.

the class ServerSideValidatorTest method testValidateRetrievedSCIMRoleObject.

@Test(dataProvider = "dataForValidateRetrievedSCIMRoleObject")
public void testValidateRetrievedSCIMRoleObject(Object objectScimObject, String requestedAttributes, String requestedExcludingAttributes) {
    Role scimObject = (Role) objectScimObject;
    ServerSideValidator.validateRetrievedSCIMRoleObject(scimObject, requestedAttributes, requestedExcludingAttributes);
    Assert.assertTrue(true, "validateRetrievedSCIMRoleObject is successful");
}
Also used : Role(org.wso2.charon3.core.objects.Role) Test(org.testng.annotations.Test)

Example 64 with Role

use of org.wso2.carbon.identity.role.mgt.core.Role in project charon by wso2.

the class JSONDecoder method setRequestData.

private void setRequestData(String requestType, String requestMethod, String requestVersion, JSONObject member, List<BulkRequestContent> usersEndpointOperationList, List<BulkRequestContent> groupsEndpointOperationList, List<BulkRequestContent> rolesEndpointOperationList) {
    // Create user request list.
    if (requestType.contains(SCIMConstants.USER_ENDPOINT)) {
        BulkRequestContent newRequestData = getBulkRequestContent(member, requestMethod, requestType, requestVersion);
        usersEndpointOperationList.add(newRequestData);
    }
    // Create group request list.
    if (requestType.contains(SCIMConstants.GROUP_ENDPOINT)) {
        BulkRequestContent newRequestData = getBulkRequestContent(member, requestMethod, requestType, requestVersion);
        groupsEndpointOperationList.add(newRequestData);
    }
    // Create role request list.
    if (requestType.contains(SCIMConstants.ROLE_ENDPOINT)) {
        BulkRequestContent newRequestData = getBulkRequestContent(member, requestMethod, requestType, requestVersion);
        rolesEndpointOperationList.add(newRequestData);
    }
}
Also used : BulkRequestContent(org.wso2.charon3.core.objects.bulk.BulkRequestContent)

Example 65 with Role

use of org.wso2.carbon.identity.role.mgt.core.Role in project charon by wso2.

the class JSONEncoder method getSCIMObjectAsJSONObject.

/*
     * Make JSON object from given SCIM object.
     *
     * @param scimObject
     * @return the resulting string after encoding.
     */
public JSONObject getSCIMObjectAsJSONObject(SCIMObject scimObject) throws CharonException {
    // root json object containing the encoded SCIM Object.
    JSONObject rootObject = new JSONObject();
    try {
        // encode schemas
        this.encodeArrayOfValues(SCIMConstants.CommonSchemaConstants.SCHEMAS, (scimObject.getSchemaList()).toArray(), rootObject);
        // encode attribute list
        Map<String, Attribute> attributes = scimObject.getAttributeList();
        if (attributes != null && !attributes.isEmpty()) {
            for (Attribute attribute : attributes.values()) {
                // using instanceof instead of polymorphic way, in order to make encoder pluggable.
                if (attribute instanceof SimpleAttribute) {
                    encodeSimpleAttribute((SimpleAttribute) attribute, rootObject);
                } else if (attribute instanceof ComplexAttribute) {
                    encodeComplexAttribute((ComplexAttribute) attribute, rootObject);
                } else if (attribute instanceof MultiValuedAttribute) {
                    encodeMultiValuedAttribute((MultiValuedAttribute) attribute, rootObject);
                }
            }
        }
        // Encode permissions of the role.
        if (scimObject instanceof Role && !((Role) scimObject).getPermissions().isEmpty()) {
            this.encodeArrayOfValues(SCIMConstants.RoleSchemaConstants.PERMISSIONS, (((Role) scimObject).getPermissions()).toArray(), rootObject);
        }
    } catch (JSONException e) {
        String errorMessage = "Error in encoding resource..";
        // TODO:log the error
        throw new CharonException(errorMessage);
    }
    return rootObject;
}
Also used : Role(org.wso2.charon3.core.objects.Role) JSONObject(org.json.JSONObject) MultiValuedAttribute(org.wso2.charon3.core.attributes.MultiValuedAttribute) SimpleAttribute(org.wso2.charon3.core.attributes.SimpleAttribute) ComplexAttribute(org.wso2.charon3.core.attributes.ComplexAttribute) Attribute(org.wso2.charon3.core.attributes.Attribute) SimpleAttribute(org.wso2.charon3.core.attributes.SimpleAttribute) ComplexAttribute(org.wso2.charon3.core.attributes.ComplexAttribute) JSONException(org.json.JSONException) CharonException(org.wso2.charon3.core.exceptions.CharonException) AbstractCharonException(org.wso2.charon3.core.exceptions.AbstractCharonException) MultiValuedAttribute(org.wso2.charon3.core.attributes.MultiValuedAttribute)

Aggregations

Test (org.testng.annotations.Test)85 ArrayList (java.util.ArrayList)74 UserStoreException (org.wso2.carbon.user.api.UserStoreException)56 HashMap (java.util.HashMap)52 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)42 Connection (java.sql.Connection)36 SQLException (java.sql.SQLException)34 Role (org.wso2.charon3.core.objects.Role)33 AbstractUserStoreManager (org.wso2.carbon.user.core.common.AbstractUserStoreManager)31 CharonException (org.wso2.charon3.core.exceptions.CharonException)29 RoleBasicInfo (org.wso2.carbon.identity.role.mgt.core.RoleBasicInfo)26 PreparedStatement (java.sql.PreparedStatement)25 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)24 RoleMapping (org.wso2.carbon.identity.application.common.model.RoleMapping)24 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)23 HashSet (java.util.HashSet)20 UserStoreManager (org.wso2.carbon.user.api.UserStoreManager)20 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)19 IdentityRoleManagementClientException (org.wso2.carbon.identity.role.mgt.core.IdentityRoleManagementClientException)19 Matchers.anyString (org.mockito.Matchers.anyString)18