我正在尝试制作自定义 AuthenticationProcessingFilter 以在成功登录后在会话中保存一些用户数据
这是我的过滤器:
package projects.internal;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.Authentication;
import org.springframework.security.ui.webapp.AuthenticationProcessingFilter;
public class MyAuthenticationProcessingFilter extends AuthenticationProcessingFilter {
protected void onSuccessfulAuthentication(HttpServletRequest request,
HttpServletResponse response, Authentication authResult)
throws IOException {
super.onSuccessfulAuthentication(request, response, authResult);
request.getSession().setAttribute("myValue", "My value is set");
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的 security.xml 文件
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
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.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.0.xsd">
<global-method-security pre-post-annotations="enabled">
</global-method-security>
<http use-expressions="true" auto-config="false" entry-point-ref="authenticationProcessingFilterEntryPoint">
<intercept-url pattern="/" access="permitAll" />
<intercept-url pattern="/images/**" filters="none" />
<intercept-url pattern="/scripts/**" filters="none" />
<intercept-url pattern="/styles/**" filters="none" />
<intercept-url pattern="/p/login.jsp" filters="none" …
Run Code Online (Sandbox Code Playgroud) 我想获得格林威治标准时间的当前时间戳; 任何想法如何做到这一点?
我设法得到gmt格式的字符串问题是我想将此字符串转换为等效的时间戳对象,即同一时间但作为时间戳对象
SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss zzz");
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
Date date=new Date();
String s=sdf.format(date);
System.out.println("GMT: "+s);
//need to convert the string to equivalent timestamp object
Run Code Online (Sandbox Code Playgroud)