Search in sources :

Example 1 with BasicAuthInfo

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));
}
Also used : Resource(org.apache.wink.client.Resource) SCIMClient(org.wso2.charon.core.client.SCIMClient) BasicAuthInfo(org.wso2.identity.integration.test.utils.BasicAuthInfo) SetEnvironment(org.wso2.carbon.automation.engine.annotations.SetEnvironment) Test(org.testng.annotations.Test) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest)

Example 2 with BasicAuthInfo

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);
}
Also used : BasicAuthHandler(org.wso2.identity.integration.test.utils.BasicAuthHandler) BasicAuthInfo(org.wso2.identity.integration.test.utils.BasicAuthInfo)

Example 3 with 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));
}
Also used : Resource(org.apache.wink.client.Resource) SCIMClient(org.wso2.charon.core.client.SCIMClient) BasicAuthInfo(org.wso2.identity.integration.test.utils.BasicAuthInfo) SetEnvironment(org.wso2.carbon.automation.engine.annotations.SetEnvironment) Test(org.testng.annotations.Test) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest)

Example 4 with BasicAuthInfo

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));
}
Also used : Group(org.wso2.charon.core.objects.Group) JSONObject(org.json.simple.JSONObject) Resource(org.apache.wink.client.Resource) BasicAuthInfo(org.wso2.identity.integration.test.utils.BasicAuthInfo) JSONObject(org.json.simple.JSONObject) SetEnvironment(org.wso2.carbon.automation.engine.annotations.SetEnvironment) Test(org.testng.annotations.Test)

Example 5 with BasicAuthInfo

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));
}
Also used : Group(org.wso2.charon.core.objects.Group) RestClient(org.apache.wink.client.RestClient) Resource(org.apache.wink.client.Resource) BasicAuthInfo(org.wso2.identity.integration.test.utils.BasicAuthInfo) SCIMResponseHandler(org.wso2.identity.integration.test.scim.utils.SCIMResponseHandler) ClientConfig(org.apache.wink.client.ClientConfig) SetEnvironment(org.wso2.carbon.automation.engine.annotations.SetEnvironment) Test(org.testng.annotations.Test)

Aggregations

BasicAuthInfo (org.wso2.identity.integration.test.utils.BasicAuthInfo)22 Resource (org.apache.wink.client.Resource)18 Test (org.testng.annotations.Test)16 SetEnvironment (org.wso2.carbon.automation.engine.annotations.SetEnvironment)16 ClientConfig (org.apache.wink.client.ClientConfig)13 RestClient (org.apache.wink.client.RestClient)13 SCIMResponseHandler (org.wso2.identity.integration.test.scim.utils.SCIMResponseHandler)13 JSONObject (org.json.simple.JSONObject)4 SCIMClient (org.wso2.charon.core.client.SCIMClient)4 BasicAuthHandler (org.wso2.identity.integration.test.utils.BasicAuthHandler)4 Group (org.wso2.charon.core.objects.Group)3 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)2 BasicAuthInfo (org.wso2.identity.ui.integration.test.utils.BasicAuthInfo)2 RemoteException (java.rmi.RemoteException)1 User (org.wso2.carbon.automation.engine.context.beans.User)1 UserAdminUserAdminException (org.wso2.carbon.user.mgt.stub.UserAdminUserAdminException)1 FlaggedName (org.wso2.carbon.user.mgt.stub.types.carbon.FlaggedName)1