[jboss-user] [JBoss Seam] - SeamLoginModule Error invoking login method

mrobinson28 do-not-reply at jboss.com
Thu Apr 12 16:45:34 EDT 2007


I am attempting to write (mostly copy from example s ;)  an integration test for a simple login process. I am using Seam 1.2.1.GA, EEJB, hsqldb, etc. The only difference that I can see from the examples is that I am building w/ Maven2...hopefully this is not the  issue :(  When I execute the test I received the following exception: 


  | 16:21:24,384 - ERROR [SeamLoginModule] Error invoking login method
  | org.jboss.seam.InstantiationException: Could not instantiate Seam component: authenticator
  |         at org.jboss.seam.Component.newInstance(Component.java:1708)
  |         at org.jboss.seam.Component.getInstance(Component.java:1611)
  |         at org.jboss.seam.Component.getInstance(Component.java:1578)
  |         at org.jboss.seam.Component.getInstance(Component.java:1572)
  |         at org.jboss.seam.jsf.SeamELResolver.getValue(SeamELResolver.java:49)
  |         at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:135)
  |         at com.sun.el.parser.AstIdentifier.getValue(AstIdentifier.java:65)
  |         at com.sun.el.parser.AstValue.getTarget(AstValue.java:62)
  |         at com.sun.el.parser.AstValue.invoke(AstValue.java:147)
  |         at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:283)
  |         at org.jboss.seam.util.UnifiedELMethodBinding.invoke(UnifiedELMethodBinding.java:36)
  |         at org.jboss.seam.actionparam.ActionParamBindingHelper.invokeTheExpression(ActionParamBindingHelper.java:58)
  |         at org.jboss.seam.actionparam.ActionParamMethodBinding.invoke(ActionParamMethodBinding.java:75)
  |         at org.jboss.seam.core.Expressions$2.invoke(Expressions.java:106)
  |         at org.jboss.seam.security.jaas.SeamLoginModule.login(SeamLoginModule.java:104)
  |         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  |         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  |         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  |         at java.lang.reflect.Method.invoke(Method.java:597)
  |         at javax.security.auth.login.LoginContext.invoke(LoginContext.java:769)
  |         at javax.security.auth.login.LoginContext.access$000(LoginContext.java:186)
  |         at javax.security.auth.login.LoginContext$5.run(LoginContext.java:706)
  |         at java.security.AccessController.doPrivileged(Native Method)
  |         at javax.security.auth.login.LoginContext.invokeCreatorPriv(LoginContext.java:703)
  |         at javax.security.auth.login.LoginContext.login(LoginContext.java:575)
  |         at org.jboss.seam.security.Identity.authenticate(Identity.java:249)
  |         at org.jboss.seam.security.Identity.authenticate(Identity.java:242)
  |         at org.jboss.seam.security.Identity.login(Identity.java:172)
  |         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  |         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  |         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  |         at java.lang.reflect.Method.invoke(Method.java:597)
  |         at com.sun.el.parser.AstValue.invoke(AstValue.java:151)
  |         at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:283)
  |         at org.jboss.seam.util.UnifiedELMethodBinding.invoke(UnifiedELMethodBinding.java:36)
  |         at org.jboss.seam.actionparam.ActionParamBindingHelper.invokeTheExpression(ActionParamBindingHelper.java:58)
  |         at org.jboss.seam.actionparam.ActionParamMethodBinding.invoke(ActionParamMethodBinding.java:75)
  |         at org.jboss.seam.actionparam.ActionParamBindingHelper.invokeTheExpression(ActionParamBindingHelper.java:58)
  |         at org.jboss.seam.actionparam.ActionParamMethodBinding.invoke(ActionParamMethodBinding.java:75)
  |         at org.jboss.seam.mock.SeamTest$Request.invokeMethod(SeamTest.java:401)
  |         at com.onlineinsight.service.system.security.AuthenticatorTest$1.invokeApplication(AuthenticatorTest.java:25)
  |         at org.jboss.seam.mock.SeamTest$Request.run(SeamTest.java:489)
  |         at com.onlineinsight.service.system.security.AuthenticatorTest.testLogin(AuthenticatorTest.java:12)
  |         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  |         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  |         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  |         at java.lang.reflect.Method.invoke(Method.java:597)
  |         at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:552)
  |         at org.testng.internal.Invoker.invokeMethod(Invoker.java:411)
  |         at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:785)
  |         at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:114)
  |         at org.testng.TestRunner.privateRun(TestRunner.java:693)
  |         at org.testng.TestRunner.run(TestRunner.java:574)
  |         at org.testng.SuiteRunner.privateRun(SuiteRunner.java:241)
  |         at org.testng.SuiteRunner.run(SuiteRunner.java:145)
  |         at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:901)
  |         at org.testng.TestNG.runSuitesLocally(TestNG.java:863)
  |         at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeTestNG(TestNGDirectoryTestSuite.java:195)
  |         at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:111)
  |         at org.apache.maven.surefire.Surefire.run(Surefire.java:84)
  |         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  |         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  |         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  |         at java.lang.reflect.Method.invoke(Method.java:597)
  |         at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:244)
  |         at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:814)
  | Caused by: javax.naming.NameNotFoundException: AuthenticatorAction not bound
  |         at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
  |         at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
  |         at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
  |         at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
  |         at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:626)
  |         at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:588)
  |         at javax.naming.InitialContext.lookup(InitialContext.java:392)
  |         at org.jboss.seam.Component.instantiateSessionBean(Component.java:1075)
  |         at org.jboss.seam.Component.instantiate(Component.java:1061)
  |         at org.jboss.seam.Component.newInstance(Component.java:1704)
  |         ... 65 more
  | 

