The Java Authentication and Authorization Service (JAAS) was introduced as an optional package (extension) to the Java 2 SDK, Standard Edition (J2SDK), v 1.3.
JAAS was integrated into the J2SDK 1.4.
JAAS can be used for two purposes:
Traditionally Java has provided codesource-based access controls (access controls based on where the code originated from and who signed the code).
It was not able to enforce access controls based on who runs the code.
JAAS provides a framework that augments the Java security architecture with such support.
It implements a Java version of the standard Pluggable Authentication Module (PAM) framework.
JAAS provides pre-defined modules.
It is possible to develop or import new modules.
JAAS is pluggable; this permits applications to remain independent from underlying authentication technologies.
Any authentication technology can be plugged under an application without requiring modifications to the application itself.
The process:
Once the user or service executing the code has been authenticated, the JAAS authorization component works in conjunction with the core Java SE access control model to protect access to sensitive resources.
Access control decisions are based both on the executing code’s CodeSource and on the user or service running the code, who is represented by a Subject object.
The Subject is updated by a LoginModule with relevant Principals and credentials if authentication succeeds.
SampleAcn.java contains a sample application class (SampleAcn) and another class used to handle user input (MyCallbackHandler).
SampleLoginModule.java is the class specified by the login configuration file as the class implementing the desired underlying authentication. SampleLoginModule’s user authentication consists of simply verifying that the name and password specified by the user have specific values.
SamplePrincipal.java is a sample class implementing the java.security.Principal interface. It is used by SampleLoginModule.
CallbackHandlers and Callbacks enable the LoginModule to gather user credentials.
JAAS provides 7 built-in Callbacks in the javax.security.auth.callback package:
The JAAS framework defines the term subject to represent the source of a request. A subject may be any entity, such as a person or a service.
Once the subject is authenticated, a javax.security.auth.Subject is populated with associated identities, or Principals.
A Subject may have many Principals.
That file contains two classes:
The main method of the SampleAcn class performs the authentication and then reports whether or not authentication succeeded. The code for authenticating the user is very simple, consisting of just two steps:
Once we have a LoginContext lc, we can call its login method to carry out the authentication process:
import javax.security.auth.login.*;
. . .
LoginContext lc = new LoginContext(“Sample”, new MyCallbackHandler());
lc.login();
——————————- file sample_jaas.config —————————-
/** Login Configuration for the JAAS Sample Application **/
Sample {
sample.module.SampleLoginModule required debug=true;
};
SampleLoginModule.java implements the LoginModule interface. SampleLoginModule is the class specified in the configuration file as the class implementing the desired underlying authentication.
SampleLoginModule’s user authentication consists of simply verifying that the name and password specified by the user have specific values.
If authentication is successful, the SampleLogin Module populates a Subject with a SamplePrincipal representing the user.
javac sample/SampleAcn.java
sample/module/SampleLoginModule.java
sample/principal/SamplePrincipal.java
java -Djava.security.auth.login.config=
=sample_jaas.config sample.SampleAcn
User: testUser
Pass: testPassword
JAAS authorization extends the existing Java security architecture that uses a security policy to specify what access rights are granted to executing code:
BEFORE JAAS:
grant codebase “file:./SampleAcn.jar” {
permission javax.security.auth.AuthPermission “createLoginContext.Sample”;
};
JAAS authorization augments the existing code-centric access controls with new user-centric access controls. Permissions can be granted based not just on what code is running but also on who is running it.
When an application uses JAAS authentication to authenticate the user (or other entity such as a service), a Subject is created as a result. The purpose of the Subject is to represent the authenticated user. A Subject is comprised of a set of Principals, where each Principal represents an identity for that user.
Permissions can be granted in the policy to specific Principals.
The Java runtime will automatically determine whether the policy grants the required permission only to a specific Principal and if so, the operation will be allowed only if the Subject associated with the access control context contains the designated Principal.
// Java 2 codesource-based policy
grant Codebase “http://foo.com”, Signedby “foo” {
permission java.io.FilePermission “/cdrom/-”, “read”; }
// JAAS principal-based policy
grant Codebase “http://bar.com, Signedby “bar”,
Principal bar.Principal “duke” {
permission java.io.FilePermission “/cdrom/duke/-”, “read”;
}
This example allows the code:
….to read only the files included in the ‘/cdrom/duke’ directory.
The Subject authenticated in the LoginContext must be associated to a Prinicipal whose getName method returns ‘duke’.
The policy must specify the information Codebase and SignedBy, too.
To make JAAS authorization take place, the following is required:
The basic format of a grant statement is:
grant , <signer(s) field> , <codeBase URL>
<Principal field(s)> {
permission perm_class_name “target_name” , “action”; ….
permission perm_class_name “target_name” , “action”; };
grant codebase “file:./SampleAction.jar”,
Principal sample.principal.SamplePrincipal “testUser”
{
permission java.util.PropertyPermission “java.home”,
“read”; permission java.util.PropertyPermission
“user.home”,”read”; permission java.io.FilePermission
“foo.txt”, “read”;
};
The static doAsPrivileged method from the Subject class may be called instead of the doAs method. In addition to the parameters passed to doAs, doAsPrivileged requires a third parameter: an AccessControlContext.
Subject mySubject = lc.getSubject();
PrivilegedAction action = new SampleAction();
Subject.doAsPrivileged(mySubject, action, null);
The doAsPrivileged method invokes execution of the run method in the PrivilegedAction action (SampleAction) to initiate execution of the rest of the code, which is considered to be executed on behalf of the Subject mySubject.
1. Course Introduction: Security basic concepts
2. Access Control models: Authentication and authorization mechanisms
6. Role Based Access Control standard (v3)
7. XACML: extensible Access Control Markup Language
8. Authentication Protocols in distributed system
10. Java Authentication and Authorization Service (JAAS)
11. Network security
12. Network security, security protocols: PGP, SSL