Announcement Announcement Module
Collapse
No announcement yet.
Custom PersistentTokenRepository to remember me function isn't working Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Custom PersistentTokenRepository to remember me function isn't working

    I am trying to use remember me function when users makes login on my application. For the authentication provider, i pass my dataSource which is the database HSQLDB.


    this is my datanbase configuration:

    Code:
    	
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
    	destroy-method="close">
    	<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
    	<property name="url" value="jdbc:hsqldb:hsql://localhost/auth" />
    	<property name="username" value="sa" />
    	<property name="password" value="" />
    	<property name="defaultAutoCommit" value="false" />
    </bean>
    in my base.xml i have PersistentTokenBasedRememberMeServicesImpl, PersistentTokenRepositoryImpl because when user select the remember me option, i need to save data in the persistent_logins table.

    Code:
    <bean id="jdbcTokenRepository" class="pt.celfocus.security.PersistentTokenRepositoryImpl">
    		<property name="dataSource" ref="dataSource" />
    		<property name="createTableOnStartup" value="true" />
    	</bean>
    
     	<bean class="pt.celfocus.service.MyUserDetailsService" id="myUserDetailsService">
    		<property name="dataSource" ref="dataSource" />
    	</bean> 
    
    	<bean id="rememberMeFilter"
    		class="org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter">
    		<property name="rememberMeServices" ref="rememberMeServices" />
    		<property name="authenticationManager" ref="authenticationManager" />
    	</bean>
      
    	<bean id="rememberMeServices"
    		class="pt.celfocus.security.PersistentTokenBasedRememberMeServicesImpl">
    		<property name="userDetailsService" ref="myUserDetailsService" />
    		<property name="tokenValiditySeconds" value="3600" />
    		<property name="tokenRepository" ref="jdbcTokenRepository" />
    		<property name="key" value="jbcpPetStore" />
    		<property name="alwaysRemember" value="false" />
    	</bean>
    
    	<bean id="rememberMeAuthenticationProvider"
    		class="org.springframework.security.authentication.RememberMeAuthenticationProvider">
    		<property name="key" value="jbcpPetStore" />
    	</bean>
    In my security config, i have:

    Code:
    	<http auto-config="true" use-expressions="true">
    		<anonymous />
    		<intercept-url pattern="/login.do" access="permitAll" />
    		<intercept-url pattern="/account/*.do"
    			access="hasRole('ROLE_USER')
    			and fullyAuthenticated" />
    		<intercept-url pattern="/**" access="hasRole('ROLE_USER')" />
    		<form-login login-page="/login.do" />
    		<logout invalidate-session="true" logout-url="/j_spring_security_logout"
    			logout-success-url="/" />
    
    		<remember-me key="jbcpPetStore" services-ref="rememberMeServices" />
    
    	</http>
    
    	<authentication-manager alias="authenticationManager">
                     <authentication-provider>
    			<jdbc-user-service data-source-ref="dataSource" />
    		</authentication-provider>
    	</authentication-manager>
    I can make the process login with the reference of database. If i pass the rememberMeAuthenticationProvider id to authentication-provider, i cant make login against my database.

    I need to catch the methods of PersistentTokenRepositoryImpl to save data. When i run my code, the remember me option is not working because the table isn't create and any data is inserted. Anyone can help me about the parameters for authentication-provider and remember-me?

    thanks

  • #2
    Originally posted by vitorpfn View Post
    I can make the process login with the reference of database. If i pass the rememberMeAuthenticationProvider id to authentication-provider, i cant make login against my database.
    To authenticate against the database you need to leave jdbc-user-service. The RememberMeAuthenticationProvider also needs to be added to the authentication-manager. This is done automatically by the remember-me element (so you should not need to do that). Note to use RememberMeAuthenticationProvider your RememberMeServices implementation must return a RememberMeAuthenticationToken (or you must provide an AuthenticationProvider that handles that type of Authentication).

    Originally posted by vitorpfn View Post
    I need to catch the methods of PersistentTokenRepositoryImpl to save data.
    I'm not sure I understand what you are trying to do here? Is there a reason you are not using Spring Security's default PersistentTokenBasedRememberMeServices?

    Originally posted by vitorpfn View Post
    When i run my code, the remember me option is not working because the table isn't create and any data is inserted. Anyone can help me about the parameters for authentication-provider and remember-me?
    So you are having problems getting the tables to be generated? You might try to have them generated using something like
    Code:
    <jdbc:initialize-database data-source="dataSource">
      <jdbc:script location="classpath:init.sql"/>
    </jdbc:initialize-database>

    Comment

    Working...
    X