title: can not login when using Interceptor in struts2
body: <p>I have a small application to learn Struts2 Application</p>
  
  <p>I write a admin page and inside that , my code will check if user logged or not, if not it will redirect to login page.</p>
  
  <p>I write interceptor to check for all pages that user try to access but not login, it will redirect this user to login page. Everything is work well, but when i enter username and password correct with database, it can not login, when i remove interceptor i can be logged into admin page</p>
  
  <p>Cause maybe interceptor check session of user before and after login, but maybe some cases i dont know why my application, session get null althought my username and password is true but it till null when i set session.</p>
  
  <p>My code bellow will show you what i said:</p>
  
  <p>Login Action </p>
  
  <pre><code>/*
   * To change this template, choose Tools | Templates
   * and open the template in the editor.
   */
  package org.dejavu.software.view;
  
  import com.opensymphony.xwork2.ActionContext;
  import com.opensymphony.xwork2.ActionSupport;
  import java.util.Map;
  import org.apache.struts2.interceptor.SessionAware;
  import org.dejavu.software.dao.UserDAO;
  import org.dejavu.software.model.GroupMember;
  import org.dejavu.software.model.User;
  
  /**
   *
   * @author Administrator
   */
  public class AdminLoginAction extends ActionSupport {
  
      private static final long serialVersionUID = -1457633455929689099L;
      private User user;
      private String username, password;
      private String role;
      private UserDAO userDAO;
      private GroupMember group;    
  
      public AdminLoginAction() {
          userDAO = new UserDAO();
  
      }
  
      @Override
      public String execute() {
          String result = null;
          System.out.println(getUsername());
          if (getUsername().length() != 0 &amp;&amp; getPassword().length() != 0) {
              setUser(userDAO.checkUsernamePassword(getUsername(), getPassword()));            
              if (getUser() != null) {
                  for (GroupMember g : getUser().getGroups()) {
                      boolean admincp = g.getAdminpermission().contains("1");
                      if (admincp == true) {
                          Map session = ActionContext.getContext().getSession();  
                          session.put("userLogged", getUsername());
                          session.put("passwordLogged", getPassword());
                          result = "success";
                      } else {
                          result = "error";
                      }
                  }
  
              }
          }        
          return result;
      }
  
      @Override
      public void validate() {
          if (getUsername().length() == 0) {
              addFieldError("username", "Username is required");
          }
          if (getPassword().length() == 0) {
              addFieldError("password", getText("Password is required"));
          }
  
      }
  
      public String getPassword() {
          return password;
      }
  
      public void setPassword(String password) {
          this.password = password;
      }
  
      public String getRole() {
          return role;
      }
  
      public void setRole(String role) {
          this.role = role;
      }
  
      public User getUser() {
          return user;
      }
  
      public void setUser(User user) {
          this.user = user;
      }
  
      public String getUsername() {
          return username;
      }
  
      public void setUsername(String username) {
          this.username = username;
      }
  
      public GroupMember getGroup() {
          return group;
      }
  
      public void setGroup(GroupMember group) {
          this.group = group;
      }
  
  
  }
  </code></pre>
  
  <p>My  custom interceptor Code:</p>
  
  <pre><code>/*
   * To change this template, choose Tools | Templates
   * and open the template in the editor.
   */
  package org.dejavu.software.interceptor;
  
  import com.opensymphony.xwork2.ActionInvocation;
  import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
  import java.util.Map;
  import org.apache.struts2.StrutsStatics;
  
  /**
   *
   * @author Anministrator
   */
  public class LoginInterceptor extends AbstractInterceptor implements StrutsStatics {
  
      private static final long serialVersionUID = -3874262922233957387L;
  
      @Override
      public void destroy() {
      }
  
      @Override
      public void init() {
      }
  
      @Override
      public String intercept(ActionInvocation ai) throws Exception {
          Map&lt;String, Object&gt; session = ai.getInvocationContext().getSession();
          Object user = session.get("userLogged");
  
          if (user == null) {
              return "login";
          } else {
              return ai.invoke();
          }
      }
  }
  </code></pre>
  
  <p>my struts config</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;!DOCTYPE struts PUBLIC
  "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
  "http://struts.apache.org/dtds/struts-2.0.dtd"&gt;
  
  &lt;struts&gt;
  
      &lt;package name="default" namespace="/" extends="struts-default"&gt;
          &lt;action name="index" class="org.dejavu.software.view.HomeAction"&gt;
              &lt;result&gt;home.jsp&lt;/result&gt;
          &lt;/action&gt;
          &lt;action name="about" class="org.dejavu.software.view.AboutHomeAction"&gt;
              &lt;result&gt;about.jsp&lt;/result&gt;
          &lt;/action&gt;
      &lt;/package&gt;  
  
      &lt;package name="admincp" namespace="/admincp" extends="struts-default"&gt;
          &lt;interceptors&gt;
              &lt;interceptor name="login" class="org.dejavu.software.interceptor.LoginInterceptor" /&gt;
              &lt;interceptor-stack name="stack-with-login"&gt;
                  &lt;interceptor-ref name="login"/&gt;
                  &lt;interceptor-ref name="defaultStack"/&gt;
              &lt;/interceptor-stack&gt;
          &lt;/interceptors&gt;
          &lt;default-interceptor-ref name="stack-with-login"/&gt;
  
          &lt;global-results&gt;
              &lt;result name="login"&gt;login.jsp&lt;/result&gt;
          &lt;/global-results&gt;
  
          &lt;action name="logincp" class="org.dejavu.software.view.AdminLoginAction"&gt;
              &lt;result name="success"&gt;dashboard.jsp&lt;/result&gt;
              &lt;result name="input"&gt;login.jsp&lt;/result&gt;
              &lt;result name="error"&gt;login.jsp&lt;/result&gt;
          &lt;/action&gt;
  
      &lt;/package&gt;  
  
  &lt;/struts&gt;
  </code></pre>
  
  <p>When i enter correct username and password match to database it till redirect to login.jsp page</p>
  
  <p>and i have no idea about that</p>
  
  <p>please help me</p>
  
  <p>Thank you very much</p>