WAR 中的安全配置文件放在哪里?
我正在尝试在我的 WAR 中使用 JAAS 进行身份验证。我了解我的配置文件 (另一个链接)应该放置在某个地方(如此处)。不幸的是,如果我们谈论战争,我不明白到底在哪里?以及如何命名该文件?
// JAAS has to find the file and retrieve "foo" from it
LoginContext ctx = new LoginContext("foo", this);
I'm trying to use JAAS for authentication in my WAR. I understand that my configuration file (another link) should be placed somewhere (as explained here). Unfortunately, I can't understand where exactly, if we're talking about WAR? And how to name the file?
// JAAS has to find the file and retrieve "foo" from it
LoginContext ctx = new LoginContext("foo", this);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我遇到了同样的问题,我想看看是否无法根据当前的类路径(位于战争本身内部)动态设置此属性。
显然,您需要将侦听器添加到 web.xml 中:
这样做的作用是在 Web 应用程序实例化时设置属性 java.security.auth.login.config(如果尚未定义) 。这意味着您可以将其放入源文件夹中并自动加载(如果没有在其他地方重新定义)。我已经对此进行了测试,它可以在 Tomcat 6 上运行。
因此,例如,如果您的 tomcat 安装在“C:\program files\tomcat6\”中,而您的 war 部署在“C:\program files\tomcat6\webapps\mywar”中,它找到的路径是“C:\program files\tomcat6\webapp\mywar\WEB-INF\classes”,它总是准确的。不确定这个解决方案是否也适用于其他 Web 应用程序,但我想是这样,因为 login.conf 将位于类路径根所在的位置。
希望有帮助!
I had the same problem and I wanted to see if I couldn't dynamically set this property based on the current classpath (which would be located inside the war itself).
Obviously, you need to add the listener to your web.xml:
What this does is set the property java.security.auth.login.config upon instantiation of the web application if it has not yet been defined. This means you could throw it in your source folder and load it automatically if not otherwise redefined elsewhere. I have tested this and it works on Tomcat 6.
So, for example if your tomcat installation was in "C:\program files\tomcat6\" with your war deployed in "C:\program files\tomcat6\webapps\mywar", the path it would find would be "C:\program files\tomcat6\webapp\mywar\WEB-INF\classes" which is always accurate. Not sure if this solution also works with other web applications, but I would imagine so since login.conf is going to be where the classpath root is.
Hope that helps!
可以将client_jaas.conf封装在jar中,使用代码动态指定配置
You can encapsulate the client_jaas.conf in the jar, and use the code to specify the configuration dynamically
不幸的是,我能够让它工作的唯一方法是创建一个文件
jass.conf
并使用以下任一方法指定它:在 Tomcat java 参数中:
或在 Java 代码中:
我还想知道指定配置的更好方法。我想将该配置打包到我的 WAR 中。
Unfortunately the only way I was able to get it to work was to create a file
jass.conf
and specify it using either:In the Tomcat java parameters:
or from within the Java code:
I'd also like to know a better way to specify the configuration. I want to package that configuration in my WAR.