Search in sources :

Example 11 with SCIMClient

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

the class SCIMServiceProviderGroupTestCase method deleteUser.

public void deleteUser() {
    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(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);
}
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)

Example 12 with SCIMClient

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

the class SCIMServiceProviderUserTestCase method getUser.

@Test(alwaysRun = true, description = "Get SCIM user", dependsOnMethods = { "createUser" })
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.ALL })
public void getUser() {
    // 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);
    String response = userResource.header(SCIMConstants.AUTHORIZATION_HEADER, encodedBasicAuthInfo.getAuthorizationHeader()).contentType(SCIMConstants.APPLICATION_JSON).accept(SCIMConstants.APPLICATION_JSON).get(String.class);
    // decode the response
    log.info(response);
    Assert.assertTrue(response.contains(""));
}
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 13 with SCIMClient

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

the class SCIMServiceProviderUserTestCase method createUser.

@Test(alwaysRun = true, description = "Add SCIM user")
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.ALL })
public void createUser() throws Exception {
    // create SCIM client
    String encodedUser = SCIMUtils.getEncodedSCIMUser(scimClient, USERNAME, "test", new String[] { "scimuser1@gmail.com", "scimuser1@wso2.com" }, "SCIMUser1", PASSWORD, "sinhala", "0772202595");
    // create a apache wink ClientHandler to intercept and identify response messages
    Resource userResource = SCIMUtils.getUserResource(scimClient, scim_url);
    BasicAuthInfo encodedBasicAuthInfo = SCIMUtils.getBasicAuthInfo(provider_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();
    userMgtClient.listUsers(USERNAME, 100);
    Assert.assertTrue(isUserExists());
    Assert.assertNotNull(scimUserId);
}
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) SetEnvironment(org.wso2.carbon.automation.engine.annotations.SetEnvironment) Test(org.testng.annotations.Test)

Example 14 with SCIMClient

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

the class SCIMUtils method getSCIMGroup.

/**
 * Constructs and returns a Group instance according to the SCIM Schema.
 *
 * @param scimClient    SCIMClient instance
 * @param scimUserId    SCIM User Id
 * @param username      Username
 * @param externalID    External ID of the Group
 * @param displayName   Display Name of the Group
 * @return              Group instance
 * @throws CharonException
 */
public static Group getSCIMGroup(SCIMClient scimClient, String scimUserId, String username, String externalID, String displayName) throws CharonException {
    Group scimGroup = scimClient.createGroup();
    scimGroup.setExternalId(externalID);
    scimGroup.setDisplayName(displayName);
    // set group members
    scimGroup.setMember(scimUserId, username);
    return scimGroup;
}
Also used : Group(org.wso2.charon.core.objects.Group)

Example 15 with SCIMClient

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

the class ProvisioningTestCase method getResource.

private Resource getResource(SCIMClient scimClient, String scim_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(scim_url + "Users");
}
Also used : RestClient(org.apache.wink.client.RestClient) SCIMResponseHandler(org.wso2.identity.integration.test.scim.utils.SCIMResponseHandler) ClientConfig(org.apache.wink.client.ClientConfig)

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