Search in sources :

Example 1 with ClientConfig

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

the class OIDCDiscoveryTestCase method testWebFinger.

@Test(alwaysRun = true, groups = "wso2.is", description = "webfinger test")
public void testWebFinger() throws IOException {
    ClientConfig clientConfig = new ClientConfig();
    BasicAuthSecurityHandler basicAuth = new BasicAuthSecurityHandler();
    basicAuth.setUserName(userInfo.getUserName());
    basicAuth.setPassword(userInfo.getPassword());
    clientConfig.handlers(basicAuth);
    RestClient restClient = new RestClient(clientConfig);
    Resource userResource = restClient.resource(webfingerEndpoint);
    String response = userResource.accept(SCIMConstants.APPLICATION_JSON).get(String.class);
    Object obj = JSONValue.parse(response);
    Object links = ((JSONObject) obj).get("links");
    Assert.assertNotNull(links);
    String openIdProviderIssuerLocation = ((JSONObject) ((JSONArray) links).get(0)).get("href").toString();
    String urlExpected = isServerBackendUrl + "/oauth2/token";
    Assert.assertEquals(openIdProviderIssuerLocation, urlExpected);
}
Also used : JSONObject(org.json.simple.JSONObject) BasicAuthSecurityHandler(org.apache.wink.client.handlers.BasicAuthSecurityHandler) RestClient(org.apache.wink.client.RestClient) Resource(org.apache.wink.client.Resource) JSONArray(org.json.simple.JSONArray) JSONObject(org.json.simple.JSONObject) ClientConfig(org.apache.wink.client.ClientConfig) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest) Test(org.testng.annotations.Test)

Example 2 with ClientConfig

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

the class SCIMUtils method getGroupResource.

/**
 * Returns the GroupResource REST access point of SCIM endpoint.
 *
 * @param scimClient SCIMClient instance
 * @param scimUrl    SCIM base endpoint URL
 * @return           GroupResource REST access point client instance
 */
public static Resource getGroupResource(SCIMClient scimClient, String scimUrl) {
    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(scimUrl + "Groups");
}
Also used : RestClient(org.apache.wink.client.RestClient) ClientConfig(org.apache.wink.client.ClientConfig)

Example 3 with ClientConfig

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

the class MasterSCIMInitiator method getGroupResource.

protected Resource getGroupResource(SCIMClient scimClient, String skim_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(skim_url + "Groups");
}
Also used : RestClient(org.apache.wink.client.RestClient) SCIMResponseHandler(org.wso2.identity.integration.test.scim.utils.SCIMResponseHandler) ClientConfig(org.apache.wink.client.ClientConfig)

Example 4 with ClientConfig

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

use of org.apache.wink.client.ClientConfig 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)

Aggregations

ClientConfig (org.apache.wink.client.ClientConfig)21 RestClient (org.apache.wink.client.RestClient)21 Resource (org.apache.wink.client.Resource)16 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)4 BasicAuthSecurityHandler (org.apache.wink.client.handlers.BasicAuthSecurityHandler)3 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 User (org.wso2.carbon.automation.engine.context.beans.User)1 UserAdminUserAdminException (org.wso2.carbon.user.mgt.stub.UserAdminUserAdminException)1 FlaggedName (org.wso2.carbon.user.mgt.stub.types.carbon.FlaggedName)1