Search in sources :

Example 91 with Group

use of org.wso2.charon.core.objects.Group in project charon by wso2.

the class ResourceTypeResourceManager method getResourceType.

/*
     * return RESOURCE_TYPE schema
     *
     * @return
     */
private SCIMResponse getResourceType() {
    JSONEncoder encoder = null;
    try {
        // obtain the json encoder
        encoder = getEncoder();
        // obtain the json decoder
        JSONDecoder decoder = getDecoder();
        // get the service provider config schema
        SCIMResourceTypeSchema schema = SCIMResourceSchemaManager.getInstance().getResourceTypeResourceSchema();
        // create a string in json format for user resource type with relevant values
        String scimUserObjectString = encoder.buildUserResourceTypeJsonBody();
        // create a string in json format for group resource type with relevant values
        String scimGroupObjectString = encoder.buildGroupResourceTypeJsonBody();
        // build the user abstract scim object
        AbstractSCIMObject userResourceTypeObject = (AbstractSCIMObject) decoder.decodeResource(scimUserObjectString, schema, new AbstractSCIMObject());
        // add meta data
        userResourceTypeObject = ServerSideValidator.validateResourceTypeSCIMObject(userResourceTypeObject);
        // build the group abstract scim object
        AbstractSCIMObject groupResourceTypeObject = (AbstractSCIMObject) decoder.decodeResource(scimGroupObjectString, schema, new AbstractSCIMObject());
        // add meta data
        groupResourceTypeObject = ServerSideValidator.validateResourceTypeSCIMObject(groupResourceTypeObject);
        // build the root abstract scim object
        AbstractSCIMObject resourceTypeObject = buildCombinedResourceType(userResourceTypeObject, groupResourceTypeObject);
        // encode the newly created SCIM Resource Type object.
        String encodedObject;
        Map<String, String> responseHeaders = new HashMap<String, String>();
        if (resourceTypeObject != null) {
            // create a deep copy of the resource type object since we are going to change it.
            AbstractSCIMObject copiedObject = (AbstractSCIMObject) CopyUtil.deepCopy(resourceTypeObject);
            encodedObject = encoder.encodeSCIMObject(copiedObject);
            // add location header
            responseHeaders.put(SCIMConstants.LOCATION_HEADER, getResourceEndpointURL(SCIMConstants.RESOURCE_TYPE_ENDPOINT));
            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 resource type object in the response header parameter.
        return new SCIMResponse(ResponseCodeConstants.CODE_OK, encodedObject, responseHeaders);
    } catch (CharonException e) {
        return encodeSCIMException(e);
    } catch (BadRequestException e) {
        return encodeSCIMException(e);
    } catch (InternalErrorException e) {
        return encodeSCIMException(e);
    } catch (NotFoundException e) {
        return encodeSCIMException(e);
    } catch (JSONException e) {
        return null;
    }
}
Also used : AbstractSCIMObject(org.wso2.charon3.core.objects.AbstractSCIMObject) HashMap(java.util.HashMap) NotFoundException(org.wso2.charon3.core.exceptions.NotFoundException) JSONException(org.json.JSONException) InternalErrorException(org.wso2.charon3.core.exceptions.InternalErrorException) 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)

Example 92 with Group

use of org.wso2.charon.core.objects.Group in project charon by wso2.

the class UserResourceManager method processUserList.

/**
 * Method to process a user list and return a SCIM response.
 *
 * @param tempList          Filtered user list
 * @param encoder           Json encoder
 * @param schema            Schema
 * @param attributes        Required attributes
 * @param excludeAttributes Exclude attributes
 * @param startIndex        Starting index
 * @return SCIM response
 * @throws NotFoundException
 * @throws CharonException
 * @throws BadRequestException
 */
private SCIMResponse processUserList(List<Object> tempList, JSONEncoder encoder, SCIMResourceTypeSchema schema, String attributes, String excludeAttributes, int startIndex) throws NotFoundException, CharonException, BadRequestException {
    int totalResults = 0;
    List<Object> returnedUsers;
    if (tempList == null) {
        tempList = Collections.emptyList();
    }
    try {
        totalResults = (int) tempList.get(0);
        tempList.remove(0);
    } catch (IndexOutOfBoundsException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Group result list is empty.");
        }
        totalResults = tempList.size();
    } catch (ClassCastException ex) {
        logger.debug("Parse error while getting the user result count. Setting result count as: " + tempList.size(), ex);
        totalResults = tempList.size();
    }
    returnedUsers = tempList;
    for (Object user : returnedUsers) {
        // Perform service provider side validation.
        ServerSideValidator.validateRetrievedSCIMObjectInList((User) user, schema, attributes, excludeAttributes);
    }
    // Create a listed resource object out of the returned users list.
    ListedResource listedResource = createListedResource(returnedUsers, startIndex, totalResults);
    // Convert the listed resource into specific format.
    String encodedListedResource = encoder.encodeSCIMObject(listedResource);
    // If there are any http headers to be added in the response header.
    Map<String, String> responseHeaders = new HashMap<String, String>();
    responseHeaders.put(SCIMConstants.CONTENT_TYPE_HEADER, SCIMConstants.APPLICATION_JSON);
    return new SCIMResponse(ResponseCodeConstants.CODE_OK, encodedListedResource, responseHeaders);
}
Also used : ListedResource(org.wso2.charon3.core.objects.ListedResource) HashMap(java.util.HashMap) SCIMResponse(org.wso2.charon3.core.protocol.SCIMResponse)

Example 93 with Group

use of org.wso2.charon.core.objects.Group in project charon by wso2.

