外部化Spring Security配置?

编程入门 行业动态 更新时间:2024-10-14 14:20:16
本文介绍了外部化Spring Security配置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个Web应用程序,该应用程序已经可以与Spring Security的几种不同配置一起使用.但是,这些差异配置都是在我的applicationContext配置文件中设置的.因此,为了在客户站点上进行调整,必须在WAR文件中对其进行修改.如果客户手动修改WAR文件,则在重新部署新的WAR之后,他们将丢失所做的更改.

I have a web application that works with several different configurations of Spring Security already. However, these difference configuration are all setup within my applicationContext configuration file. Therefore, in order to tweak these at a customer site, these would have to be modified INSIDE the WAR file. If customers manually modify the WAR file, then they'll lose their changes after redeploying a new WAR.

是否有一种可以外部化此配置的方法?有什么办法可以使用JNDI加载配置吗?

Is there a way to externalize this configuration? Is there a way I can load the configuration using JNDI somehow?

推荐答案

这是一个有趣的问题.由于应该在根webapp上下文中配置Spring Security,因此您不能将其配置外部化到其他上下文.同样,您不能从上下文内部更改配置资源集.因此,您应该从外部进行操作:

It's an interesting question. Since Spring Security should be configured in root webapp context, you can't externalize its configuration to other contexts. Also you can't change the set of config resources from inside the context. So, you should do it from outside:

  • 您可以使用众所周知的文件系统位置:

  • You can use a well-known file system location:

<context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/applicationContext.xml file:///C:\config.xml </param-value> </context-param>

  • 系统属性在contextConfigLocation中解析,因此您可以使用它:

  • System properties are resolved in contextConfigLocation, so you can use it:

    <context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/applicationContext.xml file:///${configPath} </param-value> </context-param>

    和-DconfigPath=...

    您可以覆盖XmlWebApplicationContext.getResource()并实现您想要的任何东西:

    You can override XmlWebApplicationContext.getResource() and implement whatever you want:

    public class MyXmlWebApplicationContext extends XmlWebApplicationContext { private static final String JNDI_PREFIX = "jndi:/"; @Override public Resource getResource(String location) { if (location.startsWith(JNDI_PREFIX)) return getJndiResource(location); else return super.getResource(location); } protected Resource getJndiResource(String location) { ... } }

    <context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/applicationContext.xml jndi:/... </param-value> </context-param> <context-param> <param-name>contextClass</param-name> <param-value>com.example.MyXmlWebApplicationContext</param-value> </context-param>

  • 更多推荐

    外部化Spring Security配置?

    本文发布于:2023-11-25 20:41:07,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1631274.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:Spring   Security

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!