Skip to main content

If you don't have an IBM ID and password, register here.

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. This profile includes the first name, last name, and display name you identified when you registered with developerWorks. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

J2EE pathfinder: Java security with JAAS and JSSE

A short introduction to the J2EE Web application security architecture

Kyle Gabhart (kyle@gabhart.com), Consultant, Gabhart Communications
Photo of Kyle Gabhart
Kyle Gabhart is an independent consultant and subject matter expert with J2EE, XML, and Web services technologies. Kyle is a popular public speaker, recognized for his enthusiasm and dynamic analysis and presentation of emerging technologies. Kyle can be reached at kyle@gabhart.com.

Summary:  In this installment of J2EE pathfinder, enterprise Java developer and educator Kyle Gabhart introduces the Java Authentication and Authorization Service (JAAS) and the Java Secure Socket Extension (JSSE). Follow along to find out how these two APIs combine to provide the core functions of the J2EE Web application security framework: authentication, authorization, and transport-level security.

Date:  25 Nov 2003
Level:  Introductory

Comments:  

From the early days of the so-called Java sandbox to the robust, full-featured security architecture introduced with JDK 1.4, security has always been an essential component of the Java platform. In getting from there to here, the designers of the Java language have received plenty of community input on what does and does not a secure Java application (or enterprise environment) make; and they've also pulled a trick or two on their own.

Suffice it to say that with the introduction of the J2EE Web application security architecture, we're reaping the rewards of nearly 10 years of trial and error, and it shows. The J2EE security framework consists of three APIs: the Java Authentication and Authorization Service (JAAS), Java Secure Socket Extension (JSSE), and Java Cryptography (JCE). While JCE is an interesting and important API, it's not quite so central to our interests as the "big three" of secure Web application development: authentication, authorization, and transport. So in this month's column we'll focus on the JAAS and JSSE.

Overview of JAAS and JSSE

JAAS provides a flexible, declarative mechanism for authenticating users and verifying their ability to access secure resources. JSSE defines an all-Java mechanism for securing Web traffic over a Secure Socket Layer (SSL). By combining these two technologies, we can give our applications the ability to:

  • Verify that a user is who he or she claims to be (authentication)
  • Ensure that he or she is permitted access to the requested resource (authorization)
  • Conduct the entire exchange over a secure network connection (transport)

Now, let's take a look at the individual components underlying all this functionality.


Authentication with JAAS

JAAS is built on a security architecture known as PAM (Pluggable Authentication Module). PAM's architecture is modular, which means it's designed to support the seamless exchange of one security protocol component for another by swapping out modules. Well-defined interfaces within the framework allow for the inclusion of multiple authentication technologies and authentication mechanisms without changing or interfering with any of the existing login services. The PAM architecture, and thus JAAS, is able to integrate a broad range of authentication technologies, including RSA, DCE, Kerberos, and S/Key. Additionally, the framework is compatible with smartcard-based authentication systems and LDAP authentication.

As is the case with so many of the Java 2 platform technologies, the JAAS API defines a clean abstraction between application code and the physical implementation that will execute the business logic. The abstraction layer is what allows for the run-time substitution of login modules without recompiling existing application code. Specifically, applications write to the LoginContext API, while authentication technology providers write to the LoginModule interface. At run time, the LoginContext will read a configuration file to determine which login module(s) should be used to authenticate users accessing a particular application.

The authentication scheme used by JAAS is grounded in two very important entities: principals and subjects. The person or service that is actually being authenticated is referred to as the subject. A principal is a unique entity such as the name of an individual or group, an account number, a social security number, or similar unique identifier. In order to uniquely identify a subject (which is a crucial component of authentication), one or more principals must be associated with that subject. Finally, a subject may own security-related attributes, known as credentials. A credential can be anything from simple password to a complex cryptographic key.

Applications begin the authentication process by instantiating a LoginContext object. The LoginContext queries a configuration to determine the authentication technology (or technologies) and corresponding LoginModule(s) to be used in performing the authentication. A very simple LoginModule may prompt for and verify a username and password. A more advanced one might validate identity using an existing operating-system login identity. Theoretically, a JAAS LoginModule could even be built to interface with a fingerprint reader or retina scanner.


Authorization with JAAS

Authentication is only half the battle in the Java security framework. Once a user's identity has been confirmed, his or her access rights must be examined. Only after the appropriate rights have been confirmed will the user be granted access to secured systems or resources.

