@ Override public void doFilter ( ServletRequest request , ServletResponse response , FilterChain chain ) throws IOException , ServletException { if ( ! ( request instanceof HttpServletRequest ) ) { chain . doFilter ( request , response ) ; return ; } HttpServletRequest httpServletRequest = ( ( HttpServletRequest ) request ) ; HttpServletResponse httpServletResponse = ( ( HttpServletResponse ) response ) ; if ( WebUIConfig . getInstance ( ) . getAuthentication ( ) . isAuthenticationEnabled ( ) && ! isAuthAction ( httpServletRequest . getRequestURI ( ) ) ) { // Means current page is protected by authorization if ( isAuthorized ( httpServletRequest ) ) { httpServletRequest . setAttribute ( "mskIsAuthorized" , true ) ; // Enables logout button } else { // Reset auth cookie for cases it was corrupted (encryption key is changed or something like that) Cookie authCookie = new Cookie ( AuthConstants . AUTH_COOKIE_NAME , "" ) ; authCookie . setMaxAge ( 0 ) ; httpServletResponse . addCookie ( authCookie ) ; // User be redirected to this url after success authorization httpServletRequest . getSession ( ) . setAttribute ( AuthConstants . LOGIN_REFER_PAGE_SESSION_ATTR_NAME , httpServletRequest . getRequestURL ( ) . toString ( ) ) ; // Redirect to login page httpServletResponse . sendRedirect ( "mskSignIn" ) ; return ; } } super . doFilter ( request , response , chain ) ; }
Checks user authorization if it enabled in config