Using a custom login module with JDev 10.1.3

There’s been a lot of traffic on the JDeveloper Forum in the past few days about custom LoginModule’s both inside of JDeveloper’s embedded OC4J and in OC4J standalone. After trials and tribulations, I’ve got it working in both places, and wanted to share the “how to” with others, so here goes…

What is a LoginModule?

A LoginModule is a class specified in the Java security specification that can be used to authenticate users and to assign roles to those users. In my case, I have user/role information stored in a database, so neither of the two Oracle-supplied LoginModule configurations (file-based or LDAP-based) would work for me. So, using the information in this article by Frank Nimphius and Duncan Mills for guidance, I developed my own LoginModule that would use a stored procedure to authenticate against the database. Now, the “fun” stuff starts… how to get this working in the embedded OC4J that comes with JDeveloper 10.1.3?

JDeveloper 10.1.3 Configuration for Custom Login Modules

Please note to replace brackets [ and ] with less-than and greater-than symbols in the following examples

Basically, there’s a few simple steps that need to be done:

  1. Package your login module up into a jar file. I’m not going to go into any details here, but it’s pretty straightforward to use a deployment profile to create a jar file with your login module and all of its dependent classes.
  2. Put the jar file containing your login module into [jdeveloper_home_directory]/jdev/lib. I suppose it could be anywhere, but this is a pretty convenient place for it.
  3. Make sure the embedded oc4j is shut down (go to the “Run” menu, and use the terminate option to shut it down if it’s running.
  4. The next thing to do is to ensure that your login module JAR file is visible to the embedded oc4j. The configuration files for the embedded oc4j are in [jdeveloper_home_directory]/jdev/system/oracle.j2ee. (at least for the current version as of the date I’m writing this). You need to add a line to the application.xml using your favorite text editor that looks like this:

    [library path=”C:\o\jdev1013\jdev\lib\TestLogin.jar”/]

    (my login module was in a JAR called TestLogin.jar)

  5. The next thing to do is to tell the embedded OC4J to use a custom login module and dynamic roles. In the same application.xml, locate the line that looks like this:

    [jazn provider=”XML”/]

    and replace it with this:

    [jazn provider=”XML”]
    [property name=”custom.loginmodule.provider” value=”true”/]
    [property name=”role.mapping.dynamic” value=”true”/]

  6. The next thing you need to do is to configure the application to use a custom login module. This configuration is done in the system-jazn-data.xml file in the same directory. One thing to note is that the J2EE application name is ALWAYS “current-workspace-app” in the embedded OC4J. Here is the relevant section from my system-jazn-data.xml:


    Your login module may have other options, so configure as necessary. My custom LoginModule was “john.TestLogin” and had 2 options: jdbcUrl and application_realm

  7. Configure your application for security as per the J2EE spec. In my case, it was simply adding some stuff to web.xml for my project in JDev.

  8. That’s it! Now when you run your application from within JDeveloper, it should prompt for a login (you can change the config to use a form instead of the default BASIC authentication)

OC4J Standalone and Oracle AS 10.1.3 Configuration

Fortunately, the configuration with OC4J standalone and Application Server 10.1.3 is much simpler. The enterprise manager deployment wizard actually has some screens to allow you to configure the login module. This process is documented pretty well, but here’s a short synopsis:

  1. Make your login module JAR file available in the classpath. I did this by editing application.xml (in [oc4j_home]/j2ee/home/config) to include a [library] element (just like for the embedded configuration above.
  2. Deploy your application using the OC4J/AS enterprise manager. When you get to step 3, (Deployment Settings), look what you’ve got:

  3. Now, you can click to “Select Security Provider” and “Map Security Roles”

I hope this helps those who are struggling with this, as I was.

9 Responses to Using a custom login module with JDev 10.1.3

  1. Adrian Iacob says:

    I have one question.
    I created my Custom Login Module, it is reading from db names, roles. (Thank you for your help :P, it is working)
    What I can’t undestand is how can I get the user’s id into a session bean 😀 so i know who was logged 😀 pls help :

  2. John Stegeman says:


    You can access the user name from the servlet session context. If you’re using JSF:

    ctx = FacesContext.getCurrentInstance();
    ectx = ctx.getExternalContext();

    //Ask the container who the user logged in as
    _userName = ectx.getRemoteUser();

    Hope this helps.

  3. Anonymous says:


    I have been trying to do something similar. I followed the sample in SRDemo but that doesn’t use the data from the database schema. It is possible for you to share the example you have.

    I would really appreciate that.


  4. Karthik says:


    I am experiencing the same error if I have the ‘role.mapping.dynamic’ set in orion-application.xml? Mind sharing how you addressed this issue?


  5. Karthik says:

    Oops, I am referring to your OTN thread..

    I left you a message there as well!

    I am experiencing the same error if I have the ‘role.mapping.dynamic’ set in orion-application.xml? Mind sharing how you addressed this issue?


  6. Mehrdad says:

    Thanx for the descriptive guide, I have a strange problem with my custom login module (its quite the same as DBTableLM) that I thought you might be able to help.
    I did all the things you and Frank blogged over 10 times with any combination of configurations you imagine, but still cant get my roles get read by the OC4J, I constantly get 403 Forbidden Error though the Login module works perfectly. Any idea of what the problem might be? have you done any special config for grantees in jazn policies? if so how? I’m under pressure to have it done asap, I’d be glad if you take it urgent, I’ll check here for the answer.

  7. Mehrdad says:

    I finally figured out what the problem was and thought the remedy may help some other poor guys getting stucked with the same issue, here is the case:
    I was trying to use Frank’s sample DBLoginModule, namely DBTableLM to handle security in my application, used John’s guidlines to configure embedded oc4j but I couldn’t have jazn properly recognize registered RolePrinciples in the subject to authorize the user.
    The actual problem was with the Frank’s LoginModule and what I did that solved the problem is as follow:
    1. Chenged the order of registering principles, in the original code, it first registers the UserPrinciple and then the RolePrinciple, I just swaped the parts in code (dont ask me why, its near 3 weeks Im working on it)
    2. In DBRolePricipal and DBUserPrincipal class definitions I had them to extend “serializable” interface
    3. had the role names getting out of query results trim’d before instantiating pricipal objects in the code
    That was all, the rest of configuration stuff are all that John and Frank has mentioned.

    anybody need further details may contact me on: mehrdad dot fatemi at gmail dot com

  8. Anonymous says:

    plz give an example for authentication of a Html page’s field value with corresponding schema’s table value.

  9. Anonymous says:

    I followed your steps for embedded server and Standalone server.
    My application is runing good with DBSystemLoginModule on embedded server.
    But it isn’t run on standalone OC4J server.

    I deploied my application using OEM. At step3, I chose customer for Security Provider, and then clicked add “login module” .
    At “add login modelue” I put my DBSystemLoginModule’s class,same as login module class in system-jazn-data.xml on embedded server.
    And then I ran my application.
    I got error.

    In this case unable to find loginModule class.
    Should I do something more for that?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: