How to setup seam3-security in JBoss 7

Recently, I've done some research on several Java Security Framework that can perform authentication, authorization and cryptography.

I've worked with Apache Shiro, it's really good and complete but I've found several problems like there's no default implementation for CDI interceptor for security annotations. Here's a sample implementation and setup that I did long ago:

And long time ago I've used seam2-security and now I'm trying with seam3, here goes.

1.) I started by creating a javaee6 project generated from jboss maven archetype (ear type). This could also be done on a war type project ofcourse (where the ejbs are in ejb project).

2.) In your main project maven's depedencyManagement section add:
This will ensure that we are using the correct seam-jar versions across our projects.

3.) And in the ejb project maven's dependencies section add seam3-security dependency:

4.) In web project, create a beans.xml file in WEB-INF folder. This file is also required for CDI to work. And here we define the interceptor:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="" xmlns:xsi=""
 xmlns:s="urn:java:ee" xmlns:security=""


  <s:modifies />


5.) Then we have to define the interceptor class:

import javax.enterprise.inject.Model;
import javax.inject.Inject;

import org.picketlink.idm.impl.api.PasswordCredential;
import org.picketlink.idm.impl.api.model.SimpleUser;

public class Authenticator extends BaseAuthenticator {
 Credentials credentials;

 public Authenticator() {


 public void authenticate() {
  System.out.println("logging in: " + credentials.getUsername());

  if ("demo".equals(credentials.getUsername())
    && credentials.getCredential() instanceof PasswordCredential
    && "demo".equals(((PasswordCredential) credentials.getCredential()).getValue())) {

   setUser(new SimpleUser("demo"));




6.) To hide a component in the UI you can use identity.hasPermission or identity.hasRole.

7.) You can download the source code from google code at:
How to setup seam3-security in JBoss 7 How to setup seam3-security in JBoss 7 Reviewed by Edward Legaspi on Wednesday, June 12, 2013 Rating: 5

No comments:

Powered by Blogger.