Search in sources :

Example 41 with Builder

use of javax.ws.rs.client.Invocation.Builder in project oxAuth by GluuFederation.

the class AuthorizeRestWebServiceEmbeddedTest method requestAuthorizationCodeNoRedirection.

@Parameters({ "authorizePath", "userId", "userSecret", "redirectUri" })
@Test(dependsOnMethods = "dynamicClientRegistration")
public void requestAuthorizationCodeNoRedirection(final String authorizePath, final String userId, final String userSecret, final String redirectUri) throws Exception {
    final String state = UUID.randomUUID().toString();
    List<ResponseType> responseTypes = Arrays.asList(ResponseType.CODE);
    List<String> scopes = Arrays.asList("openid", "profile", "address", "email");
    AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId1, scopes, redirectUri, null);
    authorizationRequest.setState(state);
    authorizationRequest.getPrompts().add(Prompt.NONE);
    authorizationRequest.setAuthUsername(userId);
    authorizationRequest.setAuthPassword(userSecret);
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + authorizePath + "?" + authorizationRequest.getQueryString()).request();
    request.header("Authorization", "Basic " + authorizationRequest.getEncodedCredentials());
    request.header("Accept", MediaType.TEXT_PLAIN);
    request.header("X-Gluu-NoRedirect", "");
    Response response = request.get();
    String entity = response.readEntity(String.class);
    showResponse("requestAuthorizationCodeNoRedirection", response, entity);
    assertEquals(response.getStatus(), 200, "Unexpected response code.");
    assertNotNull(entity, "Unexpected result: " + entity);
    try {
        JSONObject jsonObj = new JSONObject(entity);
        assertTrue(jsonObj.has("redirect"), "Unexpected result: redirect not found");
        URI uri = new URI(jsonObj.getString("redirect"));
        assertNotNull(uri.getQuery(), "Query string is null");
        Map<String, String> params = QueryStringDecoder.decode(uri.getQuery());
        assertNotNull(params.get(AuthorizeResponseParam.CODE), "The code is null");
        assertNotNull(params.get(AuthorizeResponseParam.SCOPE), "The scope is null");
        assertNotNull(params.get(AuthorizeResponseParam.STATE), "The state is null");
        assertEquals(params.get(AuthorizeResponseParam.STATE), state);
    } catch (JSONException e) {
        e.printStackTrace();
        fail(e.getMessage() + "\nResponse was: " + entity);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : RegisterResponse(org.xdi.oxauth.client.RegisterResponse) Response(javax.ws.rs.core.Response) AuthorizationRequest(org.xdi.oxauth.client.AuthorizationRequest) JSONObject(org.codehaus.jettison.json.JSONObject) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) JSONException(org.codehaus.jettison.json.JSONException) REGISTRATION_CLIENT_URI(org.xdi.oxauth.model.register.RegisterResponseParam.REGISTRATION_CLIENT_URI) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) JSONException(org.codehaus.jettison.json.JSONException) ResponseType(org.xdi.oxauth.model.common.ResponseType) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Example 42 with Builder

use of javax.ws.rs.client.Invocation.Builder in project oxAuth by GluuFederation.

the class AuthorizeRestWebServiceEmbeddedTest method requestAuthorizationAccessTokenStep1.

@Parameters({ "authorizePath", "userId", "userSecret", "redirectUri" })
@Test(dependsOnMethods = "dynamicClientRegistration")
public void requestAuthorizationAccessTokenStep1(final String authorizePath, final String userId, final String userSecret, final String redirectUri) throws Exception {
    final String state = UUID.randomUUID().toString();
    List<ResponseType> responseTypes = Arrays.asList(ResponseType.TOKEN, ResponseType.ID_TOKEN);
    List<String> scopes = Arrays.asList("openid", "profile", "address", "email");
    String nonce = UUID.randomUUID().toString();
    AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId1, scopes, redirectUri, nonce);
    authorizationRequest.setState(state);
    authorizationRequest.getPrompts().add(Prompt.NONE);
    authorizationRequest.setAuthUsername(userId);
    authorizationRequest.setAuthPassword(userSecret);
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + authorizePath + "?" + authorizationRequest.getQueryString()).request();
    request.header("Authorization", "Basic " + authorizationRequest.getEncodedCredentials());
    request.header("Accept", MediaType.TEXT_PLAIN);
    Response response = request.get();
    String entity = response.readEntity(String.class);
    showResponse("requestAuthorizationAccessTokenStep1", response, entity);
    assertEquals(response.getStatus(), 302, "Unexpected response code.");
    assertNotNull(response.getLocation(), "Unexpected result: " + response.getLocation());
    if (response.getLocation() != null) {
        try {
            URI uri = new URI(response.getLocation().toString());
            assertNotNull(uri.getFragment(), "Fragment is null");
            Map<String, String> params = QueryStringDecoder.decode(uri.getFragment());
            assertNotNull(params.get(AuthorizeResponseParam.ACCESS_TOKEN), "The access token is null");
            assertNotNull(params.get(AuthorizeResponseParam.STATE), "The state is null");
            assertNotNull(params.get(AuthorizeResponseParam.TOKEN_TYPE), "The token type is null");
            assertNotNull(params.get(AuthorizeResponseParam.EXPIRES_IN), "The expires in value is null");
            assertNotNull(params.get(AuthorizeResponseParam.SCOPE), "The scope must be null");
            assertNull(params.get("refresh_token"), "The refresh_token must be null");
            assertEquals(params.get(AuthorizeResponseParam.STATE), state);
            accessToken2 = params.get("access_token");
        } catch (URISyntaxException e) {
            e.printStackTrace();
            fail("Response URI is not well formed");
        }
    }
}
Also used : RegisterResponse(org.xdi.oxauth.client.RegisterResponse) Response(javax.ws.rs.core.Response) AuthorizationRequest(org.xdi.oxauth.client.AuthorizationRequest) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) URISyntaxException(java.net.URISyntaxException) REGISTRATION_CLIENT_URI(org.xdi.oxauth.model.register.RegisterResponseParam.REGISTRATION_CLIENT_URI) URI(java.net.URI) ResponseType(org.xdi.oxauth.model.common.ResponseType) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Example 43 with Builder

