Results 1 to 5 of 5

Thread: How to do authorization with basic authentication

  1. #1
    Join Date
    Aug 2004
    Location
    Atlanta, GA
    Posts
    10

    Default How to do authorization with basic authentication

    If I use Acegi-handled BASIC authentication, what type of Acegi authorization should I use.

    Would the authorization be handled by a completely different servlet filter?
    If so, which filter?
    What are my options?

    Should I use a SecurityEnforcementFilter and a FilterSecurityInterceptor so I can reference an "accessDecisionManager" to handle my authorization?

    If I do this, that means I'll use three servlet filters. One for the basic authentication, one for the AutoIntegrationFilter and one for the SecurityEnforcementFilter.
    I'm I correct?

    If I'm even close to correct, would the FilterSecurityInterceptor's authenticationManager know it's already been authenticated by the basic authentication's filter?

    Also, can I use the AuthenticationProcessingFilterEntryPoint with basic authentication.

    Thanks :!:

  2. #2
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    2,768

    Default

    Take a look at http://forum.springframework.org/showthread.php?t=9933 which talks about the two authentication "layers". To perform BASIC authentication you need to:

    - Use BasicProcessingFilter in web.xml and the application context
    - Use SecurityEnforcementFilter in web.xml and the application context
    - Add BasicProcessingFilterEntryPoint to your application context
    - Ensure the basicProcessingFilter.entryPoint and securityEnforcementFilter.entryPoint both point to the basicProcessingFilterEntryPoint

    The "entryPoint" is the link which allows you to plug a different authentication credentials collection strategy in. If you wanted to use form authentication, you'd use the AuthenticationProcessingFilterEntryPoint. If you wanted to use CAS authentication, you'd use the CasProcessingFilterEntryPoint etc.
    Last edited by Rod Johnson; Jan 18th, 2006 at 10:21 AM.

  3. #3
    Join Date
    Aug 2004
    Location
    Atlanta, GA
    Posts
    10

    Default

    Thanks so much for the help!

    I have a few more questions. Nothing was happening when I first tried this, so I started to debug and found that the...
    Code:
    String header = httpRequest.getHeader("Authorization");
    ...in the BasicProcessingFilter.doFilter() method was null, because the "Authorization" header was not in the header. So I extended BasicProcessingFilter.doFilter(), just to see if I could get something to work for me.

    Code:
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
                ServletException {       
    
            // Call the parent's doFilter()
            super.doFilter(request, response, chain);
           
            HttpServletRequest httpRequest = (HttpServletRequest) request;
            
            String header = httpRequest.getHeader("Authorization");
    
            log.info("Authorization header: " + header);
    
            if (header == null) {
                log.info("Header was null... calling EntryPoint.commence()");
                super.getAuthenticationEntryPoint().commence(request, response);
            }
    }
    All I did was call commence on the entry point if the "Authorization" header value was null. This seemed to work. So now I'm wondering why the server didn't put the "Authorization" header in there in the first place? I'm sure I'm missing something.

    Also, what is the typical stratagy for logging a user off?

    Thanks :!:

  4. #4
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    2,768

    Default

    The SecurityEnforcementFilter is included because it detects any lower-level Acegi Security exceptions. Specifically, if a security-related exception is detected, and the user is not logged in, the entry point will be commenced. In the case of BASIC authentication, this causes the response to contain a "please authenticate" header, which the browser responds to. If on the other hand a user is actually logged in when a security-related exception is detected, a 403 (forbidden) is returned.

    The preferred way of using Acegi Security is to put your protected content under a /secure/* or some other URI. Then have the filter security interceptor "protect" it, causing the SecurityEnforcementFilter to cause the entry point to commence when required.

    If for some reason you don't want to do this, you'll need to modify code as per your example or take advantage of client features which cause the BASIC authentication header to always be present, even if the server hasn't specifically asked for it. The Spring remoting client proxies are an example of this.

    AFAIK there is no "logout" option for BASIC authentication, as browsers will continue to present the credentials throughout the session. Take a look at http://www.caucho.com/support/resin-...0306/0122.html for some more info on this issue.

  5. #5
    Join Date
    May 2006
    Posts
    1

    Default

    Quote Originally Posted by Ben Alex
    The SecurityEnforcementFilter is included because it detects any lower-level Acegi Security exceptions. Specifically, if a security-related exception is detected, and the user is not logged in, the entry point will be commenced. In the case of BASIC authentication, this causes the response to contain a "please authenticate" header, which the browser responds to. If on the other hand a user is actually logged in when a security-related exception is detected, a 403 (forbidden) is returned.

    The preferred way of using Acegi Security is to put your protected content under a /secure/* or some other URI. Then have the filter security interceptor "protect" it, causing the SecurityEnforcementFilter to cause the entry point to commence when required.

    If for some reason you don't want to do this, you'll need to modify code as per your example or take advantage of client features which cause the BASIC authentication header to always be present, even if the server hasn't specifically asked for it. The Spring remoting client proxies are an example of this.

    AFAIK there is no "logout" option for BASIC authentication, as browsers will continue to present the credentials throughout the session. Take a look at http://www.caucho.com/support/resin-...0306/0122.html for some more info on this issue.
    Ben,
    I have faced more serious problem with BasicAuthenticationFilter (Acegi-1.0RC2). Except those described in previous posts (browser does not request for credentials), I am facing:
    java.lang.IllegalStateException: Cannot create a session after the response has been committed at org.apache.catalina.connector.Request.doGetSession (Request.java:2195) at
    whilst trying to add code like this:
    if (header == null) {
    authenticationEntryPoint.commence(request, response, new AuthenticationCredentialsNotFoundException("There is no authorization section in the request's header."));
    }

    but you are using completely the same call for "commence" in code below:
    if (ignoreFailure) {
    chain.doFilter(request, response);
    } else {
    authenticationEntryPoint.commence(request, response, failed);
    }

Similar Threads

  1. Replies: 11
    Last Post: Jun 1st, 2006, 04:30 PM
  2. Loosing my SecureContext
    By sklakken in forum Security
    Replies: 3
    Last Post: Jul 21st, 2005, 01:44 PM
  3. Replies: 8
    Last Post: Apr 3rd, 2005, 05:55 PM
  4. Unable to set BASIC authentication header
    By general_pattonm in forum Security
    Replies: 6
    Last Post: Mar 10th, 2005, 05:00 AM
  5. Replies: 8
    Last Post: Dec 7th, 2004, 06:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •