Published on dev2dev (http://dev2dev.bea.com/)
http://dev2dev.bea.com/pub/a/2006/12/sso-with-saml.html
See this if you're having trouble printing code examples
by Vikrant Sawant
01/04/2007
BEA WebLogic Server 9.2 provides out-of-the-box support for Security Assertion Markup Language (SAML) to build single sign-on (SSO) solutions with minimum or no coding, depending on your security requirements. Using WebLogic Server 9.2, the single sign-on capability can be easily added between multiple online applications running on trusted domains. The SAML standard defines a framework for exchanging security information between the federation of trusted servers. The primary function of the security framework is to provide configuration tools and APIs to secure your applications.
This tutorial provides step by step instructions to configure the single sign-on capability between two simple Java EE Web applications running on two different WebLogic domains. The SAML configuration for single sign-on is performed using the WebLogic Server 9.2 Administration Console with no programming involved. The tutorial also briefly introduces the basic interactions between WebLogic containers, the security providers, and the security framework during the single sign-on process.
The SAML standard defines a framework for exchanging security information within the federation of trusted servers. For some background, read Introduction to SAML by Beth Linker (Dev2Dev, 2006). This tutorial shows how to set up SAML authorization between two Web applications. The source for these applications is provided here.
This tutorial looks at a simple example involving two Web applications; appA deployed on the source (local) site, and appB deployed on the destination (remote) site. You'll learn how to configure these applications using the WebLogic Server 9.2 Administration Console and participate in a SSO process using SAML.
The source site provides an authentication service and securely passes the authentication details using SAML Inter-site Transfer Service (ITS) when requested by the destination site. The server on the source site includes an ITS servlet, which is an addressable component that provides SAML processing functionality such as artifact generation and the ability to redirect a user to the destination site.
Figure 1 shows the basic interaction between source site and destination site during the SSO process.

Figure 1. Interaction between source site and destination site, using SAML, during single sign-on
The whole single sign-on process listed above requires no coding by the developer (except for the coding of applications appA and appB, of course) and can be easily configured using the Administration Console.
|
Before starting the SAML configuration, in the first few steps you'll create and set up the server environment for the sample applications appA and appB.
The sample applications in this tutorial are hosted on two domains on the local host, so the first step is to create the domains and servers running on given ports, as listed below in Table 1.
| Host | Application Server | Application Name | Port | SSL Port | |
|---|---|---|---|---|---|
| SAML Source Site Domain: domainA | localhost | AdminServer | appA | 7001 | 7002 |
| SAML Destination Site Domain: domainB | localhost | AdminServer | appB | 7003 | 7004 |
Table 1. Sample application domains and application servers
Create domains, as shown in Table 1, using the Domain Configuration Wizard. Update the appropriate listen ports using the WebLogic Server 9.2 Administration Console.
For simplicity, this tutorial uses the default security realms on each domain, each named with the same default realm name, that is, myrealm. Create a user ssouser in each domain separately under the myrealm realm. Alternatively, you could create this user in a centralized external LDAP store and configure both domains to use this common store for authentication.
The user ssouser created here will authenticate with application appA hosted on domainA, and then access application appB hosted on domainB directly using SSO.
| Realm | User/Password | |
|---|---|---|
| SAML Source Site Domain: domainA | myrealm | ssouser/demosaml |
| SAML Destination Site Domain: domainB | myrealm | ssouser/demosaml |
Table 2. The user participating in single sign-on
Create the user, ssouser, as shown in Table 2, in both domains under the default security realms, each called myrealm.
The sample application source code for appA can be downloaded here. Import the existing Web application into WebLogic WorkShop Studio or any other IDE, such as Eclipse.
Application appA is configured to use FORM-based authentication. This application is deployed on the
SAML source site domain (domainA). A JSP page of appA called auth.jsp, under the admin folder,
requires the authenticated user to have an admin role in
order to access it. The admin role is mapped to a principal called ssouser
in weblogic.xml. Figure 2 shows the configuration of the security in web.xml.
<display-name>Saml Source Site Application</display-name> <security-constraint> <web-resource-collection> <web-resource-name>SecurePages</web-resource-name> <description>These pages are only accessible by authorized users.</description> <url-pattern>/admin/*</url-pattern> <http-method>GET</http-method> </web-resource-collection> <auth-constraint> <description>These are the roles who have access.</description> <role-name>admin</role-name> </auth-constraint> <user-data-constraint> <description>This is how the user data must be transmitted.</description> <transport-guarantee>NONE</transport-guarantee> </user-data-constraint> </security-constraint> <login-config> <auth-method>FORM</auth-method> <realm-name>myrealm</realm-name> <form-login-config> <form-login-page>/login.jsp</form-login-page> <form-error-page>/fail_login.htm</form-error-page> </form-login-config> </login-config> <security-role> <description>These are the roles who have access</description> <role-name>admin</role-name> </security-role>
Example 1. Application appA - web.xml snippet
When the user tries to access the /admin/auth.jsp
page, a configured login page, login.jsp, will be displayed, asking the user to supply credentials. After submitting the details, the container will authenticate the user ssouser. If authentication is successful,
the auth.jsp will be displayed. Before going on to explore the Web page auth.jsp,
I'll create the application appB on the SAML destination site domain (domainB).
Sample application source code for appB can be downloaded from the Download section. Application appB is configured to use CLIENT-CERT, so that it will use identity assertion for
authentication. This application should be deployed on the SAML destination site domain (domainB).
A JSP page of appB, called services.jsp and located in the /admin folder, requires the authenticated user
to have the admin role in order to access it. This role is mapped to a principal called ssouser in weblogic.xml. Figure 3 shows an excerpt from appB's web.xml configuration:
<display-name>SAML Destination Site Application</display-name> <!-- ... --> <security-constraint> <web-resource-collection> <web-resource-name>SecurePages</web-resource-name> <description>These pages are only accessible by authorized users.</description> <url-pattern>/admin/*</url-pattern> <http-method>GET</http-method> </web-resource-collection> <auth-constraint> <description>These are the roles who have access.</description> <role-name>admin</role-name> </auth-constraint> <user-data-constraint> <description>This is how the user data must be transmitted.</description> <transport-guarantee>NONE</transport-guarantee> </user-data-constraint> </security-constraint> <login-config> <auth-method>CLIENT-CERT</auth-method> <realm-name>myrealm</realm-name> </login-config> <security-role> <description>These are the roles who have access.</description> <role-name>admin</role-name> </security-role>
Example 2. Application appB - web.xml snippet
Compile and build the WAR files (appA.war,appB.war) for each application. To deploy, copy appA.war and appB.war files into the autodeploy folders of the domainA and domainB domains respectively. Restart the application servers and test to see how the applications behave without SSO.
When the SAML configuration has been completed, as described in the steps to follow, the user ssouser,
authenticated at appA (SAML source site), will be able to directly access the services.jsp page of
appB (SAML destination site) without being asked to supply the credentials again.
|
To secure communication between the SAML source and destination sites, communication between the source site and destination site should be encrypted. Additionally, certificates should be used to verify the identity of the other party during SAML interaction. In this step I'll create and register certificates that will be used in the communication between the source site and the destination site.
Generate a key using the keytool utility (part of your JDK). By default, a keystore called DemoIdentity.jks will already be configured for domainA and domainB.
Now I'll show how to generate a private key and certificate for test purposes:
WEBLOGIC_HOME/server/lib directory.keytool -genkey -keypass testkeypass -keystore DemoIdentity.jks -storepass DemoIdentityKeyStorePassPhrase -keyalg rsa -alias testalias
Figure 2. Generate test SSL certificate screen shot
Now run the keytool command with -export option, as shown in Figure 2, to generate a key file called testalias.der:
keytool -export -keypass testkeypass -keystore DemoIdentity.jks -storepass DemoIdentityKeyStorePassPhrase -alias testalias -file testalias.der
I'll begin with the SAML source site configuration.
In this step I will create and configure a SAML Credential Mapper V2 instance. The SAML Credential Mapper acts as a producer of
SAML security assertions, allowing domainA to act as a source site for using SAML for SSO.
A SAML security assertion is a package of information that supplies one or more statements made by a SAML authority (meaning an asserting party).
The statements made are of the following types; authentication statements, attribute statements, and authorization decision statements.
I'll start by configuring a SAML Credential Mapper V2 instance (note that the SAML Credential Mapper V1 is deprecated as of BEA WebLogic Server 9.2):
http://localhost:7001/console).
Figure 3. Create a new SAML credential mapping provider
http://www.bea.com/demoSAML. This unique URI tells the destination site
(domainB/appB) the origin of the SAML message and allows it to match with the key.
Typically, the URL is used to guarantee uniqueness.
Figure 4. SAML credential mapping provider settings
At this point the SAML credential mapper provider is configured to allow domainA to act as a source site (source of SAML security assertions) and also it is configured to use the keystore you generated in Step 4.
In this step I'll create and configure a relying party. When you configure WebLogic Server to act as a source of SAML security assertions, you need to register the parties that may request SAML assertions that will be accepted. For a SAML relying party, you can specify: the SAML profile used, details about the relying party, and the attributes expected in assertions for the relying party.
The relying party determines whether it trusts the assertions provided to it by the asserting party. SAML defines a number of mechanisms that enable the relying party to trust the assertions provided to it.

Figure 5. Relying party configuration
| Parameter | Value |
|---|---|
| Enabled | Select the checkbox(true) |
| Target URL | http://localhost:7003/appB/admin/services.jsp |
| Assertion Consumer URL | https://localhost:7004/samlacs/acs |
| Assertion Consumer Parameters | APID=ap_00001 |
| Signature Required | Select the checkbox(true) |
| Include Keyinfo | Select the checkbox(true) |
Table 3. Relying Party (rp_00001) Values
Although a relying party may trust the assertions provided to it for user ssouser, the
local access policy on the destination site application ssouser) may access local resources.
|
In this step I'll configure various federation services source site settings for the server instance running the application appA. These settings enable server instances running on domainA to serve as a SAML source site, define the source site URIs and service URIs, add certificate to sign assertions, and configure SSL for retrieving assertions.

Figure 6. Source site configuration
| Parameter | Value |
|---|---|
| Source Site Enabled | Select the checkbox(true) |
| Source Site URL | http://localhost:7001/appA |
| Signing Key Alias | testalias |
| Signing Key Passphrase | testkeypass |
| Intersite Transfer URIS | /samlits_cc/its(keep the other values) |
| ITS Requires SSL | Select the checkbox(true) |
| Assertion Retrieval URIs | /samlars/ars |
| ARS Requires SSL | Select the checkbox(true) |
Table 4. Source Site Values
I'm ready to begin the SAML destination site configuration. In this step I'll create and configure a SAML Identity Assertion Provider V2 instance. The SAML Identity Assertion provider acts as a consumer of SAML security assertions, allowing WebLogic Server to act as a destination site for using SAML for single sign-on. The SAML Identity Assertion provider validates SAML assertions by checking the signature and validating the certificate for trust in the certificate registry maintained by the provider. The first thing I need to do here is to create a SAML Identity Assertion Provider V2 instance and import the certificate generated in step 4 into the provider's certificate registry.
Import the certificate:
testalias.der) that you generated previously to the D:\bea\weblogic92\server\lib directory.myrealm.
Figure 7. Create a new Identity asserter

Figure 8. Create a new identity asserter certificate
In this step I'll create and configure an asserting party. When you configure WebLogic Server to act as a consumer of SAML security assertions, you need to register the parties whose SAML assertions will be accepted. For a SAML asserting party, you can specify the SAML profile used, details about the asserting party, and the attributes expected in assertions received from the asserting party.
The asserting party asserts that a user has been authenticated and given associated attributes.
For example, there is a user ssouser, and he/she is authenticated to this domain
using a password mechanism. Asserting parties are also known as SAML authorities.

Figure 9. Create a new asserting party
| Parameter | Value |
|---|---|
| Enabled | Select the checkbox(true) |
| Target URL | http://localhost:7001/appA |
| POST Signing Certificate alias | testalias |
| Source Site Redirect URIs | /appB/admin/services.jsp |
| Source Site ITS URL | https://localhost:7002/samlits_ba/its |
| Source Site ITS Parameters | RPID=rp_00001 |
| Issuer URI | http://www.bea.com/demoSAML |
| Signature Required | Select the checkbox(true) |
| Asserting Signing Certificate Alias | testalias |
Table 5. Asserting Party (ap_00001) Values
|
In this step I'll configure various destination site settings for the server instance running application appB. These settings enable a server instance running on domainB to serve as a SAML destination site, define service URIs (for example, Assertion Consumer Service URI), add a certificate to sign POST profile responses, and configure SSL for the Assertion Consumer Service.

Figure 10. SAML destination site settings
| Parameter | Value |
|---|---|
| Destination Site Enabled | Select the checkbox(true) |
| Assertion Consumer URIs | /samlacs/acs |
| ACS Requires SSL | Select the checkbox(true) |
| SSL Client Identity Alias | testalias |
| SSL Client Identity Pass Phrase | testkeypass |
| POST Recipient Check Enabled | Select the checkbox(true) |
| POST one Use Check Enabled | Select the checkbox(true) |
| Used Assertion Cache Properties | APID=ap_00001 |
Table 6. Destination Site Values
To test single sign-on, open a browser and point to the URL http://localhost:7001/appA/.
The FORM-based authentication configured for appA will display the login.jsp page, as shown in Figure 11. Enter ssouser and demosaml as the values (created in step 2).

Figure 11. Browser showing appA login
This will authenticate the user using the default authenticator configured for domainA.
The auth.jsp page will now be displayed. This page shows a link to appB (http://localhost:7003/appB/admin/services.jsp), as shown in Figure 12. Clicking this link will trigger a call to the ITS servlet and cause the assertion to be generated and the control to be transferred to the destination site.

Figure 12. Browser showing appA successful login with destination site (appB on domainB) link
Once the assertion is validated on the destination site, the ssouser is allowed to access the services.jsp page, as shown in Figure 13.

Figure 13. Browser showing appB successful login with SSO
What if ssouser visits the destination site first? In Step 9, when the asserting party was configured, the Source Site Redirect URI was set to URI /appB/admin/services.jsp.
This is the URI from which the unauthenticated user will be redirected to the ITS URL, https://localhost:7001/samlits_ba/its,
of the source site. This is done to support the destination site first scenario, whereby a user tries to access
a destination site URL prior to being authenticated and is redirected to the source site to be authenticated and then
obtain a SAML assertion. The ITS servlet at the source site will challenge the user to supply a username and password.
Upon successful authentication, the redirection to the destination site is issued, and the /appB/admin/services.jsp page is displayed.
You can enable SAML security debugging to see how the source and destination site interact using the SAML SSO process. To enable SAML security debugging:

Figure 14. Showing WebLogic console enabling SAML debug
You can then view the AdminServer log file on domainA (source) and domainB (destination) to debug the SAML-related issues (Figure 15).

Figure 15. AdminServer log showing SAML interactions
The tutorial shows how SAML source and destination site domains can be configured to allow Web applications on these domains to operate in a federation of trust based on successful single sign-on to the SAML source site Web application. This is a powerful paradigm, completely configured using the administration console, providing immediate benefit to users of your many applications.
Vikrant Sawant is Senior IT Specialist at the Legislative Counsel Bureau, California. He has over 14 years of experience in software development and has worked extensively in Java and Java EE based projects
Return to dev2dev.