Search in sources :

Example 21 with RestClient

use of org.apache.wink.client.RestClient 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 22 with RestClient

use of org.apache.wink.client.RestClient 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 23 with RestClient

use of org.apache.wink.client.RestClient 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 24 with RestClient

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

the class SelfSignUpConsentTest method getConsents.

private String getConsents(String username, String password) {
    RestClient restClient = new RestClient();
    Resource resource = restClient.resource(consentEndpoint + "?piiPrincipalId=" + MultitenantUtils.getTenantAwareUsername(username));
    User user = new User();
    user.setUserName(username);
    user.setPassword(password);
    String response = resource.contentType(MediaType.APPLICATION_JSON_TYPE).accept(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, getBasicAuthHeader(user)).get(String.class);
    return response;
}
Also used : User(org.wso2.carbon.automation.engine.context.beans.User) RestClient(org.apache.wink.client.RestClient) Resource(org.apache.wink.client.Resource)

Example 25 with RestClient

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

the class SelfSignUpConsentTest method addPurpose.

private String addPurpose(String name, String description, String group, String groupType) throws JSONException {
    RestClient restClient = new RestClient();
    Resource piiCatResource = restClient.resource(consentEndpoint + "/" + "purposes");
    String addPurposeString = "{" + "  \"purpose\": \"" + name + "\"," + "  \"description\": \"" + description + "\"," + "  \"group\": \"" + group + "\"," + "  \"groupType\": \"" + groupType + "\"," + "  \"piiCategories\": [" + "    {" + "      \"piiCategoryId\": 1," + "      \"mandatory\": true" + "    }" + "  ]" + "}";
    User user = new User();
    user.setUserName(tenantAdminUserName);
    user.setPassword(ADMIN);
    String response = piiCatResource.contentType(MediaType.APPLICATION_JSON_TYPE).accept(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, getBasicAuthHeader(user)).post(String.class, addPurposeString);
    JSONObject purpose = new JSONObject(response);
    return purpose.getString("purposeId");
}
Also used : User(org.wso2.carbon.automation.engine.context.beans.User) JSONObject(org.json.JSONObject) RestClient(org.apache.wink.client.RestClient) Resource(org.apache.wink.client.Resource)

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