use of org.apache.wink.client.ClientConfig in project product-is by wso2.
the class SCIMServiceProviderUserTestCase method UpdateUser.
@Test(alwaysRun = true, description = "Update SCIM user", dependsOnMethods = { "filterUser" })
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.ALL })
public void UpdateUser() throws Exception {
String updatedMiddleName = "testChange11";
String updatedEmail = "test123@wso2.com";
// create a apache wink ClientHandler to intercept and identify response messages
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(provider_userInfo);
// create resource endpoint to access a known user resource.
Resource userResource = restClient.resource(scim_url + "Users/" + scimUserId);
org.wso2.charon.core.objects.User decodedUser = SCIMUtils.getSCIMUser(scimClient, USERNAME, "test", new String[] { "scimuser1@gmail.com", "scimuser1@wso2.com" }, "SCIMUser1", PASSWORD, "sinhala", "0772202595");
decodedUser.setDisplayName(updatedMiddleName);
decodedUser.setWorkEmail(updatedEmail, true);
// encode updated user
String updatedUserString = scimClient.encodeSCIMObject(decodedUser, SCIMConstants.JSON);
// update user
Resource updateUserResource = restClient.resource(scim_url + "Users/" + scimUserId);
String responseUpdated = updateUserResource.header(SCIMConstants.AUTHORIZATION_HEADER, encodedBasicAuthInfo.getAuthorizationHeader()).contentType(SCIMConstants.APPLICATION_JSON).accept(SCIMConstants.APPLICATION_JSON).put(String.class, updatedUserString);
log.info("Updated user: " + responseUpdated);
String response = userResource.header(SCIMConstants.AUTHORIZATION_HEADER, encodedBasicAuthInfo.getAuthorizationHeader()).contentType(SCIMConstants.APPLICATION_JSON).accept(SCIMConstants.APPLICATION_JSON).get(String.class);
log.info("Retrieved user: " + response);
Assert.assertTrue(response.contains(updatedEmail));
Assert.assertTrue(response.contains(updatedMiddleName));
}
use of org.apache.wink.client.ClientConfig in project product-is by wso2.
the class SCIMServiceProviderUserTestCase method getUserMe.
@Test(alwaysRun = true, description = "Get logged in SCIM user", dependsOnMethods = { "getUser" })
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.ALL })
public void getUserMe() {
// create a apache wink ClientHandler to intercept and identify response messages
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);
try {
userMgtClient.updateRolesOfUser(USERNAME, new String[] { ADMIN_ROLE });
} catch (UserAdminUserAdminException | RemoteException e) {
log.error("Failed to add User to admin role", e);
Assert.fail("Failed to add User to admin role");
}
User userInfo = new User();
userInfo.setUserName(USERNAME);
userInfo.setPassword(PASSWORD);
BasicAuthInfo encodedBasicAuthInfo = SCIMUtils.getBasicAuthInfo(userInfo);
// create resource endpoint to access user resource of logged in User.
Resource userResource = restClient.resource(scim_url + SCIM_ME_ENDPOINT);
try {
userResource.header(SCIMConstants.AUTHORIZATION_HEADER, encodedBasicAuthInfo.getAuthorizationHeader()).contentType(SCIMConstants.APPLICATION_JSON).accept(SCIMConstants.APPLICATION_JSON).get(String.class);
} catch (Exception e) {
log.error("Failed to retrieve information of user through /me endpoint.", e);
Assert.fail("Failed to retrieve information of user through /me endpoint.");
}
}
use of org.apache.wink.client.ClientConfig in project product-is by wso2.
the class SCIMServiceProviderUserTestCase method DeleteUser.
@Test(alwaysRun = true, description = "Delete SCIM user", dependsOnMethods = { "UpdateUser" })
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.ALL })
public void DeleteUser() throws Exception {
ClientConfig clientConfig = new ClientConfig();
SCIMResponseHandler responseHandler = new SCIMResponseHandler();
responseHandler.setSCIMClient(scimClient);
clientConfig.handlers(new ClientHandler[] { responseHandler });
RestClient restClient = new RestClient(clientConfig);
BasicAuthInfo encodedBasicAuthInfo = SCIMUtils.getBasicAuthInfo(provider_userInfo);
Resource userResource = restClient.resource(scim_url + "Users/" + scimUserId);
String response = userResource.header(SCIMConstants.AUTHORIZATION_HEADER, encodedBasicAuthInfo.getAuthorizationHeader()).accept(SCIMConstants.APPLICATION_JSON).delete(String.class);
// decode the response
Assert.assertTrue(response.isEmpty());
Assert.assertFalse(isUserExists());
}
use of org.apache.wink.client.ClientConfig in project product-is by wso2.
the class SCIMServiceProviderUserTestCase method filterUser.
@Test(alwaysRun = true, description = "filter all SCIM users", dependsOnMethods = { "listUser" })
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.ALL })
public void filterUser() throws Exception {
// create SCIM client
SCIMClient scimClient = new SCIMClient();
// create a apache wink ClientHandler to intercept and identify response messages
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(provider_userInfo);
// create resource endpoint to access a known user resource.
Resource userResource = restClient.resource(scim_url + "Users?filter=userName%20Eq%20" + USERNAME);
String response = userResource.header(SCIMConstants.AUTHORIZATION_HEADER, encodedBasicAuthInfo.getAuthorizationHeader()).contentType(SCIMConstants.APPLICATION_JSON).accept(SCIMConstants.APPLICATION_JSON).get(String.class);
Assert.assertTrue(response.contains("\"userName\":\"" + USERNAME + "\""));
}
use of org.apache.wink.client.ClientConfig in project product-is by wso2.
the class SCIMServiceProviderUserTestCase method listUser.
@Test(alwaysRun = true, description = "list all SCIM users", dependsOnMethods = { "getUserMe" })
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.ALL })
public void listUser() throws Exception {
// create SCIM client
SCIMClient scimClient = new SCIMClient();
// create a apache wink ClientHandler to intercept and identify response messages
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(provider_userInfo);
// create resource endpoint to access a known user resource.
Resource userResource = restClient.resource(scim_url + "Users");
String response = userResource.header(SCIMConstants.AUTHORIZATION_HEADER, encodedBasicAuthInfo.getAuthorizationHeader()).contentType(SCIMConstants.APPLICATION_JSON).accept(SCIMConstants.APPLICATION_JSON).get(String.class);
Assert.assertTrue(isAllUsersExists(response));
}
Aggregations