Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I use a custom configured RememberMeAuthenticationFilter in spring security?
    text
    copied!<p>I want to use a slightly customized rememberme functionality with spring security (3.1.0).</p> <p>I declare the rememberme tag like this:</p> <pre><code>&lt;security:remember-me key="JNJRMBM" user-service-ref="gymUserDetailService" /&gt; </code></pre> <p>As I have my own rememberme service I need to inject that into the RememberMeAuthenticationFilter which I define like this: </p> <pre><code>&lt;bean id="rememberMeFilter" class="org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter"&gt; &lt;property name="rememberMeServices" ref="gymRememberMeService"/&gt; &lt;property name="authenticationManager" ref="authenticationManager" /&gt; &lt;/bean&gt; </code></pre> <p>I have spring security integrated in a standard way in my web.xml:</p> <pre><code>&lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt; &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt; </code></pre> <p>Everything works fine, except that the RememberMeAuthenticationFilter uses the standard RememberMeService, so I think that my defined RememberMeAuthenticationFilter is not being used.</p> <p>How can I make sure that my definition of the filter is being used? Do I need to create a custom filterchain? And if so, how can I see my current "implicit" filterchain and make sure I use the same one except my RememberMeAuthenticationFilter instead of the default one? </p> <p>Thanks for any advice and/or pointers!</p> <p>Here the complete spring-security.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:security="http://www.springframework.org/schema/security" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd"&gt; &lt;security:http pattern="/_ui/**" security="none" /&gt; &lt;!-- Default security config --&gt; &lt;security:http disable-url-rewriting="true"&gt; &lt;security:anonymous username="anonymous" granted-authority="ROLE_ANONYMOUS" /&gt; &lt;!-- session stealing is prevented by using secure GUID cookie --&gt; &lt;security:session-management session-fixation-protection="none" /&gt; &lt;!-- SSL / AUTHENTICATED pages --&gt; &lt;security:intercept-url pattern="/my-account*" access="ROLE_CUSTOMERGROUP" requires-channel="https" /&gt; &lt;security:intercept-url pattern="/my-account/**" access="ROLE_CUSTOMERGROUP" requires-channel="https" /&gt; &lt;!-- SSL / ANONYMOUS pages Login pages need to be SSL, but occur before authentication --&gt; &lt;security:intercept-url pattern="/login" requires-channel="https" /&gt; &lt;security:intercept-url pattern="/login/**" requires-channel="https" /&gt; &lt;security:intercept-url pattern="/register" requires-channel="https" /&gt; &lt;security:intercept-url pattern="/register/**" requires-channel="https" /&gt; &lt;security:intercept-url pattern="/j_spring_security_check" requires-channel="https" /&gt; &lt;security:intercept-url pattern="/logout" requires-channel="https" /&gt; &lt;!-- MiniCart and CartPopup can occur on either secure or insecure pages --&gt; &lt;security:intercept-url pattern="/cart/rollover/*" requires-channel="any" /&gt; &lt;security:intercept-url pattern="/cart/miniCart/*" requires-channel="any" /&gt; &lt;security:intercept-url pattern="/cart/show" requires-channel="any" /&gt; &lt;security:intercept-url pattern="/cart/lightboxmybag" requires-channel="any" /&gt; &lt;security:intercept-url pattern="/cart/remove/*" requires-channel="any" /&gt; &lt;security:intercept-url pattern="/cart/update/*" requires-channel="any" /&gt; &lt;security:intercept-url pattern="/cart/getProductSizes/**" requires-channel="any" /&gt; &lt;security:intercept-url pattern="/cart/getShippingMethods" requires-channel="any" /&gt; &lt;security:intercept-url pattern="/cart/setShippingMethod" requires-channel="any" /&gt; &lt;security:intercept-url pattern="/cart/applyVoucherDiscount" requires-channel="any" /&gt; &lt;security:intercept-url pattern="/cart/removeVoucherDiscount" requires-channel="any" /&gt; &lt;security:intercept-url pattern="/checkout/**" requires-channel="https" /&gt; &lt;!-- product suggest --&gt; &lt;security:intercept-url pattern="/suggest*" requires-channel="any" /&gt; &lt;!-- cybersource response --&gt; &lt;security:intercept-url pattern="/cybersource/response" requires-channel="any" /&gt; &lt;security:intercept-url pattern="/cybersource/csResponse" requires-channel="http" /&gt; &lt;!-- regions --&gt; &lt;security:intercept-url pattern="/regions*" requires-channel="any" /&gt; &lt;security:intercept-url pattern="/regions/*" requires-channel="any" /&gt; &lt;!-- popup links --&gt; &lt;security:intercept-url pattern="/popupLink/*" requires-channel="any" /&gt; &lt;!-- addresses --&gt; &lt;security:intercept-url pattern="/my-addresses*" requires-channel="any" /&gt; &lt;security:intercept-url pattern="/my-addresses/**" requires-channel="any" /&gt; &lt;security:intercept-url pattern="/search/autocompleteSecure/**" requires-channel="https" /&gt; &lt;!-- OPEN / ANONYMOUS pages Run all other (public) pages openly. Note that while credentials are secure, the session id can be sniffed. If this is a security concern, then this line should be re-considered --&gt; &lt;security:intercept-url pattern="/**" requires-channel="any" method="POST" /&gt; &lt;!-- Allow posts on either secure or insecure --&gt; &lt;security:intercept-url pattern="/**" requires-channel="http" /&gt; &lt;!-- Everything else should be insecure --&gt; &lt;security:form-login login-page="/login" authentication-failure-handler-ref="loginAuthenticationFailureHandler" authentication-success-handler-ref="loginGuidAuthenticationSuccessHandler" /&gt; &lt;security:logout logout-url="/logout" success-handler-ref="logoutSuccessHandler" /&gt; &lt;security:port-mappings&gt; &lt;security:port-mapping http="#{configurationService.configuration.getProperty('tomcat.http.port')}" https="#{configurationService.configuration.getProperty('tomcat.ssl.port')}" /&gt; &lt;security:port-mapping http="80" https="443" /&gt; &lt;!--security:port-mapping http="#{configurationService.configuration.getProperty('proxy.http.port')}" https="#{configurationService.configuration.getProperty('proxy.ssl.port')}" /--&gt; &lt;/security:port-mappings&gt; &lt;security:request-cache ref="httpSessionRequestCache" /&gt; &lt;security:remember-me key="JNJRMBM" user-service-ref="gymUserDetailService" /&gt; &lt;/security:http&gt; &lt;security:authentication-manager alias="authenticationManager"&gt; &lt;security:authentication-provider ref="acceleratorAuthenticationProvider" /&gt; &lt;/security:authentication-manager&gt; &lt;bean id="acceleratorAuthenticationProvider" class="org.jnj.storefront.security.AcceleratorAuthenticationProvider" scope="tenant"&gt; &lt;property name="userDetailsService" ref="gymUserDetailService" /&gt; &lt;property name="adminGroup" value="ROLE_ADMINGROUP"/&gt; &lt;property name="userService" ref="userService"/&gt; &lt;property name="gymCustomerLoginService" ref="defaultGymCustomerLoginService"/&gt; &lt;/bean&gt; &lt;bean id="gymUserDetailService" class="org.jnj.storefront.security.services.impl.GymCoreUserDetailsService" scope="tenant"&gt; &lt;property name="baseDao" ref="asyBaseDao" /&gt; &lt;/bean&gt; &lt;bean id="coreUserDetailsService" class="de.hybris.platform.spring.security.CoreUserDetailsService" scope="tenant" /&gt; &lt;bean id="guidCookieStrategy" class="org.jnj.storefront.security.impl.DefaultGUIDCookieStrategy" scope="tenant"&gt; &lt;property name="cookieGenerator" ref="guidCookieGenerator" /&gt; &lt;/bean&gt; &lt;alias name="defaultGuidCookieGenerator" alias="guidCookieGenerator"/&gt; &lt;bean id="defaultGuidCookieGenerator" class="org.jnj.storefront.security.cookie.EnhancedCookieGenerator" scope="tenant"&gt; &lt;property name="cookieSecure" value="true" /&gt; &lt;property name="cookieName" value="acceleratorSecureGUID" /&gt; &lt;property name="httpOnly" value="false"/&gt; &lt;!-- if context allows a httpOnly adjust to true --&gt; &lt;/bean&gt; &lt;bean id="autoLoginStrategy" class="org.jnj.storefront.security.impl.DefaultAutoLoginStrategy" scope="tenant"&gt; &lt;/bean&gt; &lt;bean id="httpSessionRequestCache" class="org.jnj.storefront.security.impl.WebHttpSessionRequestCache" scope="tenant" /&gt; &lt;bean id="loginUserType" class="org.jnj.storefront.security.impl.LoginUserTypeBean" scope="tenant" /&gt; &lt;bean id="redirectStrategy" class="org.springframework.security.web.DefaultRedirectStrategy" scope="tenant" /&gt; &lt;!-- Login Success Handlers --&gt; &lt;bean id="loginGuidAuthenticationSuccessHandler" class="org.jnj.storefront.security.GUIDAuthenticationSuccessHandler" scope="tenant"&gt; &lt;property name="authenticationSuccessHandler" ref="loginAuthenticationSuccessHandler" /&gt; &lt;property name="guidCookieStrategy" ref="guidCookieStrategy" /&gt; &lt;/bean&gt; &lt;bean id="loginAuthenticationSuccessHandler" class="org.jnj.storefront.security.StorefrontAuthenticationSuccessHandler" scope="tenant"&gt; &lt;property name="customerFacade" ref="customerFacade" /&gt; &lt;property name="defaultTargetUrl" value="/my-account"/&gt; &lt;property name="useReferer" value="true"/&gt; &lt;property name="alwaysUseDefaultTargetUrl" value="false"/&gt; &lt;property name="requestCache" ref="httpSessionRequestCache" /&gt; &lt;/bean&gt; &lt;bean id="loginCheckoutGuidAuthenticationSuccessHandler" class="org.jnj.storefront.security.GUIDAuthenticationSuccessHandler" scope="tenant"&gt; &lt;property name="authenticationSuccessHandler" ref="loginCheckoutAuthenticationSuccessHandler" /&gt; &lt;property name="guidCookieStrategy" ref="guidCookieStrategy" /&gt; &lt;property name="defaultGymCartFacade" ref="gymCartFacade"/&gt; &lt;/bean&gt; &lt;bean id="loginCheckoutAuthenticationSuccessHandler" class="org.jnj.storefront.security.StorefrontAuthenticationSuccessHandler" scope="tenant"&gt; &lt;property name="customerFacade" ref="customerFacade" /&gt; &lt;property name="defaultTargetUrl" value="/checkout/single/summary"/&gt; &lt;/bean&gt; &lt;!-- Login Failure Handlers --&gt; &lt;bean id="loginAuthenticationFailureHandler" class="org.jnj.storefront.security.LoginAuthenticationFailureHandler"&gt; &lt;property name="defaultFailureUrl" value="/login?error=auth"/&gt; &lt;property name="accountBlockedUrl" value="/login?error=blocked"/&gt; &lt;property name="passwordMigrationUrl" value="/login?error=migration"/&gt; &lt;/bean&gt; &lt;bean id="loginCheckoutAuthenticationFailureHandler" class="org.jnj.storefront.security.LoginAuthenticationFailureHandler"&gt; &lt;property name="defaultFailureUrl" value="/login/checkout?error=auth"/&gt; &lt;property name="accountBlockedUrl" value="/login/checkout?error=blocked"/&gt; &lt;property name="passwordMigrationUrl" value="/login/checkout?error=migration"/&gt; &lt;/bean&gt; &lt;!-- Logout Success Handler --&gt; &lt;bean id="logoutSuccessHandler" class="org.jnj.storefront.security.StorefrontLogoutSuccessHandler" scope="tenant"&gt; &lt;property name="defaultTargetUrl" value="/?logout=true"/&gt; &lt;property name="guidCookieStrategy" ref="guidCookieStrategy"/&gt; &lt;property name="cmsSiteService" ref="cmsSiteService"/&gt; &lt;/bean&gt; &lt;bean id="gymRememberMeService" class="org.jnj.storefront.security.cookie.DefaultRememberMeService" scope="tenant"&gt; &lt;property name="tokenService" ref="secureTokenService" /&gt; &lt;property name="rememberMeCookieGenerator" ref="defaultRememberMeCookieGenerator" /&gt; &lt;/bean&gt; &lt;bean id="rememberMeFilter" class="org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter"&gt; &lt;property name="rememberMeServices" ref="gymRememberMeService"/&gt; &lt;property name="authenticationManager" ref="authenticationManager" /&gt; &lt;/bean&gt; </code></pre> <p></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload