Search in sources :

Example 21 with SCIMClient

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

Example 22 with SCIMClient

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

the class SCIMServiceProviderUserTestCase method DeleteUser.

@Test(alwaysRun = true, description = "Delete SCIM user", dependsOnMethods = { "UpdateUser" })
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.ALL })
public void DeleteUser() throws Exception {
    ClientConfig clientConfig = new ClientConfig();
    SCIMResponseHandler responseHandler = new SCIMResponseHandler();
    responseHandler.setSCIMClient(scimClient);
    clientConfig.handlers(new ClientHandler[] { responseHandler });
    RestClient restClient = new RestClient(clientConfig);
    BasicAuthInfo encodedBasicAuthInfo = SCIMUtils.getBasicAuthInfo(provider_userInfo);
    Resource userResource = restClient.resource(scim_url + "Users/" + scimUserId);
    String response = userResource.header(SCIMConstants.AUTHORIZATION_HEADER, encodedBasicAuthInfo.getAuthorizationHeader()).accept(SCIMConstants.APPLICATION_JSON).delete(String.class);
    // decode the response
    Assert.assertTrue(response.isEmpty());
    Assert.assertFalse(isUserExists());
}
Also used : RestClient(org.apache.wink.client.RestClient) Resource(org.apache.wink.client.Resource) BasicAuthInfo(org.wso2.identity.integration.test.utils.BasicAuthInfo) ClientConfig(org.apache.wink.client.ClientConfig) SCIMResponseHandler(org.wso2.identity.integration.test.scim.utils.SCIMResponseHandler) SetEnvironment(org.wso2.carbon.automation.engine.annotations.SetEnvironment) Test(org.testng.annotations.Test)

Example 23 with SCIMClient

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

the class SCIMServiceProviderUserTestCase method filterUser.

@Test(alwaysRun = true, description = "filter all SCIM users", dependsOnMethods = { "listUser" })
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.ALL })
public void filterUser() throws Exception {
    // create SCIM client
    SCIMClient scimClient = new SCIMClient();
    // 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?filter=userName%20Eq%20" + USERNAME);
    String response = userResource.header(SCIMConstants.AUTHORIZATION_HEADER, encodedBasicAuthInfo.getAuthorizationHeader()).contentType(SCIMConstants.APPLICATION_JSON).accept(SCIMConstants.APPLICATION_JSON).get(String.class);
    Assert.assertTrue(response.contains("\"userName\":\"" + USERNAME + "\""));
}
Also used : RestClient(org.apache.wink.client.RestClient) Resource(org.apache.wink.client.Resource) SCIMClient(org.wso2.charon.core.client.SCIMClient) 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 24 with SCIMClient

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

the class SCIMServiceProviderUserTestCase method listUser.

@Test(alwaysRun = true, description = "list all SCIM users", dependsOnMethods = { "getUserMe" })
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.ALL })
public void listUser() throws Exception {
    // create SCIM client
    SCIMClient scimClient = new SCIMClient();
    // 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");
    String response = userResource.header(SCIMConstants.AUTHORIZATION_HEADER, encodedBasicAuthInfo.getAuthorizationHeader()).contentType(SCIMConstants.APPLICATION_JSON).accept(SCIMConstants.APPLICATION_JSON).get(String.class);
    Assert.assertTrue(isAllUsersExists(response));
}
Also used : RestClient(org.apache.wink.client.RestClient) Resource(org.apache.wink.client.Resource) SCIMClient(org.wso2.charon.core.client.SCIMClient) 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 25 with SCIMClient

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

the class SCIMUtils method getSCIMUser.

/**
 * Constructs and returns a User instance according to the SCIM Schema.
 *
 * @param scimClient    SCIMClient instance
 * @param username      Username
 * @param externalID    External ID of the user
 * @param emails        String array of emails
 * @param displayName   Display Name of the User
 * @param password      Password of the User
 * @param language      Language
 * @param phoneNumber   Phone No
 * @return              User instance
 * @throws CharonException
 */
public static User getSCIMUser(SCIMClient scimClient, String username, String externalID, String[] emails, String displayName, String password, String language, String phoneNumber) throws CharonException {
    // create a user according to SCIM User Schema
    User scimUser = scimClient.createUser();
    scimUser.setUserName(username);
    scimUser.setExternalId(externalID);
    scimUser.setEmails(emails);
    scimUser.setDisplayName(displayName);
    scimUser.setPassword(password);
    scimUser.setPreferredLanguage(language);
    scimUser.setPhoneNumber(phoneNumber, null, false);
    return scimUser;
}
Also used : User(org.wso2.charon.core.objects.User)

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