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-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to