春季安全 3.1.1
所以我做了一个自定义的记住我服务,它扩展了基于默认令牌的记住我服务,只是为了检查它是否被调用。
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices;
public class CustomTokenBasedRememberMeService extends TokenBasedRememberMeServices {
@Override
protected int calculateLoginLifetime(HttpServletRequest request, Authentication authentication) {
System.out.println("COOKIE: Process1!");
return super.calculateLoginLifetime(request, authentication);
}
@Override
protected boolean isTokenExpired(long tokenExpiryTime) {
System.out.println("COOKIE: Process2!");
return super.isTokenExpired(tokenExpiryTime);
}
@Override
protected String makeTokenSignature(long tokenExpiryTime, String username, String password) {
System.out.println("COOKIE: Process3!");
return super.makeTokenSignature(tokenExpiryTime, username, password);
}
@Override
protected String retrievePassword(Authentication authentication) {
System.out.println("COOKIE: Process4!");
return super.retrievePassword(authentication);
}
@Override
protected String retrieveUserName(Authentication authentication) {
System.out.println("COOKIE: Process5!");
return super.retrieveUserName(authentication);
}
@Override
protected UserDetails processAutoLoginCookie(String[] cookieTokens, HttpServletRequest request, HttpServletResponse response) {
System.out.println("COOKIE: Process6!");
return super.processAutoLoginCookie(cookieTokens, request, response);
}
@Override
public void onLoginSuccess(HttpServletRequest request, HttpServletResponse response, Authentication successfulAuthentication) {
System.out.println("COOKIE: Process7!");
super.onLoginSuccess(request, response, successfulAuthentication);
}
}
当我登录时,它会打印出来:
INFO: COOKIE: Process7!
INFO: COOKIE: Process5!
INFO: COOKIE: Process4!
INFO: COOKIE: Process1!
INFO: COOKIE: Process3!
这意味着它调用了 onLoginSuccess()、retrieveUserName()、retrievePassword()、calculateLoginLifetime() 和 makeTokenSignature()。
浏览器已接受 cookie,但从未处理过。即使在我删除了会话、重新启动浏览器等之后。它从未被处理过,我认为 processAutoLoginCookie 对此负责,但它也从未被调用过。
Spring Security 处理 cookie 的条件是什么?