Question

My remember-me bean definition looks like this, and works fine

<security:remember-me  data-source-ref="dataSource" user-service-ref="userService"/>

However the first time a user registers, and I want to programmatically log them in and perform a remember-me. I do not know how to access the remember-me service. I can do this

UsernamePasswordAuthenticationToken auth = 
    new UsernamePasswordAuthenticationToken(user, "", authorities);
SecurityContextHolder.getContext().setAuthentication(auth);

HttpServletRequestWrapper wrapper = new HttpServletRequestWrapper(request) {
    @Override public String getParameter(String name) { return "true"; }            
};

But how to access the remember-me service like below, as I am using the default spring implementation and not my own bean ?

getRememberMeServices().loginSuccess(wrapper, response, auth);

from here

EDIT I have changed my bean definition to look like this

<security:remember-me services-alias="rememberMeService" data-source-ref="dataSource" user-service-ref="userService"/>

But intellij is still coming back with an error when I try to inject like this :

@Resource(name = "rememberMeService")
private RememberMeServices rememberMeService;
Was it helpful?

Solution

You can use the services-alias attribute of the remember-me namespace element to set a bean alias for the RememberMeServices. You can then inject that reference into other beans you create yourself.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top