Have you ever needed to create a login authentication mechanism for an application? Odds are, you have, and probably more than once, with each new implementation being close, but not identical, to the previous one. For example, one implementation might use an Oracle database, another might use an NT authentication, and another, an LDAP (lightweight access directory protocol) directory. Wouldn't it be nice to support all these security mechanisms without changing any application-level code?
Now in the Java world, you can with the Java Authentication and Authorization Service (JAAS). This relatively new API was an extension in J2SE (Java 2 Platform, Standard Edition) 1.3, is a core API in J2SE 1.4, and is also part of the J2EE (Java 2 Platform, Enterprise Edition) 1.3 specification. In this article, we'll teach you JAAS essentials and show you how to effectively apply JAAS to real-world applications. We based this article's application on our own experiences integrating JAAS into an existing Java Web-based system that used an RDBMS (relational database management system) for storing user login information. With JAAS, we designed more robust, flexible, and consistent login and authentication mechanisms.
You can download a complete set of working examples from Resources below (includes Java sources, JSPs (JavaServer Pages), JAAS configuration, with database and build scripts). We tested these examples using the Resin server with JDBC (Java Database Connectivity) and the MySQL database.
Before JAAS, Java's security model was mostly shaped by its origin as a platform-independent language for distributed, networked
applications. In its early days, Java often appeared as mobile code, such as browser-based applets, and therefore, the initial
security model focused on protecting users based on where the code originated and who created it. Early Java security mechanisms such as SecurityManagers, the sandbox concept, code signing, and policy files were all intended to protect users from the system.
The invention of JAAS reflects Java's evolution into a general-purpose programming language, used for implementing traditional client and server applications that require login and access control. JAAS protects the system from users by allowing or denying access based upon who or what runs the program. While JAAS can perform both authentication and authorization, in this article, we focus primarily on authentication.
JAAS can simplify your Java security development by putting an abstraction layer between your application and disparate underlying authentication and authorization mechanisms. This independence from platforms and algorithms allows you to use different security mechanisms without modifying your application-level code. As with most Java security APIs, JAAS achieves this implementation-independence through an extensible framework of pluggable service provider interfaces (SPIs): a set of abstract classes and interfaces to which specific implementations are developed.
Great article! Easy to read and understand...By Anonymous on January 18, 2010, 10:46 amGreat article! Easy to read and understand. It would be great if someone give explanation how user information could be validated against Active Directory in combination...
Reply | Read entire comment
greatBy Anonymous on October 20, 2009, 1:50 amThis is a practically usable document; and not mere a collection of fancy .........
Reply | Read entire comment
Sun site - VagueBy Anonymous on September 12, 2009, 4:52 amI always think I'm the only one who thinks Sun tutorial is hard to understand. This is something Sun needs to look into. I specifically do not like to learn from...
Reply | Read entire comment
Is there any alternative to the configuration fileBy Anonymous on July 13, 2009, 8:48 amReally a very concrete and clear introduction to JAAS, however something that I do not like is to configure JAAS with an configuration file, is it the only way to...
Reply | Read entire comment
Great article..By Anonymous on July 10, 2009, 11:29 amThis was a great article and really helped shed some light on all of this! Is there another example on the Authorization part? Thanks so much!
Reply | Read entire comment
View all comments