Java Doc for BasicAuthHandler.java in  » Web-Server » Brazil » sunlabs » brazil » handler » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Server » Brazil » sunlabs.brazil.handler 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   sunlabs.brazil.handler.BasicAuthHandler

BasicAuthHandler
public class BasicAuthHandler implements Handler(Code)
The BasicAuthHandler obtains a Session ID by performing "basic" authentication, using either the "Authorization" or the "Proxy-Authorization" headers. This handler prevents subsequent downstream handlers from being accessed unless the proper authentication was seen in the request. The Session ID obtained by this handler is meant to be used by those downsteams handlers to access whatever session-dependent information they need.

If the request does not contain the authentication headers or the authentication information is not valid, this handler sends an HTTP error message along with the "WWW-Authenticate" or "Proxy-Authenticate" header, as appropriate. See code, authorization, authenticate

If the request does contain valid authentication information, the Session ID associated with the authentication information is inserted into the request properties, for use by downstream handlers. After inserting the Session ID, this handler returns false to allow the downstream handlers to run.

The set of valid Session IDs is contained either in (1) a static file or in (2) a globally accessible table managed by the SessionManager. The second case allows the list of Session IDs to be dynamically configurable and shareable amongst two or more authentication handlers. For instance, the web developer could set up one handler to dynamically populate the shared table with Session IDs based on submitted HTML forms, and then use the BasicAuthHandler to ensure that all other requests have a valid Session ID based on the shared table. See mapFile, session, ident

The format of the static file described in case (1) above is a Java properties file where keys are the Base64 encoded strings obtained from the Authentication header and the values are the associated Session IDs. Base64 strings can contain the '=' character, but the keys in a Java properties file cannot contain an '=' character, so all '=' characters in the Base64 strings must be converted to '!' in the properties file, as shown in the following sample properties file:

 bXIuIGhhdGU6a2ZqYw!! = radion
 Zm9vOmJhcg!! = foo
 
The format of the dynamic table described in case (2) above is a Hashtable where the keys are the Base64 encoded strings obtained from the Authentication header and the values are the associated Session IDs. This Hashtable is accessed via the SessionManager.getSession method, with the session argument of null and the ident argument specified by a configuration parameter.
There are several different types of authentication possible. All authentication handlers should follow these basic principles:
  • The authentication handler examines some aspect of the request to decide if the appropriate authentication is present.
  • If the request is acceptable, the authentication handler should insert the extracted Session ID into a request property and then return false, to allow subsequent handlers to run and perhaps use the Session ID.
  • If the request is not acceptable, the authentication handler can return an error message or do some other thing to try to obtain a valid authentication.
  • Handlers wishing to be protected by authentication should not subclass an authentication handler. Instead, such handler should be written to assume that authentication has already been performed and then just examine the Session ID present. The web developer is then responsible for choosing which one (of possibly many) forms of authentication to use and installing those authentication handlers before the "sensitive" handler.
  • Handlers that are protected by an authentication handler can use the Session ID stored in the request properties regardless of the specifics of the authentication handler.
 handlers=auth history file
 auth.class=BasicAuthHandler
 auth.session=account
 auth.message=Go away, you're not allowed here!
 history.class=HistoryHandler
 history.session=account
 file.class=FileHandler
 file.root=htdocs
 
In the sample pseudo-configuation file specified above, the BasicAuthHandler is first invoked to see if the HTTP "basic" authentication header is present in the request. If it isn't, a nasty message is sent back. If the "basic" authentication header is present and corresponds to a user that the BasicAuthHandler knows about, the Session ID associated with that user is stored in the specified property named "account".

Subsequently, the HistoryHandler examines its specified property (also "account") for the Session ID and uses that to keep track of which session is issuing the HTTP request.

Each handler that needs a Session ID should have a configuration parameter that allows the web developer to specify the name of the request property that holds the Session ID. Multiple handlers can all use the same request property as each other, all protected by the same authentication handler.


