package org.aktin.broker.auth.apikey;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;

import org.aktin.broker.server.auth.AbstractAuthProviderFactory;

public class ApiKeyPropertiesAuthProvider extends AbstractAuthProviderFactory {

	@Override
	public PropertyFileAPIKeys getInstance() throws IOException {

		PropertyFileAPIKeys auth;
		try( InputStream in = Files.newInputStream(path.resolve("api-keys.properties")) ){
			auth = new PropertyFileAPIKeys(in);
		}
//		if( System.getProperty("rewriteNodeDN") != null ){
//			int count = BrokerImpl.updatePrincipalDN(ds, keys.getMap());
//			// output/log what happened, use count returned from above method
//			System.out.println("Rewritten "+count+" node DN strings.");
//		}

		return auth;
	}
}

@@ -267,19 +267,43 @@
 y %7B%0A
-%0A%09@Override
+%09private PropertyFileAPIKeys keys;%0A
 %0A%09pu
@@ -311,92 +311,375 @@
 lic 
+ApiKey
 Propert
-yFileAPIKeys getInstance() throws IOException %7B%0A%0A%09%09PropertyFileAPIKeys auth;%0A
+iesAuthProvider() %7B%0A%09%09keys = null; // lazy init, load later in getInstance by using supplied path%0A%09%7D%0A%09public ApiKeyPropertiesAuthProvider(InputStream in) throws IOException %7B%0A%09%09this.keys = new PropertyFileAPIKeys(in);%0A%09%7D%0A%0A%0A%09@Override%0A%09public PropertyFileAPIKeys getInstance() throws IOException %7B%0A%09%09if( this.keys == null ) %7B%0A%09%09%09// not previously loaded%0A%09
 %09%09tr
@@ -762,20 +762,26 @@
 ) )%7B%0A%09%09%09
-auth
+%09this.keys
  = new P
@@ -806,17 +806,87 @@
 (in);%0A%09%09
-%7D
+%09%7D%0A%09%09%7Delse %7B%0A%09%09%09;// already loaded, use existing one%0A%09%09%7D%0A%09%09return keys;
 %0A//%09%09if(
@@ -1144,24 +1144,8 @@
 /%09%09%7D
-%0A%0A%09%09return auth;
 %0A%09%7D%0A

allow direct initialization with property file input stream