KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > config > SecurityMapConfigTest


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.management.config;
24
25 import java.util.Set JavaDoc;
26 import java.util.Map JavaDoc;
27
28 import javax.management.ObjectName JavaDoc;
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 /**
45  */

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 JavaDoc
59     getDefaultInstanceName()
60     {
61         return getDefaultInstanceName( "SecurityMapConfig" );
62     }
63     
64     private static final String JavaDoc DEFAULT_BACKEND_PRINCIPAL = "SecurityMapConfigTest.default";
65     private static final String JavaDoc DEFAULT_BACKEND_PASSWORD = "changeme";
66     private static final String JavaDoc[] DEFAULT_PRINCIPALS =
67         new String JavaDoc[] { "SecurityMapConfigTest.principal1" };
68     private static final String JavaDoc[] DEFAULT_USERGROUPS = new String JavaDoc[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 JavaDoc[] principalNames = smc.getPrincipalNames();
96         final String JavaDoc[] 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 JavaDoc s = bpc.getUserName();
103         bpc.setUserName( s );
104         final String JavaDoc password = bpc.getPassword();
105         bpc.setPassword( password );
106     }
107     
108     
109         public static SecurityMapConfig
110     createInstance(
111         final ConnectorConnectionPoolConfig ccpc,
112         final String JavaDoc name,
113         final String JavaDoc backendPrincipalUsername,
114         final String JavaDoc backendPrincipalPassword,
115         final String JavaDoc[] principals,
116         final String JavaDoc[] 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 JavaDoc 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 JavaDoc 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 JavaDoc smcName = "SecurityMapConfigTest.testCreateRemove";
151                 final String JavaDoc[] principals = new String JavaDoc[] { "SecurityMapConfigTest.testCreateRemove" };
152                 final String JavaDoc[] userGroups = new String JavaDoc[ 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 JavaDoc<String JavaDoc> principalsBefore = GSetUtil.newSet( smc.getPrincipalNames() );
167                     final String JavaDoc PRINCIPAL1 = "testCreateRemove.test1";
168                     smc.createPrincipal( PRINCIPAL1 );
169                     
170                     final Set JavaDoc<String JavaDoc> 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