Monday, 26 August 2013

PostProcessInterceptor: How to access HTTP request?

PostProcessInterceptor: How to access HTTP request?

I have an interceptor that looks like
@Interceptor
@Provider
@ServerInterceptor
@SecurityChecked
public class SecurityCheckInterceptor implements PreProcessInterceptor,
AcceptedByMethod, PostProcessInterceptor {
private static final Logger LOGGER =
LoggerFactory.getLogger(SecurityCheckInterceptor.class);
@Nullable
@Override
public ServerResponse preProcess(final HttpRequest request, final
ResourceMethod method) throws Failure, WebApplicationException {
final List<String> authToken =
request.getHttpHeaders().getRequestHeader(AUTH_TOKEN);
if (authToken == null || !isValidToken(authToken.get(0))) {
final ServerResponse serverResponse = new ServerResponse();
serverResponse.setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
return serverResponse;
}
return null;
}
@SuppressWarnings("rawtypes")
@Override
public boolean accept(final Class declaring, final Method method) {
// return declaring.isAnnotationPresent(SecurityChecked.class);
return method.isAnnotationPresent(SecurityChecked.class);
}
@Override
public void postProcess(final ServerResponse response) {
LOGGER.info("post-processing response " + response.getEntity());
}
}
What I want ?
- Every time the response goes back I need to add a new AUTH_TOKEN value
- The original request has access to request headers and one of the header
is of the form
signature:user:expires
I need the access to user form this request header to generate a new
time-based token
How can I have access to request headers?

No comments:

Post a Comment