我有一个配置了spring security的Web应用程序,用于限制对URL和方法的访问.我想在默认情况下完全禁用它,并允许我的客户在需要时轻松打开它们(他们只能访问“spring-security.xml”).
任何线索?
(我不想让客户更改我的web.xml,所以不幸的是每次修改“global-method-security”设置都不是一个选项……)
这是我更新的spring-security.xml配置:
fig='true' use-expressions="true">
我已经覆盖了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起),因此这样的方法可能很方便:
fig='true' use-expressions="true">...
您的应用程序现在不受默认配置文件(以及除“安全”配置文件之外的任何其他配置文件)的保护.您可以通过提供系统属性spring.profiles.active = secure或通过在上下文或servlet初始化程序中显式设置来启用安全配置文件.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。