1 23 24 package com.sun.enterprise.admin.mbeans; 25 26 import com.sun.enterprise.config.ConfigException; 27 import com.sun.enterprise.config.ConfigContext; 28 29 import com.sun.enterprise.util.i18n.StringManager; 30 import com.sun.enterprise.util.i18n.StringManagerBase; 31 32 import com.sun.enterprise.admin.config.BaseConfigMBean; 33 import com.sun.enterprise.admin.common.constant.AdminConstants; 34 35 import com.sun.enterprise.security.store.PasswordAdapter; 36 import com.sun.enterprise.security.store.IdentityManager; 37 38 import java.util.logging.Logger ; 39 import java.util.Enumeration ; 40 import java.util.ArrayList ; 41 42 import java.io.IOException ; 43 import java.security.KeyStoreException ; 44 import java.security.NoSuchAlgorithmException ; 45 import java.security.UnrecoverableKeyException ; 46 import java.security.cert.CertificateException ; 47 48 public class PasswordAliasConfigMBean extends BaseConfigMBean 49 { 50 private static final StringManager _strMgr = 51 StringManager.getManager(PasswordAliasConfigMBean.class); 52 53 private static Logger _logger = null; 54 55 private static Logger getLogger() 56 { 57 if (_logger == null) { 58 _logger = Logger.getLogger(AdminConstants.kLoggerName); 59 } 60 return _logger; 61 } 62 63 private static ExceptionHandler _handler = null; 64 65 protected static ExceptionHandler getExceptionHandler() 67 { 68 if (_handler == null) { 69 _handler = new ExceptionHandler(getLogger()); 70 } 71 return _handler; 72 } 73 74 public PasswordAliasConfigMBean() { 75 super(); 76 } 77 78 private PasswordAdapter getPasswordAdapter() 79 throws CertificateException , IOException , KeyStoreException , NoSuchAlgorithmException 80 { 81 String masterPassword = IdentityManager.getMasterPassword(); 84 return new PasswordAdapter(masterPassword.toCharArray()); 85 } 86 87 93 public void addPasswordAlias(String aliasName, String password) throws ConfigException 94 { 95 try { 96 PasswordAdapter p = getPasswordAdapter(); 97 if (p.aliasExists(aliasName)) { 98 throw new ConfigException(_strMgr.getString("passwordAliasExists", aliasName)); 99 } 100 p.setPasswordForAlias(aliasName, password.getBytes()); 101 } catch (Exception ex) { 102 throw getExceptionHandler().handleConfigException( 103 ex, "addPasswordAliasException", aliasName); 104 } 105 } 106 107 112 public void removePasswordAlias(String aliasName) throws ConfigException 113 { 114 try { 115 PasswordAdapter p = getPasswordAdapter(); 116 if (!p.aliasExists(aliasName)) { 117 throw new ConfigException(_strMgr.getString("passwordAliasDoesNotExist", aliasName)); 118 } 119 p.removeAlias(aliasName); 120 } catch (Exception ex) { 121 throw getExceptionHandler().handleConfigException( 122 ex, "removePasswordAliasException", aliasName); 123 } 124 } 125 126 132 public void updatePasswordAlias(String aliasName, String password) throws ConfigException 133 { 134 try { 135 PasswordAdapter p = getPasswordAdapter(); 136 if (!p.aliasExists(aliasName)) { 137 throw new ConfigException(_strMgr.getString("passwordAliasDoesNotExist", aliasName)); 138 } 139 p.setPasswordForAlias(aliasName, password.getBytes()); 140 } catch (Exception ex) { 141 throw getExceptionHandler().handleConfigException( 142 ex, "updatePasswordAliasException", aliasName); 143 } 144 } 145 146 151 public String [] getPasswordAliases() throws ConfigException 152 { 153 try { 154 ArrayList result = new ArrayList (); 155 Enumeration en = getPasswordAdapter().getAliases(); 156 while (en.hasMoreElements()) { 157 result.add((String )en.nextElement()); 158 } 159 return (String [])result.toArray(new String [result.size()]); 160 } catch (Exception ex) { 161 throw getExceptionHandler().handleConfigException( 162 ex, "listPasswordAliasException", ""); 163 } 164 } 165 } 166 | Popular Tags |