Search in sources :

Example 1 with SCIMClient

use of org.wso2.charon.core.client.SCIMClient 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 SCIMClient

use of org.wso2.charon.core.client.SCIMClient 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 3 with SCIMClient

use of org.wso2.charon.core.client.SCIMClient in project product-is by wso2.

the class IDENTITY4776SCIMServiceWithOAuthTestCase method addUsersUsingOAuthandSCIM.

@Test(groups = "wso2.is", description = "loginUsingSecondaryUserStoreUser")
public void addUsersUsingOAuthandSCIM() throws Exception {
    try {
        addSecondaryUserStore();
        addUserIntoSecondaryUserStore();
        registerOAuthApplication();
        loginUsingSecondaryUserStoreUser();
        // create SCIM client
        SCIMClient scimClient = new SCIMClient();
        String postData = SCIMUtils.getEncodedSCIMUser(scimClient, SCIM_USER_NAME, "test", new String[] { "scimUser@gmail.com", "scimUser@wso2.com" }, "SCIMUser", "password1", "Sinhala", "0711234567");
        // create a apache wink ClientHandler to intercept and identify response messages
        Resource userResource = SCIMUtils.getUserResource(scimClient, scimUrl);
        String response = userResource.header(SCIMConstants.AUTHORIZATION_HEADER, "Bearer " + accessToken).contentType(SCIMConstants.APPLICATION_JSON).accept(SCIMConstants.APPLICATION_JSON).post(String.class, postData);
        Object obj = JSONValue.parse(response);
        String scimUserId = ((JSONObject) obj).get("id").toString();
        Assert.assertTrue(isUserExists());
        Assert.assertNotNull(scimUserId);
    } catch (Exception e) {
        log.error("Error occured while executing the test case: " + e.getMessage(), e);
        throw e;
    }
}
Also used : Resource(org.apache.wink.client.Resource) SCIMClient(org.wso2.charon.core.client.SCIMClient) JSONObject(org.json.simple.JSONObject) Test(org.testng.annotations.Test) OAuth2ServiceAbstractIntegrationTest(org.wso2.identity.integration.test.oauth2.OAuth2ServiceAbstractIntegrationTest)

Example 4 with SCIMClient

use of org.wso2.charon.core.client.SCIMClient in project product-is by wso2.

the class MasterSCIMInitiator method getGroupResource.

protected Resource getGroupResource(SCIMClient scimClient, String skim_url) {
    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);
    // create resource endpoint to access User resource
    return restClient.resource(skim_url + "Groups");
}
Also used : RestClient(org.apache.wink.client.RestClient) SCIMResponseHandler(org.wso2.identity.integration.test.scim.utils.SCIMResponseHandler) ClientConfig(org.apache.wink.client.ClientConfig)

Example 5 with SCIMClient

use of org.wso2.charon.core.client.SCIMClient 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)

Aggregations

Resource (org.apache.wink.client.Resource)19 BasicAuthInfo (org.wso2.identity.integration.test.utils.BasicAuthInfo)18 Test (org.testng.annotations.Test)17 ClientConfig (org.apache.wink.client.ClientConfig)16 RestClient (org.apache.wink.client.RestClient)16 SetEnvironment (org.wso2.carbon.automation.engine.annotations.SetEnvironment)16 SCIMResponseHandler (org.wso2.identity.integration.test.scim.utils.SCIMResponseHandler)16 SCIMClient (org.wso2.charon.core.client.SCIMClient)6 JSONObject (org.json.simple.JSONObject)5 Group (org.wso2.charon.core.objects.Group)4 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)2 RemoteException (java.rmi.RemoteException)1 BeforeClass (org.testng.annotations.BeforeClass)1 AutomationContext (org.wso2.carbon.automation.engine.context.AutomationContext)1 User (org.wso2.carbon.automation.engine.context.beans.User)1 LoginLogoutClient (org.wso2.carbon.integration.common.utils.LoginLogoutClient)1 UserAdminUserAdminException (org.wso2.carbon.user.mgt.stub.UserAdminUserAdminException)1 FlaggedName (org.wso2.carbon.user.mgt.stub.types.carbon.FlaggedName)1 User (org.wso2.charon.core.objects.User)1 UserManagementClient (org.wso2.identity.integration.common.clients.UserManagementClient)1