struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kawczynski, David" <david_kawczyn...@merck.com>
Subject RE: Login with Struts2
Date Thu, 16 Jul 2009 18:48:08 GMT
Take a look at Spring Security (formerly ACEGI).  
http://static.springsource.org/spring-security/site/

> -----Original Message-----
> From: mathias-ewald [mailto:nitehoaxxer@gmx.net] 
> Sent: Thursday, July 16, 2009 2:37 PM
> To: user@struts.apache.org
> Subject: Login with Struts2
> 
> 
> Hi,
> 
> I am trying to implement a login mechanism. I will now 
> explain what I did
> and what error I get but in case there is a more 
> sophisticated way to do
> that - please tell me!
> 
> I created a BaseAction which is the parent of all my Actions. 
> The BaseAction
> is supposed to be responsible for displaying a login page if 
> there is no
> User object in session scope. Then the login form should put 
> the username
> and password into the BaseAction. The BaseAction then tries 
> to find a match
> in the database and places the User object into session scope:
> 
> ---------------------
> public abstract class BaseAction {
> 
> 	private String username;
> 	
> 	private String password;
> 	
> 	protected Log log;
> 	
> 	private Boolean loginStatus;
> 	
> 	
> 	public String execute() {
> 		if(log == null) {
> 			log = LogFactory.getLog(getClass());
> 		}
> 				
> 		if(isProtected()) {
> 			Map<String, Object> session = 
> ActionContext.getContext().getSession();
> 			Object o = session.get("user");
> 			if(o instanceof User) {
> 				loginStatus = true;
> 			} else {
> 				return "login";
> 			}
> 		}
> 		
> 		
> 		return executeAction();
> 	}
> 
> 	
> 	public abstract String executeAction();
> 
> 	public abstract Boolean isProtected();
> 	
> 
> 	public Boolean getLoginStatus() {
> 		return loginStatus;
> 	}
> 
> 	public void setLoginStatus(Boolean loginStatus) {
> 		this.loginStatus = loginStatus;
> 	}
> 
> 	public String getUsername() {
> 		return username;
> 	}
> 
> 	public void setUsername(String username) {
> 		this.username = username;
> 	}
> 
> 	public String getPassword() {
> 		return password;
> 	}
> 
> 	public void setPassword(String password) {
> 		this.password = password;
> 	}
> }
> ---------------------
> 
> An Action that wants to be password protected must implement 
> #isProtected()
> to return "true". This is my JSP file that is shown if 
> #isProtected() ==
> true and there's no User in session scope:
> 
> ---------------------
> ...
> <s:form>
> 	<s:textfield label="Username" 
> name="userData.username"></s:textfield>
> 	<s:password label="Password" 
> name="userData.password"></s:password>
> 	<s:submit></s:submit>
> </s:form>
> ...
> ---------------------
> 
> This is the error I get
> 
> ---------------------
> 20:35:42,179  WARN OgnlValueStack:49 - Error setting value
> ognl.OgnlException: target is null for setProperty(null, "password",
> [Ljava.lang.String;@1f22dad5)
> 	at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:1651)
> 	at ognl.ASTProperty.setValueBody(ASTProperty.java:101)
> 	at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:177)
> 	at ognl.SimpleNode.setValue(SimpleNode.java:246)
> 	at ognl.ASTChain.setValueBody(ASTChain.java:172)
> 	at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:177)
> 	at ognl.SimpleNode.setValue(SimpleNode.java:246)
> 	at ognl.Ognl.setValue(Ognl.java:476)
> ...
> ---------------------
> 
> 
> Why is that happening?
> 
> cu
> mathias
> -- 
> View this message in context: 
> http://www.nabble.com/Login-with-Struts2-tp24522078p24522078.html
> Sent from the Struts - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
Notice:  This e-mail message, together with any attachments, contains
information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station,
New Jersey, USA 08889), and/or its affiliates (which may be known
outside the United States as Merck Frosst, Merck Sharp & Dohme or
MSD and in Japan, as Banyu - direct contact information for affiliates is
available at http://www.merck.com/contact/contacts.html) that may be
confidential, proprietary copyrighted and/or legally privileged. It is
intended solely for the use of the individual or entity named on this
message. If you are not the intended recipient, and have received this
message in error, please notify us immediately by reply e-mail and
then delete it from your system.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message