Weblogic Authors: Yeshim Deniz, Elizabeth White, Michael Meiner, Michael Bushong, Avi Rosenthal

Related Topics: Weblogic

Weblogic: Article

JAAS Fundamentals

JAAS Fundamentals

Security is any mechanism that can be used to protect and validate resources. There are many security models that can be used to protect the data. The security model may use encryption, access control, or several other security methods. Authorization, or access control, has different security services that may be used to protect the resources. One method may be the Java Authentication and Authorization Service (JAAS), and another is Windows 2000 Active Directory. This article focuses on the JAAS security service.

Two of the most basic security mechanisms are authentication and authorization. Authentication is simply the identification of an entity. Authorization is the decision process for granting the entity access rights to any data resources or information. The JDK 1.4 comes standard with services that provide both authentication and authorization. These services are called the Java Authentication and Authorization Service (JAAS).

JAAS defines authentication mechanisms through a configuration file; code is not needed to define the mechanism. The authentication mechanism requires parameters in order to identify a user. The parameters used to authenticate a user, such as a name and password for each authentication mechanism, are known as a Principal. A Subject is who I am, but I may use a Principal, my driver's license, to authenticate myself to a cop, and use another Principal, my passport, to authenticate myself to the border patrol. Authorization will only occur after authentication because users must be identified before they are given access to protected resources. The JAAS framework will wrap authentication modules specified by the configuration file. A successful authentication process will return a Subject containing Principals. The Principals returned by the authentication mechanisms will be used for the authorization process.

JAAS will start with a LoginContext class to find the entries in the configuration file that will initialize the appropriate Login-Modules (see Figure 1). The configuration file will contain any initialization parameters that the LoginContext does not specify. The LoginContext will also pass the Login Module a CallbackHandler. The CallbackHandler will call back to the application to request any additional authentication information. For example, if a LoginContext did not specify a username and password through the creation of a CallbackHandler, and the LoginModule requires the information, the LoginModule will use the CallbackHandler to call the LoginContext back to get the information required.

The LoginContext may also pass the Subject to the LoginModule for the Principals to use to log in.

After the initialization of the LoginModule when the LoginContext is created, the LoginContext may call the login( ) method (see Figure 2), which will authenticate the Subject. The login process may go through a daisy chain of LoginModules, each requiring a different type of Principal based on the configuration. The configuration can specify LoginModules that are optional but not required. The LoginModule will complete a two-phase login process. The first phase is when the login( ) method of the LoginModule will get called from the login process. The second phase is when the commit( ), or abort( ), method is called to finish the login process. The commit( ) process is called from the login process when all other LoginModules complete their login( ) method. Then the last LoginModule ( ) will perform its commit, then the next, and so on. The abort method will perform any cleanup if the login( ) method did not complete successfully. If all of the required commit( ) methods completed successfully, then the login process completed successfully.

The authorization process requires the Principals established during the login process, so it is no surprise that the authorization is normally accomplished in the Subject class. The Subject class performs authorization using a PrivilegedAction class. An extended PrivilegedAction class wraps the resources that are to have the access control. Whether or not the Principal has permission to access a resource is defined in a security policy file. The Java security manager will read the appropriate security policy file and parse the permissions and Principals. The security manager will then grant or deny the resources in the Privileged Action based on these permissions and principals. If the permission for the resource is not allowed for a specific Principal, then an access exception is thrown.

Using JAAS with WebLogic
WebLogic Application Server (WLS) 7.0 does not redefine or change JAAS. JAAS remains the same regardless, but it is an extensible framework. WLS 7.0 includes its own authentication and authorization mechanisms that do not require a policy file. The configuration file will define the WLS LoginModule to be used to wrap the WLS authentication mechanism. The WLS LoginModule normally requires a username, password, and URL to point to the appropriate WLS server. WLS 7.0 also contains an authorization mechanism from mapping resources to roles. Because WLS 7.0 has an authorization mechanism implemented in the WebLogic security framework, policy files and the Java security manager do not have to be defined. A weblogic.security.Security class is required when using calling the Privileged Action.

WebLogic 7.0 comes with an example of how to perform JAAS-based authentication and authorization from a Java client application to make calls to an EJB that has access restrictions enabled on its methods. The example is a slight modification of the Sun example found at http://java.sun.com/j2se/1.4/docs/guide/security/ jaas/JAASRefGuide.html#Sample.

