1 23 package com.sun.enterprise.management.config; 24 25 import java.util.Set ; 26 import java.util.Map ; 27 28 import javax.management.ObjectName ; 29 30 import com.sun.appserv.management.config.NamedConfigElement; 31 import com.sun.appserv.management.config.DomainConfig; 32 import com.sun.appserv.management.config.SecurityMapConfig; 33 import com.sun.appserv.management.config.BackendPrincipalConfig; 34 import com.sun.appserv.management.config.ConnectorConnectionPoolConfig; 35 import com.sun.appserv.management.config.ResourceAdapterConfig; 36 37 38 import com.sun.enterprise.management.AMXTestBase; 39 import com.sun.enterprise.management.Capabilities; 40 41 import com.sun.appserv.management.util.misc.GSetUtil; 42 43 44 46 public final class SecurityMapConfigTest extends AMXTestBase 47 { 48 public 49 SecurityMapConfigTest() 50 { 51 if ( checkNotOffline( "ensureDefaultInstance" ) ) 52 { 53 ensureDefaultInstance( getDomainConfig() ); 54 } 55 } 56 57 58 public static String 59 getDefaultInstanceName() 60 { 61 return getDefaultInstanceName( "SecurityMapConfig" ); 62 } 63 64 private static final String DEFAULT_BACKEND_PRINCIPAL = "SecurityMapConfigTest.default"; 65 private static final String DEFAULT_BACKEND_PASSWORD = "changeme"; 66 private static final String [] DEFAULT_PRINCIPALS = 67 new String [] { "SecurityMapConfigTest.principal1" }; 68 private static final String [] DEFAULT_USERGROUPS = new String [0]; 69 70 public static SecurityMapConfig 71 ensureDefaultInstance( final DomainConfig domainConfig ) 72 { 73 final ConnectorConnectionPoolConfig ccpc = 74 ConnectorConnectionPoolConfigTest.ensureDefaultInstance( domainConfig ); 75 76 SecurityMapConfig result = 77 ccpc.getSecurityMapConfigMap().get( getDefaultInstanceName() ); 78 if ( result == null ) 79 { 80 result = createInstance( ccpc, 81 getDefaultInstanceName(), 82 DEFAULT_BACKEND_PRINCIPAL, 83 DEFAULT_BACKEND_PASSWORD, 84 DEFAULT_PRINCIPALS, 85 DEFAULT_USERGROUPS ); 86 } 87 88 return result; 89 } 90 91 92 private void 93 testGetters( final SecurityMapConfig smc ) 94 { 95 final String [] principalNames = smc.getPrincipalNames(); 96 final String [] userGroupNames = smc.getUserGroupNames(); 97 98 assert( principalNames != null || userGroupNames != null ) : "both principals and usergroups are null"; 99 100 final BackendPrincipalConfig bpc = smc.getBackendPrincipalConfig(); 101 assert( bpc != null ); 102 final String s = bpc.getUserName(); 103 bpc.setUserName( s ); 104 final String password = bpc.getPassword(); 105 bpc.setPassword( password ); 106 } 107 108 109 public static SecurityMapConfig 110 createInstance( 111 final ConnectorConnectionPoolConfig ccpc, 112 final String name, 113 final String backendPrincipalUsername, 114 final String backendPrincipalPassword, 115 final String [] principals, 116 final String [] userGroups ) 117 { 118 final SecurityMapConfig smc = 119 ccpc.createSecurityMapConfig( name, 120 backendPrincipalUsername, backendPrincipalPassword, 121 principals, userGroups); 122 123 return smc; 124 } 125 126 private static final String CONNECTOR_DEF_NAME = "javax.resource.cci.ConnectionFactory"; 127 128 public void 129 testCreateRemove() 130 { 131 if ( ! checkNotOffline( "testDeleteLBConfig" ) ) 132 { 133 return; 134 } 135 136 final String TEST_NAME = "SecurityMapConfigTest.testCreateRemove"; 137 final ResourceAdapterConfig rac = ResourceAdapterConfigTest.createInstance( 138 getDomainConfig(), TEST_NAME ); 139 140 try 141 { 142 final ConnectorConnectionPoolConfig ccpc = 143 ConnectorConnectionPoolConfigTest.createInstance( getDomainConfig(), 144 TEST_NAME, 145 CONNECTOR_DEF_NAME, 146 rac.getName(), null ); 147 148 try 149 { 150 final String smcName = "SecurityMapConfigTest.testCreateRemove"; 151 final String [] principals = new String [] { "SecurityMapConfigTest.testCreateRemove" }; 152 final String [] userGroups = new String [ 0 ]; 153 final SecurityMapConfig smc = createInstance( 154 ccpc, 155 smcName, 156 DEFAULT_BACKEND_PRINCIPAL, 157 DEFAULT_BACKEND_PASSWORD, 158 principals, 159 null ); 160 try 161 { 162 assert( smcName.equals( smc.getName() ) ); 163 assert( smc == ccpc.getSecurityMapConfigMap().get( smc.getName() ) ); 164 testGetters( smc ); 165 166 final Set <String > principalsBefore = GSetUtil.newSet( smc.getPrincipalNames() ); 167 final String PRINCIPAL1 = "testCreateRemove.test1"; 168 smc.createPrincipal( PRINCIPAL1 ); 169 170 final Set <String > principalsAfter = GSetUtil.newSet( smc.getPrincipalNames() ); 171 assert( principalsAfter.contains( PRINCIPAL1 ) ); 172 173 smc.removePrincipal( PRINCIPAL1 ); 174 assert( principalsBefore.equals( GSetUtil.newSet( smc.getPrincipalNames() ) ) ); 175 176 } 177 finally 178 { 179 ccpc.removeSecurityMapConfig( smc.getName() ); 180 } 181 } 182 finally 183 { 184 getDomainConfig().removeConnectorConnectionPoolConfig( ccpc.getName() ); 185 } 186 } 187 finally 188 { 189 getDomainConfig().removeResourceAdapterConfig( rac.getName() ); 190 } 191 } 192 193 } 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | Popular Tags |