- private String authFilename;
- public ObjectMapper mapper;
-
- private static enum HTTP_METHODS {
- POST, GET, PUT, DELETE, PATCH
- }
-
- public AuthCore(String filename) throws Exception {
- this.authFilename = filename;
- loadUsers(filename);
- }
-
- private static boolean usersInitialized = false;
- private static HashMap<String, AuthUser> users;
-
- public String getConfigFile() {
- return this.authFilename;
- }
-
- /**
- * Loads the auth file and caches a list of authorized users.
- * @param authFilename
- * - Absolute path of the file where authorized users are listed.
- */
- public synchronized void loadUsers(String authFilename) throws Exception {
- users = new HashMap<String, AuthUser>();
-
- mapper = new ObjectMapper(); // can reuse, share globally
- JsonNode rootNode = mapper.readTree(new File(authFilename));
- JsonNode rolesNode = rootNode.path(AuthConstants.rolesNodePath);
-
- for (JsonNode roleNode : rolesNode) {
- String roleName = roleNode.path(AuthConstants.roleNamePath).asText();
-
- AuthRole role = new AuthRole();
- JsonNode usersNode = roleNode.path(AuthConstants.usersNodePath);
- JsonNode functionsNode = roleNode.path(AuthConstants.functionsNodePath);
- for (JsonNode functionNode : functionsNode) {
- String function = functionNode.path(AuthConstants.functionNamePath).asText();
- JsonNode methodsNode = functionNode.path(AuthConstants.methodsNodePath);
- boolean hasMethods = false;
- for (JsonNode methodNode : methodsNode) {
- String methodName = methodNode.path(AuthConstants.methodNamePath).asText();
- hasMethods = true;
- String thisFunction = methodName + ":" + function;
+ private String authFilename;
+ public ObjectMapper mapper;
+
+ private enum HTTP_METHODS {
+ POST, GET, PUT, DELETE, PATCH
+ }
+
+ public AuthCore(String filename) throws Exception {
+ this.authFilename = filename;
+ loadUsers(filename);
+ }
+
+ private static boolean usersInitialized = false;
+ private static HashMap<String, AuthUser> users;
+
+ public String getConfigFile() {
+ return this.authFilename;
+ }