1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 package org.ogf.graap.wsag.wsrf.bootstrap;
36
37 import javax.security.auth.login.LoginContext;
38
39 import org.apache.log4j.Logger;
40 import org.apache.muse.core.Environment;
41 import org.apache.muse.core.descriptor.DeploymentDescriptor;
42 import org.apache.muse.core.platform.AbstractIsolationLayer;
43 import org.ogf.graap.wsag.security.core.keystore.KeystoreLoginContext;
44 import org.ogf.graap.wsag.server.engine.WsagEngine;
45
46
47
48
49
50
51
52
53 public class BootstrapIsolationLayer extends AbstractIsolationLayer
54 {
55
56 private static final Logger LOG = Logger.getLogger( BootstrapIsolationLayer.class );
57
58 private String realPath = null;
59
60 private String deplomentUri = null;
61
62 private boolean testMode = false;
63
64 private boolean overrideHasBeenInitializedValue = false;
65
66 private boolean overrideHasBeenShutdownValue = false;
67
68 private boolean overrideHasFailedToInitializeValue = false;
69
70
71
72
73
74
75
76
77
78
79
80 public BootstrapIsolationLayer( String realPath, String defaultDeploymentUri )
81 {
82 this.realPath = realPath;
83 deplomentUri = defaultDeploymentUri;
84
85 if ( LOG.isDebugEnabled() )
86 {
87 LOG.debug( "create bootstrap isolation layer [real path: " + realPath + ", deployment uri: "
88 + defaultDeploymentUri + "]" );
89 }
90 }
91
92
93
94
95
96
97 protected Environment createEnvironment()
98 {
99 return new BootstrapEnvironment( realPath, WsagEngine.getGatewayURL() + "/services/WSAG4JService" );
100 }
101
102 @Override
103 protected DeploymentDescriptor createDeploymentDescriptor()
104 {
105 return new WSAG4JDeploymentDescriptor();
106 }
107
108
109
110
111 public void initialize()
112 {
113
114 LOG.info( "BootstrapIsolationLayer -> initialize" );
115
116 synchronized ( BootstrapIsolationLayer.class )
117 {
118 if ( !hasBeenInitialized() )
119 {
120 try
121 {
122 if ( LOG.isDebugEnabled() )
123 {
124 LOG.debug( "Initialize WsagEngine..." );
125 }
126
127
128
129
130 WsagEngine.initializeEngine( deplomentUri );
131
132 if ( LOG.isDebugEnabled() )
133 {
134 LOG.debug( "Build LoginContext..." );
135 }
136
137
138
139
140 LoginContext context = new KeystoreLoginContext( WsagEngine.getWSRFConfiguration() );
141 context.login();
142
143 if ( LOG.isDebugEnabled() )
144 {
145 LOG.debug( "Set LoginContext..." );
146 }
147
148
149
150
151 WsagEngine.setLoginContext( context );
152
153 if ( LOG.isDebugEnabled() )
154 {
155 LOG.debug( "Build LoginContext..." );
156 LOG.debug( "Delegate initialization to AbstractIsolationLayer..." );
157 }
158
159
160
161
162 beforeParentInitialize();
163
164
165
166
167 super.initialize();
168
169
170 setOverrideHasBeenInitializedValue( true );
171 }
172 catch ( Exception ex )
173 {
174 throw new RuntimeException(
175 "The initialization process of the WSAG4J engine failed. Reason: "
176 + ex.getMessage(), ex );
177 }
178 }
179 }
180 }
181
182
183
184
185 public void shutdown()
186 {
187
188 LOG.info( "BootstrapIsolationLayer -> shutdown" );
189
190 synchronized ( BootstrapIsolationLayer.class )
191 {
192 if ( !hasBeenShutdown() )
193 {
194 if ( LOG.isDebugEnabled() )
195 {
196 LOG.debug( "Shutting down WSAG4JResourceRouter..." );
197 }
198
199 try
200 {
201 if ( LOG.isDebugEnabled() )
202 {
203 LOG.debug( "Delegate shutdown call..." );
204 }
205
206
207 super.shutdown();
208
209
210 setOverrideHasBeenShutdownValue( true );
211
212
213 WsagEngine.shutdownEngine();
214
215 }
216 catch ( Exception ex )
217 {
218 throw new RuntimeException( "The shutdown process of the WSAG4J engine failed. Reason: "
219 + ex.getMessage(), ex );
220 }
221 }
222 }
223 }
224
225
226
227
228 protected void beforeParentInitialize()
229 {
230 }
231
232
233
234
235
236
237
238 public void setTestMode( boolean testMode )
239 {
240 this.testMode = testMode;
241 }
242
243 @Override
244 public boolean hasBeenInitialized()
245 {
246 if ( testMode )
247 {
248 return overrideHasBeenInitializedValue;
249 }
250 else
251 {
252 return super.hasBeenInitialized();
253 }
254 }
255
256 @Override
257 public boolean hasBeenShutdown()
258 {
259 if ( testMode )
260 {
261 return overrideHasBeenShutdownValue;
262 }
263 else
264 {
265 return super.hasBeenShutdown();
266 }
267 }
268
269 @Override
270 public boolean hasFailedToInitialize()
271 {
272 if ( testMode )
273 {
274 return overrideHasFailedToInitializeValue;
275 }
276 else
277 {
278 return super.hasFailedToInitialize();
279 }
280 }
281
282
283
284
285
286 public boolean isOverrideHasBeenInitializedValue()
287 {
288 return overrideHasBeenInitializedValue;
289 }
290
291
292
293
294
295
296 public void setOverrideHasBeenInitializedValue( boolean overrideHasBeenInitializedValue )
297 {
298 this.overrideHasBeenInitializedValue = overrideHasBeenInitializedValue;
299 }
300
301
302
303
304
305 public boolean isOverrideHasBeenShutdownValue()
306 {
307 return overrideHasBeenShutdownValue;
308 }
309
310
311
312
313
314 public void setOverrideHasBeenShutdownValue( boolean overrideHasBeenShutdownValue )
315 {
316 this.overrideHasBeenShutdownValue = overrideHasBeenShutdownValue;
317 }
318
319
320
321
322
323 public boolean isOverrideHasFailedToInitializeValue()
324 {
325 return overrideHasFailedToInitializeValue;
326 }
327
328
329
330
331
332 public void setOverrideHasFailedToInitializeValue( boolean overrideHasFailedToInitializeValue )
333 {
334 this.overrideHasFailedToInitializeValue = overrideHasFailedToInitializeValue;
335 }
336 }