[jboss-user] [JBoss Seam] - Seam Identity, Duplicated Messages for the first time

grdzeli_kaci do-not-reply at jboss.com
Mon Feb 18 06:08:47 EST 2008


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

  | <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}"
  |                                          onchange="submit();" 
  |                                          valueChangeListener="#{localeSelector.select}">
  |                             <f:selectItems value="#{localeSelector.supportedLocales}"/>
  |                         </h:selectOneMenu>                        
  |                         <h:outputLabel for="rememberMe">Remember me</h:outputLabel>
  |                         <h:selectBooleanCheckbox id="rememberMe" 
  |                                                  value="#{identity.rememberMe}"/>
  |                         <h:outputLabel for="LogInButn"></h:outputLabel>
  |                         <h:commandButton id="LogInButn" value="Login" action="#{identity.login}"/>
  |                     </h:panelGrid>
  |                 </div>
  |                 <h:messages id="modalError" layout="table" style="padding:0px;"/>
  |             </rich:panel>
  |         </h:form>
  | 
1. Backing bean :

  | @Name("authenticator")
  | public class Authenticator {
  |     // logger instance
  |     @Logger
  |     Log log;
  |     // Seam Identity Session Bean For User Identification
  |     @In
  |     Identity identity;
  |     // UserName Fro Session Context.
  |     private static final String USER_VAR = "currentUser";
  |     // Session Context
  |     @In
  |     Context sessionContext;
  |     // Database Entity Manager
  |     @In(value = "#{entityManager}")
  |     EntityManager em;
  |     // Faces Messages
  |     @In
  |     private FacesMessages facesMessages;
  | 
  |     public boolean authenticate() {
  |         try {
  |             facesMessages.clear();
  |             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");
  |                     md5.reset();
  |                     md5.update(strpwd.getBytes());
  |                     byte[] userpasswd = md5.digest();
  | 
  |                     boolean result = MessageDigest.isEqual(userpasswd, dbpaswd);
  |                     if (result) {
  |                         identity.addRole("admin");
  |                         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) {
  |             e.printStackTrace();
  |             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 :
http://img2.freeimagehosting.net/image.php?69700131ef.png


any idea will be appreciated.
_______________________
Regards,
Paata.
Magticom LTD.

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

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



More information about the jboss-user mailing list