Search in sources :

Example 6 with Scope

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();
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AuthenticationCredentials(org.platformlayer.model.AuthenticationCredentials) Scope(org.platformlayer.Scope) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Aggregations

Scope (org.platformlayer.Scope)6 IOException (java.io.IOException)3 ServletException (javax.servlet.ServletException)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 AuthenticationCredentials (org.platformlayer.model.AuthenticationCredentials)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ProjectAuthorization (org.platformlayer.model.ProjectAuthorization)1 BindingScope (org.platformlayer.ops.BindingScope)1