use of org.platformlayer.Scope in project platformlayer by platformlayer.
the class AuthenticationFilter method doFilter.
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
Scope authenticatedScope = Scope.empty();
// Fail safe
authenticatedScope.put(AuthenticationCredentials.class, null);
if (servletRequest instanceof HttpServletRequest) {
HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse;
try {
AuthenticationCredentials credentials = findCredentials(httpServletRequest);
authenticatedScope.put(AuthenticationCredentials.class, credentials);
} catch (SecurityException e) {
httpServletResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
return;
} catch (Exception e) {
// If we're down, don't tell the user that their password is wrong
log.warn("Unexpected error in authentication filter", e);
httpServletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
}
authenticatedScope.push();
try {
filterChain.doFilter(servletRequest, servletResponse);
} finally {
authenticatedScope.pop();
}
}
Aggregations