use of com.sun.enterprise.deployment.ResourcePrincipal in project Payara by payara.
the class ConnectorAdminServiceUtils method getDefaultResourcePrincipal.
/*
* Returns a ResourcePrincipal object populated with a pool's
* default USERNAME and PASSWORD
*
* @throws NamingException if poolname lookup fails
*/
public static ResourcePrincipal getDefaultResourcePrincipal(PoolInfo poolInfo) throws NamingException {
// All this to get the default user name and principal
ConnectorConnectionPool connectorConnectionPool = null;
try {
String jndiNameForPool = getReservePrefixedJNDINameForPool(poolInfo);
Context ic = ConnectorRuntime.getRuntime().getNamingManager().getInitialContext();
connectorConnectionPool = (ConnectorConnectionPool) ic.lookup(jndiNameForPool);
} catch (NamingException ne) {
throw ne;
}
ConnectorDescriptorInfo cdi = connectorConnectionPool.getConnectorDescriptorInfo();
Set mcfConfigProperties = cdi.getMCFConfigProperties();
Iterator mcfConfPropsIter = mcfConfigProperties.iterator();
String userName = "";
String password = "";
while (mcfConfPropsIter.hasNext()) {
ConnectorConfigProperty prop = (ConnectorConfigProperty) mcfConfPropsIter.next();
if (prop.getName().toUpperCase(Locale.getDefault()).equals("USERNAME") || prop.getName().toUpperCase(Locale.getDefault()).equals("USER")) {
userName = prop.getValue();
} else if (prop.getName().toUpperCase(Locale.getDefault()).equals("PASSWORD")) {
password = prop.getValue();
}
}
// Now return the ResourcePrincipal
return new ResourcePrincipal(userName, password);
}
use of com.sun.enterprise.deployment.ResourcePrincipal in project Payara by payara.
the class ConnectorConnectionPoolAdminServiceImpl method getDefaultSubject.
/**
* Utility method that is used to get the default subject for the
* specified mcf and resource principal.
* @param poolInfo
* @param mcf
* @param prin
* @return
* @throws javax.resource.ResourceException
*/
protected Subject getDefaultSubject(PoolInfo poolInfo, ManagedConnectionFactory mcf, ResourcePrincipal prin) throws ResourceException {
ResourcePrincipal resourcePrincipal = null;
if (prin == null) {
try {
resourcePrincipal = getDefaultResourcePrincipal(poolInfo, mcf);
} catch (NamingException ne) {
_logger.log(Level.WARNING, "jdbc.pool_not_reachable", ne.getMessage());
String l10nMsg = localStrings.getString("pingpool.name_not_bound", poolInfo);
ResourceException e = new ResourceException(l10nMsg + poolInfo);
e.initCause(ne);
throw e;
}
} else {
resourcePrincipal = prin;
}
final Subject defaultSubject = ConnectionPoolObjectsUtils.createSubject(mcf, resourcePrincipal);
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("using subject: " + defaultSubject);
}
return defaultSubject;
}
use of com.sun.enterprise.deployment.ResourcePrincipal in project Payara by payara.
the class ConnectionManagerImpl method allocateConnection.
public Object allocateConnection(ManagedConnectionFactory mcf, ConnectionRequestInfo cxRequestInfo, String jndiNameToUse, Object conn) 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");
}
prin = defaultPrin;
} else if (!prin.equals(defaultPrin)) {
ConnectorRuntime.getRuntime().switchOnMatching(rarName, poolInfo);
}
}
return internalGetConnection(mcf, prin, cxRequestInfo, resourceShareable, jndiNameToUse, conn, false);
}
}
use of com.sun.enterprise.deployment.ResourcePrincipal in project Payara by payara.
the class ASEjbMDBConnFactory method check.
public Result check(EjbDescriptor descriptor) {
Result result = getInitializedResult();
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
boolean oneFailed = false;
boolean oneWarn = false;
try {
IASEjbExtraDescriptors iasEjbExtraDesc = descriptor.getIASEjbExtraDescriptors();
MdbConnectionFactoryDescriptor mdbConnFacDesc = iasEjbExtraDesc.getMdbConnectionFactory();
if (mdbConnFacDesc != null) {
String jndiName = mdbConnFacDesc.getJndiName();
if (jndiName == null || jndiName.length() == 0) {
oneFailed = true;
addErrorDetails(result, compName);
result.failed(smh.getLocalString(getClass().getName() + ".failed", "FAILED [AS-EJB mdb-connection-factory] : jndi-name cannot be an empty string"));
} else {
if (jndiName.startsWith("jms/")) {
addGoodDetails(result, compName);
result.passed(smh.getLocalString(getClass().getName() + ".passed", "PASSED [AS-EJB mdb-connection-factory] : jndi-name is {0}", new Object[] { jndiName }));
} else {
oneWarn = true;
addWarningDetails(result, compName);
result.warning(smh.getLocalString(getClass().getName() + ".warning", "WARNING [AS-EJB mdb-connection-factory] : jndi-name {0} should start with jms/", new Object[] { jndiName }));
}
}
ResourcePrincipal defPrinci = mdbConnFacDesc.getDefaultResourcePrincipal();
if (defPrinci != null) {
String name = defPrinci.getName();
if (name == null || name.length() == 0) {
oneFailed = true;
addErrorDetails(result, compName);
result.failed(smh.getLocalString(getClass().getName() + ".failed1", "FAILED [AS-EJB default-resource-principal] : name cannot be an empty string"));
} else {
addGoodDetails(result, compName);
result.passed(smh.getLocalString(getClass().getName() + ".passed1", "PASSED [AS-EJB default-resource-principal] : name is {0}", new Object[] { name }));
}
String password = defPrinci.getPassword();
if (password == null || password.length() == 0) {
addWarningDetails(result, compName);
result.warning(smh.getLocalString(getClass().getName() + ".warning2", "WARNING [AS-EJB default-resource-principal] : password is an empty string"));
} else {
addGoodDetails(result, compName);
result.passed(smh.getLocalString(getClass().getName() + ".passed2", "PASSED [AS-EJB default-resource-principal] : password is {0}", new Object[] { password }));
}
} else {
addNaDetails(result, compName);
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "NOT APPLICABLE [AS-EJB mdb-connection-factory] : default-resource-prncipal element is not defined"));
}
} else {
if (descriptor instanceof EjbMessageBeanDescriptor) {
boolean failed = false;
int count = getCountNodeSet("sun-ejb-jar/enterprise-beans/ejb[ejb-name=\"" + descriptor.getName() + "\"]/mdb-resource-adapter");
if (count > 0) {
String value = getXPathValue("sun-ejb-jar/enterprise-beans/ejb[ejb-name=\"" + descriptor.getName() + "\"]/mdb-resource-adapter/resource-adapter-mid");
if (value == null || value.length() == 0) {
failed = true;
}
} else {
failed = true;
}
if (failed) {
EjbMessageBeanDescriptor mdbDesc = (EjbMessageBeanDescriptor) descriptor;
if (mdbDesc.hasTopicDest() && mdbDesc.hasDurableSubscription()) {
oneFailed = true;
addErrorDetails(result, compName);
result.failed(smh.getLocalString(getClass().getName() + ".failed2", "FAILED [AS-EJB ejb] : mdb-connection-factory has to be defined for an MDB with destination-type " + "as Topic and subscription-durability as Durable"));
}
/**
* else{
* oneWarn = true;
* result.warning(smh.getLocalString(getClass().getName()+".warning1",
* "WARNING [AS-EJB ejb] : mdb-connection-factory should be defined for a Message Driven Bean"));
* }
*/
}
} else {
addNaDetails(result, compName);
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "NOT APPLICABLE [AS-EJB ejb] : mdb-connection-factory element is not defined"));
}
}
if (oneFailed)
result.setStatus(Result.FAILED);
else if (oneWarn)
result.setStatus(Result.WARNING);
} catch (Exception ex) {
addErrorDetails(result, compName);
result.failed(smh.getLocalString(getClass().getName() + ".notRun", "NOT RUN [AS-EJB cmp] Could not create descriptor Object."));
}
return result;
}
use of com.sun.enterprise.deployment.ResourcePrincipal in project Payara by payara.
the class ConnectorConnectionPoolAdminServiceImpl method getConnection.
/**
* Get a sql connection from the DataSource specified by the jdbcJndiName.
* This API is intended to be used in the DAS. The motivation for having this
* API is to provide the CMP backend a means of acquiring a connection during
* the codegen phase. If a user is trying to deploy an app on a remote server,
* without this API, a resource reference has to be present both in the DAS
* and the server instance. This makes the deployment more complex for the
* user since a resource needs to be forcibly created in the DAS Too.
* This API will mitigate this need.
*
* @param resourceInfo the jndi name of the resource being used to get Connection from
* This resource can either be a pmf resource or a jdbc resource
* @param user the user used to authenticate this request
* @param password the password used to authenticate this request
* @return a java.sql.Connection
* @throws java.sql.SQLException in case of errors
*/
public Connection getConnection(ResourceInfo resourceInfo, String user, String password) throws SQLException {
java.sql.Connection con = null;
try {
// DASResourcesUtil.setAdminConfigContext();
PoolInfo poolInfo = getPoolNameFromResourceJndiName(resourceInfo);
if (poolInfo == null) {
throw new SQLException("No pool by name exists ");
}
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("ConnectorRuntime.getConnection :: poolName : " + poolInfo);
}
// Maintain consitency with the ConnectionManagerImpl change to be checked in later
String passwd = (password == null) ? "" : password;
// From what we have seen so far, the user cannot be null
// but password can be
// if user is null we will use default authentication
// TODO: Discuss if this is the right thing to do
ResourcePrincipal prin = (user == null) ? null : new ResourcePrincipal(user, passwd);
con = (java.sql.Connection) getUnpooledConnection(poolInfo, prin, true);
if (con == null) {
String i18nMsg = localStrings.getString("ccp_adm.null_unpooled_connection");
throw new SQLException(i18nMsg);
}
} catch (ResourceException re) {
SQLException sqle = new SQLException(re.getMessage());
sqle.initCause(re);
_logger.log(Level.WARNING, "jdbc.exc_get_conn", re.getMessage());
if (_logger.isLoggable(Level.FINE)) {
_logger.fine(" getConnection in ConnectorRuntime failed : " + re);
}
throw sqle;
} catch (Exception ex) {
SQLException sqle = new SQLException(ex.getMessage());
sqle.initCause(ex);
_logger.log(Level.WARNING, "jdbc.exc_get_conn", ex.getMessage());
if (_logger.isLoggable(Level.FINE)) {
_logger.fine(" getConnection in ConnectorRuntime failed : " + ex);
}
throw sqle;
}
return con;
}
Aggregations