use of org.wso2.carbon.identity.api.server.idp.v1.model.Patch in project product-is by wso2.
the class SCIMServiceProviderGroupTestCase method patchGroup.
@Test(alwaysRun = true, description = "Add new SCIM user member to group testeng2 without removing existing users", dependsOnMethods = { "updateGroup" })
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.ALL })
public void patchGroup() throws Exception {
SCIMResponseHandler responseHandler = new SCIMResponseHandler();
responseHandler.setSCIMClient(scimClient);
// set the handler in wink client config
ClientConfig clientConfig = new ClientConfig();
clientConfig.handlers(new ClientHandler[] { responseHandler });
// create a wink rest client with the above config
RestClient restClient = new RestClient(clientConfig);
BasicAuthInfo encodedBasicAuthInfo = SCIMUtils.getBasicAuthInfo(userInfo);
// create resource endpoint to access a known user resource.
Resource groupResource = restClient.resource(scim_url + "Groups/" + scimGroupId);
String response = groupResource.header(SCIMConstants.AUTHORIZATION_HEADER, encodedBasicAuthInfo.getAuthorizationHeader()).contentType(SCIMConstants.APPLICATION_JSON).accept(SCIMConstants.APPLICATION_JSON).get(String.class);
log.info("Retrieved group: " + response);
// decode retrieved group
Group decodedGroup = (Group) scimClient.decodeSCIMResponse(response.replace("PRIMARY/", ""), SCIMConstants.JSON, 2);
decodedGroup.setUserMember(scimUserId2, USERNAME2);
String updatedGroupString = scimClient.encodeSCIMObject(decodedGroup, SCIMConstants.JSON);
Resource updateGroupResource = restClient.resource(scim_url + "Groups/" + scimGroupId);
String responseUpdated = updateGroupResource.header(SCIMConstants.AUTHORIZATION_HEADER, encodedBasicAuthInfo.getAuthorizationHeader()).contentType(SCIMConstants.APPLICATION_JSON).header("X-HTTP-Method-Override", "PATCH").accept(SCIMConstants.APPLICATION_JSON).post(String.class, updatedGroupString);
log.info("Updated group: " + responseUpdated);
Assert.assertTrue(userMgtClient.userNameExists("testeng2", USERNAME) && userMgtClient.userNameExists("testeng2", USERNAME2));
}
use of org.wso2.carbon.identity.api.server.idp.v1.model.Patch in project product-is by wso2.
the class ServerChallengeTestCase method updateChallengeQuestionPATCHTest.
/**
* This test method validate update challenge question api response.
*
* @throws JSONException thrown to indicate a problem with the JSON.
*/
@Test(dependsOnMethods = { "addsNewChallengeQuestionSetTest" })
public void updateChallengeQuestionPATCHTest() throws JSONException {
String operation = "add";
String locale = "en_US";
String questionID = "question6";
String challengeQuestion = "What is the name of your first school?";
ServerChallengeModel.Questions question = new ServerChallengeModel.Questions(locale, challengeQuestion, questionID);
ServerChallengeModel.ChallengeQuestionOperation challengeQuestionOperation = new ServerChallengeModel.ChallengeQuestionOperation(question, operation);
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String json = gson.toJson(challengeQuestionOperation);
given().auth().preemptive().basic(USER_NAME, PASSWORD).contentType(ContentType.JSON).header(HttpHeaders.ACCEPT, ContentType.JSON).body(json).log().ifValidationFails().when().patch(RESOURCE_PATH + "/{challenge-set-id}", QUESTION_SET_ID).then().log().ifValidationFails().assertThat().statusCode(HttpStatus.SC_CREATED).log().ifValidationFails();
getsChallengeQuestionTest(QUESTION_SET_ID, challengeQuestion, questionID);
}
use of org.wso2.carbon.identity.api.server.idp.v1.model.Patch in project identity-inbound-provisioning-scim2 by wso2-extensions.
the class MeResource method patchUser.
@PATCH
public Response patchUser(@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.updateWithPATCH(userId, resourceString, userManager, attribute, excludedAttributes);
return SupportUtils.buildResponse(response);
} catch (CharonException e) {
return handleCharonException(e);
} catch (FormatNotSupportedException e) {
return handleFormatNotSupportedException(e);
}
}
use of org.wso2.carbon.identity.api.server.idp.v1.model.Patch in project identity-inbound-provisioning-scim2 by wso2-extensions.
the class GroupResource method decodePatchOperation.
/**
* Decode patch operation resource string and get the permissions.
*
* @param jsonResourceString string that should decode.
* @return Map of permissions to add and remove.
* @throws BadRequestException
*/
private HashMap<String, String[]> decodePatchOperation(String jsonResourceString) throws BadRequestException {
JSONDecoder decode = new JSONDecoder();
ArrayList<PatchOperation> listOperations;
List<String> permissionsToAdd;
List<String> permissionsToRemove;
HashMap<String, String[]> permissionMap = new HashMap<>();
// Decode the JSON string and get the permissions based on operations.
listOperations = decode.decodeRequest(jsonResourceString);
if (!listOperations.isEmpty()) {
for (PatchOperation op : listOperations) {
if ((SCIMProviderConstants.ADD).equals(op.getOperation())) {
JSONArray permissions = new JSONArray(op.getValues().toString());
permissionsToAdd = IntStream.range(0, permissions.length()).mapToObj(permissions::getString).collect(Collectors.toList());
if (permissionsToAdd.isEmpty()) {
permissionMap.put(SCIMProviderConstants.ADD, null);
} else {
permissionMap.put(SCIMProviderConstants.ADD, permissionsToAdd.toArray(new String[0]));
}
} else if (SCIMProviderConstants.REMOVE.equals(op.getOperation())) {
JSONArray permissions = new JSONArray(op.getValues().toString());
permissionsToRemove = IntStream.range(0, permissions.length()).mapToObj(permissions::getString).collect(Collectors.toList());
if (permissionsToRemove.isEmpty()) {
permissionMap.put(SCIMProviderConstants.REMOVE, null);
} else {
permissionMap.put(SCIMProviderConstants.REMOVE, permissionsToRemove.toArray(new String[0]));
}
}
}
}
return permissionMap;
}
use of org.wso2.carbon.identity.api.server.idp.v1.model.Patch 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);
}
Aggregations