Search in sources :

Example 76 with JSONException

use of org.codehaus.jettison.json.JSONException in project oxAuth by GluuFederation.

the class RegistrationRestWebServiceEmbeddedTest method requestClientRegistrationFail2.

@Parameters({ "registerPath" })
@Test
public void requestClientRegistrationFail2(final String registerPath) throws Exception {
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + registerPath).request();
    String registerRequestContent = null;
    try {
        // Missing
        RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app", null);
        // redirect
        // URIs
        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("requestClientRegistrationFail 2", response, entity);
    assertEquals(response.getStatus(), 400, "Unexpected response code. " + entity);
    TestUtil.assertErrorResponse(entity);
}
Also used : RegisterResponse(org.xdi.oxauth.client.RegisterResponse) Response(javax.ws.rs.core.Response) RegisterRequest(org.xdi.oxauth.client.RegisterRequest) 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 77 with JSONException

use of org.codehaus.jettison.json.JSONException in project oxAuth by GluuFederation.

the class RegistrationRestWebServiceEmbeddedTest method requestClientRegistrationFail1.

@Parameters({ "registerPath" })
@Test
public void requestClientRegistrationFail1(final String registerPath) throws Exception {
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + registerPath).request();
    String registerRequestContent = null;
    try {
        RegisterRequest registerRequest = new RegisterRequest(null, null, null);
        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("requestClientRegistrationFail 1", response, entity);
    assertEquals(response.getStatus(), 400, "Unexpected response code. " + entity);
    TestUtil.assertErrorResponse(entity);
}
Also used : RegisterResponse(org.xdi.oxauth.client.RegisterResponse) Response(javax.ws.rs.core.Response) RegisterRequest(org.xdi.oxauth.client.RegisterRequest) 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 78 with JSONException

use of org.codehaus.jettison.json.JSONException in project oxAuth by GluuFederation.

the class RegistrationRestWebServiceEmbeddedTest method requestClientUpdate.

@Parameters({ "registerPath", "redirectUris", "contactEmail1", "contactEmail2" })
@Test(dependsOnMethods = "requestClientAssociate1")
public void requestClientUpdate(final String registerPath, final String redirectUris, final String contactEmail1, final String contactEmail2) throws Exception {
    final String contactEmailNewValue = contactEmail2;
    final String logoUriNewValue = "http://www.gluu.org/test/yuriy/logo.png";
    final String clientUriNewValue = "http://www.gluu.org/company/yuriy";
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + registerPath + "?" + registrationClientUri1.substring(registrationClientUri1.indexOf("?") + 1)).request();
    String registerRequestContent = null;
    try {
        final RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app", StringUtils.spaceSeparatedToList(redirectUris));
        registerRequest.setContacts(Arrays.asList(contactEmail1, contactEmailNewValue));
        registerRequest.setLogoUri(logoUriNewValue);
        registerRequest.setClientUri(clientUriNewValue);
        request.header("Authorization", "Bearer " + registrationAccessToken1);
        registerRequestContent = registerRequest.getJSONParameters().toString(4);
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
    Response response = request.put(Entity.json(registerRequestContent));
    String entity = response.readEntity(String.class);
    showResponse("requestClientRead", response, entity);
    readResponseAssert(response, entity);
    try {
        // check whether values are really updated
        RegisterRequest r = RegisterRequest.fromJson(entity);
        assertTrue(r.getContacts() != null && r.getContacts().contains(contactEmailNewValue));
        assertTrue(r.getClientUri().equals(clientUriNewValue));
        assertTrue(r.getLogoUri().equals(logoUriNewValue));
    } 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) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) JSONException(org.codehaus.jettison.json.JSONException) JSONException(org.codehaus.jettison.json.JSONException) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Example 79 with JSONException

use of org.codehaus.jettison.json.JSONException in project oxAuth by GluuFederation.

the class RegistrationRestWebServiceEmbeddedTest method requestClientAssociate1.

