Java Authentication and Authorization Service, or JAAS, pronounced "Jazz", is the Java implementation of the standard Pluggable Authentication Module (PAM) information security framework.

JAAS was introduced as an extension library to the Java Platform, Standard Edition 1.3 and was integrated in version 1.4. A login module is required to implement the <code>javax.security.auth.spi.LoginModule</code> interface, which specifies the following methods:

Note: A <code>Subject</code> is the user that is attempting to log in.

  • initialize: Code to initialize the login module, usually by storing the parameters passed into appropriate fields of the <code>Class</code>.
  • login: Actually check the credentials provided via an <code>Object</code> that implements the <code>javax.security.auth.Callback</code> interface (e.g. check against a database). This method could prompt the user for their login and password or it could use details previously obtained. If invalid credentials are supplied then a <code>javax.security.auth.login.FailedLoginException</code> should be thrown (rather than returning false, which indicates that this login module should be ignored, which potentially allows authentication to succeed).
  • commit: The identity of the subject has been verified, so code in this method sets up the <code>Principal</code> and <code>Groups</code> (roles) for the successfully authenticated subject. This method has to be written carefully in enterprise applications as Java EE application servers often expect the relationships between the <code>Principal</code> and <code>Group</code> objects to be set up in a certain way. This method should throw a <code>javax.security.auth.login.FailedLoginException</code> if authentication fails (e.g. a user has specified an incorrect login or password).
  • abort: Called if the authentication process itself fails. If this method returns false, then this Login Module is ignored.
  • logout: Code that should be executed upon logout (e.g. could remove the <code>Principal</code> from the <code>Subject</code> or could invalidate a web session).

Login modules can provide single sign on (SSO) via a particular SSO protocol/framework (e.g. SAML, OpenID, and SPNEGO), can check for the presence of hardware security tokens (e.g. USB token), etc. In an n-tier application, <code>LoginModules</code> can be present on both the client side and server side.

LoginModule (<code>javax.security.auth.spi.LoginModule</code>)

Login modules are written by implementing this interface; they contain the actual code for authentication. It can use various mechanisms to authenticate user credentials. The code could retrieve a password from a database and compare it to the password supplied to the module.

LoginContext (<code>javax.security.auth.login.LoginContext</code>)

The login context is the core of the JAAS framework which kicks off the authentication process by creating a Subject. As the authentication process proceeds, the subject is populated with various principals and credentials for further processing.

Subject (<code>javax.security.auth.Subject</code>)

A subject represents a single user, entity or system –in other words, a client– requesting authentication.

Principal (<code>java.security.Principal</code>)

A principal represents the face of a subject. It encapsulates features or properties of a subject. A subject can contain multiple principals.

Credentials

Credentials are nothing but pieces of information regarding the subject in consideration. They might be account numbers, passwords, certificates etc. As the credential represents some important information, the further interfaces might be useful for creating a proper and secure credential – <code>javax.security.auth.Destroyable</code> and <code>javax.security.auth.Refreshable</code>. Suppose that after the successful authentication of the user you populate the subject with a secret ID (in the form of a credential) with which the subject can execute some critical services, but the credential should be removed after a specific time. In that case, one might want to implement the <code>Destroyable</code> interface. <code>Refreshable</code> might be useful if a credential has only a limited timespan in which it is valid.

See also

  • Apache Shiro
  • Keystore
  • OACC

References

  • jGuard : open source project which can secure standalone or web applications based on JAAS
  • SPNEGO Library - open source GNU LGPL project that relies on the JAAS framework to simplify Authentication and Authorization