1 23 24 package com.sun.enterprise.admin.server.core.mbean.config; 25 26 import javax.management.*; 28 29 import com.sun.enterprise.config.ConfigException; 31 import com.sun.enterprise.config.serverbeans.ServerTags; 32 import com.sun.enterprise.config.serverbeans.ServerXPathHelper; 33 import com.sun.enterprise.config.serverbeans.SecurityService; 34 import com.sun.enterprise.config.serverbeans.AuthRealm; 35 36 import com.sun.enterprise.admin.common.exception.MBeanConfigException; 38 import com.sun.enterprise.admin.common.constant.ConfigAttributeName; 39 import com.sun.enterprise.admin.common.exception.AFOtherException; 40 import com.sun.enterprise.admin.common.ObjectNames; 41 42 import com.sun.enterprise.util.i18n.StringManager; 44 45 51 public class ManagedSecurityService extends ConfigMBeanBase implements ConfigAttributeName.SecurityService 52 { 53 56 private static final String [][] MAPLIST = 57 { 58 {kDefaultRealm , ATTRIBUTE + ServerTags.DEFAULT_REALM}, 59 {kDefaultPrincipal , ATTRIBUTE + ServerTags.DEFAULT_PRINCIPAL}, 60 {kDefaultPrincipalPassword , ATTRIBUTE + ServerTags.DEFAULT_PRINCIPAL_PASSWORD}, 61 {kAnonymousRole , ATTRIBUTE + ServerTags.ANONYMOUS_ROLE}, 62 {kAuditEnabled , ATTRIBUTE + ServerTags.AUDIT_ENABLED}, 63 }; 65 68 private static final String [] ATTRIBUTES = 69 { 70 kDefaultRealm + ", String, RW" , 71 kDefaultPrincipal + ", String, RW" , 72 kDefaultPrincipalPassword + ", String, RW" , 73 kAnonymousRole + ", String, RW" , 74 kAuditEnabled + ", boolean, RW" , 75 }; 77 80 private static final String [] OPERATIONS = 81 { 82 "createAuthRealm(String name, String classname), ACTION", 83 "deleteAuthRealm(String id), ACTION", 84 "listAuthRealms(), INFO", 85 }; 86 87 88 private static StringManager localStrings = 90 StringManager.getManager( ManagedSecurityService.class ); 91 92 95 public ManagedSecurityService() throws MBeanConfigException 96 { 97 this.setDescriptions(MAPLIST, ATTRIBUTES, OPERATIONS); 98 } 99 100 104 public ManagedSecurityService(String instanceName) throws MBeanConfigException 105 { 106 this(); initialize(ObjectNames.kSecurityServiceType, new String []{instanceName}); 108 } 109 110 114 public void createAuthRealm(String name, String classname) throws ConfigException 115 { 116 AuthRealm authRealm = new AuthRealm(); 117 if(name!=null) 118 authRealm.setName(name); 119 if(classname!=null) 120 authRealm.setClassname(classname); 121 SecurityService securityService = (SecurityService)getConfigBeanByXPath( ServerXPathHelper.getSecurityServiceXpath() ); 122 securityService.addAuthRealm(authRealm); 123 124 getConfigContext().flush(); 125 } 126 127 131 public void deleteAuthRealm(String id) throws ConfigException, MBeanException, AttributeNotFoundException 132 { 133 SecurityService securityService = (SecurityService)getConfigBeanByXPath( ServerXPathHelper.getSecurityServiceXpath() ); 134 AuthRealm authRealm = securityService.getAuthRealmByName(id); 135 if(((String ) getAttribute(kDefaultRealm)).equals(id)){ 136 String msg = localStrings.getString( "admin.server.core.mbean.config.default_realm_cannot_delete", id ); 137 throw new ConfigException( msg ); 138 } 139 140 if(authRealm!=null) 141 securityService.removeAuthRealm(authRealm); 142 getConfigContext().flush(); 143 } 144 145 148 public String [] listAuthRealms() throws ConfigException 149 { 150 SecurityService securityService = (SecurityService)getConfigBeanByXPath( ServerXPathHelper.getSecurityServiceXpath() ); 151 AuthRealm[] authRealms = securityService.getAuthRealm(); 152 String [] res = new String [authRealms.length]; 153 for(int i=0; i<authRealms.length; i++) 154 { 155 res[i] = authRealms[i].getName(); 156 } 157 return res; 158 } 159 } 160 161 162 163 164 165 166 | Popular Tags |