MongoDB Realm authenticate Glassfish 4.0
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

MongoDB Realm authenticate Glassfish 4.0

Why ?

Because there is no maven module for this !

Based on work of Martijn Blankestijn.


Step 1 : Install the JAR in Glassfish

1/ Download here.

2/ Copy in <your_glassfish_domain>/lib

Step 2 : Install dependencies

1/ Dowload latest Apache Commons Codec

2/ Copy the JAR in <your_glassfish_domain>/lib

3/ Dowload latest Mongo Java Driver

4/ Copy the JAR in <your_glassfish_domain>/lib

Step 3 : Configure Glassfish offline

1/ Shutdown Glassfish

2/ Edit <your_glassfish_domain>/config/login.conf and add :

mongoDbRealm {
        com.vaushell.gfmongodb.MongoDbLoginModule required;

Step 4 : Configure Glassfish online

1/ Start Glassfish and open Admin Console

2/ In Configurations>server-config>Security>Realms, create a new Realm (click on 'New...') :

  • Name : mongo-realm
  • Class Name : com.vaushell.gfmongodb.MongoDbUserRealm

3/ Add Additional Properties :

  • jaas-context: mongoDbRealm
  • database-name: <your mongo db. default: mongo>
  • database-collection: <your mongo collection. default: users>
  • field-username: <field for the username in the collection. default: email>
  • field-password: <field for the password in the collection. default: password>
  • field-admin: <field for the admin boolean. Is the user an admin ? default: admin>
  • group-users: <authenticated users will always be in this group. default: g_users>
  • group-admins: <authenticated admins will always be in this group. default: g_admins>

Step 5 : Create your first user

1/ With JAVA, use common-codec library and DigestUtils.sha256Hex function

2/ Insert user in mongo :

  email: "", 
  admin: true

What is the product license?

Look at LICENCE.txt

Copyright (C) 2014 - Fabien VAUCHELLES - fabien AT vauchelles DOT com