[jboss-user] [JBoss Seam] - Re: Double authentication in different parts of a site

p.chevillon do-not-reply at jboss.com
Mon Sep 17 10:12:03 EDT 2007


Hello,

I have a other problem with my authentication. My  idea was to extend RuleBasedIdentity  and so create ECIdentity  class.

Here is my program:


component.xml
<security:identity 
  |    		class="ecidentity"
  |    		authenticate-method="#{authenticator.authenticate}"
  |    		security-rules="#{securityRules}"/>
  | 

ECIdentity.java
@Name("ecidentity")
  | @Scope(SESSION)
  | @Intercept(InterceptionType.AFTER_RESTORE_VIEW)
  | @Startup
  | public class ECIdentity extends RuleBasedIdentity {
  | 
  | 	String role = null;
  | 	
  | 	
  |     public String login() {
  |     	
  |     	
  |     	System.err.println("First login");
  |     	
  |     	return super.login();
  |     	
  |     }
  | }	
  | 

Authenticator.java
@Name("authenticator")
  | public class Authenticator {
  | 	@Logger Log log;
  | 
  | 	@In(value="ecidentity") ECIdentity ecIdentity;
  | 
  | 	@In EntityManager entityManager;
  | 	
  | 	@In("#{messages['ErrorOnLogin']}") private String LoginError;
  | 
  | 	public boolean authenticate() {
  | 		
  | 		System.err.println("First authenticate");
  | 		System.err.println("Username = "+ECIdentity.instance().getUsername());
  | 		
  | 		try {
  | 			String hashedPassword = Util.createPasswordHash("MD5", Util.BASE64_ENCODING, null, null,ECIdentity.instance().getPassword());
  | 
  | 				Mb member = (Mb) entityManager.createQuery(
  | 				"from Mb where login = :username and passwd = :password")
  | 				.setParameter("username", ECIdentity.instance().getUsername())
  | 				.setParameter("password", hashedPassword)
  | 				.getSingleResult();
  | 
  | 			return true;
  | 		}
  | 		catch (NoResultException ex) {
  | 			FacesMessages.instance().add(LoginError);
  | 			return false;
  | 		}
  | 	}
  | }
  | 

And when I submit  (the action performed is #{ecidentity.login}  ), I get the following error message in the console:



15:46:53,967 ERROR [STDERR] First login
  | 15:46:54,386 ERROR [STDERR] First authenticate
  | 15:46:54,387 ERROR [STDERR] Username = null
  | 15:46:54,411 ERROR [SeamLoginModule] Error invoking login method
  | javax.faces.el.EvaluationException: Exception while invoking expression #{authenticator.authenticate}
  |         at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:153)
  |         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:148)
  |         at org.jboss.seam.security.jaas.SeamLoginModule.login(SeamLoginModule.java:104)
  |         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  | 
  | 
  | ...
  | ...
  | 
  | Caused by: java.lang.NullPointerException
  |         at org.jboss.security.Util.createPasswordHash(Util.java:407)
  |         at org.jboss.security.Util.createPasswordHash(Util.java:378)
  |         at com.easycity.ejb.Authenticator.authenticate(Authenticator.java:35)
  |         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  | 
  | 
  | 
  | 
  | 


I have no idea why my ECIdentity object isn't reacheable.

Thanks for your help.

Best regards
PC

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

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



More information about the jboss-user mailing list