the class ServerSideValidatorTest method dataToValidateResourceTypeSCIMObject.

@DataProvider(name = "dataForValidateResourceTypeSCIMObject")
public Object[][] dataToValidateResourceTypeSCIMObject() throws CharonException, InstantiationException, IllegalAccessException {
    AbstractSCIMObject userResourceTypeObject = AbstractSCIMObject.class.newInstance();
    userResourceTypeObject.setSchema("urn:ietf:params:scim:api:messages:2.0:ListResponse");
    SimpleAttribute simpleAttribute1 = new SimpleAttribute("id", "User");
    userResourceTypeObject.setAttribute(simpleAttribute1);
    SimpleAttribute simpleAttribute2 = new SimpleAttribute("name", "User");
    userResourceTypeObject.setAttribute(simpleAttribute2);
    SimpleAttribute simpleAttribute3 = new SimpleAttribute("endpoint", "/Users");
    userResourceTypeObject.setAttribute(simpleAttribute3);
    AbstractSCIMObject groupResourceTypeObject = AbstractSCIMObject.class.newInstance();
    groupResourceTypeObject.setSchema("urn:ietf:params:scim:api:messages:2.0:ListResponse");
    SimpleAttribute simpleAttribute4 = new SimpleAttribute("id", "Group");
    groupResourceTypeObject.setAttribute(simpleAttribute4);
    SimpleAttribute simpleAttribute5 = new SimpleAttribute("name", "Group");
    groupResourceTypeObject.setAttribute(simpleAttribute5);
    SimpleAttribute simpleAttribute6 = new SimpleAttribute("endpoint", "/Groups");
    groupResourceTypeObject.setAttribute(simpleAttribute6);
    return new Object[][] { { userResourceTypeObject, "https://localhost:9443/scim2/ResourceTypes/User", "ResourceType" }, { groupResourceTypeObject, "https://localhost:9443/scim2/ResourceTypes/Group", "ResourceType" } };
}
Also used : AbstractSCIMObject(org.wso2.charon3.core.objects.AbstractSCIMObject) SimpleAttribute(org.wso2.charon3.core.attributes.SimpleAttribute) AbstractSCIMObject(org.wso2.charon3.core.objects.AbstractSCIMObject) DataProvider(org.testng.annotations.DataProvider)

Example 94 with Group

use of org.wso2.charon.core.objects.Group in project charon by wso2.

the class ServerSideValidatorTest method createNewGroup.

private Group createNewGroup() throws InstantiationException, IllegalAccessException {
    Group group = Group.class.newInstance();
    group.setSchema("urn:ietf:params:scim:schemas:core:2.0:Group");
    SimpleAttribute simpleAttributeGroup = new SimpleAttribute("displayName", "manager");
    group.setAttribute(simpleAttributeGroup);
    SimpleAttribute simpleAttributeDisplay = new SimpleAttribute("display", "rashN");
    SimpleAttribute simpleAttributeValue = new SimpleAttribute("value", "008bba85-451d-414b-87de-c03b5a1f4218");
    Map<String, Attribute> valuesMapGroup = new HashMap<>();
    valuesMapGroup.put("display", simpleAttributeDisplay);
    valuesMapGroup.put("value", simpleAttributeValue);
    ComplexAttribute complexAttributeMembers = new ComplexAttribute("members_008bba85-451d-414b-87de-c03b5a1f4218_default");
    complexAttributeMembers.setType(COMPLEX);
    complexAttributeMembers.setMutability(READ_WRITE);
    complexAttributeMembers.setRequired(false);
    complexAttributeMembers.setSubAttributesList(valuesMapGroup);
    MultiValuedAttribute multiValuedAttributeMembers = new MultiValuedAttribute("members");
    multiValuedAttributeMembers.setType(SCIMDefinitions.DataType.COMPLEX);
    multiValuedAttributeMembers.setMultiValued(true);
    multiValuedAttributeMembers.setMutability(READ_WRITE);
    multiValuedAttributeMembers.setAttributeValue(complexAttributeMembers);
    group.setAttribute(multiValuedAttributeMembers);
    return group;
}
Also used : Group(org.wso2.charon3.core.objects.Group) 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) HashMap(java.util.HashMap) SimpleAttribute(org.wso2.charon3.core.attributes.SimpleAttribute) ComplexAttribute(org.wso2.charon3.core.attributes.ComplexAttribute) MultiValuedAttribute(org.wso2.charon3.core.attributes.MultiValuedAttribute)

Example 95 with Group

use of org.wso2.charon.core.objects.Group 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)

Aggregations

Test (org.testng.annotations.Test)155 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)99 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)94 Event (org.wso2.siddhi.core.event.Event)89 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)80 Group (org.wso2.charon3.core.objects.Group)57 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)53 CharonException (org.wso2.charon3.core.exceptions.CharonException)43 HashMap (java.util.HashMap)38 Connection (java.sql.Connection)34 SQLException (java.sql.SQLException)34 ArrayList (java.util.ArrayList)34 IdentitySCIMException (org.wso2.carbon.identity.scim2.common.exceptions.IdentitySCIMException)34 SCIMResourceTypeSchema (org.wso2.charon3.core.schema.SCIMResourceTypeSchema)33 SCIMResponse (org.wso2.charon3.core.protocol.SCIMResponse)32 PreparedStatement (java.sql.PreparedStatement)29 ResultSet (java.sql.ResultSet)29 Operation (io.swagger.v3.oas.annotations.Operation)27 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)27 Response (javax.ws.rs.core.Response)27