Search in sources :

Example 16 with RestClient

use of org.apache.wink.client.RestClient in project product-is by wso2.

the class SCIMServiceProviderGroupTestCase method getGroup.

@Test(alwaysRun = true, description = "Get SCIM Group", dependsOnMethods = { "createGroupTest" })
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.ALL })
public void getGroup() 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());
    Object obj = JSONValue.parse(response);
    Assert.assertTrue(((JSONObject) obj).get("id").toString().contains(scimGroupId));
}
Also used : RestClient(org.apache.wink.client.RestClient) Resource(org.apache.wink.client.Resource) BasicAuthInfo(org.wso2.identity.integration.test.utils.BasicAuthInfo) JSONObject(org.json.simple.JSONObject) 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 17 with RestClient

use of org.apache.wink.client.RestClient in project product-is by wso2.

the class SCIMServiceProviderGroupTestCase method filterGroup.

@Test(alwaysRun = true, description = "filter SCIM Groups", dependsOnMethods = { "listGroup" })
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.ALL })
public void filterGroup() 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?filter=displayNameEqeng");
    String response = groupResource.header(SCIMConstants.AUTHORIZATION_HEADER, encodedBasicAuthInfo.getAuthorizationHeader()).contentType(SCIMConstants.APPLICATION_JSON).accept(SCIMConstants.APPLICATION_JSON).get(String.class);
    log.info(response.toString());
    Assert.assertTrue(response.contains("\"displayName\":\"PRIMARY/eng\""));
}
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 18 with RestClient

use of org.apache.wink.client.RestClient in project product-is by wso2.

the class SCIMServiceProviderGroupTestCase method updateGroup.

@Test(alwaysRun = true, description = "Add SCIM user", dependsOnMethods = { "filterGroup" })
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.ALL })
public void updateGroup() 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.setDisplayName("testeng2");
    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).accept(SCIMConstants.APPLICATION_JSON).put(String.class, updatedGroupString);
    log.info("Updated group: " + responseUpdated);
    Assert.assertTrue(responseUpdated.contains("testeng2"));
}
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 19 with RestClient

use of org.apache.wink.client.RestClient 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));
}
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 20 with RestClient

use of org.apache.wink.client.RestClient 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.");
    }
}
Also used : User(org.wso2.carbon.automation.engine.context.beans.User) RestClient(org.apache.wink.client.RestClient) UserAdminUserAdminException(org.wso2.carbon.user.mgt.stub.UserAdminUserAdminException) 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) RemoteException(java.rmi.RemoteException) UserAdminUserAdminException(org.wso2.carbon.user.mgt.stub.UserAdminUserAdminException) RemoteException(java.rmi.RemoteException) SetEnvironment(org.wso2.carbon.automation.engine.annotations.SetEnvironment) Test(org.testng.annotations.Test)

Aggregations

RestClient (org.apache.wink.client.RestClient)33 Resource (org.apache.wink.client.Resource)28 ClientConfig (org.apache.wink.client.ClientConfig)21 SCIMResponseHandler (org.wso2.identity.integration.test.scim.utils.SCIMResponseHandler)16 Test (org.testng.annotations.Test)14 BasicAuthInfo (org.wso2.identity.integration.test.utils.BasicAuthInfo)13 SetEnvironment (org.wso2.carbon.automation.engine.annotations.SetEnvironment)12 JSONObject (org.json.simple.JSONObject)8 User (org.wso2.carbon.automation.engine.context.beans.User)7 BasicAuthSecurityHandler (org.apache.wink.client.handlers.BasicAuthSecurityHandler)3 JSONObject (org.json.JSONObject)2 SCIMClient (org.wso2.charon.core.client.SCIMClient)2 Group (org.wso2.charon.core.objects.Group)2 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)2 RemoteException (java.rmi.RemoteException)1 JSONArray (org.json.simple.JSONArray)1 UserAdminUserAdminException (org.wso2.carbon.user.mgt.stub.UserAdminUserAdminException)1 FlaggedName (org.wso2.carbon.user.mgt.stub.types.carbon.FlaggedName)1