Search in sources :

Example 1 with BasicAuthSecurityHandler

use of org.apache.wink.client.handlers.BasicAuthSecurityHandler 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 BasicAuthSecurityHandler

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

the class TemplateManagementTestCase method addTemplate.

private JSONObject addTemplate(String templateName, String description, String templateScript) {
    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 templateResource = restClient.resource(templateMgtEndpoint);
    String addTemplateString = "{" + "\"templateName\": \"" + templateName + "\", " + "\"description\": \"" + description + "\"," + "\"templateScript\": \"" + templateScript + "\"}";
    String response = templateResource.contentType(MediaType.APPLICATION_JSON_TYPE).accept(MediaType.APPLICATION_JSON_TYPE).post(String.class, addTemplateString);
    return (JSONObject) JSONValue.parse(response);
}
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) ClientConfig(org.apache.wink.client.ClientConfig)

Example 3 with BasicAuthSecurityHandler

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

the class OIDCDiscoveryTestCase method testDiscovery.

@Test(alwaysRun = true, groups = "wso2.is", description = "Discovery test", dependsOnMethods = { "testWebFinger" })
public void testDiscovery() 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);
    String discoveryUrl = isServerBackendUrl + "/oauth2/oidcdiscovery/.well-known/openid-configuration";
    Resource userResource = restClient.resource(discoveryUrl);
    String response = userResource.accept(SCIMConstants.APPLICATION_JSON).get(String.class);
    Object obj = JSONValue.parse(response);
    String authorization_endpoint = ((JSONObject) obj).get("authorization_endpoint").toString();
    Assert.assertEquals(authorization_endpoint, isServerBackendUrl + "/oauth2/authorize");
    String token_endpoint = ((JSONObject) obj).get("token_endpoint").toString();
    Assert.assertEquals(token_endpoint, isServerBackendUrl + "/oauth2/token");
    String userinfo_endpoint = ((JSONObject) obj).get("userinfo_endpoint").toString();
    Assert.assertEquals(userinfo_endpoint, isServerBackendUrl + "/oauth2/userinfo");
}
Also used : BasicAuthSecurityHandler(org.apache.wink.client.handlers.BasicAuthSecurityHandler) RestClient(org.apache.wink.client.RestClient) Resource(org.apache.wink.client.Resource) JSONObject(org.json.simple.JSONObject) ClientConfig(org.apache.wink.client.ClientConfig) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest) Test(org.testng.annotations.Test)

Aggregations

ClientConfig (org.apache.wink.client.ClientConfig)3 Resource (org.apache.wink.client.Resource)3 RestClient (org.apache.wink.client.RestClient)3 BasicAuthSecurityHandler (org.apache.wink.client.handlers.BasicAuthSecurityHandler)3 JSONObject (org.json.simple.JSONObject)3 Test (org.testng.annotations.Test)2 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)2 JSONArray (org.json.simple.JSONArray)1