use of org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor in project Payara by payara.
the class TransactionTypeBeanManaged method check.
/**
* Session Bean's bean-managed transaction demarcation test.
*
* The enterprise bean with bean-managed transaction demarcation must
* be a Session bean.
*
* @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();
String transactionType = descriptor.getTransactionType();
if (EjbSessionDescriptor.BEAN_TRANSACTION_TYPE.equals(transactionType)) {
if (descriptor instanceof EjbSessionDescriptor) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed", "[ {0} ] is valid transactionType within Session bean [ {1} ]", new Object[] { transactionType, descriptor.getName() }));
} else if (descriptor instanceof EjbEntityDescriptor) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: [ {0} ] is not valid transactionType within entity bean [ {1} ]", new Object[] { transactionType, descriptor.getName() }));
}
return result;
} else if (EjbSessionDescriptor.CONTAINER_TRANSACTION_TYPE.equals(transactionType)) {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "Expected [ {0} ] transaction demarcation, but [ {1} ] bean has [ {2} ] transaction demarcation.", new Object[] { EjbSessionDescriptor.BEAN_TRANSACTION_TYPE, descriptor.getName(), EjbSessionDescriptor.CONTAINER_TRANSACTION_TYPE }));
return result;
} else {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "Expected [ {0} ] transaction demarcation, but [ {1} ] bean has [ {2} ] transaction demarcation.", new Object[] { EjbSessionDescriptor.BEAN_TRANSACTION_TYPE, descriptor.getName(), transactionType }));
return result;
}
}
use of org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor in project Payara by payara.
the class LocalInterfaceExposed method check.
/**
* Bean interface type test.
* The bean provider must provide either Local or Remote or Both interfaces
*
* @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 EjbSessionDescriptor) && !(descriptor instanceof EjbEntityDescriptor)) {
addNaDetails(result, compName);
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "Test apply only to session or entity beans."));
return result;
}
EjbBundleDescriptorImpl bundle = descriptor.getEjbBundleDescriptor();
Iterator<EjbDescriptor> iterator = (bundle.getEjbs()).iterator();
Set<String> localInterfaces = new HashSet<String>();
while (iterator.hasNext()) {
EjbDescriptor entity = iterator.next();
if (entity.getLocalClassName() != null)
localInterfaces.add(entity.getLocalClassName());
localInterfaces.addAll(entity.getLocalBusinessClassNames());
}
ClassLoader jcl = getVerifierContext().getClassLoader();
try {
Set<String> remoteInterfaces = new HashSet<String>();
if (descriptor.getRemoteClassName() != null)
remoteInterfaces.add(descriptor.getRemoteClassName());
remoteInterfaces.addAll(descriptor.getRemoteBusinessClassNames());
for (String intf : remoteInterfaces) {
Class c = Class.forName(intf, false, getVerifierContext().getClassLoader());
Method[] methods = c.getDeclaredMethods();
for (int i = 0; i < methods.length; i++) {
// check all the local interfaces in the ejb bundle
for (Iterator itr = localInterfaces.iterator(); itr.hasNext(); ) {
String localIntf = (String) itr.next();
Class returnType = methods[i].getReturnType();
if ((getBaseComponentType(returnType).getName()).equals(localIntf) || (contains(methods[i].getParameterTypes(), localIntf))) {
addErrorDetails(result, compName);
result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error : Local Interface [ {0} ] has been " + "exposed in remote interface [ {1} ]", new Object[] { localIntf, c.getName() }));
return result;
}
}
}
}
addGoodDetails(result, compName);
result.passed(smh.getLocalString(getClass().getName() + ".passed", "Valid Remote interface."));
} catch (ClassNotFoundException e) {
Verifier.debug(e);
addErrorDetails(result, compName);
result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: [ {0} ] class not found.", new Object[] { descriptor.getRemoteClassName() }));
}
return result;
}
use of org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor in project Payara by payara.
the class MethodPermissionComponentInterface method check.
/**
* All methods should have a
* @param descriptor the Enterprise Java Bean deployment descriptor
*
* @return <code>Result</code> the results for this assertion
*/
public Result check(EjbDescriptor descriptor) {
result = getInitializedResult();
try {
if (descriptor instanceof EjbSessionDescriptor || descriptor instanceof EjbEntityDescriptor) {
Set methods = descriptor.getMethodDescriptors();
// Set methodPermissions = new HashSet();
boolean noPermissions = false;
for (Iterator i = methods.iterator(); i.hasNext(); ) {
MethodDescriptor md = (MethodDescriptor) i.next();
Set permissions = descriptor.getMethodPermissionsFor(md);
if (permissions.isEmpty() || (permissions == null)) {
result.addWarningDetails(smh.getLocalString(getClass().getName() + ".failed", "Warning: Method [ {0} ] of EJB [ {1} ] does not have assigned security-permissions", new Object[] { md.getName(), descriptor.getName() }));
result.setStatus(result.WARNING);
noPermissions = true;
}
}
if (!noPermissions) {
result.passed(smh.getLocalString(getClass().getName() + ".passed", "Valid: All [ {0} ]EJB interfaces methods have security-permissions assigned.", new Object[] { descriptor.getName() }));
}
} else {
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "The bean [ {0} ] is neither a Session nor Entity Bean", new Object[] { descriptor.getName() }));
return result;
}
} catch (Exception e) {
result.failed(smh.getLocalString(getClass().getName() + ".exception", "The test generated the following exception [ {0} ]", new Object[] { e.getLocalizedMessage() }));
}
return result;
}
use of org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor 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.EjbSessionDescriptor in project Payara by payara.
the class TransactionDemarcationType method check.
/**
* Session/Entity Bean Transaction demarcation type test.
* Application Assembler may define attributes for the methods of the
* remote/home interfaces of the beans that require container managed
* transaction demarcation. All beans of the this type (container managed
* transactions) require container managed tranaction demarcation through
* the use of "container-transaction" element.
*
* @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();
// <ejb-class>verifier.ejb.hello.BogusEJB...
try {
if ((descriptor instanceof EjbSessionDescriptor) || (descriptor instanceof EjbEntityDescriptor)) {
boolean oneFailed = false;
String transactionType = descriptor.getTransactionType();
if (EjbDescriptor.CONTAINER_TRANSACTION_TYPE.equals(transactionType)) {
try {
Arrays.sort(EJBObjectMethods);
ContainerTransaction containerTransaction = null;
if (!descriptor.getMethodContainerTransactions().isEmpty()) {
for (Enumeration ee = descriptor.getMethodContainerTransactions().keys(); ee.hasMoreElements(); ) {
MethodDescriptor methodDescriptor = (MethodDescriptor) ee.nextElement();
if (Arrays.binarySearch(EJBObjectMethods, methodDescriptor.getName()) < 0) {
containerTransaction = (ContainerTransaction) descriptor.getMethodContainerTransactions().get(methodDescriptor);
if (containerTransaction != null && containerTransaction.getTransactionAttribute() != null) {
String transactionAttribute = containerTransaction.getTransactionAttribute();
// don't need this check here
if (ContainerTransaction.NOT_SUPPORTED.equals(transactionAttribute) || ContainerTransaction.SUPPORTS.equals(transactionAttribute) || ContainerTransaction.REQUIRED.equals(transactionAttribute) || ContainerTransaction.REQUIRES_NEW.equals(transactionAttribute) || ContainerTransaction.MANDATORY.equals(transactionAttribute) || ContainerTransaction.NEVER.equals(transactionAttribute)) {
addGoodDetails(result, compName);
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "TransactionAttribute [ {0} ] for method [ {1} ] is valid.", new Object[] { transactionAttribute, methodDescriptor.getName() }));
} else {
oneFailed = true;
addErrorDetails(result, compName);
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: TransactionAttribute [ {0} ] for method [ {1} ] is not valid.", new Object[] { transactionAttribute, methodDescriptor.getName() }));
}
} else {
// Null transaction attributes are allowed in EJB 3. Default is REQUIRED.
if (getVerifierContext().getJavaEEVersion().compareTo(SpecVersionMapper.JavaEEVersion_5) < 0) {
oneFailed = true;
addErrorDetails(result, compName);
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failedException", "Error: TransactionAttribute is null for method [ {0} ]", new Object[] { methodDescriptor.getName() }));
}
}
} else // if you found a business method
{
// check if the ejb is a session bean
// and the method with transaction attribute belongs
// to home/local home interface
String ejbClass = methodDescriptor.getEjbClassSymbol();
/**
* Fixed the bug: 4883730. ejbClassSymbol is null when method-intf is not
* defined in the xml, since it is an optional field. Removed the earlier
* checks. A null method-intf indicates that the method is supposed to be
* in both Local & Home interfaces. **
*/
/*
String methodIntf = null;
try {
methodIntf = methodDescriptor.getEjbClassSymbol();
} catch ( Exception ex ) {}
if ( methodIntf == null ) { //|| methodIntf.equals("")
continue;
}
*/
boolean session = descriptor instanceof EjbSessionDescriptor;
boolean entity = descriptor instanceof EjbEntityDescriptor;
if (((ejbClass == null) || ejbClass.equals(MethodDescriptor.EJB_HOME) || ejbClass.equals(MethodDescriptor.EJB_LOCALHOME)) && session) {
oneFailed = true;
addErrorDetails(result, compName);
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failedHome", "Error: TransactionAttribute for method [ {0} ] is not valid. Home or Local Home interface methods of a session bean must not hvae a transaction attribute.", new Object[] { methodDescriptor.getName() }));
} else // and method with Tx attribute is "remove"
if (((ejbClass == null) || ejbClass.equals(MethodDescriptor.EJB_REMOTE) || ejbClass.equals(MethodDescriptor.EJB_LOCAL)) && session && methodDescriptor.getName().equals("remove")) {
// if remove method defined has parameters then pass else fail
if (methodDescriptor.getParameterClassNames() == null || methodDescriptor.getParameterClassNames().length == 0) {
// style 2
oneFailed = true;
addErrorDetails(result, compName);
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failedComp", "Error: TransactionAttribute for method [ {0} ] is not valid. 'remove' method in Remote/Local interface of a session bean must not have a transaction attribute.", new Object[] { methodDescriptor.getName() }));
} else {
addGoodDetails(result, compName);
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passedTest", "TransactionAttribute for method [ {0} ] is valid.", new Object[] { methodDescriptor.getName() }));
}
} else if (((ejbClass == null) || ejbClass.equals(MethodDescriptor.EJB_HOME) || ejbClass.equals(MethodDescriptor.EJB_LOCALHOME)) && entity) {
if (methodDescriptor.getParameterClassNames() == null || methodDescriptor.getParameterClassNames().length == 0) {
// style 2
oneFailed = true;
addErrorDetails(result, compName);
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed1", "Error: TransactionAttribute for method [ {0} ] is not valid. ", new Object[] { methodDescriptor.getName() }));
} else {
addGoodDetails(result, compName);
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passedTest", "TransactionAttribute for method [ {0} ] is valid.", new Object[] { methodDescriptor.getName() }));
}
} else if (((ejbClass == null) || ejbClass.equals(MethodDescriptor.EJB_REMOTE) || ejbClass.equals(MethodDescriptor.EJB_LOCAL)) && entity) {
if ((methodDescriptor.getName()).equals("isIdentical")) {
if (methodDescriptor.getParameterClassNames() == null || methodDescriptor.getParameterClassNames().length == 0) {
addGoodDetails(result, compName);
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passedTest", "TransactionAttribute for method [ {0} ] is valid.", new Object[] { methodDescriptor.getName() }));
} else {
String[] paramList = methodDescriptor.getParameterClassNames();
if (Array.getLength(paramList) == 1) {
if (paramList[0].equals("javax.ejb.EJBObject")) {
// style 3
oneFailed = true;
addErrorDetails(result, compName);
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed1", "Error: TransactionAttribute for method [ {0} ] is not valid.", new Object[] { methodDescriptor.getName() }));
} else {
addGoodDetails(result, compName);
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passedTest", "TransactionAttribute for method [ {0} ] is valid.", new Object[] { methodDescriptor.getName() }));
}
} else {
addGoodDetails(result, compName);
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passedTest", "TransactionAttribute for method [ {0} ] is valid.", new Object[] { methodDescriptor.getName() }));
}
}
} else {
// for all other methods in entity bean
if ((methodDescriptor.getName()).equals("remove")) {
addGoodDetails(result, compName);
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passedTest", "TransactionAttribute for method [ {0} ] is valid.", new Object[] { methodDescriptor.getName() }));
} else {
if (methodDescriptor.getParameterClassNames() == null || methodDescriptor.getParameterClassNames().length == 0) {
// style 2
oneFailed = true;
addErrorDetails(result, compName);
result.failed(smh.getLocalString(getClass().getName() + ".failedException1", "Error: [ {0} ] should not have a Transaction Attribute", new Object[] { methodDescriptor.getName() }));
}
}
}
}
}
}
} else {
addNaDetails(result, compName);
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "There are no method permissions within this bean [ {0} ]", new Object[] { descriptor.getName() }));
}
} catch (Exception e) {
oneFailed = true;
addErrorDetails(result, compName);
result.failed(smh.getLocalString(getClass().getName() + ".failedException2", "Error: [ {0} ] does not contain class [ {1} ] within bean [ {2} ]", new Object[] { descriptor.getName(), e.getMessage(), descriptor.getName() }));
return result;
}
if (oneFailed) {
result.setStatus(Result.FAILED);
} else {
result.setStatus(Result.PASSED);
}
return result;
} else {
// not container managed, but is a session/entity bean
addNaDetails(result, compName);
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "Bean [ {0} ] is not {1} managed, it is [ {2} ] managed.", new Object[] { descriptor.getName(), EjbDescriptor.CONTAINER_TRANSACTION_TYPE, transactionType }));
}
return result;
} else {
addNaDetails(result, compName);
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "[ {0} ] not called \n with a Session or Entity bean.", new Object[] { getClass() }));
return result;
}
} catch (Throwable t) {
addErrorDetails(result, compName);
result.failed(smh.getLocalString(getClass().getName() + ".failedException2", "Error: [ {0} ] does not contain class [ {1} ] within bean [ {2} ]", new Object[] { descriptor.getName(), t.getMessage(), descriptor.getName() }));
return result;
}
}
Aggregations