} }

 Files   Prepare   Run   Troubleshooting   Related Topics 

 

About the Example

This package demonstrates the use of the Java Authentication and Authorization Service by validating a username and password, and then, if they are valid, executing the stateless session Trader EJB.

The SampleClient creates a login context that uses the WebLogic Server UsernamePasswordLoginModule and SampleCallbackHandler to validate the user. The example can be run with or without supplying the username and password as parameters. The URL of WebLogic Server is required as a parameter to access the Trader EJB. If a username and password are not supplied, then SampleCallbackHandler prompts the user for both. The supplied URL will be used by SampleCallbackHandler as the location on the WebLogic Server where the user's credentials are validated. If the user is valid, has provided the correct password, and has sufficient permissions to execute the EJB, then SampleClient uses the WebLogic Server Security class weblogic.security.Security.runAs to call SampleAction, which handles the execution of the Trader EJB.

NOTE: The UsernamePasswordLoginModule class is located on the WebLogic Server distribution in the weblogic.jar file.


 

Files Used in the Example

Directory Location:

MW_HOME/wlserver_10.3/samples/server/examples/src/examples/security/jaas/

(where MW_HOME is the directory containing your WebLogic Server installation)

File

Click source files to view code.

Description

build.xml An ant build file that contains targets for building and running the example.
SampleAction.java This class extends BaseClient, implements PrivilegedAction.
SampleCallbackHandler.java This class implements CallbackHandler.
SampleClient.java This class provides the sample client for JAAS user authentication.
sample_jaas.config Login configuration for the JAAS sample application.

 

Prepare the Example

 

Prerequisites

Before working with this example:

  1. Install WebLogic Server, including the examples.
  2. Start the Examples server.
  3. Set up your environment.

 

Configure WebLogic Server

  No special configuration is required for this example

 

Build and Deploy the Example

  1. Change to the SAMPLES_HOME\server\examples\src\examples\security\jaas directory, where SAMPLES_HOME refers to the main WebLogic Server examples directory, such as d:\Oracle\Middleware\wlserver_10.3\samples.

  2. Execute the following command:

    ant build

    This command compiles and stages the example.
  3. Execute the following command:

    ant deploy

    This command deploys the example on the wl_server domain of your WebLogic Server installation.

    The ant command builds and deploys the files in the JAAS example as follows:


 

Run the Example

  1. Complete the steps in the "Prepare the Example" section.
  2. Execute the following command (from the shell where you set your environment):

    ant run

    This command runs the example.
  3. Here is an example of the output:
      C:\Oracle\Middleware\wlserver_10.3\samples\server\examples\src\examples\security\jaas>ant run
       Buildfile: build.xml
       
       run:
            [java] username: weblogic
            [java] password: ********
            [java] URL: t3://localhost:7001
            [java] Creating a trader
            [java] Buying 100 shares of BEAS.
            [java] Buying 200 shares of MSFT.
            [java] Buying 300 shares of AMZN.
            [java] Buying 400 shares of HWP.
            [java] Selling 100 shares of BEAS.
            [java] Selling 200 shares of MSFT.
            [java] Selling 300 shares of AMZN.
            [java] Selling 400 shares of HWP.
            [java] Removing the trader
       
       BUILD SUCCESSFUL
       
       Total time: 6 seconds

 

Troubleshooting


 

Related Topics

(Internet connection required.)