1 19 package org.openharmonise.dav.server.webservice; 20 21 import java.rmi.*; 22 import java.util.*; 23 import java.util.logging.*; 24 25 import org.openharmonise.rm.config.*; 26 27 34 public class ConfigSettingsService { 35 36 39 private static final Logger m_logger = Logger.getLogger(ConfigSettingsService.class.getName()); 40 41 44 public ConfigSettingsService() { 45 super(); 46 } 47 48 56 public static ConfigProperty[] getAllProperties(String username, String password) throws RemoteException { 57 ConfigProperty[] props = null; 58 59 try { 60 authenticateSuperUser(username, password); 61 62 List propNames = ConfigSettings.getPropertyNameArray(); 63 64 props = new ConfigProperty[propNames.size()]; 65 66 for(int i=0;i<propNames.size();i++) { 67 String sName = (String ) propNames.get(i); 68 String sVal = ConfigSettings.getProperty(sName); 69 props[i] = new ConfigProperty(sName,sVal); 70 System.out.println(props[i]); 71 } 72 73 System.out.println(props.toString()); 74 75 } catch (ConfigException e) { 76 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e); 77 } 78 79 return props; 80 } 81 82 91 public static ConfigProperty[] getProperties(String username, String password, String [] propNames) throws RemoteException { 92 ConfigProperty[] props = null; 93 94 try { 95 authenticateSuperUser(username, password); 96 97 props = new ConfigProperty[propNames.length]; 98 99 for(int i=0;i<propNames.length;i++) { 100 String sName = (String ) propNames[i]; 101 String sVal = ConfigSettings.getProperty(sName); 102 props[i] = new ConfigProperty(sName,sVal); 103 System.out.println(props[i]); 104 } 105 106 System.out.println(props.toString()); 107 108 } catch (ConfigException e) { 109 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e); 110 } 111 112 return props; 113 } 114 115 124 public static void setProperties(String username, String password, ConfigProperty[] props) throws ConfigException, RemoteException { 125 126 authenticateSuperUser(username, password); 127 128 for(int i=0;i<props.length;i++) { 129 130 try { 131 ConfigSettings.setProperty(props[i].getName(), props[i].getValue()); 132 } catch (ConfigException e) { 133 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e); 134 } 135 } 136 137 } 138 139 148 public static void addProperties(String username, String password, ConfigProperty[] props) throws ConfigException, RemoteException { 149 150 151 authenticateSuperUser(username, password); 152 153 for(int i=0;i<props.length;i++) { 154 155 try { 156 ConfigSettings.insertProperty(props[i].getName(), props[i].getValue()); 157 } catch (ConfigException e) { 158 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e); 159 } 160 161 } 162 163 } 164 165 175 public static void removeProperties(String username, String password, String [] propNames) throws ConfigException, RemoteException { 176 177 authenticateSuperUser(username, password); 178 179 for(int i=0;i<propNames.length;i++) { 180 181 try { 182 ConfigSettings.removeProperty(propNames[i]); 183 } catch (ConfigException e) { 184 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e); 185 } 186 187 } 188 189 } 190 191 200 static private void authenticateSuperUser(String username, String password) throws ConfigException, RemoteException { 201 if(UserConfigService.isSuperUser(username, password) == false) { 202 throw new ConfigException("Forbidden: User is not super user"); 203 } 204 } 205 } 206 | Popular Tags |