1 17 18 package org.apache.geronimo.security.bridge; 19 20 import javax.security.auth.Subject ; 21 import javax.security.auth.callback.Callback ; 22 import javax.security.auth.callback.CallbackHandler ; 23 import javax.security.auth.callback.NameCallback ; 24 import javax.security.auth.callback.PasswordCallback ; 25 import javax.security.auth.callback.UnsupportedCallbackException ; 26 27 import org.apache.geronimo.gbean.GBeanInfo; 28 import org.apache.geronimo.gbean.GBeanInfoBuilder; 29 30 31 38 public class ConfiguredIdentityUserPasswordRealmBridge extends AbstractRealmBridge { 39 private String configuredUser; 40 private char[] configuredPassword; 41 42 public ConfiguredIdentityUserPasswordRealmBridge() { 43 } 44 45 public ConfiguredIdentityUserPasswordRealmBridge(String targetRealm, String configuredUser, String configuredPassword) { 46 super(targetRealm); 47 this.configuredUser = configuredUser; 48 setConfiguredPassword(configuredPassword); 49 } 50 51 public String getConfiguredUser() { 52 return configuredUser; 53 } 54 55 public void setConfiguredUser(String configuredUser) { 56 this.configuredUser = configuredUser; 57 } 58 59 public String getConfiguredPassword() { 60 return configuredPassword == null ? null : new String (configuredPassword); 61 } 62 63 public void setConfiguredPassword(String configuredPassword) { 64 this.configuredPassword = configuredPassword == null ? null : configuredPassword.toCharArray(); 65 } 66 67 protected CallbackHandler getCallbackHandler(Subject sourceSubject) { 68 return new CallbackHandler () { 69 public void handle(Callback [] callbacks) throws UnsupportedCallbackException { 70 for (int i = 0; i < callbacks.length; i++) { 71 Callback callback = callbacks[i]; 72 if (callback instanceof NameCallback ) { 73 ((NameCallback ) callback).setName(configuredUser); 74 } else if (callback instanceof PasswordCallback ) { 75 ((PasswordCallback ) callback).setPassword(configuredPassword); 76 } else { 77 throw new UnsupportedCallbackException (callback); 78 } 79 } 80 } 81 82 }; 83 } 84 85 public static final GBeanInfo GBEAN_INFO; 86 87 static { 88 GBeanInfoBuilder infoFactory = new GBeanInfoBuilder(ConfiguredIdentityUserPasswordRealmBridge.class, AbstractRealmBridge.GBEAN_INFO); 89 infoFactory.addAttribute("configuredUser", String .class, true); 90 infoFactory.addAttribute("configuredPassword", String .class, true); 91 infoFactory.setConstructor(new String []{"targetRealm", "configuredUser", "configuredPassword"}); 92 GBEAN_INFO = infoFactory.getBeanInfo(); 93 } 94 95 public static GBeanInfo getGBeanInfo() { 96 return GBEAN_INFO; 97 } 98 99 } 100 | Popular Tags |