简体   繁体   中英

Can i set relative path to java.security.auth.login.config?

In my Spring Boot app i need to call to:

System.setProperty("java.security.auth.login.config", authConf);

where authConf seems to be expected as an absolute path to the file.

the problem is, my Spring Boot app is packaged and executed as a jar and i want to package the file inside the jar.

The answer provided in this question might work only when a WAR is deployed in a server. It doesn't seem to work when we run JARs with embedded container.

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 ?

I know that the answer is about 6 years too late, but I recently faced the same issue and found and answer. 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. Using this method I was able to bundle our jaas.conf inside the jar and use a relative path to it.

To give a concrete example:

  1. Get the URL of the security configuration file you want to use
    URL configLocation=YourClass.getClassLoader().getResource("resources/jaas.conf);"
  2. Create the JavaLoginConfig configuration
    Configuration secConfig=Configuration.getInstance("JavaLoginConf", new URIParameter(configLocation.toURI());
  3. Set the configuration to the one you created in step 2
    Configuration.setConfiguration(secConfig);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM