1 Reply Latest reply on May 21, 2007 7:22 PM by Shane Bryzak

    Could not create Component Error

    Jeffrey Himmel Newbie

      I tried to run a test page which uses the built-in identity class for logging a user in. When I tried to run the application, I recieved an error which included "Exception sending context initialized event to listener instance of class org.jboss.seam.servlet.SeamListener" and "java.lang.RuntimeException: Could not create Component: org.jboss.seam.security.identity".

      The login page is called loginTestPage.xhtml. Its code is:

      <?xml version="1.0" encoding="ISO-8859-1" ?>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
       xmlns:s="http://jboss.com/products/seam/taglib"
       xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:h="http://java.sun.com/jsf/html" template="layout/template.xhtml">
      
       <ui:define name="body">
      
       <h:form>
       <h2>Login Test: Testing authenticate() and identity Class</h2>
       <br />
      
       User Name: <h:inputText id="userName2" value="#{identity.username}"
       size="16" maxlength="26" required="true" />
       <br />
       Password: <h:inputSecret id="password2"
       value="#{identity.password}" size="16" maxlength="26"
       required="true" />
       <br />
       <h:commandButton value="Login" action="#{identity.login}" />
      
       <br />
       <h:outputLabel id="LoginErrorMessage2"
       for="password2" styleClass="errorFont"
       value="#{authenticator.errorMessage}" />
      
      
       </h:form>
      
       </ui:define>
      </ui:composition>
      
      


      The webpage uses the standard AuthenticatorAction class, to which I added the login code and the local interface. The local interface code includes the following:

      package com.pmacui;
      
      public interface IAuthenticator
      {
       public boolean authenticate();
       public String logout();
      }
      
      


      The AuthenticatorAction class code includes:

      package com.pmacui;
      
      import java.math.BigInteger;
      import java.security.MessageDigest;
      
      import javax.naming.Context;
      import javax.naming.InitialContext;
      
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.core.FacesMessages;
      import org.jboss.seam.log.Log;
      import org.jboss.seam.security.Identity;
      
      import com.netcentricinc.pmac.core.account.IAccountManagerLocal;
      
      @Name("authenticator")
      public class AuthenticatorAction implements IAuthenticator
      {
       // Note: In the webpage login.xhtml, remember to replace "authenticator" with
       // "identity" when it comes time to use the built in Seam features for
       // authentication. Also remember to change "checkLogin" back to "login".
       @Logger
       Log log;
      
       @In
       Identity identity;
      
       // @EJB(name = "AccountManager")
       // IAccountManagerLocal accountManagerLocal;
      
       private static final String USER_NAME_CONST = "user";
       private static final String PASSWORD_CONST = "pwd";
       private String username = "";
       private String password = "";
       private String sResult = null;
       private String errorMessage = "";
       private boolean b_IsLoggedIn = false;
      
       public String getUsername()
       {
       return this.username;
       }
       public void setUsername(String username)
       {
       this.username = username;
       }
       public String getPassword()
       {
       return password;
       }
       public void setPassword(String password)
       {
       this.password = password;
       }
       public String getResult()
       {
       return sResult;
       }
       public void setResult(String sres)
       {
       this.sResult = sres;
       }
       public String getErrorMessage()
       {
       return errorMessage;
       }
       public void setErrorMessage(String s_error)
       {
       this.errorMessage = s_error;
       }
       public boolean getB_IsLoggedIn()
       {
       return this.b_IsLoggedIn;
       }
       public void setB_IsLoggedIn(boolean b_IsLoggedIn)
       {
       this.b_IsLoggedIn = b_IsLoggedIn;
       }
      
       // TODO we should be able to inject the AccountManager when we switch
       // to JBOSS 4.2 or 5.0
       // @EJB(name = "AccountManager")
       // IAccountManagerLocal accountManagerLocal;
      
       public boolean authenticate()
       {
       log.info("authenticating #0", identity.getUsername());
       Context jndiContext;
       IAccountManagerLocal accountManagerLocal;
       boolean result = false;
      
       try
       {
       jndiContext = new InitialContext();
       accountManagerLocal =
       (IAccountManagerLocal) jndiContext.lookup("PMACServer/AccountManager/local");
      
       String passHash = getPasswordHash(identity.getPassword());
      
       String loginResult = accountManagerLocal.verifyCredentials(identity.getUsername(), passHash);
      
       if (loginResult.matches(IAccountManagerLocal.SUCCESS))
       {
       result = true;
       } // End If.
       else
       {
       log.info(loginResult);
       // FacesMessages.instance().add(loginResult);
       this.errorMessage = this.errorMessage + " Invalid Login! ";
       result = false;
       } // End Else.
      
       } // End Try.
       catch (Exception e)
       {
       // FacesMessages.instance().add("Invalid username/password");
       this.errorMessage = this.errorMessage + " A problem exists with Authenticator(). ";
       return false;
       } // End Catch.
       return result;
       }
      
       /**
       * Password hash creation so we don't store it in the db as clear text
       * @param password
       * @return String - password hash
       */
       private String getPasswordHash(String password)
       {
       StringBuilder hash = new StringBuilder();
       try
       {
       password = password.trim();
       //Make the hash
       MessageDigest md5 = MessageDigest.getInstance("MD5");
       hash.append(new BigInteger(1, md5.digest(password.getBytes())).toString(32));
       }
       catch (Exception e)
       {
       //TODO either catch the exception and print it to the log - or throw it back to the caller
       e.printStackTrace();
       }
       return hash.toString();
       }
      
      public String logout()
       {
       username = "";
       password = "";
       return "/login.xhtml";
       }
      
      


      What am I missing? Am I missing something in my Seam configuration? Is there something missing in the code? Any help would be greatly appreciated. Thanks.

        • 1. Re: Could not create Component Error
          Shane Bryzak Master

          It's likely a configuration error. I recommend that you use seam-gen to generate a functioning authentication configuration, then compare what it generates to what you have. As a side note, you don't need the IAuthenticator interface for your POJO AuthenticatorAction component. Also, Identity implements its own logout() method which I recommend you use instead of writing your own.