use of org.wso2.identity.integration.test.utils.BasicAuthInfo in project product-is by wso2.
the class ProvisioningTestCase method createUserForSecondServer.
@Test(alwaysRun = true, description = "Add SCIM provisioning user on second server", dependsOnMethods = "createUser")
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.ALL })
public void createUserForSecondServer() throws Exception {
buildSCIMProvisioningConnector(PORT_OFFSET_1);
addSP(PORT_OFFSET_1);
scimClient = new SCIMClient();
String encodedUser = getScimUser(2);
// create a apache wink ClientHandler to intercept and identify response messages
Resource userResource = getResource(scimClient, scim_url_1);
BasicAuthInfo encodedBasicAuthInfo = getBasicAuthInfo(automationContextMap.get(PORT_OFFSET_0));
String response = userResource.header(SCIMConstants.AUTHORIZATION_HEADER, encodedBasicAuthInfo.getAuthorizationHeader()).contentType(SCIMConstants.APPLICATION_JSON).accept(SCIMConstants.APPLICATION_JSON).post(String.class, encodedUser);
Assert.assertTrue(response.contains(userName2));
}
use of org.wso2.identity.integration.test.utils.BasicAuthInfo in project product-is by wso2.
the class ProvisioningTestCase method getBasicAuthInfo.
private BasicAuthInfo getBasicAuthInfo(AutomationContext context) throws XPathExpressionException {
BasicAuthInfo basicAuthInfo = new BasicAuthInfo();
basicAuthInfo.setUserName(context.getSuperTenant().getTenantAdmin().getUserName());
basicAuthInfo.setPassword(context.getSuperTenant().getTenantAdmin().getPassword());
BasicAuthHandler basicAuthHandler = new BasicAuthHandler();
return (BasicAuthInfo) basicAuthHandler.getAuthenticationToken(basicAuthInfo);
}
use of org.wso2.identity.integration.test.utils.BasicAuthInfo in project product-is by wso2.
the class ProvisioningTestCase method createUser.
@Test(alwaysRun = true, description = "Add SCIM Provisioning user", priority = 1)
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.STANDALONE })
public void createUser() throws Exception {
buildSCIMProvisioningConnector(PORT_OFFSET_0);
addSP(PORT_OFFSET_0);
scimClient = new SCIMClient();
String encodedUser = getScimUser(1);
// create a apache wink ClientHandler to intercept and identify response messages
Resource userResource = getResource(scimClient, scim_url_0);
BasicAuthInfo encodedBasicAuthInfo = getBasicAuthInfo(automationContextMap.get(PORT_OFFSET_0));
String response = userResource.header(SCIMConstants.AUTHORIZATION_HEADER, encodedBasicAuthInfo.getAuthorizationHeader()).contentType(SCIMConstants.APPLICATION_JSON).accept(SCIMConstants.APPLICATION_JSON).post(String.class, encodedUser);
log.info(response);
scimUserId = response.split(",")[0].split(":")[1].replace('"', ' ').trim();
// userMgtServiceClients.get(PORT_OFFSET_2).listUsers(userName, 100);
Assert.assertNotNull(scimUserId);
Assert.assertTrue(isUserExists(userName));
}
use of org.wso2.identity.integration.test.utils.BasicAuthInfo in project product-is by wso2.
the class SCIMServiceProviderGroupTestCase method createGroupTest.
@Test(alwaysRun = true, description = "Add SCIM Group")
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.ALL })
public void createGroupTest() throws Exception {
// create a group according to SCIM Group Schema
Group scimGroup = SCIMUtils.getSCIMGroup(scimClient, scimUserId, USERNAME, EXTERNAL_ID, DISPLAY_NAME);
String encodedGroup = scimClient.encodeSCIMObject(scimGroup, SCIMConstants.JSON);
Resource groupResource = SCIMUtils.getGroupResource(scimClient, scim_url);
BasicAuthInfo encodedBasicAuthInfo = SCIMUtils.getBasicAuthInfo(userInfo);
// send previously registered SCIM consumer credentials in http headers.
String response = groupResource.header(SCIMConstants.AUTHORIZATION_HEADER, encodedBasicAuthInfo.getAuthorizationHeader()).contentType(SCIMConstants.APPLICATION_JSON).accept(SCIMConstants.APPLICATION_JSON).post(String.class, encodedGroup);
// decode the response
log.info(response);
Object obj = JSONValue.parse(response);
scimGroupId = ((JSONObject) obj).get("id").toString();
Assert.assertTrue(userMgtClient.roleNameExists(DISPLAY_NAME));
}
use of org.wso2.identity.integration.test.utils.BasicAuthInfo 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));
}
Aggregations