简体   繁体   English

我可以设置 java.security.auth.login.config 的相对路径吗?

[英]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:举个具体的例子:

  1. Get the URL of the security configuration file you want to use获取要使用的安全配置文件的 URL
    URL configLocation=YourClass.getClassLoader().getResource("resources/jaas.conf);"
  2. Create the JavaLoginConfig configuration创建 JavaLoginConfig 配置
    Configuration secConfig=Configuration.getInstance("JavaLoginConf", new URIParameter(configLocation.toURI());
  3. Set the configuration to the one you created in step 2将配置设置为您在步骤 2 中创建的配置
    Configuration.setConfiguration(secConfig);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 带空格的路径中的java.security.auth.login.config文件 - java.security.auth.login.config file in path with space spring 启动 jar 未连接到 Kafka 代理(通过系统变量 java.security.auth.login.config 设置 client_jaas.conf) - spring boot jar not connecting to Kafka brokers ( setting client_jaas.conf through he system variable java.security.auth.login.config) Spring Security / Java配置-无法使用现有用户登录 - Spring Security/Java config - Can not login with existing user 使用UserDetailsS​​ervice和Java配置登录Spring Security - Spring Security login with UserDetailsService and Java config 如何使用来自Ant的相对路径运行Java类? - How can I run a java class with a relative path from Ant? 如何在Java中使用相对路径写入文件 - How I can write a file using relative path in Java 在jaas中我们可以使用javax.security.auth.login.Configuration类的对象作为使用.config文件的LoginModule配置的替代方法 - In jaas can we use an object of javax.security.auth.login.Configuration class as an alternative to LoginModule configuration using .config files Spring Security - 使用 java 配置的自定义预授权过滤器 - Spring Security - Custom Pre Auth filter using java config WEB-INF中配置的相对路径[Java Spring] - Relative path to config in WEB-INF [Java Spring] Java-JSP:多个登录配置和身份验证方法 - Java - JSP: Multiple login-config and auth-method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM