Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  //
  //  ========================================================================
  //  Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd.
  //  ------------------------------------------------------------------------
  //  All rights reserved. This program and the accompanying materials
  //  are made available under the terms of the Eclipse Public License v1.0
  //  and Apache License v2.0 which accompanies this distribution.
  //
  //      The Eclipse Public License is available at
 //      http://www.eclipse.org/legal/epl-v10.html
 //
 //      The Apache License v2.0 is available at
 //      http://www.opensource.org/licenses/apache2.0.php
 //
 //  You may elect to redistribute this code under either of these licenses.
 //  ========================================================================
 //
 
 package org.eclipse.jetty.security.authentication;
 
 
 

Version:
$Rev: 4793 $ $Date: 2009-03-19 00:00:01 +0100 (Thu, 19 Mar 2009) $
 
 public class BasicAuthenticator extends LoginAuthenticator 
 {   
     /* ------------------------------------------------------------ */
     public BasicAuthenticator()
     {
     }
     
     /* ------------------------------------------------------------ */
    
 
     public String getAuthMethod()
     {
         return .;
     }
 
  
 
     /* ------------------------------------------------------------ */
    
 
     public Authentication validateRequest(ServletRequest reqServletResponse resboolean mandatorythrows ServerAuthException
     {
         HttpServletRequest request = (HttpServletRequest)req;
         HttpServletResponse response = (HttpServletResponse)res;
         String credentials = request.getHeader(.);
 
         try
         {
             if (!mandatory)
                 return new DeferredAuthentication(this);
 
             if (credentials != null)
             {                 
                 int space=credentials.indexOf(' ');
                 if (space>0)
                 {
                     String method=credentials.substring(0,space);
                     if ("basic".equalsIgnoreCase(method))
                     {
                         credentials = credentials.substring(space+1);
                         credentials = B64Code.decode(credentials,.);
                         int i = credentials.indexOf(':');
                         if (i>0)
                         {
                             String username = credentials.substring(0,i);
                             String password = credentials.substring(i+1);
 
                             UserIdentity user = login (usernamepasswordrequest);
                             if (user!=null)
                             {
                                 return new UserAuthentication(getAuthMethod(),user);
                             }
                         }
                     }
                 }
             }
 
            if (DeferredAuthentication.isDeferred(response))
                return .;
            
            response.setHeader(."basic realm=\"" + .getName() + '"');
            response.sendError(.);
            return .;
        }
        catch (IOException e)
        {
            throw new ServerAuthException(e);
        }
    }
    public boolean secureResponse(ServletRequest reqServletResponse resboolean mandatoryUser validatedUserthrows ServerAuthException
    {
        return true;
    }
New to GrepCode? Check out our FAQ X