throws ResourceException {
validateResourceAndPool();
PoolManager poolmgr = ConnectorRuntime.getRuntime().getPoolManager();
boolean resourceShareable = true;
ResourceReferenceDescriptor ref = poolmgr.getResourceReference(jndiNameToUse, logicalName);
if (ref != null) {
String shareableStr = ref.getSharingScope();
if (shareableStr.equals(ref.RESOURCE_UNSHAREABLE)) {
resourceShareable = false;
}
}
//TODO V3 refactor all the 3 cases viz, no res-ref, app-auth, cont-auth.
if (ref == null) {
if(getLogger().isLoggable(Level.FINE)) {
getLogger().log(Level.FINE, "poolmgr.no_resource_reference", jndiNameToUse);
}
return internalGetConnection(mcf, defaultPrin, cxRequestInfo,
resourceShareable, jndiNameToUse, conn, true);
}
String auth = ref.getAuthorization();
if (auth.equals(ResourceReferenceDescriptor.APPLICATION_AUTHORIZATION)) {
if (cxRequestInfo == null) {
String msg = getLocalStrings().getString("con_mgr.null_userpass");
throw new ResourceException(msg);
}
ConnectorRuntime.getRuntime().switchOnMatching(rarName, poolInfo);
return internalGetConnection(mcf, null, cxRequestInfo,
resourceShareable, jndiNameToUse, conn, false);
} else {
ResourcePrincipal prin = null;
Set principalSet = null;
Principal callerPrincipal = null;
SecurityContext securityContext = null;
ConnectorRuntime connectorRuntime = ConnectorRuntime.getRuntime();
//TODO V3 is SecurityContext.getCurrent() the right way ? Does it need to be injected ?
if (connectorRuntime.isServer() &&
(securityContext = SecurityContext.getCurrent()) != null &&
(callerPrincipal = securityContext.getCallerPrincipal()) != null &&
(principalSet = securityContext.getPrincipalSet()) != null) {
AuthenticationService authService =
connectorRuntime.getAuthenticationService(rarName, poolInfo);
if (authService != null) {
prin = (ResourcePrincipal) authService.mapPrincipal(
callerPrincipal, principalSet);
}
}
if (prin == null) {
prin = ref.getResourcePrincipal();
if (prin == null) {
if (getLogger().isLoggable(Level.FINE)) {
getLogger().log(Level.FINE, "default-resource-principal not"
+ "specified for " + jndiNameToUse + ". Defaulting to"
+ " user/password specified in the pool");