Search code examples
jboss7.xseam3

Seam 3 Security not working on JBoss7 custom authenticator class not found


I've been trying seam3 security in Jboss7.1.3 with an ear project generated with maven archetype (javaee6-jboss-ear) but I can't get around the error wherein my custom class cannot be loaded.

Caused by: java.lang.ClassNotFoundException: com.czetsuya.javaee6.security.Authenticator from [Module "deployment.javaee6-demo.ear.javaee6-demo-ejb-0.0.1-SNAPSHOT.jar:main" from Service Module Loader]

My project is structured as: myProject -ear -jar (where beans.xml and authenticator is defined) -war

My Authenticator class: package com.czetsuya.javaee6.security;

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

import org.jboss.seam.security.BaseAuthenticator; import org.jboss.seam.security.Credentials; import org.picketlink.idm.impl.api.PasswordCredential; import org.picketlink.idm.impl.api.model.SimpleUser;

@Model
public class Authenticator extends BaseAuthenticator {
    @Inject
    Credentials credentials;

    public Authenticator() { }

    @Override
    public void authenticate() {
        if ("demo".equals(credentials.getUsername())
                && credentials.getCredential() instanceof PasswordCredential
                && "demo".equals(((PasswordCredential) credentials.getCredential()).getValue())) {    
            setStatus(AuthenticationStatus.SUCCESS);
            setUser(new SimpleUser("demo"));    
        }    
    }    
}

My beans.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:s="urn:java:ee" xmlns:security="urn:java:org.jboss.seam.security"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://jboss.org/schema/cdi/beans_1_0.xsd">

    <interceptors>
        <class>org.jboss.seam.security.SecurityInterceptor</class>
    </interceptors>

    <security:IdentityImpl>
        <s:modifies />
        <security:authenticatorClass>com.czetsuya.javaee6.security.Authenticator
        </security:authenticatorClass>
    </security:IdentityImpl>

</beans>

In myProject, I have defined seam-bom:

<dependency>
    <groupId>org.jboss.seam</groupId>
    <artifactId>seam-bom</artifactId>
    <version>3.1.0.Final</version>
    <scope>import</scope>
    <type>pom</type>
</dependency>

In ejb/pom.xml, I've defined seam-security:

<dependency>
    <groupId>org.jboss.seam.security</groupId>
    <artifactId>seam-security</artifactId>
    <scope>provided</scope>
</dependency>

Scope is provided, otherwise I'll get compilation issues: missing classes.

The weird thing is, the same setup works when I deploy the war project, any idea? I just put the war inside the ear :-)

I am also doing the same with an ear generated from maven archetype with minimal changes, I just add the Authenticator and seam-security dependency. The big difference to the project I'm having error is I replaced most of the jboss jars with javaee-api because it's the standard. And I thought JBoss is standard :-), seems like there's some magic happening again with its own jars.

*The working pure jboss project is uploaded here: https://code.google.com/p/czetsuya/source/browse/#svn%2Ftrunk%2Fjboss7-seam3-security


Solution

  • What worked for me is excluding the seam-security jar in the war pom.xml, something like:

    <dependency>
        <groupId>com.czetsuya</groupId>
        <artifactId>javaee7-ejb</artifactId>
        <type>ejb</type>
        <scope>provided</scope>
        <exclusions>
            <exclusion>
                <artifactId>seam-security</artifactId>
                <groupId>org.jboss.seam.security</groupId>
            </exclusion>
        </exclusions>
    </dependency>