[英]Can i set relative path to java.security.auth.login.config?
In my Spring Boot app i need to call to:在我的 Spring Boot 应用程序中,我需要调用:
System.setProperty("java.security.auth.login.config", authConf);
where authConf seems to be expected as an absolute path to the file.其中 authConf 似乎被认为是文件的绝对路径。
the problem is, my Spring Boot app is packaged and executed as a jar and i want to package the file inside the jar.问题是,我的 Spring Boot 应用程序被打包并作为 jar 执行,我想将文件打包到 jar 中。
The answer provided in this question might work only when a WAR is deployed in a server.在所提供的答案这个问题,当一个WAR被部署在一台服务器可能只工作。 It doesn't seem to work when we run JARs with embedded container.
当我们使用嵌入式容器运行 JAR 时,它似乎不起作用。
is there way i could set a relative path to java.security.auth.login.config to refer to my conf file packaged within my jar ?有什么方法可以设置 java.security.auth.login.config 的相对路径来引用我的 jar 中打包的 conf 文件?
I know that the answer is about 6 years too late, but I recently faced the same issue and found and answer.我知道答案晚了大约 6 年,但我最近遇到了同样的问题并找到并回答了。 Maybe my answer will at least help the next dev who will face this issue.
也许我的回答至少会帮助下一个面临这个问题的开发者。
I was able to solve it is by first creating a javax.security.auth.login.Configuration
of type JavaLoginConfig
and then use the Configuration.setConfiguration(configuration method)
of the same Configuration class.我能够通过首先创建一个
JavaLoginConfig
类型的javax.security.auth.login.Configuration
然后使用相同 Configuration 类的Configuration.setConfiguration(configuration method)
来解决它。 Using this method I was able to bundle our jaas.conf
inside the jar and use a relative path to it.使用这种方法,我能够将我们的
jaas.conf
捆绑在 jar 中并使用它的相对路径。
To give a concrete example:举个具体的例子:
URL configLocation=YourClass.getClassLoader().getResource("resources/jaas.conf);"
Configuration secConfig=Configuration.getInstance("JavaLoginConf", new URIParameter(configLocation.toURI());
Configuration.setConfiguration(secConfig);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.