If we want to do a Database login for JavaEE6 application, We need to configure the DatabaseServerLoginModule of Jboss by creating a Realm. Put following lines in standalone.xml ( or domain.xml) :
Now the realm is configured into server, We need to tell our application to use this realm. This can be achieved using web.xml
Next we need to declare the security roles in the application. We have declared 4 roles SuperAdmin, Admin, Manager and Employee from lines 9 to 20.
Now we have configured the application we will add security constraint in web.xml to our application as below.
Replace values with your respected values. If you are using custom database module class replace code="Database" with code="<your class name>"
From lines 1 to 8 we inform the application to make use of FORM method to authenticate users with Realm MyRealm and also provide the login and error pages.FORM MyRealm /login.jsp /loginerror.jsp SuperAdmin Admin Manager Employee
Next we need to declare the security roles in the application. We have declared 4 roles SuperAdmin, Admin, Manager and Employee from lines 9 to 20.
Now we have configured the application we will add security constraint in web.xml to our application as below.
We added two security constraints. First is to allow only SuperAdmin and Admin to enter the admin panel. Another example is when you have protected entire site but want to allow access to resources to all.MyApplication /administration/* GET POST SuperAdmin Admin Unprotected area /resources/*