Develop Custom Realm in NetBeans

I will write simple custom realm for Sun Application server in NetBeans. This realm will be used for authentication of users. I will implement very simple realm that will check password that are stored in Hashtable. I guess, extending this realm for using JDBC or other technology is easy task.
Implementation involves the following three steps:
  • Implement a JAAS LoginModule
  • Implement a Realm class
  • Configure the Realm and LoginModule into the server
The realm will be developed in NetBeans IDE. Final SimpleRealm project is avalaible here.Create new J2SE project and follow these steps:
  • Add appserv-rt.jar on project's classpath. This jar is located under lib directory in you App server.
  • First, create new class SimpleLoginModule in simplerealm package. This class must extend PasswordLoginModule. In this class we should implement authenticate() method that performs actual authentication. Our implementation calls method in Realm Class that did authentication itself. See attached sources for more info.
  • Create new class SimpleRealm in package simplerealm. The realm class is used to hook the custom realm into the Application Server. In this class the properties from domain.xml are read and authentication is performed.
  • Build project. In next steps we should register new realm in Application server.
  • I created targets that allow to register and delete realm in Application server. These tasks are in realm-targets.xml file in mentioned sources. Download sources and copy this file in project directory. You should copy login.conf, adminpw.txt and build.properties too in same directory. These files are needed for realm's targets.
  • Import realm targets in build.xml file. Open this file and add these lines in the file:
          <!DOCTYPE project [<!ENTITY RealmTargets SYSTEM "realm-targets.xml">]>
          .......
          &RealmTargets;
        
  • Run create-realm target. The target copies realm jar in App server directory and register realm
  • Logg in web console and go to Application server -- JVM Settings -- Path Settings and this ${com.sun.aas.installRoot}/domains/domain1/lib/SimpleRealm.jar in suffix classpath text field. Save and restart server.
  • Now, you can change realm config in your application and test new Simple realm. How you can change realm for web application? Very simple, open web.xml file and change realm-name value in SimpleRealm.
What's about debugging realm in NetBeans?
Start Application server in debug mode and put breakpoint in Realm class and attach debugger to port 9009. Then, you can login in your application and then debugg realm. ~
Comments:

It would also nice to have a JACC realm tutorial.

Posted by Heiko Wagner on December 16, 2005 at 02:53 AM CET #

Will you plz send me the information of Realms for javaee5 which stores user credential in database

Posted by Geetanjalee Paygude on March 22, 2006 at 12:10 AM CET #

jnjknjnn

Posted by oo on May 31, 2006 at 11:17 AM CEST #

Test Mail

Posted by Test on December 20, 2006 at 12:38 AM CET #

I performed step by step all in this tutorial. But when I put's jar file in domains/domain1/lib directory and correct's classpath suffix of JVM's classpath settings, app serv (Sun Java System Application Server 9.1 (build b58g-fcs)) can't find MyJDBCRealm class. Could you pleas prompt me what the reason of this problem.

Posted by Alex on October 15, 2007 at 12:50 AM CEST #

ety

Posted by guest on October 30, 2007 at 12:36 AM CET #

Post a Comment:
  • HTML Syntax: NOT allowed
About

pblaha

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today
Bookmarks