[jboss-user] [JBoss Seam] - Re: Seam security adds default messages

onyii5119 do-not-reply at jboss.com
Sun Mar 25 10:04:43 EDT 2007


"fernando_jmt" wrote : The messages you should add to your .properties file are
  | 
  | org.jboss.seam.loginSuccessful = Welcome, #0
  | 
  | and
  | 
  | org.jboss.seam.loginFailed = Login failed 
  | 
  | 
  | In case of login fails it is natural to add the message (which I can configure as I want), but in the case of the login is successfully not all cases it is required to add a success message.
  | 
  | Is there a way in order to turn off the success message?
  | 
  | 

I am using a custom resource bundle (not the jsf style resource bundle) because of the requirements of our multi-language application. In that case  what you recommended may not apply. 


I tried setting my own message as shown below but got my own message and the default message ("Login failed") displayed as error messages. The result tells me that you set the error message only after the authenticate() method returns false.

Error messages displayed:

* Invalid username or password
* Login failed

in that order.

	public boolean authenticate(){
			
		try	{            
				
			user = (TsUsersEntityBean) em.createQuery("from TsUsersEntityBean where userLoginId = :username")
            	.setParameter("username", identity.getUsername())
            	.getSingleResult();

		}catch (NoResultException ex){
				FacesMessages.instance().add("Invalid username or password");
			return false;
		}      

To make the error handling more generic, I am recommending that you have methods that return and set the various messages. Your indentity class might be the appropriate class to add the methods - similar to Identity.addRole(String) method.

Hence, one can then set the appropriate message based on your specified key. For example: Identity.setLoginError("org.jboss.seam.loginFailed", "Invalid username or password"); The message set could be in any locale.

In your own code(seam code) if the user authenticate method returns false, you can then call Identity.getLoginError("org.jboss.seam.loginFailed"), if it returns null then set it to "Login failed" otherwise use the returned value.

Do a similar thing for all the other messages related to authentication (login). Doing so will make your authentication method usable by any locale.

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

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



More information about the jboss-user mailing list