|
1
|
|
|
|
2
|
|
/*
|
|
3
|
|
* JBoss, the OpenSource J2EE webOS
|
|
4
|
|
*
|
|
5
|
|
* Distributable under LGPL license.
|
|
6
|
|
* See terms of license at gnu.org.
|
|
7
|
|
*
|
|
8
|
|
*/
|
|
9
|
|
|
|
10
|
|
package org.jboss.resource.connectionmanager;
|
|
11
|
|
|
|
12
|
|
|
|
13
|
|
|
|
14
|
|
import java.io.Serializable;
|
|
15
|
|
import java.lang.SecurityException;
|
|
16
|
|
import java.security.Principal;
|
|
17
|
|
import java.util.ArrayList;
|
|
18
|
|
import java.util.Collection;
|
|
19
|
|
import java.util.Collections;
|
|
20
|
|
import java.util.HashMap;
|
|
21
|
|
import java.util.HashSet;
|
|
22
|
|
import java.util.Iterator;
|
|
23
|
|
import java.util.LinkedList;
|
|
24
|
|
import java.util.List;
|
|
25
|
|
import java.util.Map;
|
|
26
|
|
import java.util.Set;
|
|
27
|
|
import javax.management.ListenerNotFoundException;
|
|
28
|
|
import javax.management.MBeanNotificationInfo;
|
|
29
|
|
import javax.management.Notification;
|
|
30
|
|
import javax.management.NotificationBroadcaster;
|
|
31
|
|
import javax.management.NotificationBroadcasterSupport;
|
|
32
|
|
import javax.management.NotificationFilter;
|
|
33
|
|
import javax.management.NotificationListener;
|
|
34
|
|
import javax.management.ObjectName;
|
|
35
|
|
import javax.naming.InitialContext;
|
|
36
|
|
import javax.resource.ResourceException;
|
|
37
|
|
import javax.resource.ResourceException;
|
|
38
|
|
import javax.resource.spi.ConnectionEventListener;
|
|
39
|
|
import javax.resource.spi.ConnectionManager;
|
|
40
|
|
import javax.resource.spi.ConnectionManager;
|
|
41
|
|
import javax.resource.spi.ConnectionRequestInfo;
|
|
42
|
|
import javax.resource.spi.ConnectionRequestInfo;
|
|
43
|
|
import javax.resource.spi.ManagedConnection;
|
|
44
|
|
import javax.resource.spi.ManagedConnectionFactory;
|
|
45
|
|
import javax.resource.spi.ManagedConnectionFactory;
|
|
46
|
|
import javax.security.auth.Subject;
|
|
47
|
|
import javax.transaction.SystemException;
|
|
48
|
|
import javax.transaction.Transaction;
|
|
49
|
|
import javax.transaction.TransactionManager;
|
|
50
|
|
import org.jboss.deployment.DeploymentException;
|
|
51
|
|
import org.jboss.logging.Logger;
|
|
52
|
|
import org.jboss.management.j2ee.JCAConnectionFactory;
|
|
53
|
|
import org.jboss.management.j2ee.JCAManagedConnectionFactory;
|
|
54
|
|
import org.jboss.security.SecurityAssociation;
|
|
55
|
|
import org.jboss.security.SecurityDomain;
|
|
56
|
|
import org.jboss.security.SubjectSecurityManager;
|
|
57
|
|
import org.jboss.security.plugins.JaasSecurityManagerServiceMBean;
|
|
58
|
|
import org.jboss.system.Registry;
|
|
59
|
|
import org.jboss.system.ServiceMBean;
|
|
60
|
|
import org.jboss.system.ServiceMBeanSupport;
|
|
61
|
|
import org.jboss.util.jmx.JMXExceptionDecoder;
|
|
62
|
|
import org.jboss.util.jmx.MBeanServerLocator;
|
|
63
|
|
|
|
64
|
|
|
|
65
|
|
/**
|
|
66
|
|
* The BaseConnectionManager2 is an abstract base class for JBoss ConnectionManager
|
|
67
|
|
* implementations. It includes functionality to obtain managed connections from
|
|
68
|
|
* a ManagedConnectionPool mbean, find the Subject from a SubjectSecurityDomain,
|
|
69
|
|
* and interact with the CachedConnectionManager for connections held over
|
|
70
|
|
* transaction and method boundaries. Important mbean references are to a
|
|
71
|
|
* ManagedConnectionPool supplier (typically a JBossManagedConnectionPool), and a
|
|
72
|
|
* RARDeployment representing the ManagedConnectionFactory.
|
|
73
|
|
*
|
|
74
|
|
*
|
|
75
|
|
* Created: Wed Jan 2 12:16:09 2002
|
|
76
|
|
*
|
|
77
|
|
* @author <a href="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
|
|
78
|
|
* @author <a href="mailto:E.Guib@ceyoniq.com">Erwin Guib</a>
|
|
79
|
|
* @version $$
|
|
80
|
|
* @jmx:mbean name="jboss.jca:service=BaseConnectionManager"
|
|
81
|
|
* extends="org.jboss.system.ServiceMBean"
|
|
82
|
|
*/
|
|
83
|
|
|
|
84
|
|
public abstract class BaseConnectionManager2
|
|
85
|
|
extends ServiceMBeanSupport
|
|
86
|
|
implements BaseConnectionManager2MBean, ConnectionCacheListener
|
|
87
|
|
{
|
|
88
|
|
|
|
89
|
|
/** Note that this copy has a trailing / unlike the original in
|
|
90
|
|
* JaasSecurityManagerService.
|
|
91
|
|
*/
|
|
92
|
|
private static final String SECURITY_MGR_PATH = "java:/jaas/";
|
|
93
|
|
|
|
94
|
|
public static final String STOPPING_NOTIFICATION = "jboss.jca.connectionmanagerstopping";
|
|
95
|
|
|
|
96
|
|
private ObjectName managedConnectionPoolName;
|
|
97
|
|
|
|
98
|
|
private ManagedConnectionPool poolingStrategy;
|
|
99
|
|
|
|
100
|
|
private ObjectName managedConnectionFactoryName;
|
|
101
|
|
|
|
102
|
|
private ManagedConnectionFactory mcf;
|
|
103
|
|
|
|
104
|
|
protected String mcfJndiName;
|
|
105
|
|
|
|
106
|
|
//private ObjectName securityDomainName; //for the future??
|
|
107
|
|
private String securityDomainJndiName;
|
|
108
|
|
private SubjectSecurityManager securityDomain;
|
|
109
|
|
|
|
110
|
|
private ObjectName jaasSecurityManagerService;
|
|
111
|
|
|
|
112
|
|
|
|
113
|
|
private ObjectName ccmName;
|
|
114
|
|
private CachedConnectionManager ccm;
|
|
115
|
|
|
|
116
|
|
// JSR-77 Managed Object
|
|
117
|
|
ObjectName jcaConnectionFactory;
|
|
118
|
|
ObjectName jcaManagedConnectionFactory;
|
|
119
|
|
|
|
120
|
|
private final Map managedConnectionToListenerMap = Collections.synchronizedMap(new HashMap());
|
|
121
|
|
|
|
122
|
|
protected final Logger log = Logger.getLogger(getClass());
|
|
123
|
|
/**
|
|
124
|
|
* Default BaseConnectionManager2 managed constructor for use by subclass mbeans.
|
|
125
|
|
*
|
|
126
|
|
*/
|
|
127
|
11
|
public BaseConnectionManager2()
|
|
128
|
|
{
|
|
129
|
|
}
|
|
130
|
|
|
|
131
|
|
|
|
132
|
|
|
|
133
|
|
/**
|
|
134
|
|
* Creates a new <code>BaseConnectionManager2</code> instance.
|
|
135
|
|
* for TESTING ONLY! not a managed operation.
|
|
136
|
|
* @param mcf a <code>ManagedConnectionFactory</code> value
|
|
137
|
|
* @param ccm a <code>CachedConnectionManager</code> value
|
|
138
|
|
* @param poolingStrategy a <code>ManagedConnectionPool</code> value
|
|
139
|
|
*/
|
|
140
|
9
|
public BaseConnectionManager2(ManagedConnectionFactory mcf,
|
|
141
|
|
CachedConnectionManager ccm,
|
|
142
|
|
ManagedConnectionPool poolingStrategy)
|
|
143
|
|
{
|
|
144
|
9
|
this.mcf = mcf;
|
|
145
|
9
|
this.ccm = ccm;
|
|
146
|
9
|
this.poolingStrategy = poolingStrategy;
|
|
147
|
|
}
|
|
148
|
|
|
|
149
|
|
|
|
150
|
|
/**
|
|
151
|
|
* ManagedConnectionFactoryName holds the ObjectName of the mbean that
|
|
152
|
|
* represents the ManagedConnectionFactory. Normally this can be an
|
|
153
|
|
* embedded mbean in a depends element rather than a separate mbean
|
|
154
|
|
* reference.
|
|
155
|
|
* @return the ManagedConnectionFactoryName value.
|
|
156
|
|
* @jmx:managed-attribute
|
|
157
|
|
*/
|
|
158
|
0
|
public ObjectName getManagedConnectionFactoryName()
|
|
159
|
|
{
|
|
160
|
0
|
return managedConnectionFactoryName;
|
|
161
|
|
}
|
|
162
|
|
|
|
163
|
|
/**
|
|
164
|
|
* Set the ManagedConnectionFactoryName value.
|
|
165
|
|
* @param newManagedConnectionFactoryName The new ManagedConnectionFactoryName value.
|
|
166
|
|
* @jmx:managed-attribute
|
|
167
|
|
*/
|
|
168
|
11
|
public void setManagedConnectionFactoryName(ObjectName newManagedConnectionFactoryName)
|
|
169
|
|
{
|
|
170
|
11
|
this.managedConnectionFactoryName = newManagedConnectionFactoryName;
|
|
171
|
|
}
|
|
172
|
|
|
|
173
|
|
|
|
174
|
|
/**
|
|
175
|
|
* The ManagedConnectionPool holds the ObjectName of the mbean representing
|
|
176
|
|
* the pool for this connection manager. Normally it will be an embedded
|
|
177
|
|
* mbean in a depends tag rather than an ObjectName reference to the mbean.
|
|
178
|
|
* @return the ManagedConnectionPool value.
|
|
179
|
|
* @jmx:managed-attribute
|
|
180
|
|
*/
|
|
181
|
0
|
public ObjectName getManagedConnectionPool()
|
|
182
|
|
{
|
|
183
|
0
|
return managedConnectionPoolName;
|
|
184
|
|
}
|
|
185
|
|
|
|
186
|
|
/**
|
|
187
|
|
* Set the ManagedConnectionPool value.
|
|
188
|
|
* @param newManagedConnectionPool The new ManagedConnectionPool value.
|
|
189
|
|
* @jmx:managed-attribute
|
|
190
|
|
*/
|
|
191
|
11
|
public void setManagedConnectionPool(ObjectName newManagedConnectionPool)
|
|
192
|
|
{
|
|
193
|
11
|
this.managedConnectionPoolName = newManagedConnectionPool;
|
|
194
|
|
}
|
|
195
|
|
|
|
196
|
|
|
|
197
|
|
|
|
198
|
|
|
|
199
|
|
/**
|
|
200
|
|
* The CachecConnectionManager holds the ObjectName of the
|
|
201
|
|
* CachedConnectionManager mbean used by this ConnectionManager.
|
|
202
|
|
* Normally this will be a depends tag with the ObjectName of the
|
|
203
|
|
* unique CachedConnectionManager for the server.
|
|
204
|
|
*
|
|
205
|
|
* @param ccmName an <code>ObjectName</code> value
|
|
206
|
|
* @jmx:managed-attribute
|
|
207
|
|
*/
|
|
208
|
11
|
public void setCachedConnectionManager(ObjectName ccmName)
|
|
209
|
|
{
|
|
210
|
11
|
this.ccmName = ccmName;
|
|
211
|
|
}
|
|
212
|
|
|
|
213
|
|
/**
|
|
214
|
|
* Describe <code>getCachedConnectionManager</code> method here.
|
|
215
|
|
*
|
|
216
|
|
* @return an <code>ObjectName</code> value
|
|
217
|
|
* @jmx:managed-attribute
|
|
218
|
|
*/
|
|
219
|
0
|
public ObjectName getCachedConnectionManager()
|
|
220
|
|
{
|
|
221
|
0
|
return ccmName;
|
|
222
|
|
}
|
|
223
|
|
|
|
224
|
|
|
|
225
|
|
|
|
226
|
|
|
|
227
|
|
/**
|
|
228
|
|
* The SecurityDomainJndiName holds the jndi name of the security domain
|
|
229
|
|
* configured for the ManagedConnectionFactory this ConnectionManager
|
|
230
|
|
* manages. It is normally of the form java:/jaas/firebirdRealm,
|
|
231
|
|
* where firebirdRealm is the name found in auth.conf or equivalent file.
|
|
232
|
|
*
|
|
233
|
|
* @param name an <code>String</code> value
|
|
234
|
|
* @jmx:managed-attribute
|
|
235
|
|
*/
|
|
236
|
1
|
public void setSecurityDomainJndiName(String securityDomainJndiName)
|
|
237
|
|
{
|
|
238
|
1
|
if (securityDomainJndiName != null
|
|
239
|
|
&& securityDomainJndiName.startsWith(SECURITY_MGR_PATH))
|
|
240
|
|
{
|
|
241
|
0
|
securityDomainJndiName = securityDomainJndiName.substring(SECURITY_MGR_PATH.length());
|
|
242
|
0
|
log.warn("WARNING: UPDATE YOUR SecurityDomainJndiName! REMOVE " + SECURITY_MGR_PATH);
|
|
243
|
|
} // end of if ()
|
|
244
|
1
|
this.securityDomainJndiName = securityDomainJndiName;
|
|
245
|
|
}
|
|
246
|
|
/**
|
|
247
|
|
* Get the SecurityDomainJndiName value.
|
|
248
|
|
* @return the SecurityDomainJndiName value.
|
|
249
|
|
* @jmx:managed-attribute
|
|
250
|
|
*/
|
|
251
|
0
|
public String getSecurityDomainJndiName()
|
|
252
|
|
{
|
|
253
|
0
|
return securityDomainJndiName;
|
|
254
|
|
}
|
|
255
|
|
|
|
256
|
|
/**
|
|
257
|
|
* Get the JaasSecurityManagerService value.
|
|
258
|
|
* @return the JaasSecurityManagerService value.
|
|
259
|
|
* @jmx:managed-attribute
|
|
260
|
|
*/
|
|
261
|
0
|
public ObjectName getJaasSecurityManagerService()
|
|
262
|
|
{
|
|
263
|
0
|
return jaasSecurityManagerService;
|
|
264
|
|
}
|
|
265
|
|
|
|
266
|
|
/**
|
|
267
|
|
* Set the JaasSecurityManagerService value.
|
|
268
|
|
* @param newJaasSecurityManagerService The new JaasSecurityManagerService value.
|
|
269
|
|
* @jmx:managed-attribute
|
|
270
|
|
*/
|
|
271
|
11
|
public void setJaasSecurityManagerService(final ObjectName jaasSecurityManagerService)
|
|
272
|
|
{
|
|
273
|
11
|
this.jaasSecurityManagerService = jaasSecurityManagerService;
|
|
274
|
|
}
|
|
275
|
|
|
|
276
|
|
|
|
277
|
|
|
|
278
|
|
/**
|
|
279
|
|
* ManagedConnectionFactory is an internal attribute that holds the
|
|
280
|
|
* ManagedConnectionFactory instance managed by this ConnectionManager.
|
|
281
|
|
*
|
|
282
|
|
* @return value of managedConnectionFactory
|
|
283
|
|
*
|
|
284
|
|
* @jmx.managed-attribute access="READ"
|
|
285
|
|
*/
|
|
286
|
1
|
public ManagedConnectionFactory getManagedConnectionFactory()
|
|
287
|
|
{
|
|
288
|
1
|
return mcf;
|
|
289
|
|
}
|
|
290
|
|
|
|
291
|
|
|
|
292
|
|
|
|
293
|
|
|
|
294
|
|
/**
|
|
295
|
|
* Describe <code>getInstance</code> method here.
|
|
296
|
|
*
|
|
297
|
|
* @return a <code>BaseConnectionManager2</code> value
|
|
298
|
|
*
|
|
299
|
|
* @jmx.managed-attribute access="READ"
|
|
300
|
|
*/
|
|
301
|
1
|
public BaseConnectionManager2 getInstance()
|
|
302
|
|
{
|
|
303
|
1
|
return this;
|
|
304
|
|
}
|
|
305
|
|
|
|
306
|
|
//ServiceMBeanSupport
|
|
307
|
|
|
|
308
|
86
|
public String getName()
|
|
309
|
|
{
|
|
310
|
86
|
return "BaseConnectionManager";
|
|
311
|
|
}
|
|
312
|
|
|
|
313
|
11
|
protected void createService() throws Exception
|
|
314
|
|
{
|
|
315
|
|
// Create JSR-77 JCAConnectionFactory Managed Object
|
|
316
|
11
|
jcaConnectionFactory = JCAConnectionFactory.create(getServer(),
|
|
317
|
|
getServiceName().getKeyProperty("name") +
|
|
318
|
|
"-" +
|
|
319
|
|
getServiceName().getKeyProperty("service"),
|
|
320
|
|
getServiceName());
|
|
321
|
|
|
|
322
|
|
// Create JSR-77 JCAManagedConnectionFactory Managed Object
|
|
323
|
11
|
jcaManagedConnectionFactory = JCAManagedConnectionFactory.create(
|
|
324
|
|
getServer(),
|
|
325
|
|
managedConnectionFactoryName.getKeyProperty("name") +
|
|
326
|
|
"-" +
|
|
327
|
|
managedConnectionFactoryName.getKeyProperty("service"),
|
|
328
|
|
jcaConnectionFactory);
|
|
329
|
|
}
|
|
330
|
|
|
|
331
|
12
|
protected void startService() throws Exception
|
|
332
|
|
{
|
|
333
|
12
|
super.startService();
|
|
334
|
12
|
try
|
|
335
|
|
{
|
|
336
|
12
|
ccm = (CachedConnectionManager)getServer().getAttribute(ccmName, "Instance");
|
|
337
|
|
|
|
338
|
|
}
|
|
339
|
|
catch (Exception e)
|
|
340
|
|
{
|
|
341
|
0
|
JMXExceptionDecoder.rethrow(e);
|
|
342
|
|
} // end of try-catch
|
|
343
|
|
|
|
344
|
12
|
if (ccm == null)
|
|
345
|
|
{
|
|
346
|
0
|
throw new DeploymentException("cached ConnectionManager not found: " + ccmName);
|
|
347
|
|
} // end of if ()
|
|
348
|
|
|
|
349
|
12
|
if (securityDomainJndiName != null && jaasSecurityManagerService == null)
|
|
350
|
|
{
|
|
351
|
0
|
throw new DeploymentException("You must supply both securityDomainJndiName and jaasSecurityManagerService to use container managed security");
|
|
352
|
|
} // end of if ()
|
|
353
|
|
|
|
354
|
|
|
|
355
|
12
|
if (securityDomainJndiName != null)
|
|
356
|
|
{
|
|
357
|
1
|
securityDomain = (SubjectSecurityManager)new InitialContext().lookup(SECURITY_MGR_PATH + securityDomainJndiName);
|
|
358
|
|
} // end of if ()
|
|
359
|
|
|
|
360
|
12
|
if (managedConnectionPoolName == null)
|
|
361
|
|
{
|
|
362
|
0
|
throw new DeploymentException("managedConnectionPool not set!");
|
|
363
|
|
} // end of if ()
|
|
364
|
12
|
try
|
|
365
|
|
{
|
|
366
|
12
|
poolingStrategy = (ManagedConnectionPool)getServer().getAttribute(
|
|
367
|
|
managedConnectionPoolName,
|
|
368
|
|
"ManagedConnectionPool");
|
|
369
|
|
}
|
|
370
|
|
catch (Exception e)
|
|
371
|
|
{
|
|
372
|
0
|
JMXExceptionDecoder.rethrow(e);
|
|
373
|
|
} // end of try-catch
|
|
374
|
|
|
|
375
|
|
|
|
376
|
12
|
if (managedConnectionFactoryName == null)
|
|
377
|
|
{
|
|
378
|
0
|
throw new DeploymentException("ManagedConnectionFactory not set!");
|
|
379
|
|
} // end of if ()
|
|
380
|
12
|
try
|
|
381
|
|
{
|
|
382
|
12
|
mcf = (ManagedConnectionFactory)getServer().invoke(
|
|
383
|
|
managedConnectionFactoryName,
|
|
384
|
|
"startManagedConnectionFactory",
|
|
385
|
|
new Object[] {new ConnectionManagerProxy(this, this.serviceName)},
|
|
386
|
|
new String[] {ConnectionManager.class.getName()});
|
|
387
|
|
|
|
388
|
|
// save the JNDI Name for this connector
|
|
389
|
|
// we need it later to check if the connector gets called from a
|
|
390
|
|
// bean with shared or unshared resource-ref
|
|
391
|
12
|
mcfJndiName = (String)getServer().getAttribute(managedConnectionFactoryName,
|
|
392
|
|
"JndiName");
|
|
393
|
|
}
|
|
394
|
|
catch (Exception e)
|
|
395
|
|
{
|
|
396
|
0
|
JMXExceptionDecoder.rethrow(e);
|
|
397
|
|
} // end of try-catch
|
|
398
|
|
|
|
399
|
|
|
|
400
|
12
|
poolingStrategy.setManagedConnectionFactory(mcf);
|
|
401
|
|
}
|
|
402
|
|
|
|
403
|
10
|
protected void stopService()
|
|
404
|
|
throws Exception
|
|
405
|
|
{
|
|
406
|
|
//notify the login modules the mcf is going away, they need to look it up again later.
|
|
407
|
10
|
sendNotification(new Notification(STOPPING_NOTIFICATION,
|
|
408
|
|
getServiceName(),
|
|
409
|
|