1 17 18 package org.apache.geronimo.security.bridge; 19 20 import java.io.IOException ; 21 import java.net.URL ; 22 import java.util.Iterator ; 23 import java.util.Map ; 24 import java.util.Properties ; 25 import java.util.StringTokenizer ; 26 27 import org.apache.geronimo.gbean.GBeanInfo; 28 import org.apache.geronimo.gbean.GBeanInfoBuilder; 29 30 31 41 public class PropertiesFilePrincipalMappingUserPasswordRealmBridge extends AbstractPrincipalMappingUserPasswordRealmBridge { 42 private URL propertyFileURL; 43 44 public PropertiesFilePrincipalMappingUserPasswordRealmBridge() { 45 } 46 47 public PropertiesFilePrincipalMappingUserPasswordRealmBridge(String targetRealm, 48 Class principalSourceType, 49 String principalTargetCallbackName, 50 Class userNameSourceType, 51 String userNameTargetCallbackName, 52 Class passwordSourceType, 53 URL propertyFileURL) { 54 55 super(targetRealm, 56 principalSourceType, 57 principalTargetCallbackName, 58 userNameSourceType, 59 userNameTargetCallbackName, 60 passwordSourceType); 61 this.propertyFileURL = propertyFileURL; 62 } 63 64 public URL getPropertyFileURL() { 65 return propertyFileURL; 66 } 67 68 public void setPropertyFileURL(URL propertyFileURL) throws IOException { 69 this.propertyFileURL = propertyFileURL; 70 principalMap.clear(); 71 userNameMap.clear(); 72 passwordMap.clear(); 73 Properties properties = new Properties (); 74 properties.load(propertyFileURL.openStream()); 75 setMaps(properties, principalMap, userNameMap, passwordMap); 76 } 77 78 void setMaps(Properties properties, Map principalMap, Map userNameMap, Map passwordMap) { 79 for (Iterator iterator = properties.entrySet().iterator(); iterator.hasNext();) { 80 Map.Entry entry = (Map.Entry ) iterator.next(); 81 String key = (String ) entry.getKey(); 82 String values = (String ) entry.getValue(); 83 StringTokenizer tokenizer = new StringTokenizer (values, ":"); 84 String targetPrincipal = tokenizer.nextToken(); 85 String targetUserName = tokenizer.nextToken(); 86 char[] targetPassword = tokenizer.nextToken().toCharArray(); 87 principalMap.put(key, targetPrincipal); 88 userNameMap.put(key, targetUserName); 89 passwordMap.put(key, targetPassword); 90 } 91 } 92 93 public static final GBeanInfo GBEAN_INFO; 94 95 static { 96 GBeanInfoBuilder infoFactory = new GBeanInfoBuilder(PropertiesFilePrincipalMappingUserPasswordRealmBridge.class, AbstractPrincipalMappingUserPasswordRealmBridge.GBEAN_INFO); 97 infoFactory.addAttribute("propertyFileURL", URL .class, true); 98 infoFactory.setConstructor(new String []{"targetRealm", "principalSourceType", "principalTargetCallbackName", "userNameSourceType", "userNameTargetCallbackName", "passwordSourceType", "propertyFileURL"}); 99 GBEAN_INFO = infoFactory.getBeanInfo(); 100 } 101 102 public static GBeanInfo getGBeanInfo() { 103 return GBEAN_INFO; 104 } 105 106 } 107 | Popular Tags |