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