Java Spring MVC自定义身份验证

Java Spring MVC自定义身份验证,java,spring,spring-mvc,cas,Java,Spring,Spring Mvc,Cas,我需要在Spring 3.2 MVC web应用程序中包含Jasig CAS身份验证 目前我有两个JAR(CAS核心客户机和一个特定于公司的扩展),一组web.xml中的过滤器。 一旦CAS服务器重定向请求,一些会话属性就会提供记录的配置文件数据 我正在使用单例服务处理它们。 调用此服务是一个棘手的部分。我可以使用拦截器在每次控制器调用时调用我的身份验证服务吗 我很确定有更好的方法使用Spring安全性,但我无法正确理解它应该是什么样子。我最终使用了拦截器 @Component public c

我需要在Spring 3.2 MVC web应用程序中包含Jasig CAS身份验证

目前我有两个JAR(CAS核心客户机和一个特定于公司的扩展),一组web.xml中的过滤器。 一旦CAS服务器重定向请求,一些会话属性就会提供记录的配置文件数据

我正在使用单例服务处理它们。 调用此服务是一个棘手的部分。我可以使用拦截器在每次控制器调用时调用我的身份验证服务吗


我很确定有更好的方法使用Spring安全性,但我无法正确理解它应该是什么样子。

我最终使用了拦截器

@Component
public class InterceptorAuth extends HandlerInterceptorAdapter {
    @Autowired
    private IAuthService authService;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //AuthService checks session for login attributes, given through CAS servlet
        //AuthBean contains login data ; if it's null, login has failed
        AuthBean authBean = authService.getAuthBean(request);
        String reqUri = request.getRequestURI();
        String serviceName = reqUri.substring(reqUri.lastIndexOf("/") + 1, reqUri.length());
        String action = request.getParameter("action") != null ? request.getParameter("action") : "";
        //If Login failed, redirect to Error Page (Auth Controller / Error Action)
        //We let through if requested URL is Error Page itself
        //(This allows us to use a dynamic page ; unless we'll use a static HTML page called directly from here)
        if (authBean == null && !serviceName.equals("authError") && !action.equals("errorAuth")) {
            ModelAndView mv = new ModelAndView("redirect:auth.ctrl?action=errorAuth"); 
            ModelAndViewDefiningException mvde = new ModelAndViewDefiningException(mv); 
            throw mvde; 
        }
        return super.preHandle(request, response, handler);
    }
}
必需的SpringXML配置

<mvc:interceptors>
  <bean class="com.demo.sample.interceptor.InterceptorAuth"></bean>
</mvc:interceptors>