My login method looks like: 

 
  | import static org.jboss.seam.ScopeType.SESSION;
  | 
  | import javax.ejb.Stateless;
  | import javax.persistence.EntityManager;
  | import javax.persistence.NoResultException;
  | import javax.persistence.PersistenceContext;
  | import javax.persistence.Query;
  | 
  | import org.apache.commons.codec.digest.DigestUtils;
  | import org.jboss.seam.annotations.In;
  | import org.jboss.seam.annotations.Name;
  | import org.jboss.seam.annotations.Out;
  | import org.jboss.seam.security.Identity;
  | 
  | @Stateless
  | @Name("authenticator")
  | public class AuthenticatorAction implements Authenticator {
  | 
  |     @PersistenceContext
  |     private EntityManager entityManager;
  | 
  |     // user attempting to login
  |     @Out(required = false, scope = SESSION)
  |     private User currentUser;
  | 
  |     // built in seam security component
  |     @In(required = false)
  |     private Identity identity;
  | 
  |     /**
  |      * Authenticate the user
  |      * 
  |      * @return boolean true if the user is authenticated, false otherwise
  |      */
  |     public boolean authenticate() {
  |         try {
  |             // query by username
  |             Query query = this.entityManager.createQuery("select u from User u where u.username= :username").setParameter("username", identity.getUsername());
  |             User user = (User) query.getSingleResult();
  | 
  |             // compare the passwords
  |             if (!this.compareHash(user.getHashedPassword(), this.identity.getPassword())) {
  |                 return false;
  |             }
  | 
  |             this.currentUser = user;
  | 
  |             // populate built in security object with user roles
  |             for (UserRole userRoles : this.currentUser.getRoles()) {
  |                 this.identity.addRole(userRoles.getName());
  |             }
  | 
  |             return true;
  |         } catch (NoResultException ex) {
  |             return false;
  |         }
  |     }
  | 
  |     /**
  |      * Compares a hash with a string value
  |      * 
  |      * @param hash the hase value
  |      * @param password the string value
  |      * @return true if the value of the string hased equals the orignal hash value
  |      */
  |     private boolean compareHash(String hash, String password) {
  |         if (hash == null || password == null) {
  |             return false;
  |         }
  | 
  |         // compute the hash of the sting value
  |         String newHash = DigestUtils.md5Hex(password); 
  |         if (newHash == null) {
  |             return false;
  |         }
  |         
  |         // compare
  |         return hash.equalsIgnoreCase(newHash);
  |     }
  | 
  | }
  |  

My components.xml is: 


  | <?xml version="1.0" encoding="UTF-8"?>
  | <components xmlns="http://jboss.com/products/seam/components"
  |             xmlns:core="http://jboss.com/products/seam/core"
  |             xmlns:security="http://jboss.com/products/seam/security"
  |             xmlns:theme="http://jboss.com/products/seam/theme"
  |             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  |             xsi:schemaLocation=
  |                 "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-1.2.xsd 
  |                  http://jboss.com/products/seam/components http://jboss.com/products/seam/components-1.2.xsd
  |                  http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-1.2.xsd
  |                  http://jboss.com/products/seam/security http://jboss.com/products/seam/security-1.2.xsd">                
  | 	
  |     <core:init jndi-pattern="@jndiPattern@" my-faces-lifecycle-bug="true" debug="true"/>
  |      
  | 
  |   	<core:ejb installed="@embeddedEjb@"/>
  |    
  |     <core:manager conversation-timeout="120000" 
  |                   concurrent-request-timeout="500"
  |                   conversation-id-parameter="cid"
  |                   conversation-is-long-running-parameter="clr"/>
  |                   
  |     <core:entity-manager-factory name="test-persistence-unit"/>
  |     
  |     <core:managed-persistence-context name="ems" 
  |                                auto-create="true" 
  |                     entity-manager-factory="#{test-persistence-unit}"/>
  |                     
  | 	<!--  seam event listener -->         
  | 	<core:transactionListener/>
  | 	                     
  | 	<!--  seam security for authentication -->	                   
  | 	<security:identity authenticate-method="#{authenticator.authenticate}"/>
  | 	
  | 	<!--  delcare themes below -->
  | 	<theme:theme-selector cookie-enabled="true">
  | 	    <theme:available-themes>
  | 	        <value>default</value>
  | 	    </theme:available-themes>
  |     </theme:theme-selector>
  |     
  |     <!-- redirect to the originally requested view   -->
  |     <event type="org.jboss.seam.notLoggedIn">
  |     	<action expression="#{redirect.captureCurrentView}"/>
  | 	</event>
  |     <event type="org.jboss.seam.postAuthenticate">
  | 	    <action expression="#{redirect.returnToCapturedView}"/>
  | 	</event>
  | </components>
  |  

And finally my stripped down integration test (i can't get past the first invokeMethod): 


  | import org.jboss.seam.mock.SeamTest;
  | import org.testng.annotations.Test;
  | 
  | public class AuthenticatorTest extends SeamTest {
  | 
  |    
  |     @Test(groups = "integration")
  |     public void testLogin() throws Exception {
  | 
  |         new FacesRequest() {
  | 
  |             @Override
  |             protected void updateModelValues() throws Exception
  |             {
  |                assert !isSessionInvalid();
  |                setValue("#{identity.username}", "test");
  |                setValue("#{identity.password}", "test");
  |             }
  | 
  |             @Override
  |             protected void invokeApplication()
  |             {
  |                assert (Boolean) invokeMethod("#{identity.login}");
  |             }
  | 
  |         }.run();
  |     }
  |   }
  |   

I didn't include the complete stack trace b/c it is quite long... but I can if it would help! 

Thanks, 

Michael

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4036860#4036860

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4036860



More information about the jboss-user mailing list