spring - 在 3.0.x 版本中禁用 Spring 方法安全性

标签 spring security spring-security spring-3

我有一个配置了 spring 安全性的 Web 应用程序,用于限制对 URL 和方法的访问。我想在默认情况下完全禁用它,并允许我的客户根据需要轻松打开它(他们只能访问“spring-security.xml”)。

我设法关闭了 URL 拦截,但我的方法安全性仍然启用...

有什么线索吗?

(我不想让客户改变我的 web.xml,所以不幸的是,每次修改“global-method-security”设置不是一个选项......)

这是我更新的 spring-security.xml 配置:

<http auto-config='true' use-expressions="true">
    <intercept-url pattern="/**" access="permitAll" />
    <http-basic />
    <anonymous />
</http>

我已经像这样覆盖了 DelegatingFilterProxy.doFilter 方法:

public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
            throws ServletException, IOException {
    final String springSecured = System.getProperty("springSecured");

    if (StringUtils.isNotBlank(springSecured) && springSecured.equalsIgnoreCase("true")) {
        // Call the delegate
        super.doFilter(request, response, filterChain);
    } else {
        // Ignore the DelegatingProxyFilter delegate
        filterChain.doFilter(request, response);
    }
}

这是我拥有的方法安全性的一个示例:

@RequestMapping(
        value = "applications/{applicationName}/timeout/{timeout}",
        method = RequestMethod.POST)
public
@ResponseBody
@PreAuthorize("isFullyAuthenticated() and hasPermission(#authGroups, 'deploy')")
Object deployApplication() {
    // ...
}

最佳答案

如果我是你,我不会使用自定义过滤器链实现,只是开箱即用。您可以使用嵌套元素启用和禁用 bean 配置的部分(自 Spring 3.0 起),因此这样的事情可能很方便:

<beans profile="secure">
    <http auto-config='true' use-expressions="true">...</http>
</beans>

您的应用程序现在在默认配置文件(以及除“安全”配置文件之外的任何其他配置文件)中不 protected 。您可以通过提供系统属性 spring.profiles.active=secure 或通过在上下文或 servlet 初始化程序中显式设置它来启用安全配置文件。

关于spring - 在 3.0.x 版本中禁用 Spring 方法安全性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13343469/

相关文章:

java - Spring - 获取拦截器/过滤器中给定请求的方法

java - Spring websockets Broken pipe & client 没有收到消息

linux - 共享内存性能和对其他进程的保护

php - 如何防止 PHP 中的 SQL 注入(inject)?

java - 使用spring加密敏感信息

java - Spring Security 允许 root 的所有内容,但保护其他所有内容

java - 将 JSF Managed Beans 移动到 Spring beans

java - 创建 AnnotationActionEndpointMapping bean 时出错

php - 在同一网络服务器上运行的安全网站

java - 用户名和密码未与 Spring 中的身份验证映射