Search in sources :

Example 1 with EndSessionRequest

use of org.xdi.oxauth.client.EndSessionRequest in project oxAuth by GluuFederation.

the class EndSessionAction method exec.

public void exec() {
    try {
        EndSessionRequest req = new EndSessionRequest(idTokenHint, postLogoutRedirectUri, state);
        String authorizationRequest = endSessionEndpoint + "?" + req.getQueryString();
        FacesContext.getCurrentInstance().getExternalContext().redirect(authorizationRequest);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}
Also used : EndSessionRequest(org.xdi.oxauth.client.EndSessionRequest)

Example 2 with EndSessionRequest

use of org.xdi.oxauth.client.EndSessionRequest in project oxAuth by GluuFederation.

the class EndSessionRestWebServiceEmbeddedTest method requestEndSessionStep3.

@Parameters({ "endSessionPath", "postLogoutRedirectUri" })
@Test(dependsOnMethods = "requestEndSessionStep2")
public void requestEndSessionStep3(final String endSessionPath, final String postLogoutRedirectUri) throws Exception {
    String state = UUID.randomUUID().toString();
    EndSessionRequest endSessionRequest = new EndSessionRequest(idToken, postLogoutRedirectUri, state);
    endSessionRequest.setSessionState(sessionState);
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + endSessionPath + "?" + endSessionRequest.getQueryString()).request();
    request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
    Response response = request.get();
    String entity = response.readEntity(String.class);
    showResponse("requestEndSessionStep3", response, entity);
    assertEquals(response.getStatus(), 200, "Unexpected response code.");
    assertNotNull(entity, "Unexpected html.");
    assertTrue(entity.contains(postLogoutRedirectUri));
    assertTrue(entity.contains(postLogoutRedirectUri));
}
Also used : RegisterResponse(org.xdi.oxauth.client.RegisterResponse) Response(javax.ws.rs.core.Response) EndSessionRequest(org.xdi.oxauth.client.EndSessionRequest) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Example 3 with EndSessionRequest

use of org.xdi.oxauth.client.EndSessionRequest in project oxAuth by GluuFederation.

the class EndSessionRestWebServiceEmbeddedTest method requestEndSessionFail1.

// private void validateNonHttpBasedLogout(EnhancedMockHttpServletResponse
// response) {
// if (response.getLocation() != null) {
// try {
// URI uri = new URI(response.getLocation().toString());
// assertNotNull(uri.getQuery(), "The query string is null");
//
// Map<String, String> params = QueryStringDecoder.decode(uri.getQuery());
//
// assertNotNull(params.get(EndSessionResponseParam.STATE), "The state is
// null");
// assertEquals(params.get(EndSessionResponseParam.STATE), endSessionState);
// } catch (URISyntaxException e) {
// e.printStackTrace();
// fail("Response URI is not well formed");
// } catch (Exception e) {
// e.printStackTrace();
// fail(e.getMessage());
// }
// }
// }
@Parameters({ "endSessionPath" })
@Test
public void requestEndSessionFail1(final String endSessionPath) throws Exception {
    EndSessionRequest endSessionRequest = new EndSessionRequest(null, null, null);
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + endSessionPath + "?" + endSessionRequest.getQueryString()).request();
    request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
    Response response = request.get();
    String entity = response.readEntity(String.class);
    showResponse("requestEndSessionFail1", response, entity);
    assertEquals(response.getStatus(), 400, "Unexpected response code.");
    assertNotNull(entity, "Unexpected result: " + entity);
    try {
        JSONObject jsonObj = new JSONObject(entity);
        assertTrue(jsonObj.has("error"), "The error type is null");
        assertTrue(jsonObj.has("error_description"), "The error description is null");
    } 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) JSONObject(org.codehaus.jettison.json.JSONObject) EndSessionRequest(org.xdi.oxauth.client.EndSessionRequest) 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 4 with EndSessionRequest

use of org.xdi.oxauth.client.EndSessionRequest in project oxAuth by GluuFederation.

the class EndSessionRestWebServiceEmbeddedTest method requestEndSessionFail2.

@Parameters({ "endSessionPath", "postLogoutRedirectUri" })
@Test
public void requestEndSessionFail2(final String endSessionPath, final String postLogoutRedirectUri) throws Exception {
    String endSessionState = UUID.randomUUID().toString();
    EndSessionRequest endSessionRequest = new EndSessionRequest("INVALID_ACCESS_TOKEN", postLogoutRedirectUri, endSessionState);
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + endSessionPath + "?" + endSessionRequest.getQueryString()).request();
    request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
    Response response = request.get();
    String entity = response.readEntity(String.class);
    showResponse("requestEndSessionFail2", response, entity);
    assertEquals(response.getStatus(), 401, "Unexpected response code.");
    assertNotNull(entity, "Unexpected result: " + entity);
    try {
        JSONObject jsonObj = new JSONObject(entity);
        assertTrue(jsonObj.has("error"), "The error type is null");
        assertTrue(jsonObj.has("error_description"), "The error description is null");
    } 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) JSONObject(org.codehaus.jettison.json.JSONObject) EndSessionRequest(org.xdi.oxauth.client.EndSessionRequest) 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)

Aggregations

EndSessionRequest (org.xdi.oxauth.client.EndSessionRequest)4 Builder (javax.ws.rs.client.Invocation.Builder)3 Response (javax.ws.rs.core.Response)3 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)3 Parameters (org.testng.annotations.Parameters)3 Test (org.testng.annotations.Test)3 BaseTest (org.xdi.oxauth.BaseTest)3 RegisterResponse (org.xdi.oxauth.client.RegisterResponse)3 JSONException (org.codehaus.jettison.json.JSONException)2 JSONObject (org.codehaus.jettison.json.JSONObject)2