src/main/java/org/jcasbin/plugins/HttpBasicAuthnFilter.java
// Filters all requests through HTTP basic authentication.
Filters all requests through HTTP basic authentication.
Filters all requests through HTTP basic authentication .
@Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
            throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        String credentials = getUserPassword(request, response);
        if (credentials.equals("")) {
            return;
        }
        int p = credentials.indexOf(":");
        String username = credentials.substring(0, p).trim();
        String password = credentials.substring(p + 1).trim();
        if (!checkUserPassword(username, password)) {
            unauthorized(response, "Bad credentials");
        }
        filterChain.doFilter(servletRequest, servletResponse);
    }
@ Override public void doFilter ( ServletRequest servletRequest , ServletResponse servletResponse , FilterChain filterChain ) throws IOException , ServletException { HttpServletRequest request = ( HttpServletRequest ) servletRequest ; HttpServletResponse response = ( HttpServletResponse ) servletResponse ; String credentials = getUserPassword ( request , response ) ; if ( credentials . equals ( "" ) ) { return ; } int p = credentials . indexOf ( ":" ) ; String username = credentials . substring ( 0 , p ) . trim ( ) ; String password = credentials . substring ( p + 1 ) . trim ( ) ; if ( ! checkUserPassword ( username , password ) ) { unauthorized ( response , "Bad credentials" ) ; } filterChain . doFilter ( servletRequest , servletResponse ) ; }
Filters all requests through HTTP basic authentication.
Filters all requests through HTTP basic authentication .
// Get user name and password from HTTP header. // Check the user name and password. // All passed, go to the next handler.