Search in sources :

Example 31 with Builder

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

the class EndSessionRestWebServiceEmbeddedTest method requestEndSessionStep1.

@Parameters({ "registerPath", "redirectUris", "postLogoutRedirectUri" })
@Test
public void requestEndSessionStep1(final String registerPath, final String redirectUris, final String postLogoutRedirectUri) throws Exception {
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + registerPath).request();
    String registerRequestContent = null;
    try {
        RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app", StringUtils.spaceSeparatedToList(redirectUris));
        registerRequest.setResponseTypes(Arrays.asList(ResponseType.TOKEN, ResponseType.ID_TOKEN));
        registerRequest.setPostLogoutRedirectUris(Arrays.asList(postLogoutRedirectUri));
        registerRequest.setFrontChannelLogoutUris(Lists.newArrayList(postLogoutRedirectUri));
        registerRequest.addCustomAttribute("oxAuthTrustedClient", "true");
        registerRequestContent = registerRequest.getJSONParameters().toString(4);
    } catch (JSONException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    Response response = request.post(Entity.json(registerRequestContent));
    String entity = response.readEntity(String.class);
    showResponse("requestEndSessionStep1", response, entity);
    assertEquals(response.getStatus(), 200, "Unexpected response code. " + entity);
    assertNotNull(entity, "Unexpected result: " + entity);
    try {
        final RegisterResponse registerResponse = RegisterResponse.valueOf(entity);
        ClientTestUtil.assert_(registerResponse);
        JSONObject jsonObj = new JSONObject(entity);
        assertTrue(jsonObj.has(CLIENT_ID.toString()));
        clientId = jsonObj.getString(CLIENT_ID.toString());
    } catch (JSONException e) {
        e.printStackTrace();
        fail(e.getMessage() + "\nResponse was: " + entity);
    }
}
Also used : RegisterResponse(org.xdi.oxauth.client.RegisterResponse) Response(javax.ws.rs.core.Response) RegisterRequest(org.xdi.oxauth.client.RegisterRequest) RegisterResponse(org.xdi.oxauth.client.RegisterResponse) 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) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Example 32 with Builder

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

the class OpenIDRequestObjectEmbeddedTest method requestParameterMethodFail4.

@Parameters({ "authorizePath", "userId", "userSecret", "redirectUri" })
@Test(dependsOnMethods = "dynamicClientRegistration")
public void requestParameterMethodFail4(final String authorizePath, final String userId, final String userSecret, final String redirectUri) throws Exception {
    final String state = UUID.randomUUID().toString();
    Builder request = null;
    try {
        List<ResponseType> responseTypes = Arrays.asList(ResponseType.TOKEN);
        List<String> scopes = Arrays.asList("openid");
        String nonce = UUID.randomUUID().toString();
        AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId, scopes, redirectUri, nonce);
        authorizationRequest.setState(state);
        authorizationRequest.getPrompts().add(Prompt.NONE);
        authorizationRequest.setAuthUsername(userId);
        authorizationRequest.setAuthPassword(userSecret);
        OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider();
        JwtAuthorizationRequest jwtAuthorizationRequest = new JwtAuthorizationRequest(authorizationRequest, SignatureAlgorithm.HS256, clientSecret, cryptoProvider);
        jwtAuthorizationRequest.addIdTokenClaim(new Claim(JwtClaimName.SUBJECT_IDENTIFIER, ClaimValue.createSingleValue("INVALID_USER_ID")));
        String authJwt = jwtAuthorizationRequest.getEncodedJwt();
        authorizationRequest.setRequest(authJwt);
        System.out.println("Request JWT: " + authJwt);
        request = ResteasyClientBuilder.newClient().target(url.toString() + authorizePath + "?" + authorizationRequest.getQueryString()).request();
        request.header("Authorization", "Basic " + authorizationRequest.getEncodedCredentials());
        request.header("Accept", MediaType.TEXT_PLAIN);
    } catch (Exception e) {
        fail(e.getMessage(), e);
    }
    Response response = request.get();
    String entity = response.readEntity(String.class);
    showResponse("requestParameterMethodFail4", 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("error"), "The error value is null");
            assertNotNull(params.get("error_description"), "The errorDescription value is null");
            assertNotNull(params.get(AuthorizeResponseParam.STATE), "The state is null");
            assertEquals(params.get(AuthorizeResponseParam.STATE), state);
        } catch (URISyntaxException e) {
            e.printStackTrace();
            fail("Response URI is not well formed");
        }
    }
}
Also used : AuthorizationRequest(org.xdi.oxauth.client.AuthorizationRequest) JwtAuthorizationRequest(org.xdi.oxauth.client.model.authorize.JwtAuthorizationRequest) Builder(javax.ws.rs.client.Invocation.Builder) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) URISyntaxException(java.net.URISyntaxException) 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) OxAuthCryptoProvider(org.xdi.oxauth.model.crypto.OxAuthCryptoProvider) RegisterResponse(org.xdi.oxauth.client.RegisterResponse) Response(javax.ws.rs.core.Response) JwtAuthorizationRequest(org.xdi.oxauth.client.model.authorize.JwtAuthorizationRequest) Claim(org.xdi.oxauth.client.model.authorize.Claim) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Example 33 with Builder

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

