0 Replies Latest reply on Feb 18, 2008 6:08 AM by paata lominadze

    Seam Identity, Duplicated Messages for the first time

    paata lominadze Master

      hi all,
      i have simple login page, i use seam identity,
      here is my example :

      <h:form id="login">
       <rich:panel style="width: 400px;">
       <f:facet name="header">Login</f:facet>
       <p class="LogintCaption">Please login using any username and password</p>
       <div class="dialog">
       <h:panelGrid columns="2" rowClasses="prop" columnClasses="name,value" style="text-align:left">
       <h:outputLabel for="username">Username</h:outputLabel>
       <h:inputText id="username"
       value="#{identity.username}" styleClass="LoginInput"/>
       <h:outputLabel for="password">Password</h:outputLabel>
       <h:inputSecret id="password"
       value="#{identity.password}" styleClass="LoginInput"/>
       <h:outputLabel for="language">Language</h:outputLabel>
       <h:selectOneMenu id="language" styleClass="LoginLangCombo" value="#{localeSelector.language}"
       <f:selectItems value="#{localeSelector.supportedLocales}"/>
       <h:outputLabel for="rememberMe">Remember me</h:outputLabel>
       <h:selectBooleanCheckbox id="rememberMe"
       <h:outputLabel for="LogInButn"></h:outputLabel>
       <h:commandButton id="LogInButn" value="Login" action="#{identity.login}"/>
       <h:messages id="modalError" layout="table" style="padding:0px;"/>

      1. Backing bean :
      public class Authenticator {
       // logger instance
       Log log;
       // Seam Identity Session Bean For User Identification
       Identity identity;
       // UserName Fro Session Context.
       private static final String USER_VAR = "currentUser";
       // Session Context
       Context sessionContext;
       // Database Entity Manager
       @In(value = "#{entityManager}")
       EntityManager em;
       // Faces Messages
       private FacesMessages facesMessages;
       public boolean authenticate() {
       try {
       log.info("authenticating = " + identity.getUsername());
       List<Users> users = (List<Users>) em.createNamedQuery("Users.findByUserName").setParameter("userName", identity.getUsername()).getResultList();
       if (users == null || (users != null && users.isEmpty())) {
       facesMessages.addToControl("username", "User #{user.username} does not exists");
       //FacesMessages.instance().add("User #{user.username} does not exists");
       return false;
       } else {
       for (Users user : users) {
       byte dbpaswd[] = user.getUserPwd();
       String strpwd = identity.getPassword();
       MessageDigest md5 = MessageDigest.getInstance("MD5");
       byte[] userpasswd = md5.digest();
       boolean result = MessageDigest.isEqual(userpasswd, dbpaswd);
       if (result) {
       sessionContext.set(USER_VAR, user);
       return true;
       facesMessages.addToControl("password", "Incorrect Password For This User");
       //FacesMessages.instance().add("Incorrect Password For This User");
       return false;
       } catch (Exception e) {
       facesMessages.add("Could not login. System Error");
       //FacesMessages.instance().add("Could not login. System Error");
       return false;

      but for the first time i got two messages into view :
      Incorrect Password For This User
      Incorrect Password For This User

      here is screen shot of my program :

      any idea will be appreciated.
      Magticom LTD.