1 19 20 package com.sslexplorer.properties.impl.realms; 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 RealmProperties extends AbstractXMLDefinedPropertyClass { 43 44 final static Log log = LogFactory.getLog(RealmProperties.class); 45 46 49 public final static String NAME = "realmProperties"; 50 51 57 public RealmProperties() 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 RealmKey realmKey = (RealmKey)key; 69 try { 70 String val = ProfilesFactory.getInstance().retrieveGenericProperty( 71 realmKey.getName(), "", "0", String.valueOf(realmKey.getRealmID()), ""); 72 if (val == null) { 73 val = def.getDefaultValue(); 74 } else { 75 if (def.getType() == PropertyDefinition.TYPE_PASSWORD) { 76 try { 77 val = ContextHolder.getContext().deobfuscatePassword(val); 78 } catch (Throwable t) { 79 log.warn( 80 "Password property " + def.getName() + " could not be decoded. It has been result to the default.", t); 81 } 82 } 83 } 84 return val; 85 } catch (Exception e) { 86 log.error("Failed to retrieve property.", e); 87 } 88 return null; 89 } 90 91 public String storePropertyImpl(AbstractPropertyKey key, String value) throws IllegalArgumentException { 92 PropertyDefinition def = getDefinition(key.getName()); 93 RealmKey realmKey = (RealmKey)key; 94 String oldValue = retrieveProperty(key); 95 96 if (def.getType() == PropertyDefinition.TYPE_PASSWORD) { 97 try { 98 value = ContextHolder.getContext().obfuscatePassword(value); 99 } catch (Throwable t) { 100 log.warn("Password property " + def.getName() + " could not be encoded.", t); 101 } 102 } 103 try { 104 ProfilesFactory.getInstance().storeGenericProperty( 105 realmKey.getName(), "", "0", String.valueOf(realmKey.getRealmID()), "", value); 106 } catch (Exception e) { 107 log.error("Could not store properties in database."); 108 } 109 return oldValue; 110 } 111 } 112 | Popular Tags |