Search in sources :

Example 1 with RPTResponse

use of org.xdi.oxauth.model.uma.RPTResponse in project oxAuth by GluuFederation.

the class ObtainRptTokenFlowHttpTest method testObtainRptTokenFlow.

/**
     * Test for the obtaining UMA RPT token
     */
@Test
@Parameters({ "umaAmHost" })
public void testObtainRptTokenFlow(final String umaAmHost) throws Exception {
    showTitle("testObtainRptTokenFlow");
    CreateRptService requesterPermissionTokenService = UmaClientFactory.instance().createRequesterPermissionTokenService(this.metadataConfiguration);
    // Get requester permission token
    RPTResponse requesterPermissionTokenResponse = null;
    try {
        requesterPermissionTokenResponse = requesterPermissionTokenService.createRPT("Bearer " + m_aat.getAccessToken(), umaAmHost);
    } catch (ClientResponseFailure ex) {
        System.err.println(ex.getResponse().getEntity(String.class));
        throw ex;
    }
    UmaTestUtil.assert_(requesterPermissionTokenResponse);
    this.rptToken = requesterPermissionTokenResponse.getRpt();
}
Also used : CreateRptService(org.xdi.oxauth.client.uma.CreateRptService) RPTResponse(org.xdi.oxauth.model.uma.RPTResponse) ClientResponseFailure(org.jboss.resteasy.client.ClientResponseFailure) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Example 2 with RPTResponse

use of org.xdi.oxauth.model.uma.RPTResponse in project oxAuth by GluuFederation.

the class ObtainRptTokenFlowHttpTest method testObtainRptTokenFlowWithInvalidAat.

/**
     * Test for the obtaining UMA RPT token
     */
@Test
@Parameters({ "umaAmHost" })
public void testObtainRptTokenFlowWithInvalidAat(final String umaAmHost) throws Exception {
    showTitle("testObtainRptTokenFlowWithInvalidAat");
    CreateRptService requesterPermissionTokenService = UmaClientFactory.instance().createRequesterPermissionTokenService(this.metadataConfiguration);
    // Get requester permission token
    RPTResponse requesterPermissionTokenResponse = null;
    try {
        requesterPermissionTokenResponse = requesterPermissionTokenService.createRPT("Bearer " + m_aat.getAccessToken() + "_invalid", umaAmHost);
    } catch (ClientResponseFailure ex) {
        System.err.println(ex.getResponse().getEntity(String.class));
        assertEquals(ex.getResponse().getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(), "Unexpected response status");
    }
    assertNull(requesterPermissionTokenResponse, "Requester permission token response is not null");
}
Also used : CreateRptService(org.xdi.oxauth.client.uma.CreateRptService) RPTResponse(org.xdi.oxauth.model.uma.RPTResponse) ClientResponseFailure(org.jboss.resteasy.client.ClientResponseFailure) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Example 3 with RPTResponse

use of org.xdi.oxauth.model.uma.RPTResponse in project oxAuth by GluuFederation.

the class CreateRptWS method getGat.

