use of org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor 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.EjbEntityDescriptor 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.EjbEntityDescriptor 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;
}
}
use of org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor in project Payara by payara.
the class EjbBundleNode method writeDescriptor.
@Override
public Node writeDescriptor(Node parent, EjbBundleDescriptorImpl ejbDesc) {
Node jarNode = super.writeDescriptor(parent, ejbDesc);
Node entrepriseBeansNode = appendChild(jarNode, EjbTagNames.EJBS);
for (EjbDescriptor ejb : ejbDesc.getEjbs()) {
if (EjbSessionDescriptor.TYPE.equals(ejb.getType())) {
EjbSessionNode subNode = new EjbSessionNode();
subNode.writeDescriptor(entrepriseBeansNode, EjbTagNames.SESSION, (EjbSessionDescriptor) ejb);
} else if (EjbEntityDescriptor.TYPE.equals(ejb.getType())) {
EjbEntityNode subNode = new EjbEntityNode();
subNode.writeDescriptor(entrepriseBeansNode, EjbTagNames.ENTITY, (EjbEntityDescriptor) ejb);
} else if (EjbMessageBeanDescriptor.TYPE.equals(ejb.getType())) {
MessageDrivenBeanNode subNode = new MessageDrivenBeanNode();
subNode.writeDescriptor(entrepriseBeansNode, EjbTagNames.MESSAGE_DRIVEN, (EjbMessageBeanDescriptor) ejb);
} else {
throw new IllegalStateException("Unknown ejb type " + ejb.getType());
}
}
if (ejbDesc.hasInterceptors()) {
Node interceptorsNode = appendChild(jarNode, EjbTagNames.INTERCEPTORS);
EjbInterceptorNode interceptorNode = new EjbInterceptorNode();
for (EjbInterceptor next : ejbDesc.getInterceptors()) {
interceptorNode.writeDescriptor(interceptorsNode, EjbTagNames.INTERCEPTOR, next);
}
}
// relationships*
if (ejbDesc.hasRelationships()) {
(new RelationshipsNode()).writeDescriptor(jarNode, EjbTagNames.RELATIONSHIPS, ejbDesc);
}
// assembly-descriptor
writeAssemblyDescriptor(jarNode, ejbDesc);
appendTextChild(jarNode, EjbTagNames.EJB_CLIENT_JAR, ejbDesc.getEjbClientJarUri());
return jarNode;
}
use of org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor in project Payara by payara.
the class EjbEntityNode method getEjbDescriptor.
@Override
public EjbEntityDescriptor getEjbDescriptor() {
if (descriptor == null) {
descriptor = new EjbEntityDescriptor();
descriptor.setEjbBundleDescriptor((EjbBundleDescriptorImpl) getParentNode().getDescriptor());
}
return descriptor;
}
Aggregations