1 23 24 25 package com.sun.enterprise.management.offline; 26 27 import java.util.Set ; 28 29 import javax.management.AttributeNotFoundException ; 30 31 import com.sun.enterprise.config.ConfigContext; 32 import com.sun.enterprise.config.ConfigBean; 33 import com.sun.enterprise.config.ConfigException; 34 35 import com.sun.appserv.management.config.AuthRealmConfig; 36 37 import com.sun.appserv.management.util.misc.GSetUtil; 38 import com.sun.appserv.management.util.misc.StringUtil; 39 40 41 final class AuthRealmConfigBeanHelper extends StdConfigBeanHelper 42 { 43 private AuthRealmSupport mSupport; 44 45 public 46 AuthRealmConfigBeanHelper( 47 final ConfigContext configContext, 48 final ConfigBean configBean ) 49 { 50 super( configContext, configBean ); 51 52 mSupport = createSupport(); 53 } 54 55 private static final String TEMPLATE_PREFIX = "${"; 56 57 private AuthRealmSupport 58 createSupport() 59 { 60 AuthRealmSupport support = null; 61 62 if ( isStdFileRealm() ) 63 { 64 String file = null; 65 try 66 { 67 file = getFile(); 68 } 69 catch( Exception e ) 70 { 71 } 73 74 if ( file != null && file.indexOf( TEMPLATE_PREFIX ) < 0 ) 75 { 76 support = new AuthRealmSupport( this ); 77 } 78 else if ( file != null ) 79 { 80 } 82 } 83 84 return support; 85 } 86 87 private boolean 88 isStdFileRealm() 89 { 90 return AuthRealmConfig.DEFAULT_REALM_CLASSNAME.equals( getClassname() ); 91 } 92 93 private void 94 checkRealmType() 95 { 96 if ( ! isStdFileRealm() ) 97 { 98 throw new IllegalArgumentException ( 99 "AuthRealm type " + getClassname() +" not supported." ); 100 } 101 } 102 103 private static final String USER_NAMES_ATTR = "UserNames"; 104 private static final String GROUP_NAMES_ATTR = "GroupNames"; 105 106 protected Set <String > 107 _getAttributeNames() 108 { 109 final Set <String > attrNames = super._getAttributeNames(); 110 111 if ( isStdFileRealm() ) 112 { 113 attrNames.add( GROUP_NAMES_ATTR ); 114 attrNames.add( USER_NAMES_ATTR ); 115 } 116 117 return attrNames; 118 } 119 120 protected Class 121 getAttributeClass( final String attrName ) 122 { 123 Class result = null; 124 125 if ( isStdFileRealm() && 126 ( GROUP_NAMES_ATTR.equals( attrName ) || 127 USER_NAMES_ATTR.equals( attrName ) ) ) 128 { 129 result = String [].class; 130 } 131 else 132 { 133 result = super.getAttributeClass( attrName ); 134 } 135 return result; 136 } 137 138 public Object 139 getAttribute( final String attrName ) 140 throws AttributeNotFoundException 141 { 142 Object result = null; 143 144 if ( GROUP_NAMES_ATTR.equals( attrName ) ) 145 { 146 checkRealmType(); 147 result = mSupport.getGroupNames(); 148 } 150 else if ( USER_NAMES_ATTR.equals( attrName ) ) 151 { 152 checkRealmType(); 153 result = mSupport.getUserNames(); 154 } 156 else 157 { 158 result = super.getAttribute( attrName ); 159 } 160 return result; 161 } 162 163 static private final Set <String > SUPPORTED_OPERATIONS = 164 GSetUtil.newUnmodifiableStringSet( 165 "getUserGroupNames", "addUser", "updateUser", "removeUser" ); 166 167 public Object 168 handleInvoke( 169 String operationName, 170 Object [] args, 171 String [] types ) 172 { 173 Object result = null; 174 final int numArgs = args == null ? 0 : args.length; 175 176 if ( isStdFileRealm() && 177 SUPPORTED_OPERATIONS.contains( operationName ) && numArgs >= 1 ) 178 { 179 final String user = (String )args[ 0 ]; 180 181 if ( operationName.equals( "getUserGroupNames" ) && numArgs == 1) 182 { 183 result = mSupport.getUserGroupNames( user ); 184 } 185 else if ( operationName.equals( "addUser" ) && numArgs == 3) 186 { 187 final String password = (String )args[ 1 ]; 188 final String [] groupList = (String [])args[ 2 ]; 189 mSupport.addUser( user, password, groupList ); 190 } 191 else if ( operationName.equals( "updateUser" ) && numArgs == 3) 192 { 193 final String password = (String )args[ 1 ]; 194 final String [] groupList = (String [])args[ 2 ]; 195 mSupport.updateUser( user, password, groupList ); 196 } 197 else if ( operationName.equals( "removeUser" ) && numArgs == 1) 198 { 199 mSupport.removeUser( user ); 200 } 201 else 202 { 203 unsupportedOperation( operationName, args, types ); 204 } 205 } 206 else 207 { 208 unsupportedOperation( operationName, args, types ); 209 } 210 212 return result; 213 } 214 215 public String 216 getFile() 217 { 218 return getPropertyValue( "file" ); 219 } 220 221 222 public String 223 getClassname() 224 { 225 try 226 { 227 return (String )getAttribute( "Classname" ); 228 } 229 catch( AttributeNotFoundException e ) 230 { 231 e.printStackTrace(); 232 throw new RuntimeException ( e ); 233 } 234 } 235 } 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | Popular Tags |