use of javax.ws.rs.client.Invocation.Builder in project oxAuth by GluuFederation.

the class TAuthorization method requestAuthorization.

public RptAuthorizationResponse requestAuthorization(String p_umaPermissionAuthorizationPath, final String p_umaAmHost, final Token p_aat, final RptAuthorizationRequest p_request) {
    final Holder<RptAuthorizationResponse> h = new Holder<RptAuthorizationResponse>();
    try {
        Builder request = ResteasyClientBuilder.newClient().target(baseUri.toString() + p_umaPermissionAuthorizationPath).request();
        request.header("Accept", UmaConstants.JSON_MEDIA_TYPE);
        request.header("Authorization", "Bearer " + p_aat.getAccessToken());
        request.header("Host", p_umaAmHost);
        final String json = ServerUtil.createJsonMapper().writeValueAsString(p_request);
        Response response = request.post(Entity.json(json));
        String entity = response.readEntity(String.class);
        BaseTest.showResponse("UMA : TAuthorization.requestAuthorization() : ", response, entity);
        assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), "Unexpected response code.");
        try {
            RptAuthorizationResponse result = ServerUtil.createJsonMapper().readValue(entity, RptAuthorizationResponse.class);
            // UmaTestUtil.assert_(result);
            h.setT(result);
        } catch (IOException e) {
            e.printStackTrace();
            fail();
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
    return h.getT();
}
Also used : Response(javax.ws.rs.core.Response) Holder(org.xdi.oxauth.model.common.Holder) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) IOException(java.io.IOException) IOException(java.io.IOException)

Example 44 with Builder

use of javax.ws.rs.client.Invocation.Builder in project oxAuth by GluuFederation.

the class TConfiguration method configuration.

private void configuration(final String umaConfigurationPath) throws Exception {
    Builder request = ResteasyClientBuilder.newClient().target(baseUri.toString() + umaConfigurationPath).request();
    request.header("Accept", UmaConstants.JSON_MEDIA_TYPE);
    Response response = request.get();
    String entity = response.readEntity(String.class);
    BaseTest.showResponse("UMA : TConfiguration.configuration", response, entity);
    assertEquals(response.getStatus(), 200, "Unexpected response code.");
    try {
        configuration = ServerUtil.createJsonMapper().readValue(entity, UmaConfiguration.class);
        UmaTestUtil.assert_(configuration);
    } catch (IOException e) {
        e.printStackTrace();
        fail();
    }
}
Also used : Response(javax.ws.rs.core.Response) Builder(javax.ws.rs.client.Invocation.Builder) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) IOException(java.io.IOException)

Example 45 with Builder

use of javax.ws.rs.client.Invocation.Builder in project oxAuth by GluuFederation.

the class UmaScopeWSTest method scopePresence.

// private MetadataConfiguration m_configuration;
//
// @Parameters({"umaConfigurationPath"})
// @Test
// public void init(final String umaConfigurationPath) {
// m_configuration = TUma.requestConfiguration(this, umaConfigurationPath);
// UmaTestUtil.assert_(m_configuration);
// }
@Parameters({ "umaScopePath" })
@Test
public void scopePresence(final String umaScopePath) throws Exception {
    String path = umaScopePath + "/" + "modify";
    System.out.println("Path: " + path);
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + path).request();
    request.header("Accept", UmaConstants.JSON_MEDIA_TYPE);
    Response response = request.get();
    String entity = response.readEntity(String.class);
    BaseTest.showResponse("UMA : UmaScopeWSTest.scopePresence() : ", response, entity);
    assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), "Unexpected response code.");
    final ScopeDescription scope = TUma.readJsonValue(entity, ScopeDescription.class);
    UmaTestUtil.assert_(scope);
}
Also used : Response(javax.ws.rs.core.Response) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) ScopeDescription(org.xdi.oxauth.model.uma.ScopeDescription) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Aggregations

Builder (javax.ws.rs.client.Invocation.Builder)319 Response (javax.ws.rs.core.Response)316 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)287 Test (org.testng.annotations.Test)273 BaseTest (org.xdi.oxauth.BaseTest)273 Parameters (org.testng.annotations.Parameters)270 JSONException (org.codehaus.jettison.json.JSONException)248 JSONObject (org.codehaus.jettison.json.JSONObject)173 URISyntaxException (java.net.URISyntaxException)121 ResponseType (org.xdi.oxauth.model.common.ResponseType)120 RegisterResponse (org.xdi.oxauth.client.RegisterResponse)92 AuthorizationRequest (org.xdi.oxauth.client.AuthorizationRequest)88 URI (java.net.URI)86 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)79 RegisterRequest (org.xdi.oxauth.client.RegisterRequest)78 REGISTRATION_CLIENT_URI (org.xdi.oxauth.model.register.RegisterResponseParam.REGISTRATION_CLIENT_URI)73 OxAuthCryptoProvider (org.xdi.oxauth.model.crypto.OxAuthCryptoProvider)60 JwtAuthorizationRequest (org.xdi.oxauth.client.model.authorize.JwtAuthorizationRequest)44 TokenRequest (org.xdi.oxauth.client.TokenRequest)39 Claim (org.xdi.oxauth.client.model.authorize.Claim)39