小编use*_*682的帖子

15
推荐指数
1
解决办法
4万
查看次数

在 Spring Security 中添加自定义过滤器

我正在尝试制作自定义 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)

spring-security

3
推荐指数
1
解决办法
2万
查看次数

如何获得格林威治标准时间的当前时间?

可能重复:
如何在Java中获取UTC或GMT中的当前日期和时间?

我想获得格林威治标准时间的当前时间戳; 任何想法如何做到这一点?


我设法得到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)

java date gmt

2
推荐指数
1
解决办法
3万
查看次数

标签 统计

java ×2

date ×1

gmt ×1

javascript ×1

jsp ×1

spring-security ×1

timezone ×1