use of com.sun.enterprise.deployment.ResourcePrincipal in project Payara by payara.
the class ASEntBeanCmpResource method check.
public Result check(EjbDescriptor descriptor) {
Result result = getInitializedResult();
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
try {
EjbBundleDescriptorImpl ejbBundleDesc = descriptor.getEjbBundleDescriptor();
ResourceReferenceDescriptor cmpResource = ejbBundleDesc.getCMPResourceReference();
if (cmpResource != null) {
// String jndiName = cmpResource.getJndiName();
String jndiName = getXPathValue("sun-ejb-jar/enterprise-beans/cmp-resource/jndi-name");
if (jndiName == null || jndiName.length() == 0) {
// 4698046
oneFailed = true;
addErrorDetails(result, compName);
result.failed(smh.getLocalString(getClass().getName() + ".failed", "FAILED [AS-EJB cmp-resource] : jndi-name cannot be an empty string"));
} else {
if (jndiName.startsWith("jdbc/") || jndiName.startsWith("jdo/")) {
addGoodDetails(result, compName);
result.passed(smh.getLocalString(getClass().getName() + ".passed", "PASSED [AS-EJB cmp-resource] : jndi-name is {0}", new Object[] { jndiName }));
} else {
// 4698046
oneWarning = true;
addWarningDetails(result, compName);
result.warning(smh.getLocalString(getClass().getName() + ".warning", "WARNING [AS-EJB cmp-resource] : The jndi-name is {0}, the preferred jndi-name should start with jdbc/ or jdo/", new Object[] { jndiName }));
}
}
ResourcePrincipal defPrincipal = cmpResource.getResourcePrincipal();
if (defPrincipal != null) {
// String name = defPrincipal.getName();
String name = getXPathValue("sun-ejb-jar/enterprise-beans/cmp-resource/default-resource-principal/name");
if (name == null || name.length() == 0) {
// 4698046
oneFailed = true;
addErrorDetails(result, compName);
result.failed(smh.getLocalString(getClass().getName() + ".failed2", "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 = defPrincipal.getPassword();
char[] password = getXPathValueasCharArray("sun-ejb-jar/enterprise-beans/cmp-resource/default-resource-principal/password");
if (password == null || password.length == 0) {
// 4698046
oneWarning = true;
addWarningDetails(result, compName);
result.warning(smh.getLocalString(getClass().getName() + ".warning1", "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[] { new String(password) }));
}
Arrays.fill(password, ' ');
} else {
addNaDetails(result, compName);
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "NOT APPLICABLE [AS-EJB cmp-resource] : default-resource-principal Element not defined"));
}
Float specVer = getRuntimeSpecVersion();
if ((Float.compare(specVer.floatValue(), (new Float("2.1")).floatValue()) >= 0)) {
// property
result = testProperty("property", result, "sun-ejb-jar/enterprise-beans/cmp-resource/property", compName, descriptor);
// schema-generator-properties
result = testProperty("schema-generator-properties", result, "sun-ejb-jar/enterprise-beans/cmp-resource/schema-generator-properties/property", compName, descriptor);
}
if (// 4698046
oneFailed)
result.setStatus(Result.FAILED);
else if (oneWarning)
result.setStatus(Result.WARNING);
} else {
addNaDetails(result, compName);
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "NOT APPLICABLE [AS-EJB enterprise-beans] : cmp-resource element is not defined"));
}
} 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 ASEjbRRefDefResPrincipal method check.
public Result check(EjbDescriptor descriptor) {
Result result = getInitializedResult();
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
boolean oneFailed = false;
try {
Set resRef = descriptor.getResourceReferenceDescriptors();
if (!(resRef.isEmpty())) {
Iterator it = resRef.iterator();
while (it.hasNext()) {
ResourceReferenceDescriptor resDesc = ((ResourceReferenceDescriptor) it.next());
String refName = resDesc.getName();
String refJndiName = resDesc.getJndiName();
ResourcePrincipal resPrinci = resDesc.getResourcePrincipal();
if (resPrinci == null) {
try {
resDesc = descriptor.getResourceReferenceByName(refName);
String resAuth = resDesc.getAuthorization();
if (resAuth.equals(ResourceReferenceDescriptor.APPLICATION_AUTHORIZATION)) {
addErrorDetails(result, compName);
result.failed(smh.getLocalString(getClass().getName() + ".failed", "FAILED [AS-EJB resource-ref] : res-auth for res-ref-name {0} is defined as Application." + "Therefore the default-resource-principal should be supplied with valid properties", new Object[] { refName }));
} else {
addNaDetails(result, compName);
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "NOT APPLICABLE [AS-EJB resource-ref] : default-resource-principal Element not defined"));
}
} catch (IllegalArgumentException iaex) {
addErrorDetails(result, compName);
result.failed(smh.getLocalString(getClass().getName() + ".failed2", "FAILED [AS-EJB resource-ref] : res-ref-name {0} is not defined in the ejb-jar.xml", new Object[] { refName }));
}
} else {
String name = resPrinci.getName();
if (name == null || name.length() == 0) {
oneFailed = true;
addErrorDetails(result, compName);
result.failed(smh.getLocalString(getClass().getName() + ".failed3", "FAILED [AS-EJB default-resource-principal] : name cannot be an empty string"));
} else {
addGoodDetails(result, compName);
result.passed(smh.getLocalString(getClass().getName() + ".passed", "PASSED [AS-EJB default-resource-principal] : name is {0}", new Object[] { name }));
}
String password = resPrinci.getPassword();
if (password == null || password.length() == 0) {
addWarningDetails(result, compName);
result.warning(smh.getLocalString(getClass().getName() + ".warning1", "WARNING [AS-EJB default-resource-principal] : password is an empty string"));
} else {
addGoodDetails(result, compName);
result.passed(smh.getLocalString(getClass().getName() + ".passed1", "PASSED [AS-EJB default-resource-principal] : password is {0}", new Object[] { password }));
}
if (oneFailed)
result.setStatus(Result.FAILED);
}
}
} else {
addNaDetails(result, compName);
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "{0} Does not define any resource-ref Elements"));
}
} catch (Exception ex) {
addErrorDetails(result, compName);
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".notRun", "NOT RUN [AS-EJB] : Could not create the descriptor object"));
}
return result;
}
use of com.sun.enterprise.deployment.ResourcePrincipal in project Payara by payara.
the class SecurityMapUtils method generateResourcePrincipal.
/**
* Creates the ResourcePrincipal object from the given securityMap
*
* @param securityMap SecurityMap
* @return created ResourcePrincipal object
*/
private static ResourcePrincipal generateResourcePrincipal(ConnectorSecurityMap securityMap) {
EisBackendPrincipal backendPrincipal = securityMap.getBackendPrincipal();
String userName = backendPrincipal.getUserName();
String password = backendPrincipal.getPassword();
return new ResourcePrincipal(userName, password);
}
use of com.sun.enterprise.deployment.ResourcePrincipal in project Payara by payara.
the class JdbcRecoveryResourceHandler method loadXAResourcesAndItsConnections.
/**
* {@inheritDoc}
*/
@Override
public void loadXAResourcesAndItsConnections(List xaresList, List connList) {
// Done so as to initialize connectors-runtime before loading jdbc-resources. need a better way ?
ConnectorRuntime crt = connectorRuntimeProvider.get();
Collection<JdbcResource> jdbcResources = getAllJdbcResources();
if (jdbcResources == null || jdbcResources.size() == 0) {
if (_logger.isLoggable(Level.FINEST)) {
_logger.finest("loadXAResourcesAndItsConnections : no resources");
}
return;
}
List<JdbcConnectionPool> jdbcPools = new ArrayList<JdbcConnectionPool>();
for (Resource resource : jdbcResources) {
JdbcResource jdbcResource = (JdbcResource) resource;
if (getResourcesUtil().isEnabled(jdbcResource)) {
ResourceInfo resourceInfo = ConnectorsUtil.getResourceInfo(jdbcResource);
JdbcConnectionPool pool = JdbcResourcesUtil.createInstance().getJdbcConnectionPoolOfResource(resourceInfo);
if (pool != null && "javax.sql.XADataSource".equals(pool.getResType())) {
jdbcPools.add(pool);
}
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("JdbcRecoveryResourceHandler:: loadXAResourcesAndItsConnections :: " + "adding : " + (jdbcResource.getPoolName()));
}
}
}
loadAllJdbcResources();
// Read from the transaction-service , if the replacement of
// Vendor XAResource class with our version required.
// If yes, put the mapping in the xaresourcewrappers properties.
Properties XAResourceWrappers = new Properties();
XAResourceWrappers.put("oracle.jdbc.xa.client.OracleXADataSource", "com.sun.enterprise.transaction.jts.recovery.OracleXAResource");
Config c = habitat.getService(Config.class, ServerEnvironment.DEFAULT_INSTANCE_NAME);
txService = c.getExtensionByType(TransactionService.class);
List<Property> properties = txService.getProperty();
if (properties != null) {
for (Property property : properties) {
String name = property.getName();
String value = property.getValue();
if (name.equals("oracle-xa-recovery-workaround")) {
if ("false".equals(value)) {
XAResourceWrappers.remove("oracle.jdbc.xa.client.OracleXADataSource");
}
} else if (name.equals("sybase-xa-recovery-workaround")) {
if (value.equals("true")) {
XAResourceWrappers.put("com.sybase.jdbc2.jdbc.SybXADataSource", "com.sun.enterprise.transaction.jts.recovery.SybaseXAResource");
}
}
}
}
for (JdbcConnectionPool jdbcConnectionPool : jdbcPools) {
if (jdbcConnectionPool.getResType() == null || jdbcConnectionPool.getName() == null || !jdbcConnectionPool.getResType().equals("javax.sql.XADataSource")) {
if (_logger.isLoggable(Level.FINEST)) {
_logger.finest("skipping pool : " + jdbcConnectionPool.getName());
}
continue;
}
if (_logger.isLoggable(Level.FINEST)) {
_logger.finest(" using pool : " + jdbcConnectionPool.getName());
}
PoolInfo poolInfo = ConnectorsUtil.getPoolInfo(jdbcConnectionPool);
try {
String[] dbUserPassword = getdbUserPasswordOfJdbcConnectionPool(jdbcConnectionPool);
String dbUser = dbUserPassword[0];
String dbPassword = dbUserPassword[1];
if (dbPassword == null) {
dbPassword = "";
if (_logger.isLoggable(Level.FINEST)) {
_logger.log(Level.FINEST, "datasource.xadatasource_nullpassword_error", poolInfo);
}
}
if (dbUser == null) {
dbUser = "";
if (_logger.isLoggable(Level.FINEST)) {
_logger.log(Level.FINEST, "datasource.xadatasource_nulluser_error", poolInfo);
}
}
ManagedConnectionFactory fac = crt.obtainManagedConnectionFactory(poolInfo);
Subject subject = new Subject();
PasswordCredential pc = new PasswordCredential(dbUser, dbPassword.toCharArray());
pc.setManagedConnectionFactory(fac);
Principal prin = new ResourcePrincipal(dbUser, dbPassword);
subject.getPrincipals().add(prin);
subject.getPrivateCredentials().add(pc);
ManagedConnection mc = fac.createManagedConnection(subject, null);
connList.add(mc);
try {
XAResource xares = mc.getXAResource();
if (xares != null) {
// See if a wrapper class for the vendor XADataSource is
// specified if yes, replace the XAResouce class of database
// vendor with our own version
String datasourceClassname = jdbcConnectionPool.getDatasourceClassname();
String wrapperclass = (String) XAResourceWrappers.get(datasourceClassname);
if (wrapperclass != null) {
// need to load wrapper class provided by "transactions" module.
// Using connector-class-loader so as to get access to "transaction" module.
XAResourceWrapper xaresWrapper = null;
xaresWrapper = (XAResourceWrapper) crt.getConnectorClassLoader().loadClass(wrapperclass).newInstance();
xaresWrapper.init(mc, subject);
if (_logger.isLoggable(Level.FINEST)) {
_logger.finest("adding resource " + poolInfo + " -- " + xaresWrapper);
}
xaresList.add(xaresWrapper);
} else {
if (_logger.isLoggable(Level.FINEST)) {
_logger.finest("adding resource " + poolInfo + " -- " + xares);
}
xaresList.add(xares);
}
}
} catch (ResourceException ex) {
_logger.log(Level.WARNING, "datasource.xadatasource_error", poolInfo);
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "datasource.xadatasource_error_excp", ex);
}
// ignored. Not at XA_TRANSACTION level
}
} catch (Exception ex) {
_logger.log(Level.WARNING, "datasource.xadatasource_error", poolInfo);
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "datasource.xadatasource_error_excp", ex);
}
}
}
}
use of com.sun.enterprise.deployment.ResourcePrincipal in project Payara by payara.
the class ConnectorsRecoveryResourceHandler method loadXAResourcesAndItsConnections.
/**
* {@inheritDoc}
*/
public void loadXAResourcesAndItsConnections(List xaresList, List connList) {
// Done so as to initialize connectors-runtime before loading connector-resources. need a better way ?
ConnectorRuntime crt = connectorRuntimeProvider.get();
// ApplicationLoaderService already guarantees that connectors are loaded before any other applications.
// Recovery will not start sooner than transaction is first needed on EE application startup, therefore
// it is safe to continue here without waiting for startupProvider, as that ultimately creates a deadlock
// between ApplicationLoaderService needed a transaction manager, and recovery wainting for applications
// to finish loading.
Collection<ConnectorResource> connectorResources = getAllConnectorResources();
if (connectorResources == null || connectorResources.size() == 0) {
return;
}
List<ConnectorConnectionPool> connPools = new ArrayList<ConnectorConnectionPool>();
for (Resource resource : connectorResources) {
ConnectorResource connResource = (ConnectorResource) resource;
if (getResourcesUtil().isEnabled(connResource)) {
ResourceInfo resourceInfo = ConnectorsUtil.getResourceInfo(connResource);
ConnectorConnectionPool pool = ResourcesUtil.createInstance().getConnectorConnectionPoolOfResource(resourceInfo);
if (pool != null && ConnectorConstants.XA_TRANSACTION_TX_SUPPORT_STRING.equals(getTransactionSupport(pool))) {
connPools.add(pool);
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("ConnectorsRecoveryResourceHandler loadXAResourcesAndItsConnections :: " + "adding : " + connResource.getPoolName());
}
}
}
}
loadAllConnectorResources();
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Recovering pools : " + connPools.size());
}
for (ConnectorConnectionPool connPool : connPools) {
PoolInfo poolInfo = ConnectorsUtil.getPoolInfo(connPool);
try {
String[] dbUserPassword = getdbUserPasswordOfConnectorConnectionPool(connPool);
if (dbUserPassword == null) {
continue;
}
String dbUser = dbUserPassword[0];
String dbPassword = dbUserPassword[1];
Subject subject = new Subject();
// username [pointbase interprets this as "root"]/password.
if (dbPassword == null) {
dbPassword = "";
if (_logger.isLoggable(Level.FINEST)) {
_logger.log(Level.FINEST, "datasource.xadatasource_nullpassword_error", poolInfo);
}
}
if (dbUser == null) {
dbUser = "";
if (_logger.isLoggable(Level.FINEST)) {
_logger.log(Level.FINEST, "datasource.xadatasource_nulluser_error", poolInfo);
}
}
String rarName = connPool.getResourceAdapterName();
// TODO V3 JMS-RA ??
if (ConnectorAdminServiceUtils.isJMSRA(rarName)) {
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Performing recovery for JMS RA, poolName " + poolInfo);
}
ManagedConnectionFactory[] mcfs = crt.obtainManagedConnectionFactories(poolInfo);
_logger.log(Level.INFO, "JMS resource recovery has created CFs = " + mcfs.length);
for (int i = 0; i < mcfs.length; i++) {
PasswordCredential pc = new PasswordCredential(dbUser, dbPassword.toCharArray());
pc.setManagedConnectionFactory(mcfs[i]);
Principal prin = new ResourcePrincipal(dbUser, dbPassword);
subject.getPrincipals().add(prin);
subject.getPrivateCredentials().add(pc);
ManagedConnection mc = mcfs[i].createManagedConnection(subject, null);
connList.add(mc);
try {
XAResource xares = mc.getXAResource();
if (xares != null) {
xaresList.add(xares);
}
} catch (ResourceException ex) {
// ignored. Not at XA_TRANSACTION level
}
}
} else {
ManagedConnectionFactory mcf = crt.obtainManagedConnectionFactory(poolInfo);
PasswordCredential pc = new PasswordCredential(dbUser, dbPassword.toCharArray());
pc.setManagedConnectionFactory(mcf);
Principal prin = new ResourcePrincipal(dbUser, dbPassword);
subject.getPrincipals().add(prin);
subject.getPrivateCredentials().add(pc);
ManagedConnection mc = mcf.createManagedConnection(subject, null);
connList.add(mc);
try {
XAResource xares = mc.getXAResource();
if (xares != null) {
xaresList.add(xares);
}
} catch (ResourceException ex) {
// ignored. Not at XA_TRANSACTION level
}
}
} catch (Exception ex) {
_logger.log(Level.WARNING, "datasource.xadatasource_error", poolInfo);
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "datasource.xadatasource_error_excp", ex);
}
}
}
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Total XAResources identified for recovery is " + xaresList.size());
_logger.log(Level.FINE, "Total connections identified for recovery is " + connList.size());
}
}
Aggregations