1 19 20 package com.sslexplorer.properties.impl.systemconfig; 21 22 import java.io.IOException ; 23 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 import org.jdom.JDOMException; 27 28 import com.sslexplorer.boot.AbstractPropertyKey; 29 import com.sslexplorer.boot.AbstractXMLDefinedPropertyClass; 30 import com.sslexplorer.boot.ContextHolder; 31 import com.sslexplorer.boot.PropertyClass; 32 import com.sslexplorer.boot.PropertyDefinition; 33 import com.sslexplorer.core.CoreServlet; 34 import com.sslexplorer.properties.ProfilesFactory; 35 36 42 public class SystemConfiguration extends AbstractXMLDefinedPropertyClass { 43 44 final static Log log = LogFactory.getLog(SystemConfiguration.class); 45 46 49 public final static String NAME = "systemConfig"; 50 51 57 public SystemConfiguration() throws IOException , JDOMException { 58 super(NAME, false); 59 } 60 61 66 public String retrievePropertyImpl(AbstractPropertyKey key) throws IllegalArgumentException { 67 PropertyDefinition def = getDefinition(key.getName()); 68 try { 69 String val = ProfilesFactory.getInstance().retrieveGenericProperty( 70 key.getName(), "", "0", "0", ""); 71 if (val == null) { 72 val = def.getDefaultValue(); 73 } else { 74 if (def.getType() == PropertyDefinition.TYPE_PASSWORD) { 75 try { 76 val = ContextHolder.getContext().deobfuscatePassword(val); 77 } catch (Throwable t) { 78 log.warn( 79 "Password property " + def.getName() + " could not be decoded. It has been result to the default.", t); 80 } 81 } 82 } 83 return val; 84 } catch (Exception e) { 85 log.error("Failed to retrieve property.", e); 86 } 87 return null; 88 } 89 90 public String storePropertyImpl(AbstractPropertyKey key, String value) throws IllegalArgumentException { 91 PropertyDefinition def = getDefinition(key.getName()); 92 93 String oldValue = retrieveProperty(key); 94 95 if (def.getType() == PropertyDefinition.TYPE_PASSWORD) { 96 try { 97 value = ContextHolder.getContext().obfuscatePassword(value); 98 } catch (Throwable t) { 99 log.warn("Password property " + def.getName() + " could not be encoded.", t); 100 } 101 } 102 try { 103 ProfilesFactory.getInstance().storeGenericProperty( 104 key.getName(), "", "0", "0", "", value); 105 } catch (Exception e) { 106 log.error("Could not store properties in database."); 107 } 108 return oldValue; 109 } 110 } 111 | Popular Tags |