the class TRegisterPermission method registerPermission.

public PermissionTicket registerPermission(final Token p_pat, final String p_umaAmHost, String p_umaHost, final UmaPermission p_request, String path) {
    final Holder<PermissionTicket> ticketH = new Holder<PermissionTicket>();
    Builder request = ResteasyClientBuilder.newClient().target(baseUri.toString() + path).request();
    request.header("Accept", UmaConstants.JSON_MEDIA_TYPE);
    request.header("Authorization", "Bearer " + p_pat.getAccessToken());
    request.header("Host", p_umaAmHost);
    String json = null;
    try {
        json = ServerUtil.createJsonMapper().writeValueAsString(p_request);
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
    Response response = request.post(Entity.json(json));
    String entity = response.readEntity(String.class);
    BaseTest.showResponse("UMA : TRegisterPermission.registerPermission() : ", response, entity);
    assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode(), "Unexpected response code.");
    try {
        final PermissionTicket t = ServerUtil.createJsonMapper().readValue(entity, PermissionTicket.class);
        UmaTestUtil.assert_(t);
        ticketH.setT(t);
    } catch (IOException e) {
        e.printStackTrace();
        fail();
    }
    return ticketH.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 34 with Builder

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

the class TRegisterResourceSet method registerResourceSetInternal.

private ResourceSetResponse registerResourceSetInternal(final Token p_pat, String umaRegisterResourcePath, final ResourceSet p_resourceSet) throws Exception {
    String path = umaRegisterResourcePath;
    System.out.println("Path: " + path);
    System.out.println("PAT: " + p_pat.getAccessToken());
    Builder request = ResteasyClientBuilder.newClient().target(baseUri.toString() + path).request();
    request.header("Accept", UmaConstants.JSON_MEDIA_TYPE);
    request.header("Authorization", "Bearer " + p_pat.getAccessToken());
    String json = null;
    try {
        // final String json = "{\"resourceSet\":{\"name\":\"Server Photo
        // Album22\",\"iconUri\":\"http://www.example.com/icons/flower.png\",\"scopes\":[\"http://photoz.example.com/dev/scopes/view\",\"http://photoz.example.com/dev/scopes/all\"]}}";
        // final String json =
        // ServerUtil.jsonMapperWithWrapRoot().writeValueAsString(p_resourceSet);
        json = ServerUtil.createJsonMapper().writeValueAsString(p_resourceSet);
        System.out.println("Json: " + json);
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
    Response response = request.post(Entity.json(json));
    String entity = response.readEntity(String.class);
    BaseTest.showResponse("UMA : TRegisterResourceSet.registerResourceSetInternal() : ", response, entity);
    assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode(), "Unexpected response code.");
    registerStatus = TUma.readJsonValue(entity, ResourceSetResponse.class);
    UmaTestUtil.assert_(registerStatus);
    return registerStatus;
}
Also used : Response(javax.ws.rs.core.Response) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) IOException(java.io.IOException)

Example 35 with Builder

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

the class TRegisterResourceSet method getResourceSetList.

public List<String> getResourceSetList(final Token p_pat, String p_umaRegisterResourcePath) {
    final List<String> result = new ArrayList<String>();
    try {
        Builder request = ResteasyClientBuilder.newClient().target(baseUri.toString() + p_umaRegisterResourcePath).request();
        request.header("Accept", UmaConstants.JSON_MEDIA_TYPE);
        request.header("Authorization", "Bearer " + p_pat.getAccessToken());
        Response response = request.get();
        String entity = response.readEntity(String.class);
        BaseTest.showResponse("UMA : TRegisterResourceSet.getResourceSetList() : ", response, entity);
        assertEquals(response.getStatus(), 200, "Unexpected response code.");
        List<String> list = TUma.readJsonValue(entity, List.class);
        if (list != null) {
            result.addAll(list);
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
    return result;
}
Also used : Response(javax.ws.rs.core.Response) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

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