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;
}
}
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);
}
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" } };
}
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;
}
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);
}
}
Aggregations