Jace
Jace

Reputation: 23

Specifying JAAS config file in a local application

Here is the backstory: I am doing a project on something like a database. I'm trying to use Java Authentication and Authorisation Service(JAAS) to create a login system. I'm trying to merge this tutorial (https://docs.oracle.com/javase/7/docs/technotes/guides/security/jaas/tutorials/GeneralAcnOnly.html#SampleAcnClass) with my project.

I cannot figure out how to specify Login Configuration inside my java project itself. So far the 2 ways of specifying Login Configuration are:

  1. on the command line
  2. inside the Java securities property file

Both of which would not work as I have to submit the project and thus will not have the chance to enter a command or modify the securities property file of my grader.

Is there any other way I can specify the Login Configuration inside my project (i.e. in the *.java file)?

TLDR: how can I specify Login Configuration (the *.config files) in my project (*.java files)?

Upvotes: 2

Views: 3019

Answers (1)

Uux
Uux

Reputation: 1218

You can reference your own login configuration at runtime via java.lang.System.setProperty("java.security.auth.login.config", "=<your_config_resource_url>"). Note that the value's leading equals sign will prevent any other config referenced by the java.security file's corresponding properties from being processed. Note also that the value is a URL, hence it is not limited to local filesystem resources.

For more granular control at runtime you may also modify any java.security property via java.security.Security#setProperty.

As a last resort, when in need of a radically different syntax and/or processing capabilities, you may as well install your own custom javax.security.auth.login.Configuration, either by directly subclassing the base class, or by subclassing javax.security.auth.login.ConfigurationSpi and wrapping/exposing it to the security runtime as a java.security.Provider.

Upvotes: 3

Related Questions