To put this another way, once a user or service has been authenticated, a Subject object is created to represent the authenticated entity. This object is then passed by JAAS to any authorization components that have been established to guard access to sensitive systems or resources.

To determine authorization, the Java 2 Security Manager is supplied with the Subject and its Principals, as well as the privileged action the Subject wants to perform (reading/writing to the file system, database access, and so on.). The Security Manager consults a policy file which associates Principals and permissions. If one of the Subject's Principals has permission to perform the specified action, then the Subject is authorized and the action is allowed; otherwise the action is denied and a SecurityException is thrown.

A one-two security punch

For a comprehensive, hands-on look at the Java security model, see Brad Rubin's two-part tutorial:

Part 1: Crypto basics
Part 2: Authentication and authorization


Secure transport with JSSE

Thanks to JAAS we are able to identify users who access our system and restrict their access to the parts of the system they're authorized to use. While JAAS is a solid first step toward a secure Web application, application security isn't complete without secure transport.

At this point, we're still transmitting secure information (including authentication information) in plain text -- that is, HTTP, TCP/IP, FTP, and so on. So we need to make sure that, while in transit, the data isn't accessible to unauthorized parties. We also need to be sure, on arrival, that the data hasn't been modified during transit, whether intentionally or unintentionally. For both of these functions we can leverage the Secure Sockets Layer (SSL) and Transport Layer Security (TLS) protocols.

SSL and TLS are not Java-specific protocols, but rather network-layer protocols designed to maintain the integrity and privacy of traffic across a socket. The Java Secure Socket Extension (JSSE) enables secure Internet communications with SSL/TLS. It provides an application framework -- a Java version of the SSL and TLS protocols -- complete with the full range of functionality including data encryption, server authentication, message integrity, and more. Using JSSE, we can define secure socket connections between a client and server running any application protocol, including HTTP, TCP/IP, FTP, or even Telnet. From a data-encryption standpoint, JSSE encompasses many of the same concepts and algorithms as those in the JCE. More importantly though, it automatically applies them as necessary beneath a simple stream socket API.

To leverage the JSSE API, we only need to do a few simple things. First, we need to obtain a JSSE provider (see Resources). Second, we need to obtain sockets from one of the JSSE socket factories, rather than directly from the java.net.Socket class. Client-side code retrieves sockets from the SSLSocketFactory, while server-side code retrieves sockets from the SSLServerSocketFactory. By retrieving our sockets from these factories, we are able to leverage the framework provided by the JSSE provider, rather than simply creating standard, unsecured sockets as the java.net package allows us to do.

For more details on JSSE, see Resources.


Conclusion

The Java platform is known for its rock-solid application security. With each passing year the Java security framework becomes more flexible and robust, and the addition of JAAS and JSSE suggests that the legacy will continue.

This month, we took a quick peek at the technologies for securing a Java Web application. JAAS provides a modular mechanism for authenticating users and controlling access to resources. JSSE delivers a Java implementation of the SSL and TLS protocols supporting data integrity and privacy. Next month, we'll explore the brave new world of servlet filters. Until then, happy pathfinding!


Resources

About the author

Photo of Kyle Gabhart

Kyle Gabhart is an independent consultant and subject matter expert with J2EE, XML, and Web services technologies. Kyle is a popular public speaker, recognized for his enthusiasm and dynamic analysis and presentation of emerging technologies. Kyle can be reached at kyle@gabhart.com.

Report abuse help

Report abuse

Thank you. This entry has been flagged for moderator attention.


Report abuse help

Report abuse

Report abuse submission failed. Please try again later.


developerWorks: Sign in

If you don't have an IBM ID and password, register here.


Forgot your IBM ID?


Forgot your password?
Change your password


By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. This profile includes the first name, last name, and display name you identified when you registered with developerWorks. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

Choose your display name

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

(Must be between 3 – 31 characters.)


By clicking Submit, you agree to the developerWorks terms of use.

 


Rate this article

Comments

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Java technology
ArticleID=10892
ArticleTitle=J2EE pathfinder: Java security with JAAS and JSSE
publish-date=11252003
author1-email=kyle@gabhart.com
author1-email-cc=

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

For articles in technology zones (such as Java technology, Linux, Open source, XML), Popular tags shows the top tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), Popular tags shows the top tags for just that product zone.

For articles in technology zones (such as Java technology, Linux, Open source, XML), My tags shows your tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), My tags shows your tags for just that product zone.

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).