1 14 package org.jmanage.core.auth; 15 16 import org.jmanage.core.util.Loggers; 17 import org.jmanage.core.util.CoreUtils; 18 19 import java.util.Properties ; 20 import java.util.logging.Logger ; 21 import java.util.logging.Level ; 22 import java.io.InputStream ; 23 import java.io.FileInputStream ; 24 25 29 public class ExternalUserRolesConfig extends Properties { 30 private static final Logger logger = 31 Loggers.getLogger(ExternalUserRolesConfig.class); 32 33 private String EXTERNAL_USER_ROLES_CONFIG_FILE = CoreUtils.getConfigDir() + 34 "/external-user-roles.properties"; 35 36 private final String ASTERIX = "*"; 37 38 39 private static ExternalUserRolesConfig instance = 40 new ExternalUserRolesConfig(); 41 42 45 private ExternalUserRolesConfig(){ 46 super(); 47 try{ 48 InputStream property = 49 new FileInputStream (EXTERNAL_USER_ROLES_CONFIG_FILE); 50 load(property); 51 }catch(Exception e){ 52 logger.log(Level.SEVERE, "Error reading " + 53 EXTERNAL_USER_ROLES_CONFIG_FILE, e); 54 CoreUtils.exitSystem(); 55 } 56 } 57 58 public static ExternalUserRolesConfig getInstance(){ 59 return instance; 60 } 61 62 public String getUserRole(String username){ 63 String role = instance.getProperty(username); 64 return role != null ? role : instance.getProperty(ASTERIX); 65 } 66 } 67 | Popular Tags |