1 19 20 package com.sslexplorer.core.stringreplacement; 21 22 import java.util.regex.Matcher ; 23 import java.util.regex.Pattern ; 24 25 import com.sslexplorer.boot.PropertyClass; 26 import com.sslexplorer.boot.PropertyClassManager; 27 import com.sslexplorer.properties.Property; 28 import com.sslexplorer.properties.attributes.AttributeDefinition; 29 import com.sslexplorer.properties.impl.userattributes.UserAttributeKey; 30 import com.sslexplorer.properties.impl.userattributes.UserAttributes; 31 32 public class UserAttributesReplacer extends AbstractReplacementVariableReplacer { 33 34 private String username; 35 private int realm; 36 37 public UserAttributesReplacer(String username, int realm) { 38 super(); 39 this.username = username; 40 this.realm = realm; 41 } 42 43 @Override 44 public String processReplacementVariable(Pattern pattern, Matcher matcher, String replacementPattern, String type, String key) throws Exception { 45 if (type.equalsIgnoreCase("attr") || type.equals("userAttributes")) { 46 PropertyClass propertyClass = PropertyClassManager.getInstance().getPropertyClass(UserAttributes.NAME); 47 AttributeDefinition def = (AttributeDefinition) propertyClass.getDefinition(key); 48 if (def == null) { 49 VariableReplacement.log.warn("Invalid user attribute '" + key + "'"); 50 return null; 51 } else { 52 String val = Property.getProperty(new UserAttributeKey(username, key, realm)); 53 if(val.equals("")) { 54 val = def.getDefaultValue(); 55 } 56 return val; 57 } 58 } 59 return null; 60 } 61 62 } | Popular Tags |