package com.hclsoftware.sso.kerberos;

import org.apache.xmlbeans.impl.tool.CommandLine;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.nio.file.Paths;

@SpringBootApplication
public class SpringbootKerberosSsoApplication implements CommandLineRunner {
	@Value("${java.security.krb5.conf}")
	private  String adConfigLocation;
	@Value("${sun.security.krb5.debug}")
	private  String krb5Debug;
	@Value("${javax.security.auth.useSubjectCredsOnly}")
	private  String useSubjectCredsOnly;
	@Value("${com.sun.security.auth.module.Krb5LoginModule}")
	private  String krb5LoginModule;
	@Value("${com.sun.security.auth.module.Krb5LoginModule.storeKey}")
	private  String krb5LoginModuleStoreKey;
	@Value("${com.sun.security.auth.module.Krb5LoginModule.principal}")
	private  String krb5LoginModulePrincipal;
	@Value("${com.sun.security.auth.module.Krb5LoginModule.debug}")
	private  String krb5LoginModuleDebug;

	@Value("${sun.security.krb5.principal}")
	private String krb5Principal;
	@Value("${sun.security.krb5.internal.Krb5.debug}")
	private String krb5Internal;

	@Override
	public void run(String... args) throws Exception {
		System.setProperty("java.security.krb5.conf", Paths.get(adConfigLocation)
				.normalize().toAbsolutePath().toString());
		System.setProperty("sun.security.krb5.debug", krb5Debug);
		System.setProperty("java.awt.headless", "true");
		//System.setProperty("javax.security.auth.useSubjectCredsOnly", useSubjectCredsOnly);
		/*System.setProperty("com.sun.security.auth.module.Krb5LoginModule", krb5LoginModule);
		System.setProperty("com.sun.security.auth.module.Krb5LoginModule.storeKey", krb5LoginModuleStoreKey);
		System.setProperty("com.sun.security.auth.module.Krb5LoginModule.principal", krb5LoginModulePrincipal);
		System.setProperty("com.sun.security.auth.module.Krb5LoginModule.debug", krb5LoginModuleDebug);*/
		//System.setProperty("sun.security.krb5.principal", krb5Principal);
		//System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");
		//System.setProperty("java.security.auth.login.config", "C:\\Users\\KushagraG.NONPROD\\SSOLab\\SagarSSO\\src\\login.conf");
		//System.setProperty("signonHandler", "C:\\Users\\KushagraG.NONPROD\\SSOLab\\SagarSSO\\src\\login.conf");
	}

	public static void main(String[] args) {
		SpringApplication.run(SpringbootKerberosSsoApplication.class, args);
	}

}
