1 19 20 package com.sslexplorer.properties.impl.policyattributes; 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.ContextHolder; 30 import com.sslexplorer.boot.PropertyClass; 31 import com.sslexplorer.boot.PropertyDefinition; 32 import com.sslexplorer.core.CoreServlet; 33 import com.sslexplorer.properties.ProfilesFactory; 34 import com.sslexplorer.properties.attributes.AbstractXMLDefinedAttributesPropertyClass; 35 import com.sslexplorer.properties.attributes.AttributeDefinition; 36 import com.sslexplorer.properties.attributes.DefaultAttributeDefinition; 37 38 43 public class PolicyAttributes extends AbstractXMLDefinedAttributesPropertyClass { 44 45 final static Log log = LogFactory.getLog(PolicyAttributes.class); 46 47 50 public final static String NAME = "policyAttributes"; 51 52 58 public PolicyAttributes() throws IOException , JDOMException { 59 super(NAME, false, "properties", false); 60 } 61 62 public String retrievePropertyImpl(AbstractPropertyKey key) 63 throws IllegalArgumentException { 64 AttributeDefinition def = (AttributeDefinition) getDefinition(key 65 .getName()); 66 PolicyAttributeKey policyAttrKey = (PolicyAttributeKey) key; 67 try { 68 String val = ProfilesFactory.getInstance() 69 .retrieveAttributeValue(policyAttrKey); 70 71 if (def.getType() == PropertyDefinition.TYPE_PASSWORD 73 && val != null) { 74 try { 75 val = ContextHolder.getContext().deobfuscatePassword(val); 76 } catch (Throwable t) { 77 log 78 .warn( 79 "Password property " 80 + def.getName() 81 + " could not be decoded. It has been result to the default.", 82 t); 83 } 84 } 85 return val == null ? def.getDefaultValue() : val; 87 } catch (Exception e) { 88 log.error("Failed to retrieve property.", e); 89 } 90 return null; 91 } 92 93 public String storePropertyImpl(AbstractPropertyKey key, String value) 94 throws IllegalArgumentException { 95 AttributeDefinition def = (AttributeDefinition) getDefinition(key 96 .getName()); 97 PolicyAttributeKey policyAttrKey = (PolicyAttributeKey) key; 98 String oldValue = retrieveProperty(key); 99 if (def.getDefaultValue().equals(value)) { 100 value = null; 101 } 102 103 if ((oldValue == null && value != null) 104 || (oldValue != null && value == null) 105 || !oldValue.equals(value)) { 106 107 109 if (def.getType() == PropertyDefinition.TYPE_PASSWORD) { 110 try { 111 value = ContextHolder.getContext().obfuscatePassword(value); 112 } catch (Throwable t) { 113 log.warn("Password property " + def.getName() 114 + " could not be encoded.", t); 115 } 116 } 117 118 try { 120 ProfilesFactory.getInstance() 121 .storeAttributeValue(policyAttrKey, value); 122 } catch (Exception e) { 123 log.error("Failed to update user attributes.", e); 124 } 125 } 126 return oldValue; 127 } 128 129 public AttributeDefinition createAttributeDefinition(int type, String name, 130 String typeMeta, int category, String categoryLabel, 131 String defaultValue, int visibility, int sortOrder, 132 String messageResourcesKey, boolean hidden, String label, 133 String description, boolean system, boolean replaceable, 134 String validationString) { 135 AttributeDefinition def = new DefaultAttributeDefinition(type, name, typeMeta, category, 136 categoryLabel, defaultValue, visibility, sortOrder, 137 messageResourcesKey, hidden, label, description, system, 138 replaceable, validationString); 139 def.init(this); 140 return def; 141 } 142 } 143 | Popular Tags |