use of com.sun.enterprise.deployment.MethodPermission in project Payara by payara.
the class EjbMethodIntfElement method check.
/**
* The method-intf element must be one of the following "Remote" or "Home" or "LocalHome" or "Local".
*
* @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();
// method-intf don't make sense for messagedriven bean
if (descriptor instanceof EjbMessageBeanDescriptor) {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "There are no <method-intf> elements within this bean [ {0} ]", new Object[] { descriptor.getName() }));
return result;
}
// <ejb-class>verifier.ejb.hello.BogusEJB...
try {
boolean na = false;
boolean na1 = false;
boolean oneFailed = false;
if (!descriptor.getMethodContainerTransactions().isEmpty()) {
for (Enumeration ee = descriptor.getMethodContainerTransactions().keys(); ee.hasMoreElements(); ) {
MethodDescriptor methodDescriptor = (MethodDescriptor) ee.nextElement();
String methodIntf = methodDescriptor.getEjbClassSymbol();
if (methodIntf == null) {
// || methodIntf.equals("")
continue;
}
// Home Remote LocalHome Local ServiceEndpoint
if (!((methodIntf.equals(MethodDescriptor.EJB_REMOTE)) || (methodIntf.equals(MethodDescriptor.EJB_HOME)) || (methodIntf.equals(MethodDescriptor.EJB_LOCALHOME)) || (methodIntf.equals(MethodDescriptor.EJB_LOCAL)) || (methodIntf.equals(MethodDescriptor.EJB_WEB_SERVICE)) || (methodIntf.length() == 0))) {
// The method-intf element must be one of the following "Remote" or "Home"
// if (!((methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_REMOTE)) ||
// (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_HOME)) ||
// (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCALHOME)) ||
// (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCAL)) ||
// (methodDescriptor.getEjbClassSymbol().length()==0))) {
oneFailed = true;
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: Container transaction method [ {0} ] method-intf element [ {1} ] must be one of the following: [ {2} ] or [ {3} ] or [ {4} ] or [ {5} ] within bean [ {6} ]", new Object[] { methodDescriptor.getName(), methodDescriptor.getEjbClassSymbol(), MethodDescriptor.EJB_REMOTE.toString(), MethodDescriptor.EJB_HOME, MethodDescriptor.EJB_LOCAL, MethodDescriptor.EJB_LOCALHOME, descriptor.getName() }));
} else {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "Container Transaction method [ {0} ] method-intf element [ {1} ] is one of the following: [ {2} ] or [ {3} ] or [ {4} ] or [ {5} ] within bean [ {6} ]", new Object[] { methodDescriptor.getName(), methodDescriptor.getEjbClassSymbol(), MethodDescriptor.EJB_REMOTE, MethodDescriptor.EJB_HOME, MethodDescriptor.EJB_LOCAL, MethodDescriptor.EJB_LOCALHOME, descriptor.getName() }));
}
}
} else {
na = true;
}
Map permissionedMethods = descriptor.getPermissionedMethodsByPermission();
if (permissionedMethods.size() > 0) {
for (Iterator e = permissionedMethods.keySet().iterator(); e.hasNext(); ) {
MethodPermission nextPermission = (MethodPermission) e.next();
Set permissionedMethodsForRole = (HashSet) permissionedMethods.get(nextPermission);
if (permissionedMethodsForRole != null) {
Set convertedPermissionedMethods = new HashSet();
for (Iterator itr = permissionedMethodsForRole.iterator(); itr.hasNext(); ) {
MethodDescriptor methodDescriptor = (MethodDescriptor) itr.next();
String methodIntf = methodDescriptor.getEjbClassSymbol();
if (methodIntf == null) {
// || methodIntf.equals("")
continue;
}
// Home Remote LocalHome Local ServiceEndpoint
if (!((methodIntf.equals(MethodDescriptor.EJB_REMOTE)) || (methodIntf.equals(MethodDescriptor.EJB_HOME)) || (methodIntf.equals(MethodDescriptor.EJB_LOCALHOME)) || (methodIntf.equals(MethodDescriptor.EJB_LOCAL)) || (methodIntf.equals(MethodDescriptor.EJB_WEB_SERVICE)) || (methodIntf.length() == 0))) {
// The method-intf element must be one of the following "Remote" or "Home"
// if (!((methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_REMOTE)) ||
// (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_HOME)) ||
// (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCAL)) ||
// (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCALHOME)) ||
// (methodDescriptor.getEjbClassSymbol().length()==0))) {
oneFailed = true;
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed1", "Error: Method permissions method [ {0} ] method-intf element [ {1} ] must be one of the interfaces of the bean [ {2} ]", new Object[] { methodDescriptor.getName(), methodDescriptor.getEjbClassSymbol(), descriptor.getName() }));
} else {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed1", "Method permissions method [ {0} ] method-intf element [ {1} ] is one of the interfaces of the bean [ {2} ]", new Object[] { methodDescriptor.getName(), methodDescriptor.getEjbClassSymbol(), descriptor.getName() }));
}
}
}
}
} else {
na1 = true;
}
if (oneFailed) {
result.setStatus(Result.FAILED);
} else if (na && na1) {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "There are no <method-intf> elements within this bean [ {0} ]", new Object[] { descriptor.getName() }));
} else {
result.setStatus(Result.PASSED);
}
return result;
} catch (Throwable t) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: [ {0} ] does not contain class [ {1} ] within bean [ {2} ]", new Object[] { descriptor.getName(), t.getMessage(), descriptor.getName() }));
return result;
}
}
use of com.sun.enterprise.deployment.MethodPermission in project Payara by payara.
the class EjbBundleNode method addDescriptor.
@Override
public void addDescriptor(Object newDescriptor) {
if (newDescriptor instanceof EjbDescriptor) {
descriptor.addEjb((EjbDescriptor) newDescriptor);
} else if (newDescriptor instanceof RelationshipDescriptor) {
descriptor.addRelationship((RelationshipDescriptor) newDescriptor);
} else if (newDescriptor instanceof MethodPermissionDescriptor) {
MethodPermissionDescriptor nd = (MethodPermissionDescriptor) newDescriptor;
MethodDescriptor[] array = nd.getMethods();
for (int i = 0; i < array.length; i++) {
EjbDescriptor target = descriptor.getEjbByName(array[i].getEjbName());
MethodPermission[] mps = nd.getMethodPermissions();
for (int j = 0; j < mps.length; j++) {
DOLUtils.getDefaultLogger().fine("Adding mp " + mps[j] + " to " + array[i] + " for ejb " + array[i].getEjbName());
target.addPermissionedMethod(mps[j], array[i]);
}
}
} else
super.addDescriptor(newDescriptor);
}
use of com.sun.enterprise.deployment.MethodPermission in project Payara by payara.
the class EjbBundleNode method addMethodPermissions.
private void addMethodPermissions(EjbDescriptor ejb, Map mpToMethods, Vector excludedMethods, MethodPermissionNode mpNode, Node assemblyNode) {
if (mpToMethods == null || mpToMethods.size() == 0) {
return;
}
for (Object o : mpToMethods.entrySet()) {
Map.Entry entry = (Map.Entry) o;
MethodPermission mp = (MethodPermission) entry.getKey();
if (mp.isExcluded()) {
// we need to be sure the method descriptors knows who owns them
Set methods = (Set) entry.getValue();
excludedMethods.addAll(methods);
} else {
MethodPermissionDescriptor mpd = new MethodPermissionDescriptor();
mpd.addMethodPermission(mp);
mpd.addMethods((Set) mpToMethods.get(mp));
mpNode.writeDescriptor(assemblyNode, EjbTagNames.METHOD_PERMISSION, mpd, ejb);
}
}
}
use of com.sun.enterprise.deployment.MethodPermission in project Payara by payara.
the class MethodPermissionNode method writeDescriptorInNode.
/**
* Write the descriptor in a DOM tree which root element is provided
*
* @param subNode the root element for the DOM fragment
* @param descriptor the method permisison descriptor
* @param ejb the ejb descriptor the above method permission belongs to
*/
public Node writeDescriptorInNode(Node subNode, MethodPermissionDescriptor descriptor, EjbDescriptor ejb) {
writeLocalizedDescriptions(subNode, descriptor);
MethodPermission[] mps = descriptor.getMethodPermissions();
if (mps.length == 0)
return null;
if (!mps[0].isExcluded()) {
if (mps[0].isUnchecked()) {
appendChild(subNode, EjbTagNames.UNCHECKED);
} else {
for (int i = 0; i < mps.length; i++) {
appendTextChild(subNode, TagNames.ROLE_NAME, mps[i].getRole().getName());
}
}
}
MethodDescriptor[] methods = descriptor.getMethods();
MethodNode mn = new MethodNode();
for (int i = 0; i < methods.length; i++) {
String ejbName = ejb.getName();
mn.writeDescriptor(subNode, EjbTagNames.METHOD, methods[i], ejbName);
}
return subNode;
}
use of com.sun.enterprise.deployment.MethodPermission in project Payara by payara.
the class MethodPermissionNode method setElementValue.
/**
* receives notification of the value for a particular tag
*
* @param element the xml element
* @param value it's associated value
*/
@Override
public void setElementValue(XMLElement element, String value) {
if (TagNames.ROLE_NAME.equals(element.getQName())) {
Role role = new Role(value);
descriptor.addMethodPermission(new MethodPermission(role));
} else {
super.setElementValue(element, value);
}
}
Aggregations