How to Secure an EJB in JBoss EAP

SampleBean.java

import javax.annotation.security.RolesAllowed;
import javax.ejb.Stateless;

@RolesAllowed("SampleRole")
@Stateless
public class SampleBean {
}

jboss-ejb3.xml

<?xml version="1.0" encoding="UTF-8"?>
<jboss:ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" xmlns:jboss="http://www.jboss.com/xml/ns/javaee" xmlns:s="urn:security" 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/ejb-jar_3_1.xsd http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-ejb3-2_0.xsd" impl-version="2.0" version="3.1">
  <assembly-descriptor>
    <s:security>
      <ejb-name>SampleBean</ejb-name>
      <s:security-domain>SampleSecurityDomain</s:security-domain> <!-- recommended over the SecurityDomain annotation -->
    </s:security>
  </assembly-descriptor>
</jboss:ejb-jar>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s