@Path("gat")
@POST
@Produces({ UmaConstants.JSON_MEDIA_TYPE })
@ApiOperation(value = "The endpoint at which the requester asks the AM to issue an GAT", produces = UmaConstants.JSON_MEDIA_TYPE, notes = "The endpoint at which the requester asks the AM to issue an GAT")
@ApiResponses(value = { @ApiResponse(code = 401, message = "Unauthorized") })
public Response getGat(@HeaderParam("Authorization") String authorization, @HeaderParam("Host") String amHost, GatRequest request, @Context HttpServletRequest httpRequest) {
    try {
        umaValidationService.assertHasAuthorizationScope(authorization);
        String validatedAmHost = umaValidationService.validateAmHost(amHost);
        UmaRPT rpt = rptManager.createRPT(authorization, validatedAmHost, true);
        authorizeGat(request, rpt, authorization, httpRequest);
        String rptResponse = rpt.getCode();
        final Boolean umaRptAsJwt = appConfiguration.getUmaRptAsJwt();
        if (umaRptAsJwt != null && umaRptAsJwt) {
            rptResponse = createJwr(rpt, authorization, request.getScopes()).asString();
        }
        return Response.status(Response.Status.CREATED).entity(ServerUtil.asJson(new RPTResponse(rptResponse))).build();
    } catch (Exception ex) {
        log.error("Exception happened", ex);
        if (ex instanceof WebApplicationException) {
            throw (WebApplicationException) ex;
        }
        throw new WebApplicationException(Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorResponseFactory.getUmaJsonErrorResponse(UmaErrorResponseType.SERVER_ERROR)).build());
    }
}
Also used : UmaRPT(org.xdi.oxauth.model.common.uma.UmaRPT) WebApplicationException(javax.ws.rs.WebApplicationException) RPTResponse(org.xdi.oxauth.model.uma.RPTResponse) WebApplicationException(javax.ws.rs.WebApplicationException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ApiResponses(com.wordnik.swagger.annotations.ApiResponses)

Example 4 with RPTResponse

use of org.xdi.oxauth.model.uma.RPTResponse in project oxAuth by GluuFederation.

the class CreateRptWS method getRpt.

@Path("rpt")
@POST
@Produces({ UmaConstants.JSON_MEDIA_TYPE })
@ApiOperation(value = "The endpoint at which the requester asks the AM to issue an RPT", produces = UmaConstants.JSON_MEDIA_TYPE, notes = "The endpoint at which the requester asks the AM to issue an RPT")
@ApiResponses(value = { @ApiResponse(code = 401, message = "Unauthorized") })
public Response getRpt(@HeaderParam("Authorization") String authorization, @HeaderParam("Host") String amHost) {
    try {
        umaValidationService.assertHasAuthorizationScope(authorization);
        String validatedAmHost = umaValidationService.validateAmHost(amHost);
        UmaRPT rpt = rptManager.createRPT(authorization, validatedAmHost, false);
        String rptResponse = rpt.getCode();
        final Boolean umaRptAsJwt = appConfiguration.getUmaRptAsJwt();
        if (umaRptAsJwt != null && umaRptAsJwt) {
            rptResponse = createJwr(rpt, authorization, Lists.<String>newArrayList()).asString();
        }
        return Response.status(Response.Status.CREATED).entity(ServerUtil.asJson(new RPTResponse(rptResponse))).build();
    } catch (Exception ex) {
        log.error("Exception happened", ex);
        if (ex instanceof WebApplicationException) {
            throw (WebApplicationException) ex;
        }
        throw new WebApplicationException(Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorResponseFactory.getUmaJsonErrorResponse(UmaErrorResponseType.SERVER_ERROR)).build());
    }
}
Also used : UmaRPT(org.xdi.oxauth.model.common.uma.UmaRPT) WebApplicationException(javax.ws.rs.WebApplicationException) RPTResponse(org.xdi.oxauth.model.uma.RPTResponse) WebApplicationException(javax.ws.rs.WebApplicationException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ApiResponses(com.wordnik.swagger.annotations.ApiResponses)

Example 5 with RPTResponse

use of org.xdi.oxauth.model.uma.RPTResponse in project oxAuth by GluuFederation.

the class ObtainRptWSTest method obtainRpt.

@Test(dependsOnMethods = "init")
@Parameters({ "umaRptPath", "umaAmHost" })
public void obtainRpt(String umaRptPath, String umaAmHost) {
    final RPTResponse r = TUma.requestRpt(url, aat, umaRptPath, umaAmHost);
    UmaTestUtil.assert_(r);
}
Also used : RPTResponse(org.xdi.oxauth.model.uma.RPTResponse) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Aggregations

RPTResponse (org.xdi.oxauth.model.uma.RPTResponse)5 Parameters (org.testng.annotations.Parameters)3 Test (org.testng.annotations.Test)3 BaseTest (org.xdi.oxauth.BaseTest)3 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)2 ApiResponses (com.wordnik.swagger.annotations.ApiResponses)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 ClientResponseFailure (org.jboss.resteasy.client.ClientResponseFailure)2 CreateRptService (org.xdi.oxauth.client.uma.CreateRptService)2 UmaRPT (org.xdi.oxauth.model.common.uma.UmaRPT)2