Search in sources :

Example 1 with RestClient

use of org.apache.wink.client.RestClient in project ppm-octane-connector by MicroFocus.

the class UsernamePasswordClient method oneResource.

private Resource oneResource(String url, String[] fields, FieldQuery... queries) {
    // Only allowing secure protocols to connect
    System.setProperty("https.protocols", "TLSv1.2,SSLv3");
    Resource rsc = new RestClient(this.config).resource(baseURL + url);
    if (fields != null && fields.length > 0) {
        rsc.queryParam(getURLParamNameForVisibleFields(), StringUtils.join(fields, ','));
    }
    if (queries.length > 0) {
        StringBuffer sb = new StringBuffer();
        sb.append("%7B");
        boolean isFirst = true;
        for (FieldQuery q : queries) {
            if (isFirst) {
                isFirst = false;
            } else {
                sb.append(';');
            }
            sb.append(q.toQueryString());
        }
        sb.append("%7D");
        rsc.queryParam(getURLParamNameForFieldQuery(), sb.toString());
    }
    return rsc;
}
Also used : Resource(org.apache.wink.client.Resource) RestClient(org.apache.wink.client.RestClient)

Example 2 with RestClient

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

the class ConsentMgtTestCase method addReceipt.

private JSONObject addReceipt(String piiPrincipalId, String service, String serviceDisplayName, String serviceDescription, String consentType, String collectionMethod, String jurisdiction, String language, String policyURL) {
    RestClient restClient = new RestClient();
    Resource piiCatResource = restClient.resource(consentEndpoint);
    String addReceiptString = "{" + "  \"services\": [" + "    {" + "      \"service\": \"" + service + "\"," + "      \"serviceDisplayName\": \"" + serviceDisplayName + "\"," + "      \"serviceDescription\": \"" + serviceDescription + "\"," + "      \"purposes\": [" + "        {" + "          \"purposeId\": 1," + "          \"purposeCategoryId\": [" + "            1" + "          ]," + "          \"consentType\": \"" + consentType + "\"," + "          \"piiCategory\": [" + "            {" + "              \"piiCategoryId\": 1," + "              \"validity\": \"3\"" + "            }" + "          ]," + "          \"primaryPurpose\": true," + "          \"termination\": \"string\"," + "          \"thirdPartyDisclosure\": true," + "          \"thirdPartyName\": \"string\"" + "        }" + "      ]" + "    }" + "  ]," + "  \"collectionMethod\": \"" + collectionMethod + "\"," + "  \"jurisdiction\": \"" + jurisdiction + "\"," + "  \"language\": \"" + language + "\"," + "  \"policyURL\": \"" + policyURL + "\"" + "}";
    String response = piiCatResource.contentType(MediaType.APPLICATION_JSON_TYPE).accept(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, getBasicAuthHeader(userInfo)).post(String.class, addReceiptString);
    return (JSONObject) JSONValue.parse(response);
}
Also used : JSONObject(org.json.simple.JSONObject) RestClient(org.apache.wink.client.RestClient) Resource(org.apache.wink.client.Resource)

Example 3 with RestClient

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

the class ConsentMgtTestCase method addPurpose.

private JSONObject addPurpose(String name, String description, String group, String groupType) {
    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" + "    }" + "  ]" + "}";
    String response = piiCatResource.contentType(MediaType.APPLICATION_JSON_TYPE).accept(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, getBasicAuthHeader(userInfo)).post(String.class, addPurposeString);
    return (JSONObject) JSONValue.parse(response);
}
Also used : JSONObject(org.json.simple.JSONObject) RestClient(org.apache.wink.client.RestClient) Resource(org.apache.wink.client.Resource)

Example 4 with RestClient

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

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

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