- Step-by-Step Tutorial – JDBCRealm (netbeans.org)
- Understanding Web Security (DZone)
Deployment Descriptor Files for JAAS Configuration
To configure JAAS, they are different configuration files, which can to the same. For that, look the graphic below.

Web Application
In a Web Application the web.xml and the sun-web.xml configure the JAAS.
- Login Module configuration (<login-config>)
Which kind of login prompt is used to itenticate the user, i.e. a standard http-Login or a self created formbased page - Authenticate the users (<security-constraint>)
Which user have access to specific web resources - Usage of TLS/SSL encryption of specific pages or subfolders (<user-data-constraint>)
- Define the exists security roles in the Web Application (<security-role>). It is not a mapping, is the same as the annotation @DeclareRoles
Example File:
<xml version="1.0" encoding="UTF-8"> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> <!-- Not Security related properties --> <!-- Define a constraint to restrict access to /private/* --> <security-constraint> <web-resource-collection> <web-resource-name>Secure Pages</web-resource-name> <url-pattern>/faces/pages/secure/*</url-pattern> </web-resource-collection> <user-data-constraint> <!-- Access to this will be TLS/SSL protected --> <transport-guarantee>CONFIDENTIAL</transport-guarantee> </user-data-constraint> </security-constraint> <!-- Login Module to identicate the user --> <login-config> <auth-method>FORM</auth-method> <realm-name>jdbc-realm</realm-name> <form-login-config> <form-login-page>/pages/login.xhtml</form-login-page> <form-error-page>/pages/loginerr.xhtml</form-error-page> </form-login-config> </login-config> <security-role> <role-name>secure</role-name> </security-role> </web-app>
<security-role-mapping> <role-name>admin</role-name> <!-- Name inside the Web Applicatoin --> <group-name>Admins</group-name> <!-- in extern resources --> </security-role-mapping>
EJB-Module
- Role-mapping between physical resource (i.e. DB, ldap) and application roles inside ejb-module, alike above.
- declarativ security configuration
Define, which Enterprise bean should secured by JAAS<enterprise-beans> <ejb> <ejb-name>MyBean</ejb-name> <!-- Bean Name --> <ior-security-config> <as-context> <auth-method>USERNAME_PASSWORD</auth-method> <realm>usrRealm</realm> <!-- if not desired the default one --> <required>true</required> </as-context> </ior-security-config> </ejb> </enterprise-beans>
Enterprise Application
<sun-application> <security-role-mapping> <role-name>user</role-name> <group-name>Users</group-name> </security-role-mapping> <realm>jdbcRealm</realm> </sun-application>
Summary
- For an individually deployed EJB-module, you can set the same element in the sun-ejb-jar.xml as in the sun-application.xml file. If pass-by-reference is used at both the bean and application level, the bean level takes precedence
- Make sure that you have <security-role-mapping> in a sun-*.xml deployment description file
- Specify the realm that is to be used in the follow specified deployment descriptor: sun-application.xml (for EAR) or, web.xml (for WAR) or sun-ejb-jar.xml (for EJB JAR)
- If modules within an application specify realms, these are ignored. If present, the realm defined in sun-application.xml is used, otherwise the domain’s default realm is used.

