Noa*_*erg 6 security spring spring-security spring-3
我有一个配置了spring security的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>
Run Code Online (Sandbox Code Playgroud)
我已经覆盖了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);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我拥有的方法安全性的一个例子:
@RequestMapping(
value = "applications/{applicationName}/timeout/{timeout}",
method = RequestMethod.POST)
public
@ResponseBody
@PreAuthorize("isFullyAuthenticated() and hasPermission(#authGroups, 'deploy')")
Object deployApplication() {
// ...
}
Run Code Online (Sandbox Code Playgroud)
如果我是你,我不会使用自定义过滤器链实现,而只会使用开箱即用的过滤器链实现。您可以使用嵌套元素启用和禁用 bean 配置部分(自 Spring 3.0 起),因此类似这样的操作可能会很方便:
<beans profile="secure">
<http auto-config='true' use-expressions="true">...</http>
</beans>
Run Code Online (Sandbox Code Playgroud)
您的应用程序现在在默认配置文件(以及除“安全”配置文件之外的任何其他配置文件)中不受保护。您可以通过提供系统属性 spring.profiles.active=secure 或通过在上下文或 servlet 初始值设定项中显式设置它来启用安全配置文件。
| 归档时间: |
|
| 查看次数: |
703 次 |
| 最近记录: |