This handler uses the following configuration properties:
prefix
This handler will attempt to authenticate URLs beginning with this string only. The default value is "/".
code
The type of authentication to perform. The default value is 401.

The value 401 corresponds to standard "basic" authentication. The "Authorization" request header is supposed to contain the authentication string. If the request was not authenticated, the "WWW-Authenticate" header is sent in the HTTP error response to cause the browser to prompt the client to authenticate.

The value 407 corresponds to "basic" proxy/firewall authentication. The "Proxy-Authorization" request header is supposed to contain the authentication string. If the request was not authenticated, the "Proxy-Authenticate" header is sent in the HTTP error response to cause the browser to prompt the client to authenticate.

Any other value may also be specified. Whatever the value, it will be returned as the HTTP result code of the error message.

authorization
If specified, this is the request header that will contain the "basic" authentication string, instead of the "Authorization" or "Proxy-Authorization" header implied by code.
authenticate
If specified, this is the response header that will be sent in the HTTP error response if the user is not authenticated.

If this string is "", then this handler will authenticate the request if the authorization header is present, but will not send an HTTP error message if the request could not be authenticated. This is useful if the web developer wants to do something more complex (such as invoking an arbitrary set of handlers) instead of just sending a simple error message if the request was not authenticated. In this case, the web developer can determine that the request was not authenticated because no Session ID will be present in the request properties.

realm
The "realm" of the HTTP authentication error message. This is a string that the browser is supposed to present to the client when asking the client the authenticate. It provides a human-friendly name describing who wants the authentication.
message
The body of the HTTP authentication error message. This will be displayed by the browser if the client chooses not to authenticate. The default value is "". Patterns of the form ${xxx} are replaced with the value of the xxx entry of request.props.
mapFile
If specified, this is the Session ID file. This is expected to be a java properties file, whose keys are the authentication tokens, and whose values are the Session IDs that are inserted into the request properties.

The keys in the file are basic authentication (base64) tokens with any trailing "=" characters changed to "!".

session
The name of the request property that the Session ID will be stored in, to be passed to downstream handlers. The default value is "SessionID".
ident
The ident argument to SessionManager.getSession to get the table of valid sessions. The default value is "authorized".

author:
   Stephen Uhler (stephen.uhler@sun.com)
author:
   Colin Stevens (colin.stevens@sun.com)
version:
   1.27, 01/01/12


Field Summary
public  Stringauthenticate
    
public  Stringauthorization
    
public  intcode
    
public  Stringident
    
public  Propertiesmap
    
public  StringmapFile
    
public  Stringmessage
    
public  Stringprefix
    
 StringpropsPrefix
    
public  Stringrealm
    
public  Stringsession
    


Method Summary
public  booleancomplain(Request request, String reason)
     Authentication failed.
public  booleaninit(Server server, String propsPrefix)
     Initializes this handler.
public  booleanrespond(Request request)
     Looks up the credentials for this request, and insert them into the request stream.

Field Detail
authenticate
public String authenticate(Code)



authorization
public String authorization(Code)



code
public int code(Code)



ident
public String ident(Code)



map
public Properties map(Code)



mapFile
public String mapFile(Code)



message
public String message(Code)



prefix
public String prefix(Code)



propsPrefix
String propsPrefix(Code)



realm
public String realm(Code)



session
public String session(Code)





Method Detail
complain
public boolean complain(Request request, String reason) throws IOException(Code)
Authentication failed. Send the appropriate authentication required header as a response.
Parameters:
  request - The request to respond to
Parameters:
  reason - The reason for failure (for diagnostics)



init
public boolean init(Server server, String propsPrefix)(Code)
Initializes this handler. It is an error if the mapFile parameter is specified but that file cannot be loaded.
Parameters:
  server - The HTTP server that created this handler.
Parameters:
  prefix - A prefix to prepend to all of the keys that thishandler uses to extract configuration information. true if this Handler initializedsuccessfully, false otherwise.



respond
public boolean respond(Request request) throws IOException(Code)
Looks up the credentials for this request, and insert them into the request stream. If no credentials are found, prompt the user for them.



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.