This example includes a JAAS configuration file, which specifies the class name of the LoginModule used to perform authentication of the EJB client; a CallbackHandler used to gather the client credentials and the URL of the authentication server; a PrivilegedAction, which contains the code that performs the EJB access; and a client application that creates a LoginContext, calls the login method, and invokes the PrivilegedAction through the weblogic.security.Security.runAs method. The flow of this example application is diagrammed in Figure 3. You can refer to the full example by looking in $WL_HOME/weblogic700/samples/server/src/ examples/security/jaas. The remainder of this article will refer to this example to discuss JAAS-based authentication and authorization in WLS from remote clients and to compare that with server-side components such as servlets.

Java Client Authentication
Authentication of a stand-alone Java client is used by client applications that need to directly access EJBs or JMS Destinations located on a WebLogic Server. The client-side example, supplied by BEA with the WLS 7.0 release, uses a JAAS policy file, sample_jaas.config, to specify a single LoginModule, weblogic.security.auth.login.UsernamePasswordLoginModule, to the application. Here are the contents of this file:

Sample {
required debug=false;

The code for the UsernamePasswordLoginModule is not included in the example package, but the class file is located in weblogic.jar. Details of the code can be found at http://edocs.bea.com/wls/ docs70/security/intro.html#1047392 .

It uses the weblogic.security.auth.Authenticate class, a WebLogic-specific class, to perform the actual authentication to a WebLogic server instance that is specified to the LoginModule through a URLCallback. The application's CallbackHandler supplies the URL of the server that will perform the authentication through the server's configured Authentication Provider.

The LoginModule passes a NameCallback and a PasswordCallback to the CallbackHandler to acquire the username and password of the client initiating the application. Once the user is authenticated, the LoginModule populates the Subject passed to it by the LoginContext. The application then retrieves the authenticated Subject using the LoginContext.getSubject method. The Subject holds the WebLogic Principals - which can be a WLSUser or WLSGroup - which will be used for authorization when the Subject is passed to the Security.runAs method. The entire JAAS authentication sequence is initiated by the application when it instantiates a LoginContext and calls the LoginContext.login() method. The LoginContext locates a Configuration object that loads the configuration information found in the JAAS policy file. It uses the Configuration to create an instance of the LoginModule that will be used for the authentication sequence.

// Create LoginContext; specify username/password login module
loginContext = new LoginContext
("Sample", new SampleCallbackHandler(username, password, url));

This instantiation of the LoginContext will locate and instantiate a LoginModule found in the Configuration, using the name "Sample" to locate the LoginModule in the Configuration, and pass the SampleCallbackHandler to its initialize method. From the entry in the sample_jaas.config file, you can see that the LoginContext will instantiate an instance of UsernamePasswordLoginModule to perform the authentication.

The WebLogic documentation states that the use of the weblogic.jndi.Environment class is deprecated in the WLS 7.0 release. However, the LoginModule supplied with the example uses the weblogic.jndi.Environment object to perform the authentication by passing the Environment, which contains the username, password, and URL of the server, to the Authenticate.authenticate method. This apparent contradiction is a good opportunity to plug the advantages of the pluggable nature of the LoginModule. The mechanism of the example LoginModule, the use of the Authenticate class, is not visible to the client application attempting to authenticate itself to the WebLogic server. Since the LoginModule is an instance of a Pluggable Authentication Module (PAM), it can be replaced or rewritten without affecting the client application. This is a good example of how the pluggable nature of a LoginModule prevents the development of brittle application code.

The Authenticate.authenticate method makes a connection to the WebLogic server specified in the URL and passes the Subject and the Environment, which holds the credentials, to the server to be authenticated by the Authentication provider configured for the WebLogic Security Realm of the server. The Authentication provider configured in the server's security realm also implements a LoginModule. The implementation of the Authentication provider can perform the authentication using any number of technologies, such as LDAP or a relational database. If the authentication succeeds, the Authentication provider adds the authenticated Principal(s) to the Subject. Before it adds the Principal to the Subject it makes a request to the Principal Validator to digitally sign the Principal. This prevents potentially malicious clients from tampering with the Principal embedded in the returned Subject in an attempt to circumvent authorization checks when the Subject is returned via a Security.runAs call. The Principal Validator is consulted during authorization to ensure that the returned Subject is the same one that was digitally signed during authentication.

Browser-Based Authentication
Many, if not most, WebLogic-based applications are accessed through browser-based clients. These applications are generally composed of servlets, JSPs, and EJBs. Authentication to these applications is specified as BASIC or FORM in the element of the web.xml deployment descriptor of the Web application that will present the initial access page of the application. For example:


When one of these methods is used to authenticate a Web client, the Web container calls to the WebLogic Security Framework, on behalf of the client, to access the Authentication provider. This mechanism results in the creation of a JAAS Subject, which contains an authenticated Principal, that is stored within an internal session object. Subsequent requests from the client are authorized by locating the Subject in the internal session using the session id passed in a cookie in the HttpRequest. The point here is that resource containers on WebLogic, such as the Web container, use JAAS-based authentication as well by calling the Authentication provider on behalf of the Web client to get a Subject populated with an authenticated Principal. The LoginModule used by the Authentication provider is not configured in a JAAS configuration file as it is in the Java client example. The Authentication provider is configured by adding it to the active Security Realm through the administration console. The default Authentication provider and LoginModule configured for WLS 7.0, out-of-the-box, use an embedded LDAP server. The server-side LoginModule that authenticates the Web-based client is the same LoginModule that is used to authenticate a Java client application when the client-side UsernamePasswordLoginModule calls the Authenticate.authenticate method passing the Subject and Environment objects. The Subject is not passed back to the Web client, but rather is kept by the Web container in an internal session object and is later referenced by the session id.

JAAS-Based Authorization
While authorization in WLS does not use the JAAS Subject.doAs method, it is JAAS Subject based. Applications that require access to protected WebLogic resources request access to them through the weblogic.security.Security.runAs method. A Subject and PrivilegedAction are passed to this WLS Security Framework method to perform a task involving a WebLogic resource.

WebLogic Resources
Unlike Java system resources that are protected through security policies found in the Java security policy file, WebLogic resources are protected by WebLogic security policies that are specified by the association of a WebLogic role with a WebLogic resource. A WebLogic resource is defined as a structured object that represents a server-side entity that can be protected from unauthorized access. Examples of WebLogic resources are EJB methods, servlets, and JMS Destinations. See the WebLogic 7.0 documentation at http://edocs.bea.com/wls/docs70/ dvspisec/atz.html#1134702 for examples of the types of WebLogic resources that can be protected using WebLogic roles.

WebLogic Roles
WebLogic roles, found in WLS 7.0, are used to replace ACL-based authorization found in previous releases of WebLogic. A role is defined by the WLS documentation as an abstract, logical collection of users similar to a group. Roles are different from groups because they are dynamically updated based on username, group membership, and time of day. Roles are used with resources to create WebLogic security policies. JAAS-based security policies are defined in the Java security policy file by granting Permissions to codebases, signers, and Principals. Associating a WebLogic role with a WebLogic resource creates a WebLogic security policy. WebLogic does not consult a Java policy file to apply security policies. A user who is in the role defined by a security policy for a resource at the time an access decision for the resource is made is allowed to access the resource.

WebLogic roles can be global, which associates them with all WebLogic resources, or scoped, which associates them with a specific WebLogic resource. Global roles are declared using the administrative console. Security policies are created dynamically, using scoped roles, for Web applications and EJBs through the use of deployment descriptors. These roles are declared and associated with the resource in the web.xml file for Web application components and in the ejb-jar.xml file for EJBs using the <security-role> element. The declared roles are granted to Principals through the vendor-specific deployment descriptors, weblogic.xml, and weblogic-ejb-jar.xml respectively, using the <security-role-assignment> element. Dynamic roles may be configured in the console too, but the deployment descriptors of the components are not updated with the console modifications. The Role Mapper does the work of associating the roles granted to the principals at deployment time.

WebLogic Authorization
Authorization of the Java client application is initiated when the application attempts to execute a PrivilegedAction through the Security.runAs method (see Figure 4). The application passes the authenticated Subject and the PrivilegedAction to the WebLogic security framework when it calls this method. In the WLS example, an EJB method is invoked from a PrivilegedAction, SampleAction.java, using the authenticated Subject as the identity of the caller. The EJB container on the server receives the request from the client-side EJB stub in the context of the PrivilegedAction, which propagates the authenticated Subject to the EJB container with the method invocation. The EJB container calls to the Security Framework on the server to determine if the Subject is allowed to access the EJB method. This activates the Authorization provider and the Role Mapper to make a decision regarding the Subject's access to the EJB method being called. The Role Mapper determines what Roles are held by the Principals in the Subject. The Authorization provider determines if the Roles held by the Principals allow access to the method. If access is allowed, the container proceeds with the method invocation. It should be noted that before the authorization process begins, the Principal Validator validates that the Principals in the passed Subject have not been tampered with since authentication.

Browser-based clients are authorized by the same mechanism on the server. The difference is that the Subject is kept on the server by the Web container rather than being passed from the client application. The browser sends the session id in a cookie and the Web container locates the subject in an internal session before calling to the security framework to perform authorization.

The JAAS mechanisms of authentication and authorization, defined by the JAAS specification and implemented in JDK 1.4, use the Java SecurityManager, the AccessController, LoginModules, and Subjects to perform authentication and authorization checks. These mechanisms, used to protect system resources and properties, are configured using the Java security and policy files. WebLogic uses JAAS LoginModules and Subjects to perform authentication and authorization; however, the Configuration is not specified with, or retrieved from, the Java security and policy files.

Security providers that are configured through the WebLogic console implement the roles of the Java SecurityManager and AccessController in a WebLogic server. These security providers control access to WebLogic resources using security policies that are defined by the association WebLogic roles and WebLogic resources. Roles may be configured through the console or through deployment descriptors. A WebLogic authentication provider uses LoginModules and Subjects to establish the identity of a user. An authenticated Subject is used by a WebLogic Authorization provider to grant or deny access to WebLogic resources based on the security policies defined for those resources and the roles held by the Principals in the authenticated Subject.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.

IoT & Smart Cities Stories
Enterprises have taken advantage of IoT to achieve important revenue and cost advantages. What is less apparent is how incumbent enterprises operating at scale have, following success with IoT, built analytic, operations management and software development capabilities - ranging from autonomous vehicles to manageable robotics installations. They have embraced these capabilities as if they were Silicon Valley startups.
"MobiDev is a Ukraine-based software development company. We do mobile development, and we're specialists in that. But we do full stack software development for entrepreneurs, for emerging companies, and for enterprise ventures," explained Alan Winters, U.S. Head of Business Development at MobiDev, in this SYS-CON.tv interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
Recently, REAN Cloud built a digital concierge for a North Carolina hospital that had observed that most patient call button questions were repetitive. In addition, the paper-based process used to measure patient health metrics was laborious, not in real-time and sometimes error-prone. In their session at 21st Cloud Expo, Sean Finnerty, Executive Director, Practice Lead, Health Care & Life Science at REAN Cloud, and Dr. S.P.T. Krishnan, Principal Architect at REAN Cloud, discussed how they built...
When talking IoT we often focus on the devices, the sensors, the hardware itself. The new smart appliances, the new smart or self-driving cars (which are amalgamations of many ‘things'). When we are looking at the world of IoT, we should take a step back, look at the big picture. What value are these devices providing. IoT is not about the devices, its about the data consumed and generated. The devices are tools, mechanisms, conduits. This paper discusses the considerations when dealing with the...
Bill Schmarzo, author of "Big Data: Understanding How Data Powers Big Business" and "Big Data MBA: Driving Business Strategies with Data Science," is responsible for setting the strategy and defining the Big Data service offerings and capabilities for EMC Global Services Big Data Practice. As the CTO for the Big Data Practice, he is responsible for working with organizations to help them identify where and how to start their big data journeys. He's written several white papers, is an avid blogge...
Business professionals no longer wonder if they'll migrate to the cloud; it's now a matter of when. The cloud environment has proved to be a major force in transitioning to an agile business model that enables quick decisions and fast implementation that solidify customer relationships. And when the cloud is combined with the power of cognitive computing, it drives innovation and transformation that achieves astounding competitive advantage.
Machine learning has taken residence at our cities' cores and now we can finally have "smart cities." Cities are a collection of buildings made to provide the structure and safety necessary for people to function, create and survive. Buildings are a pool of ever-changing performance data from large automated systems such as heating and cooling to the people that live and work within them. Through machine learning, buildings can optimize performance, reduce costs, and improve occupant comfort by ...
René Bostic is the Technical VP of the IBM Cloud Unit in North America. Enjoying her career with IBM during the modern millennial technological era, she is an expert in cloud computing, DevOps and emerging cloud technologies such as Blockchain. Her strengths and core competencies include a proven record of accomplishments in consensus building at all levels to assess, plan, and implement enterprise and cloud computing solutions. René is a member of the Society of Women Engineers (SWE) and a m...
JETRO showcased Japan Digital Transformation Pavilion at SYS-CON's 21st International Cloud Expo® at the Santa Clara Convention Center in Santa Clara, CA. The Japan External Trade Organization (JETRO) is a non-profit organization that provides business support services to companies expanding to Japan. With the support of JETRO's dedicated staff, clients can incorporate their business; receive visa, immigration, and HR support; find dedicated office space; identify local government subsidies; get...
With 10 simultaneous tracks, keynotes, general sessions and targeted breakout classes, @CloudEXPO and DXWorldEXPO are two of the most important technology events of the year. Since its launch over eight years ago, @CloudEXPO and DXWorldEXPO have presented a rock star faculty as well as showcased hundreds of sponsors and exhibitors! In this blog post, we provide 7 tips on how, as part of our world-class faculty, you can deliver one of the most popular sessions at our events. But before reading...