Enterprise Java Development@TOPIC@

Chapter 112. EJB Security

112.1. Declarative EJB Access Control
112.2. Programmatic Security
112.3. Optional Role Mapping: ejb-jar.xml
112.4. EJB Security Setup: META-INF/jboss-ejb3.xml
112.5. Summary


  • Access restrictions can also be defined in the ejb-jar.xml deployment descriptor


  • Permits method to determine when access should be checked


  • Permits more fine-grain access control down to the object level

  • Caller is not only required to have "admin" role -- they must be admin of specific resource


    <enterprise-beans>
        <session>
            <ejb-name>SecurePingEJB</ejb-name>
            <security-role-ref>
                <description>role-name checked within EJB</description>
                <role-name>internalRole</role-name>
                <role-link>admin</role-link>
            </security-role-ref>
        </session>
    </enterprise-beans>    
    <assembly-descriptor>
        <security-role>
            <role-name>admin</role-name>
        </security-role>
        <security-role>
            <role-name>user</role-name>
        </security-role>
    </assembly-descriptor>

<?xml version="1.0"?>  
<jboss:ejb-jar 
   xmlns:jboss="http://www.jboss.com/xml/ns/javaee"
   xmlns:sec="urn:security" 
   xmlns="http://java.sun.com/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-ejb3-2_0.xsd
      http://java.sun.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-ejb3-spec-2_0.xsd
      urn:security urn:security"
   version="3.1"
   impl-version="2.0">
    <assembly-descriptor>
        <sec:security>
            <ejb-name>*</ejb-name>
            <sec:security-domain>other</sec:security-domain>
            <sec:run-as-principal/>
        </sec:security>
    </assembly-descriptor>    
</jboss:ejb-jar>