<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Seam3 on despatches</title><link>https://icle.es/tags/seam3/</link><description>Recent content in Seam3 on despatches</description><generator>Hugo</generator><language>en</language><lastBuildDate>Fri, 20 Jun 2025 08:42:17 +0100</lastBuildDate><atom:link href="https://icle.es/tags/seam3/index.xml" rel="self" type="application/rss+xml"/><item><title>Getting started on seam-security, picketlink IDM and JPAIdentityStore</title><link>https://icle.es/2012/10/17/getting-started-on-seam-security-picketlink-idm-and-jpaidentitystore/</link><pubDate>Wed, 17 Oct 2012 10:40:28 +0000</pubDate><guid>https://icle.es/2012/10/17/getting-started-on-seam-security-picketlink-idm-and-jpaidentitystore/</guid><description>&lt;p>I love how JBoss 7(.1) has everything working out of the box - not much fiddling
with jars or suchlike and with Arquillian, everything really was a treat to get
started on a new project. This was until I had to sort out security with
seam-security.&lt;/p>
&lt;p>To be fair, the main issue was just poor documentation. It took me a day to sort
out what should essentially have taken an hour(or two)&lt;/p>
&lt;p>The documentation you get to from
&lt;a href="http://www.seamframework.org/Seam3/SecurityModule">http://www.seamframework.org/Seam3/SecurityModule&lt;/a> seems to be out of date. The
fact that the page referes to version 3.0.0.Alpha1 and Alpha2 should have tipped
me off but the url for the doc suggested it was the latest.&lt;/p>
&lt;p>The more up to date documentation I found was
at http://docs.jboss.org/seam/3/3.1.0.Final/reference/en-US/html/pt04.html&lt;/p>
&lt;p>I followed
&lt;a href="http://docs.jboss.org/seam/3/3.1.0.Final/reference/en-US/html/security-identitymanagement.html" title="Identity Management">chapter 33&lt;/a>
on there and I won't repeat it here for the sake of brevity.&lt;/p>
&lt;p>What follows are the additional steps I had to take to get it to work.&lt;/p></description><content:encoded><![CDATA[<p>I love how JBoss 7(.1) has everything working out of the box - not much fiddling
with jars or suchlike and with Arquillian, everything really was a treat to get
started on a new project. This was until I had to sort out security with
seam-security.</p>
<p>To be fair, the main issue was just poor documentation. It took me a day to sort
out what should essentially have taken an hour(or two)</p>
<p>The documentation you get to from
<a href="http://www.seamframework.org/Seam3/SecurityModule">http://www.seamframework.org/Seam3/SecurityModule</a> seems to be out of date. The
fact that the page referes to version 3.0.0.Alpha1 and Alpha2 should have tipped
me off but the url for the doc suggested it was the latest.</p>
<p>The more up to date documentation I found was
at http://docs.jboss.org/seam/3/3.1.0.Final/reference/en-US/html/pt04.html</p>
<p>I followed
<a href="http://docs.jboss.org/seam/3/3.1.0.Final/reference/en-US/html/security-identitymanagement.html" title="Identity Management">chapter 33</a>
on there and I won't repeat it here for the sake of brevity.</p>
<p>What follows are the additional steps I had to take to get it to work.</p>
<p>I ran into a javax.enterprise.inject.CreationException, the relevant part of the
stack trace being:</p>
```
    Caused by: java.lang.IllegalArgumentException: targetClass parameter may not be null
        at org.jboss.solder.properties.query.PropertyQuery.(PropertyQuery.java:54) [solder-impl-3.1.0.Final.jar:3.1.0.Final]
        at org.jboss.solder.properties.query.PropertyQueries.createQuery(PropertyQueries.java:39) [solder-impl-3.1.0.Final.jar:3.1.0.Final]
        at org.jboss.seam.security.management.picketlink.JpaIdentityStore.findNamedProperty(JpaIdentityStore.java:441) [seam-security-3.1.0.Final.jar:3.1.0.Final]
        at org.jboss.seam.security.management.picketlink.JpaIdentityStore.configureRoleTypeName(JpaIdentityStore.java:877) [seam-security-3.1.0.Final.jar:3.1.0.Final]
        at org.jboss.seam.security.management.picketlink.JpaIdentityStore.bootstrap(JpaIdentityStore.java:328) [seam-security-3.1.0.Final.jar:3.1.0.Final]
        at org.picketlink.idm.impl.configuration.IdentityConfigurationImpl.createRealmMap(IdentityConfigurationImpl.java:192) [picketlink-idm-core-1.5.0.Alpha02.jar:1.5.0.Alpha02]
        at org.picketlink.idm.impl.configuration.IdentityConfigurationImpl.buildIdentitySessionFactory(IdentityConfigurationImpl.java:147) [picketlink-idm-core-1.5.0.Alpha02.jar:1.5.0.Alpha02]
        ... 109 more
```
<p>To resolve this,  I had to add in the @IdentityEntity Annotation to the
IdentityObjectType class</p>
```java
    @Entity
    @IdentityEntity(EntityType.IDENTITY_ROLE_NAME)
    public class IdentityObjectType {
    ...
```
<p>The next exception was org.picketlink.idm.common.exception.IdentityException:
Error creating identity object. The relevant part of the strack trace being:</p>
```
    Caused by: java.lang.NullPointerException
        at org.jboss.seam.security.management.picketlink.JpaIdentityStore.lookupIdentityType(JpaIdentityStore.java:966) [seam-security-3.1.0.Final.jar:3.1.0.Final]
        at org.jboss.seam.security.management.picketlink.JpaIdentityStore.createIdentityObject(JpaIdentityStore.java:999) [seam-security-3.1.0.Final.jar:3.1.0.Final]
        ... 87 more
```
<p>It turned out that the entitymanager was not being picked up and it was null.
This part was probably in the documentation earlier with regards to configuring
seam but I had skipped directly to the security section so missed it. We need to
define the persistence unit with the beans.xml. I have included my full file
below.</p>
```xml
    <?xml version="1.0"?>
    <beans xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:em="urn:java:javax.persistence"
        xmlns:s="urn:java:ee"
        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>

        <em:EntityManager>
            <s:Produces />
            <em:PersistenceContext unitName="invision-users" />
        </em:EntityManager>
    </beans>
```
<p>This brought us further forward still. The next exception was:</p>
```
    javax.persistence.NoResultException: No entity found for query
        at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:286) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
        at org.hibernate.ejb.criteria.CriteriaQueryCompiler$3.getSingleResult(CriteriaQueryCompiler.java:264) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
        at org.jboss.seam.security.management.picketlink.JpaIdentityStore.lookupCredentialTypeEntity(JpaIdentityStore.java:1112) [seam-security-3.1.0.Final.jar:3.1.0.Final]
        at org.jboss.seam.security.management.picketlink.JpaIdentityStore.updateCredential(JpaIdentityStore.java:1633) [seam-security-3.1.0.Final.jar:3.1.0.Final]
        at org.picketlink.idm.impl.repository.WrapperIdentityStoreRepository.updateCredential(WrapperIdentityStoreRepository.java:310) [picketlink-idm-core-1.5.0.Alpha02.jar:1.5.0.Alpha02]
        at org.picketlink.idm.impl.api.session.managers.AttributesManagerImpl.updatePassword(AttributesManagerImpl.java:563) [picketlink-idm-core-1.5.0.Alpha02.jar:1.5.0.Alpha02]
```
<p>This was related to missing data in the database. It needed a credential type. I
created one for password.</p>
```sql
    INSERT INTO CredentialType(id, name) VALUES (1, 'password');
```
<p>This brought us forward on to the next exception:
org.picketlink.idm.common.exception.IdentityException: Exception creating
relationship</p>
<p>with the relevant part of</p>
```
    Caused by: javax.persistence.NoResultException: No entity found for query
        at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:286) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
        at org.hibernate.ejb.criteria.CriteriaQueryCompiler$3.getSingleResult(CriteriaQueryCompiler.java:264) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
        at org.jboss.seam.security.management.picketlink.JpaIdentityStore.lookupRelationshipType(JpaIdentityStore.java:1127) [seam-security-3.1.0.Final.jar:3.1.0.Final]
        at org.jboss.seam.security.management.picketlink.JpaIdentityStore.createRelationship(JpaIdentityStore.java:1066) [seam-security-3.1.0.Final.jar:3.1.0.Final]
        ... 86 more
```
<p>This was solved by adding in a relationship type</p>
```sql
    INSERT INTO RelationshipType(id, name) VALUES (1, 'JBOSS_IDENTITY_MEMBERSHIP');
```
<p>Both the sql statements were put into import.sql and hibernate is configured to
create tables. My test case is as follows. It was taken
from <a href="https://github.com/seam/seam-example-confbuzz/blob/develop/src/test/java/seam/example/confbuzz/test/integration/LoginIntegrationTest.java">https://github.com/seam/seam-example-confbuzz/blob/develop/src/test/java/seam/example/confbuzz/test/integration/LoginIntegrationTest.java</a> and
modified.</p>
```java
    @RunWith(Arquillian.class)
    public class LoginIntegrationTest {

        @Inject
        private IdentitySession identitySession;

        @Inject
        private Identity identity;

        @Inject
        @DefaultTransaction
        SeamTransaction tx;

        @Deployment(name = "authentication")
        public static Archive createLoginDeployment() {
            // This is the simplest way to test the full archive as you will be
            // deploying it
            final MavenDependencyResolver resolver =
                    DependencyResolvers.use(MavenDependencyResolver.class)
                        .loadMetadataFromPom("pom.xml")
                        .goOffline();

            Archive archive = ShrinkWrap
                    .create(WebArchive.class)
                    .addPackages(true, "uk.co.kraya.test-seam.auth")
                    .addAsResource("META-INF/test-persistence.xml", "META-INF/persistence.xml")
                    .addAsResource("META-INF/beans.xml", "META-INF/beans.xml")
                    .addAsResource("test-import.sql", "import.sql")
                    .addAsLibraries(resolver.artifact("org.jboss.seam.security:seam-security").resolveAsFiles());

            System.out.println(archive.toString(true));

            return archive;

        }

        @Before
        public void setupTestUser() throws IdentityException, SystemException,
                NotSupportedException, RollbackException,
                HeuristicRollbackException, HeuristicMixedException {

            if (!tx.isActive())
                tx.begin();

            final PersistenceManager pm = identitySession.getPersistenceManager();
            final AttributesManager am = identitySession.getAttributesManager();
            final RelationshipManager rm = identitySession.getRelationshipManager();

            // Setup the group we want our user to belong to
            final Group memberGroup = pm.createGroup("member2", "USER2");
            final User user = pm.createUser("test");

            am.updatePassword(user, "password");

            rm.associateUser(memberGroup, user);

            tx.commit();
        }

        @Test
        public void assertUserCanAuthenticate(Credentials credentials) {
            credentials.setUsername("test");
            credentials.setCredential(new PasswordCredential("password"));
            assertEquals(identity.login(), Identity.RESPONSE_LOGIN_SUCCESS);
        }
```
<p>Do comment and let me know if it helped :-D</p>]]></content:encoded></item></channel></rss>