@Parameters({ "registerPath", "redirectUris" })
@Test
public void requestClientAssociate1(final String registerPath, final String redirectUris) 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));
        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("requestClientAssociate1", 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);
        registrationAccessToken1 = registerResponse.getRegistrationAccessToken();
        registrationClientUri1 = registerResponse.getRegistrationClientUri();
    } catch (Exception 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) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) JSONException(org.codehaus.jettison.json.JSONException) JSONException(org.codehaus.jettison.json.JSONException) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Example 80 with JSONException

use of org.codehaus.jettison.json.JSONException in project oxAuth by GluuFederation.

the class RegistrationRestWebServiceEmbeddedTest method requestClientAssociate2.

@Parameters({ "registerPath", "redirectUris", "sectorIdentifierUri", "contactEmail1", "contactEmail2" })
@Test
public void requestClientAssociate2(final String registerPath, final String redirectUris, final String sectorIdentifierUri, final String contactEmail1, final String contactEmail2) throws Exception {
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + registerPath).request();
    String registerRequestContent = null;
    try {
        List<String> contacts = Arrays.asList(contactEmail1, contactEmail2);
        RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app", StringUtils.spaceSeparatedToList(redirectUris));
        registerRequest.setContacts(contacts);
        registerRequest.setScopes(Arrays.asList("openid", "clientinfo", "profile", "email", "invalid_scope"));
        registerRequest.setLogoUri("http://www.gluu.org/wp-content/themes/gluursn/images/logo.png");
        registerRequest.setClientUri("http://www.gluu.org/company/team");
        registerRequest.setTokenEndpointAuthMethod(AuthenticationMethod.CLIENT_SECRET_JWT);
        registerRequest.setPolicyUri("http://www.gluu.org/policy");
        registerRequest.setJwksUri("http://www.gluu.org/jwks");
        registerRequest.setSectorIdentifierUri(sectorIdentifierUri);
        registerRequest.setSubjectType(SubjectType.PAIRWISE);
        registerRequest.setRequestObjectSigningAlg(SignatureAlgorithm.RS256);
        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("requestClientAssociate2", 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);
        // Registered Metadata
        assertTrue(jsonObj.has(CLIENT_URI.toString()));
        assertTrue(jsonObj.has(SCOPES.toString()));
        JSONArray scopesJsonArray = jsonObj.getJSONArray(SCOPES.toString());
        assertEquals(scopesJsonArray.getString(0), "openid");
        assertEquals(scopesJsonArray.getString(1), "clientinfo");
        assertEquals(scopesJsonArray.getString(2), "profile");
        assertEquals(scopesJsonArray.getString(3), "email");
    } 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) JSONArray(org.codehaus.jettison.json.JSONArray) JSONException(org.codehaus.jettison.json.JSONException) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Aggregations

JSONException (org.codehaus.jettison.json.JSONException)281 JSONObject (org.codehaus.jettison.json.JSONObject)256 Response (javax.ws.rs.core.Response)183 Builder (javax.ws.rs.client.Invocation.Builder)179 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)179 Test (org.testng.annotations.Test)174 BaseTest (org.xdi.oxauth.BaseTest)174 Parameters (org.testng.annotations.Parameters)171 RegisterRequest (org.xdi.oxauth.client.RegisterRequest)78 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)68 JSONArray (org.codehaus.jettison.json.JSONArray)44 RegisterResponse (org.xdi.oxauth.client.RegisterResponse)43 URISyntaxException (java.net.URISyntaxException)35 TokenRequest (org.xdi.oxauth.client.TokenRequest)35 ResponseType (org.xdi.oxauth.model.common.ResponseType)35 WebApplicationException (javax.ws.rs.WebApplicationException)18 IOException (java.io.IOException)17 OxAuthCryptoProvider (org.xdi.oxauth.model.crypto.OxAuthCryptoProvider)17 Path (javax.ws.rs.Path)14 Produces (javax.ws.rs.Produces)14