【问题标题】:Spring Security Method Annotations -- Do they require DispatchServletSpring Security 方法注解——它们是否需要 DispatcherServlet
【发布时间】:2012-01-18 03:34:30
【问题描述】:

我正在学习 Spring Security。 (我多年前曾大量使用 Java 编程)。尽管多次阅读文档并阅读多个网站(包括 StackOverflow),但我无法让 Spring 方法 安全工作。

但是,我现在想知道是否必须实现“DispatchServlet”才能使 Spring Method Security 注释生效? (当我阅读 Spring Security 文档时,他们甚至没有引用 DispatchServlet (http://static.springsource.org/spring-security/site/docs/3.0.x/reference/springsecurity-single.html);但是,示例安全示例可以。 也就是说,我知道如果想要使用 Spring Security Authentication 模块就不需要 DispatchServlet ——似乎在这种情况下,只需使用“DelegatingProxy”过滤器就足够了。)

【问题讨论】:

  • 不,DispatchServlet 与此无关。
  • 好的,我已经尝试了几乎所有方法。有没有办法我可以通过 GoToMeeting 等方式实际支付一些帮助? (我是一个小型企业家,所以我完全没有现金,但我现在真的需要帮助。)我的电子邮件是 gsaxena888@gmail.com
  • 我与戴夫·牛顿(上图)进行了交谈。他帮助很大。长话短说:由于我使用 GWT 作为我的解决方案,因此仅使用 FilterChain 不足以让带有“@Service”注释的类成为 Spring 容器的一部分。相反,Dave 为我指明了正确的方向,我使用了“Spring4GWT”:[链接] (code.google.com/p/spring4gwt)。尽管示例中的文档并非 100% 正确(尽管它很容易修复),但它确实有效。
  • 您应该将其添加为答案并接受它;你做了所有的腿部工作,我敢打赌其他人想看看这一切是如何结束的。

标签: security spring


【解决方案1】:

除非您需要将请求分派到基于 Spring 的控制器,否则您不需要 DispatcherServlet。即,当您使用 Spring MVC 时。阅读here了解更多信息。

如果您使用的是 Spring 安全,您需要正确编写配置文件,这可以通过 web.xml 中的 ContextLoaderListener 或通过 ClassPathXmlApplicationContext- 进行加载-

web.xml 配置示例如下。此外,您还需要 Spring-Security 依赖项。

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        classpath:spring/spring-security.xml,
    </param-value>       
</context-param>

【讨论】:

    猜你喜欢
    • 2018-01-26
    • 1970-01-01
    • 2020-03-09
    • 2012-03-31
    • 2013-05-18
    • 1970-01-01
    • 2011-04-04
    • 2020-03-18
    • 2018-06-27
    相关资源
    最近更新 更多