Search in sources :

Example 6 with SCIMClient

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

Example 7 with SCIMClient

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

the class SCIMServiceProviderGroupTestCase method createUser.

public void createUser() throws CharonException {
    // create SCIM client
    String encodedUser = SCIMUtils.getEncodedSCIMUser(scimClient, USERNAME, "test", new String[] { "scimuser1@gmail.com", "scimuser2@wso2.com" }, "SCIMUser2", "password1", "sinhala", "0772202595");
    // create a apache wink ClientHandler to intercept and identify response messages
    Resource userResource = SCIMUtils.getUserResource(scimClient, scim_url);
    BasicAuthInfo encodedBasicAuthInfo = SCIMUtils.getBasicAuthInfo(userInfo);
    String response = userResource.header(SCIMConstants.AUTHORIZATION_HEADER, encodedBasicAuthInfo.getAuthorizationHeader()).contentType(SCIMConstants.APPLICATION_JSON).accept(SCIMConstants.APPLICATION_JSON).post(String.class, encodedUser);
    log.info(response);
    Object obj = JSONValue.parse(response);
    scimUserId = ((JSONObject) obj).get("id").toString();
    encodedUser = SCIMUtils.getEncodedSCIMUser(scimClient, USERNAME2, "test2", new String[] { "dkasunw2@gmail.com", "dharshanaw2@wso2.com" }, USERNAME2, "testPW2", "sinhala", "0712202541");
    response = userResource.header(SCIMConstants.AUTHORIZATION_HEADER, encodedBasicAuthInfo.getAuthorizationHeader()).contentType(SCIMConstants.APPLICATION_JSON).accept(SCIMConstants.APPLICATION_JSON).post(String.class, encodedUser);
    obj = JSONValue.parse(response);
    scimUserId2 = ((JSONObject) obj).get("id").toString();
}
Also used : JSONObject(org.json.simple.JSONObject) Resource(org.apache.wink.client.Resource) BasicAuthInfo(org.wso2.identity.integration.test.utils.BasicAuthInfo) JSONObject(org.json.simple.JSONObject)

Example 8 with SCIMClient

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

the class SCIMServiceProviderGroupTestCase method listGroup.

@Test(alwaysRun = true, description = "list SCIM Groups", dependsOnMethods = { "getGroup" })
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.ALL })
public void listGroup() 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(response.toString());
    FlaggedName[] roleNames = userMgtClient.listRoles("eng", 100);
    for (FlaggedName role : roleNames) {
        if (!role.getItemName().contains("false")) {
            Assert.assertTrue(response.contains(role.getItemName()));
        }
    }
}
Also used : RestClient(org.apache.wink.client.RestClient) Resource(org.apache.wink.client.Resource) FlaggedName(org.wso2.carbon.user.mgt.stub.types.carbon.FlaggedName) 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)

Example 9 with SCIMClient

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

the class SCIMServiceProviderGroupTestCase method deleteGroup.

@Test(alwaysRun = true, description = "Add SCIM user", dependsOnMethods = { "patchGroup" })
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.ALL })
public void deleteGroup() 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);
    // had to set content type for the delete request as well, coz wink client sets */* by default.
    String response = groupResource.header(SCIMConstants.AUTHORIZATION_HEADER, encodedBasicAuthInfo.getAuthorizationHeader()).accept(SCIMConstants.APPLICATION_JSON).delete(String.class);
    // decode the response
    log.info(response.toString());
    Assert.assertFalse(userMgtClient.roleNameExists(DISPLAY_NAME));
}
Also used : 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)

Example 10 with SCIMClient

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

the class SCIMServiceProviderGroupTestCase method initiate.

@BeforeClass(alwaysRun = true)
public void initiate() throws Exception {
    AutomationContext automationContext = new AutomationContext("IDENTITY", TestUserMode.SUPER_TENANT_ADMIN);
    userInfo = automationContext.getContextTenant().getContextUser();
    backendUrl = automationContext.getContextUrls().getBackEndUrl();
    serviceEndPoint = automationContext.getContextUrls().getServiceUrl();
    scim_url = backendUrl.substring(0, 22) + "/wso2/scim/";
    sessionCookie = new LoginLogoutClient(automationContext).login();
    userMgtClient = new UserManagementClient(backendUrl, sessionCookie);
    scimConfigAdminClient = new SCIMConfigAdminClient(backendUrl, sessionCookie);
    scimClient = new SCIMClient();
    // creating users for the test
    createUser();
}
Also used : AutomationContext(org.wso2.carbon.automation.engine.context.AutomationContext) LoginLogoutClient(org.wso2.carbon.integration.common.utils.LoginLogoutClient) SCIMConfigAdminClient(org.wso2.identity.integration.common.clients.scim.SCIMConfigAdminClient) SCIMClient(org.wso2.charon.core.client.SCIMClient) UserManagementClient(org.wso2.identity.integration.common.clients.UserManagementClient) BeforeClass(org.testng.annotations.BeforeClass)

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