use of org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl in project Payara by payara.
the class SecurityIdentityRefs method check.
/**
* Security role references test.
* The Bean provider must declare all of the enterprise's bean references
* to security roles as specified in section 15.2.1.3 of the Moscone spec.
* Role names must be mapped to names within the jar.
*
* @param descriptor the Enterprise Java Bean deployment descriptor
*
* @return <code>Result</code> the results for this assertion
*/
public Result check(EjbDescriptor descriptor) {
Result result = getInitializedResult();
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
if (descriptor.getUsesCallerIdentity()) {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.SecurityIdentityRefs.notApplicable3", "Bean [ {0} ] does not specify a run-as identity", new Object[] { descriptor.getName() }));
return result;
}
RunAsIdentityDescriptor identity = descriptor.getRunAsIdentity();
if (identity == null) {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.SecurityIdentityRefs.notApplicable2", "Bean [ {0} ] does not specify a security identity", new Object[] { descriptor.getName() }));
return result;
}
EjbBundleDescriptorImpl bundleDescriptor = descriptor.getEjbBundleDescriptor();
Set roles = bundleDescriptor.getRoles();
Iterator roleIterator = roles.iterator();
while (roleIterator.hasNext()) {
Role role = (Role) roleIterator.next();
if (role.getName().equals(identity.getRoleName())) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.SecurityIdentityRefs.passed", "Security identity run-as specified identity [ {0} ] role is found in the list of roles", new Object[] { role.getName() }));
return result;
}
}
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.SecurityIdentityRefs.failed", "Security identity run-as specified identity [ {0} ] role is not valid", new Object[] { identity.getRoleName() }));
return result;
}
use of org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl in project Payara by payara.
the class SecurityRolesRefs method check.
/**
* Security role references test.
* The Bean provider must declare all of the enterprise's bean references
* to security roles as specified in section 15.2.1.3 of the Moscone spec.
* Role names must be mapped to names within the jar.
*
* @param descriptor the Enterprise Java Bean deployment descriptor
*
* @return <code>Result</code> the results for this assertion
*/
public Result check(EjbDescriptor descriptor) {
Result result = getInitializedResult();
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
if ((descriptor instanceof EjbEntityDescriptor) || (descriptor instanceof EjbSessionDescriptor)) {
// RULE: Role names must be mapped to names within the ejb-jar
Set roleReferences = descriptor.getRoleReferences();
Iterator roleRefsIterator = roleReferences.iterator();
EjbBundleDescriptorImpl bundleDescriptor = descriptor.getEjbBundleDescriptor();
Set roles = bundleDescriptor.getRoles();
Iterator roleIterator = roles.iterator();
Role role = null;
RoleReference roleReference = null;
boolean found = false;
boolean oneFailed = false;
if (roleRefsIterator.hasNext()) {
while (roleRefsIterator.hasNext()) {
found = false;
roleReference = (RoleReference) roleRefsIterator.next();
while (roleIterator.hasNext()) {
role = (Role) roleIterator.next();
if (role.getName().equals(roleReference.getValue())) {
found = true;
// reset this so next time it drop back into here
roleIterator = roles.iterator();
break;
}
}
if (!found) {
// print the roleReference with no corresponding env-prop
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Erro: The security role reference [ {0} ] has no corresponding linked security role name [ {1} ]", new Object[] { roleReference.getName(), roleReference.getValue() }));
if (!oneFailed) {
oneFailed = true;
}
} else {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "The security role reference [ {0} ] has corresponding linked security role name [ {1} ]", new Object[] { roleReference.getName(), roleReference.getValue() }));
}
}
} else {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "There are no role references within this bean [ {0} ]", new Object[] { descriptor.getName() }));
return result;
}
// status got stomped on within the while loop by the next env-prop
if (oneFailed) {
result.setStatus(Result.FAILED);
} else {
result.setStatus(Result.PASSED);
}
return result;
} else {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "[ {0} ] not called \n with a Session or Entity bean.", new Object[] { getClass() }));
return result;
}
}
use of org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl in project Payara by payara.
the class SecurityRolesBind method check.
/**
* If the Application assembler defines security roles in the deployment
* descriptor, the Application Assembler must bind security role references
* declared by the Bean Provider to the security roles.
*
* @param descriptor the Enterprise Java Bean deployment descriptor
*
* @return <code>Result</code> the results for this assertion
*/
public Result check(EjbDescriptor descriptor) {
Result result = getInitializedResult();
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
EjbBundleDescriptorImpl bundleDescriptor = descriptor.getEjbBundleDescriptor();
Set ejbs = bundleDescriptor.getEjbs();
Iterator ejbIterator = ejbs.iterator();
EjbDescriptor ejb = null;
Set roleReferences = null;
Iterator roleRefsIterator = null;
Set roles = bundleDescriptor.getRoles();
Iterator rolesIterator = roles.iterator();
RoleReference roleReference = null;
Role role = null;
boolean oneFailed = false;
// check to see if there are any undefined roles being referenced
while (ejbIterator.hasNext()) {
ejb = (EjbDescriptor) ejbIterator.next();
roleReferences = ejb.getRoleReferences();
roleRefsIterator = roleReferences.iterator();
if (roleRefsIterator.hasNext()) {
while (roleRefsIterator.hasNext()) {
roleReference = (RoleReference) roleRefsIterator.next();
role = roleReference.getRole();
if (!role.getName().equals("") && !bundleDescriptor.getRoles().contains(role)) {
// print the undefine role
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: The role [ {0} ] for bean [ {1} ] is undefined.", new Object[] { role.getName(), ejb.getName() }));
if (!oneFailed) {
oneFailed = true;
}
} else {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed", "The role [ {0} ] for bean [ {1} ] is defined.", new Object[] { role.getName(), ejb.getName() }));
}
}
} else {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "There are no role references which need to be bound to other security roles within this bean [ {0} ]", new Object[] { ejb.getName() }));
}
}
if (oneFailed) {
result.setStatus(Result.FAILED);
}
return result;
}
use of org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl in project Payara by payara.
the class EjbLinkElement method check.
/**
* The referenced bean must be an enterprise bean in the same ear file.
*
* @param descriptor the Enterprise Java Bean deployment descriptor
* @return <code>Result</code> the results for this assertion
*/
public Result check(EjbDescriptor descriptor) {
Result result = getInitializedResult();
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
boolean resolved = false;
boolean oneFailed = false;
int na = 0;
// bean in the same application .ear file.
if (!descriptor.getEjbReferenceDescriptors().isEmpty()) {
for (Iterator itr = descriptor.getEjbReferenceDescriptors().iterator(); itr.hasNext(); ) {
EjbReferenceDescriptor nextEjbReference = (EjbReferenceDescriptor) itr.next();
if (nextEjbReference.isLinked()) {
String ejb_link = nextEjbReference.getLinkName();
ejb_link = ejb_link.substring(ejb_link.indexOf("#") + 1);
try {
// applicationName = application.getName();
// File tmpFile = new File(System.getProperty("java.io.tmpdir"));
// tmpFile = new File(tmpFile, Verifier.TMPFILENAME + ".tmp");
Set ejbBundles = descriptor.getApplication().getBundleDescriptors(EjbBundleDescriptorImpl.class);
Iterator ejbBundlesIterator = ejbBundles.iterator();
EjbBundleDescriptorImpl ejbBundle = null;
while (ejbBundlesIterator.hasNext()) {
ejbBundle = (EjbBundleDescriptorImpl) ejbBundlesIterator.next();
// }
for (Iterator itr2 = ejbBundle.getEjbs().iterator(); itr2.hasNext(); ) {
EjbDescriptor ejbDescriptor = (EjbDescriptor) itr2.next();
if (ejbDescriptor.getName().equals(ejb_link)) {
resolved = true;
logger.log(Level.FINE, getClass().getName() + ".passed", new Object[] { ejb_link, ejbDescriptor.getName() });
addGoodDetails(result, compName);
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "Valid referenced bean [ {0} ].", new Object[] { ejb_link }));
break;
}
}
}
} catch (Exception e) {
addErrorDetails(result, compName);
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failedException1", "Exception occured while opening or saving the J2EE archive.", new Object[] {}));
logger.log(Level.FINE, "com.sun.enterprise.tools.verifier.testsprint", new Object[] { "[" + getClass() + "] Error: " + e.getMessage() });
if (!oneFailed) {
oneFailed = true;
}
}
// resolved the last ejb-link okay
if (!resolved) {
if (!oneFailed) {
oneFailed = true;
}
addErrorDetails(result, compName);
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: No EJB matching [ {0} ] found within [ {1} ] jar file.", new Object[] { ejb_link, descriptor.getName() }));
} else {
// clear the resolved flag for the next ejb-link
resolved = false;
}
} else {
// Cannot get the link name of an ejb reference referring
// to an external bean, The value of the ejb-link element
// must be the ejb-name of an enterprise bean in the same
// ejb-ear file.
addNaDetails(result, compName);
result.addNaDetails(smh.getLocalString(getClass().getName() + ".notApplicable1", "Warning: Cannot verify the existence of an ejb reference [ {0} ] to external bean within different .ear file.", new Object[] { nextEjbReference.getName() }));
na++;
}
}
if (oneFailed) {
result.setStatus(Result.FAILED);
} else if (na == descriptor.getEjbReferenceDescriptors().size()) {
result.setStatus(Result.NOT_APPLICABLE);
} else {
result.setStatus(Result.PASSED);
}
// tmpFile.delete();
return result;
} else {
addNaDetails(result, compName);
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "There are no ejb references to other beans within this bean [ {0} ]", new Object[] { descriptor.getName() }));
}
return result;
}
use of org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl in project Payara by payara.
the class EjbDeployer method prepare.
@Override
public boolean prepare(DeploymentContext dc) {
EjbBundleDescriptorImpl ejbBundle = dc.getModuleMetaData(EjbBundleDescriptorImpl.class);
if (ejbBundle == null) {
String errMsg = localStrings.getLocalString("context.contains.no.ejb", "DeploymentContext does not contain any EJB", dc.getSourceDir());
throw new RuntimeException(errMsg);
}
// Get application-level properties (*not* module-level)
Properties appProps = dc.getAppProps();
long uniqueAppId;
if (!appProps.containsKey(APP_UNIQUE_ID_PROP)) {
// This is the first time load is being called for any ejb module in an
// application, so generate the unique id.
uniqueAppId = getNextEjbAppUniqueId();
appProps.setProperty(APP_UNIQUE_ID_PROP, uniqueAppId + "");
} else {
uniqueAppId = Long.parseLong(appProps.getProperty(APP_UNIQUE_ID_PROP));
}
OpsParams params = dc.getCommandParameters(OpsParams.class);
if (params.origin.isDeploy()) {
// KEEP_STATE is saved to AppProps in EjbApplication.stop
String keepStateVal = (String) dc.getAppProps().get(EjbApplication.KEEP_STATE);
if (keepStateVal != null) {
// save KEEP_STATE to Application so subsequent to make it available
// to subsequent deploy-related methods.
ejbBundle.getApplication().setKeepStateResolved(keepStateVal);
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "EjbDeployer.prepare set keepstate to {0} for application.", ejbBundle.getApplication().getKeepStateResolved());
}
}
}
Application app = ejbBundle.getApplication();
if (!app.isUniqueIdSet()) {
// This will set the unique id for all EJB components in the application.
// If there are multiple ejb modules in the app, we'll only call it once
// for the first ejb module load(). All the old
// .xml processing for unique-id in the sun-* descriptors is removed so
// this is the only place where Application.setUniqueId() should be called.
app.setUniqueId(uniqueAppId);
}
return super.prepare(dc);
}
Aggregations