-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathAuth.java
More file actions
30 lines (28 loc) · 1.5 KB
/
Copy pathAuth.java
File metadata and controls
30 lines (28 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.io.IOException;
import java.util.*;
import java.io.File;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.SAXException;
public class Auth {
public HashMap<String, String> getAuthCreds() throws IOException {
HashMap<String, String> authInstance = new HashMap<String, String>();
try {
ClassLoader classLoader = this.getClass().getClassLoader();
File authFile = new File(classLoader.getResource("auth_config.xml").getFile());
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(authFile);
doc.getDocumentElement().normalize();
authInstance.put("username", doc.getElementsByTagName("username").item(0).getTextContent());
authInstance.put("password", doc.getElementsByTagName("password").item(0).getTextContent());
authInstance.put("keystore_path", doc.getElementsByTagName("keystore_path").item(0).getTextContent());
authInstance.put("keystore_password", doc.getElementsByTagName("keystore_password").item(0).getTextContent());
authInstance.put("private_key_password", doc.getElementsByTagName("private_key_password").item(0).getTextContent());
return authInstance;
} catch (Exception e) {
System.out.println(e.getStackTrace());
throw new IOException("Failed to load Auth Config File");
}
}
}