1 16 17 package org.jmanage.core.auth; 18 19 import org.jdom.Document; 20 import org.jdom.JDOMException; 21 import org.jdom.Element; 22 import org.jdom.input.SAXBuilder; 23 import org.jmanage.core.util.Loggers; 24 25 import java.io.File ; 26 import java.util.List ; 27 import java.util.ArrayList ; 28 import java.util.Iterator ; 29 import java.util.logging.Logger ; 30 31 37 public class RoleManager implements AuthConstants{ 38 private static long lastModified = -1; 39 private static List roles = null; 40 private static final Logger logger = Loggers.getLogger(RoleManager.class); 41 42 static{ 43 init(new File (ROLE_CONFIG_FILE_NAME)); 44 } 45 46 private RoleManager(){} 47 48 53 private static void init(File roleConfigFile) { 54 try{ 55 lastModified = roleConfigFile.lastModified(); 56 Document roleConfig = new SAXBuilder().build(roleConfigFile); 57 roles = loadUserRoles(roleConfig); 58 }catch(JDOMException jdEx){ 59 logger.info("Error reading roles "+ROLE_CONFIG_FILE_NAME); 60 jdEx.printStackTrace(); 61 } 62 } 63 64 69 public static List getAll(){ 70 File roleConfigFile = new File (ROLE_CONFIG_FILE_NAME); 71 if(lastModified < roleConfigFile.lastModified()){ 72 73 init(roleConfigFile); 74 } 75 return roles; 76 } 77 78 84 private static List loadUserRoles(Document roleConfig){ 85 List userRoles = new ArrayList (); 86 List configuredRoles = roleConfig.getRootElement().getChildren(); 87 Iterator roleIterator = configuredRoles.iterator(); 88 while(roleIterator.hasNext()){ 89 Element role = (Element)roleIterator.next(); 90 userRoles.add(new Role(role.getTextTrim())); 91 } 92 return userRoles; 93 } 94 } | Popular Tags |