I'm building a simple Spring app and I'd like to use Apache Shiro for my
security implementation.  I've configured AS via Spring successfully and
everything seems to be running OK but I just can't seem to get the remember
me feature working.

My first question is:

Is the Remember Me feature supposed to automatically login users that have
selected to be remembered?  Presumably "yes" but I wanted to confirm.

Under the assumption that the question above is "yes", I am not seeing the
automatic login take place when "rememberMe" is true.  When I debug it, I
can verify that it does indeed obtain the correct principals for the
browser's session, but nowhere do I see it obtaining any serialized
credentials nor do I see it attempt an automated login.

I'm sure this is a misconfiguration or something on my end and I was hoping
the community could point me in the right direction.  I have included some
snippets of code below for reference:

web.xml snippet:

  <listener>
   
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
  </listener>
  <listener>
   
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <filter>
    <filter-name>shiroFilter</filter-name>
   
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    <init-param>
      <param-name>targetFilterLifecycle</param-name>
      <param-value>true</param-value>
    </init-param>
  </filter>
  <filter>
    <filter-name>RequestContextFilter</filter-name>
   
<filter-class>org.springframework.web.filter.RequestContextFilter</filter-class>
  </filter>

  <filter-mapping>
    <filter-name>shiroFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <filter-mapping>
    <filter-name>RequestContextFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

  
  <servlet>
    <servlet-name>Spring Dispatcher Servlet</servlet-name>
   
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>
        /WEB-INF/myApp.xml
      </param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>Spring Dispatcher Servlet</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>

Spring Shiro Config:

  <bean id="shiroFilter"
class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
    <property name="securityManager" ref="securityManager"/>
    <property name="loginUrl" value="/login"/>
    <property name="successUrl" value="/profile"/>
    <property name="filterChainDefinitions">
      <value>
        /profile/** = authc
        /** = anon
      </value>
    </property>
  </bean>

  <bean id="securityManager"
class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
    <property name="realm" ref="realmService"/>
  </bean>

  <bean id="lifecycleBeanPostProcessor"
class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>

  <bean id="hashedCredentialsMatcher"
class="org.apache.shiro.authc.credential.HashedCredentialsMatcher">
    <property name="hashAlgorithmName" value="SHA-256"/>
    <property name="hashIterations" value="1024"/>
    <property name="storedCredentialsHexEncoded" value="false"/>
  </bean>

  
  <bean id="randomNumberGenerator"
class="org.apache.shiro.crypto.SecureRandomNumberGenerator"/>

RealmService snippet:

  protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken
token) throws AuthenticationException {

    UsernamePasswordToken thisToken = (UsernamePasswordToken)token;
    String email = thisToken.getUsername();

    try {
      Account account = accountService.findByEmail(email);
      SecurityPrincipal principal = new SecurityPrincipal(email);
      String hashedCredentials = account.getEncryptedPassword();
      byte[] salt = account.getPasswordSalt();
      ByteSource credentialsSalt = securityService.convertSalt(salt);

      return new SimpleAccount(principal, hashedCredentials,
credentialsSalt, getName());
    } catch (NoResultException e) {
      return null;
    }
  }

SecurityPrincipal snippet:

public class SecurityPrincipal implements Serializable {

  public static final long serialVersionUID = 1950203249783644233L;

  private String email;

  public SecurityPrincipal(String email) {
    this.email = email;
  }

  public String getEmail() {
    return email;
  }
}

SecurityService snippet:

  @Override
  public ByteSource convertSalt(byte[] salt) {
    return new SimpleByteSource(salt);
  }


--
View this message in context: 
http://shiro-user.582556.n2.nabble.com/RememberMe-Issues-tp6608110p6608110.html
Sent from the Shiro User mailing list archive at Nabble.com.

Reply via email to