[jbossseam-issues] [JBoss JIRA] Created: (JBSEAM-1318) Seam 1.2.1.GA Integration Testing of #{identity.login}; NullPointerException in SeamLoginModule.java:104

Maarten Haubrich (JIRA) jira-events at lists.jboss.org
Thu May 10 12:49:52 EDT 2007


Seam 1.2.1.GA Integration Testing of #{identity.login}; NullPointerException in SeamLoginModule.java:104
--------------------------------------------------------------------------------------------------------

                 Key: JBSEAM-1318
                 URL: http://jira.jboss.com/jira/browse/JBSEAM-1318
             Project: JBoss Seam
          Issue Type: Bug
          Components: Security
    Affects Versions: 1.2.1.GA
         Environment: Windows XP SP2, JRE 1.5.0_10, JBoss 4.0.5.GA
            Reporter: Maarten Haubrich


I am having problems with the integration testing of the login process with the 1.2.1.GA version.
Upon invoking #{identity.login} I get a NullPointerException in the SeamLoginModule.
I suspect the test environment does not load the authenticate-method from the components.xml ...


Here is the JSF view

[CODE]
<h:form>
		
		<table cellspacing="2" cellpadding="2" border="0" >
		<tr>
			<td>#{messages['login.login']}:</td><td><h:inputText value="#{identity.username}" id="login" /></td>
		</tr>
		<tr>
			<td>#{messages['login.pwd']}:</td><td><h:inputSecret value="#{identity.password}" id="password"  /></td>
		</tr>
		<tr>
			<td colspan="2" align="right"><h:commandButton value="#{messages['login.button']}" action="#{identity.login}"  /></td>
		</tr>
		</table>
	</h:form>	
[/CODE]

I added this to components.xml :

[CODE]
<security:identity authenticate-method="#{authenticator.authenticate}"/>
[/CODE]



My AuthenticatorAction class looks like so:

[CODE]
@Name("authenticator")
public class AuthenticatorAction implements Serializable 
{
	private static final long serialVersionUID = 4836686434984261542L;

	private static final String USER_VAR = "currentUser";

	@In 
	private Context sessionContext;

	@Logger
	private Log log;
	
	
	/**
	 * validate the username and password
	 */
	public boolean authenticate() 
	{

		User user = ServiceLocator.instance()										// find user in database
						.getLoginService()
							.authenticate(Identity.instance().getUsername(), Identity.instance().getPassword());
		if(user==null)
		{		
			log.debug("invalid login!");				
			return false;
		}
		
		Identity.instance().addRole("user");
		
		if(user.isAdmin())															// add admin role if the user is an admin
			Identity.instance().addRole("admin");

		sessionContext.set(USER_VAR, user);											// save in session context

		log.debug("login successful: #0", user);	
		
		return true;
	}
	
	
}	
[/CODE]


My SeamTest class is as follows:

[CODE]
public class AuthenticatorActionTest extends SeamTest {
	

	@Test
	public void testAuthenticate() throws Exception 
	{
		
		new FacesRequest() 
		{

			@Override
			protected void updateModelValues() throws Exception 
			{
				setValue("#{identity.username}", "test");											// inject the login values
				setValue("#{identity.password}", "test");	
			}
   
			@Override
			protected void invokeApplication() 
			{
				invokeMethod("#{identity.login}");
			}
   
			@Override
			protected void renderResponse() 
			{
				assertTrue("identity.loggedIn", getValue("#{identity.loggedIn}").equals(true));		// TEST FAILS HERE !
			}
		   
		}.run();
	
	
	}
}	
[/CODE]

When running the test I get the following error message:

[CODE]
ERROR 2007-05-08 11:59:49,578  org.jboss.seam.security.jaas.SeamLoginModule -- Error invoking login 
method 
java.lang.NullPointerException
	at org.jboss.seam.security.jaas.SeamLoginModule.login(SeamLoginModule.java:104)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at javax.security.auth.login.LoginContext.invoke(Unknown Source)
	at javax.security.auth.login.LoginContext.access$000(Unknown Source)
	at javax.security.auth.login.LoginContext$5.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at javax.security.auth.login.LoginContext.invokeCreatorPriv(Unknown Source)
	at javax.security.auth.login.LoginContext.login(Unknown Source)
	at org.jboss.seam.security.Identity.authenticate(Identity.java:247)
	at org.jboss.seam.security.Identity.authenticate(Identity.java:240)
	at org.jboss.seam.security.Identity.login(Identity.java:170)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at com.sun.el.parser.AstValue.invoke(AstValue.java:174)
	at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:286)
	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.booknolia.AuthenticatorTest$1.invokeApplication(AuthenticatorTest.java:48)
	at org.jboss.seam.mock.SeamTest$Request.run(SeamTest.java:489)
	at com.booknolia.AuthenticatorTest.testAuthenticate(AuthenticatorTest.java:66)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:645)
	at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:479)
	at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:715)
	at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
	at org.testng.TestRunner.runWorkers(TestRunner.java:673)
	at org.testng.TestRunner.privateRun(TestRunner.java:620)
	at org.testng.TestRunner.run(TestRunner.java:480)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:278)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:273)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:253)
	at org.testng.SuiteRunner.run(SuiteRunner.java:168)
	at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:987)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:951)
	at org.testng.TestNG.run(TestNG.java:719)
	at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:73)
	at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:122)	
[/CODE]


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the seam-issues mailing list