use of io.jans.as.server.service.external.context.ExternalIntrospectionContext in project jans by JanssenProject.
the class AuthorizationGrant method runIntrospectionScriptAndInjectValuesIntoJwt.
private void runIntrospectionScriptAndInjectValuesIntoJwt(Jwt jwt, ExecutionContext executionContext) {
JSONObject responseAsJsonObject = new JSONObject();
ExternalIntrospectionContext context = new ExternalIntrospectionContext(this, executionContext.getHttpRequest(), executionContext.getHttpResponse(), appConfiguration, attributeService);
context.setAccessTokenAsJwt(jwt);
if (externalIntrospectionService.executeExternalModifyResponse(responseAsJsonObject, context)) {
log.trace("Successfully run external introspection scripts.");
if (context.isTranferIntrospectionPropertiesIntoJwtClaims()) {
log.trace("Transfering claims into jwt ...");
JwtUtil.transferIntoJwtClaims(responseAsJsonObject, jwt);
log.trace("Transfered.");
}
}
}
use of io.jans.as.server.service.external.context.ExternalIntrospectionContext in project jans by JanssenProject.
the class IntrospectionWebService method introspect.
private Response introspect(String authorization, String token, String tokenTypeHint, String responseAsJwt, HttpServletRequest httpRequest, HttpServletResponse httpResponse) {
try {
if (log.isTraceEnabled()) {
log.trace("Introspect token, authorization: {}, token to introspect: {}, tokenTypeHint: {}", escapeLog(authorization), escapeLog(token), escapeLog(tokenTypeHint));
}
AuthorizationGrant authorizationGrant = validateAuthorization(authorization, token);
if (StringUtils.isBlank(token)) {
log.trace("Bad request: Token is blank.");
return Response.status(Response.Status.BAD_REQUEST).type(MediaType.APPLICATION_JSON_TYPE).entity(errorResponseFactory.errorAsJson(AuthorizeErrorResponseType.INVALID_REQUEST, "")).build();
}
final io.jans.as.model.common.IntrospectionResponse response = new io.jans.as.model.common.IntrospectionResponse(false);
final AuthorizationGrant grantOfIntrospectionToken = authorizationGrantList.getAuthorizationGrantByAccessToken(token);
AbstractToken tokenToIntrospect = fillResponse(token, response, grantOfIntrospectionToken);
JSONObject responseAsJsonObject = createResponseAsJsonObject(response, tokenToIntrospect);
ExternalIntrospectionContext context = new ExternalIntrospectionContext(authorizationGrant, httpRequest, httpResponse, appConfiguration, attributeService);
context.setGrantOfIntrospectionToken(grantOfIntrospectionToken);
if (externalIntrospectionService.executeExternalModifyResponse(responseAsJsonObject, context)) {
log.trace("Successfully run external introspection scripts.");
} else {
responseAsJsonObject = createResponseAsJsonObject(response, tokenToIntrospect);
log.trace("Canceled changes made by external introspection script since method returned `false`.");
}
// Make scopes conform as required by spec, see #1499
if (response.getScope() != null && !appConfiguration.getIntrospectionResponseScopesBackwardCompatibility()) {
String scopes = StringUtils.join(response.getScope().toArray(), " ");
responseAsJsonObject.put("scope", scopes);
}
if (Boolean.TRUE.toString().equalsIgnoreCase(responseAsJwt)) {
return Response.status(Response.Status.OK).entity(createResponseAsJwt(responseAsJsonObject, grantOfIntrospectionToken)).build();
}
return Response.status(Response.Status.OK).entity(responseAsJsonObject.toString()).type(MediaType.APPLICATION_JSON_TYPE).build();
} catch (WebApplicationException e) {
if (log.isErrorEnabled()) {
log.error(e.getMessage(), e);
}
throw e;
} catch (Exception e) {
log.error(e.getMessage(), e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).type(MediaType.APPLICATION_JSON_TYPE).build();
}
}
Aggregations