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();
}
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");
}
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());
}
}
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());
}
}
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);
}
Aggregations