use of org.xdi.oxauth.model.common.AuthorizationGrant in project oxAuth by GluuFederation.
the class ClientInfoRestWebServiceImpl method requestClientInfo.
public Response requestClientInfo(String accessToken, String authorization, SecurityContext securityContext) {
if (authorization != null && !authorization.isEmpty() && authorization.startsWith("Bearer ")) {
accessToken = authorization.substring(7);
}
log.debug("Attempting to request Client Info, Access token = {}, Is Secure = {}", new Object[] { accessToken, securityContext.isSecure() });
Response.ResponseBuilder builder = Response.ok();
if (!ClientInfoParamsValidator.validateParams(accessToken)) {
builder = Response.status(400);
builder.entity(errorResponseFactory.getErrorAsJson(ClientInfoErrorResponseType.INVALID_REQUEST));
} else {
AuthorizationGrant authorizationGrant = authorizationGrantList.getAuthorizationGrantByAccessToken(accessToken);
if (authorizationGrant == null) {
builder = Response.status(400);
builder.entity(errorResponseFactory.getErrorAsJson(ClientInfoErrorResponseType.INVALID_TOKEN));
} else {
CacheControl cacheControl = new CacheControl();
cacheControl.setPrivate(true);
cacheControl.setNoTransform(false);
cacheControl.setNoStore(true);
builder.cacheControl(cacheControl);
builder.header("Pragma", "no-cache");
builder.entity(getJSonResponse(authorizationGrant.getClient(), authorizationGrant.getScopes()));
}
}
return builder.build();
}
use of org.xdi.oxauth.model.common.AuthorizationGrant in project oxAuth by GluuFederation.
the class CreateRptWS method createJwr.
private JsonWebResponse createJwr(UmaRPT rpt, String authorization, List<String> gluuAccessTokenScopes) throws Exception {
final AuthorizationGrant grant = tokenService.getAuthorizationGrant(authorization);
JwtSigner jwtSigner = JwtSigner.newJwtSigner(appConfiguration, webKeysConfiguration, grant.getClient());
Jwt jwt = jwtSigner.newJwt();
jwt.getClaims().setExpirationTime(rpt.getExpirationDate());
jwt.getClaims().setIssuedAt(rpt.getCreationDate());
if (!gluuAccessTokenScopes.isEmpty()) {
jwt.getClaims().setClaim("scopes", gluuAccessTokenScopes);
}
return jwtSigner.sign();
}
use of org.xdi.oxauth.model.common.AuthorizationGrant in project oxAuth by GluuFederation.
the class CreateRptWS method authorizeGat.
private void authorizeGat(GatRequest request, UmaRPT rpt, String authorization, HttpServletRequest httpRequest) {
if (request.getScopes().isEmpty()) {
// nothing to authorize
return;
}
AuthorizationGrant grant = tokenService.getAuthorizationGrant(authorization);
if (umaAuthorizationService.allowToAddPermissionForGat(grant, rpt, request.getScopes(), httpRequest, request.getClaims())) {
final List<String> scopes = new ArrayList<String>();
if (rpt.getPermissions() != null) {
scopes.addAll(rpt.getPermissions());
}
scopes.addAll(request.getScopes());
rpt.setPermissions(scopes);
try {
ldapEntryManager.merge(rpt);
return;
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
// throw not authorized exception
throw new WebApplicationException(Response.status(Response.Status.FORBIDDEN).entity(errorResponseFactory.getUmaJsonErrorResponse(UmaErrorResponseType.NOT_AUTHORIZED_PERMISSION)).build());
}
use of org.xdi.oxauth.model.common.AuthorizationGrant in project oxAuth by GluuFederation.
the class ResourceSetRegistrationWS method putResourceSetImpl.
private Response putResourceSetImpl(Response.Status status, String authorization, String rsid, ResourceSet resourceSet) throws IllegalAccessException, InvocationTargetException, IOException {
log.trace("putResourceSetImpl, rsid: {}, status:", rsid, status.name());
String patToken = tokenService.getTokenFromAuthorizationParameter(authorization);
AuthorizationGrant authorizationGrant = authorizationGrantList.getAuthorizationGrantByAccessToken(patToken);
String userDn = authorizationGrant.getUserDn();
String clientDn = authorizationGrant.getClientDn();
final String resourceSetDn;
if (status == Response.Status.CREATED) {
resourceSetDn = addResourceSet(rsid, resourceSet, userDn, clientDn);
} else {
resourceSetDn = updateResourceSet(rsid, resourceSet);
}
// Load resource set description
org.xdi.oxauth.model.uma.persistence.ResourceSet ldapUpdatedResourceSet = resourceSetService.getResourceSetByDn(resourceSetDn);
ResourceSetResponse response = new ResourceSetResponse();
response.setId(ldapUpdatedResourceSet.getId());
return Response.status(status).entity(ServerUtil.asJson(response)).build();
}
use of org.xdi.oxauth.model.common.AuthorizationGrant in project oxAuth by GluuFederation.
the class RptPermissionAuthorizationWS method requestRptPermissionAuthorization.
@POST
@Consumes({ UmaConstants.JSON_MEDIA_TYPE })
@Produces({ UmaConstants.JSON_MEDIA_TYPE })
public Response requestRptPermissionAuthorization(@HeaderParam("Authorization") String authorization, @HeaderParam("Host") String amHost, RptAuthorizationRequest rptAuthorizationRequest, @Context HttpServletRequest httpRequest) {
try {
final AuthorizationGrant grant = umaValidationService.assertHasAuthorizationScope(authorization);
final String validatedAmHost = umaValidationService.validateAmHost(amHost);
final UmaRPT rpt = authorizeRptPermission(authorization, rptAuthorizationRequest, httpRequest, grant, validatedAmHost);
// convert manually to avoid possible conflict between resteasy providers, e.g. jettison, jackson
return Response.ok(ServerUtil.asJson(new RptAuthorizationResponse(rpt.getCode()))).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());
}
}
Aggregations