use of com.sun.enterprise.deployment.RoleReference 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 com.sun.enterprise.deployment.RoleReference 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 com.sun.enterprise.deployment.RoleReference in project Payara by payara.
the class EjbDescriptor method removeRole.
void removeRole(Role role) {
// this.getPermissionedRoles().remove(role);
this.getPermissionedMethodsByPermission().remove(new MethodPermission(role));
Set roleReferences = new HashSet(this.getRoleReferences());
for (Iterator itr = roleReferences.iterator(); itr.hasNext(); ) {
RoleReference roleReference = (RoleReference) itr.next();
if (roleReference.getRole().equals(role)) {
roleReference.setValue("");
}
}
}
use of com.sun.enterprise.deployment.RoleReference in project Payara by payara.
the class EjbNode method writeRoleReferenceDescriptors.
/**
* write the security role references to the DOM Tree
*
* @param parentNode for the DOM tree
* @param refs iterator over the RoleReference descriptors to write
*/
protected void writeRoleReferenceDescriptors(Node parentNode, Iterator refs) {
SecurityRoleRefNode node = new SecurityRoleRefNode();
for (; refs.hasNext(); ) {
RoleReference roleRef = (RoleReference) refs.next();
node.writeDescriptor(parentNode, TagNames.ROLE_REFERENCE, roleRef);
}
}
use of com.sun.enterprise.deployment.RoleReference in project Payara by payara.
the class EjbBundleTracerVisitor method accept.
protected void accept(EjbDescriptor ejb) {
logInfo("==================");
logInfo(ejb.getType() + " Bean " + ejb.getName());
logInfo("\thomeClassName " + ejb.getHomeClassName());
logInfo("\tremoteClassName " + ejb.getRemoteClassName());
logInfo("\tlocalhomeClassName " + ejb.getLocalHomeClassName());
logInfo("\tlocalClassName " + ejb.getLocalClassName());
logInfo("\tremoteBusinessIntfs " + ejb.getRemoteBusinessClassNames());
logInfo("\tlocalBusinessIntfs " + ejb.getLocalBusinessClassNames());
logInfo("\tjndiName " + ejb.getJndiName());
logInfo("\tejbClassName " + ejb.getEjbClassName());
logInfo("\ttransactionType " + ejb.getTransactionType());
if (ejb.getUsesCallerIdentity() == false) {
logInfo("\trun-as role " + ejb.getRunAsIdentity());
} else {
logInfo("\tuse-caller-identity " + ejb.getUsesCallerIdentity());
}
for (EjbReference aRef : ejb.getEjbReferenceDescriptors()) {
accept(aRef);
}
for (Iterator e = ejb.getPermissionedMethodsByPermission().keySet().iterator(); e.hasNext(); ) {
MethodPermission mp = (MethodPermission) e.next();
Set methods = (Set) ejb.getPermissionedMethodsByPermission().get(mp);
accept(mp, methods);
}
if (ejb.getStyledPermissionedMethodsByPermission() != null) {
for (Iterator e = ejb.getStyledPermissionedMethodsByPermission().keySet().iterator(); e.hasNext(); ) {
MethodPermission mp = (MethodPermission) e.next();
Set methods = (Set) ejb.getStyledPermissionedMethodsByPermission().get(mp);
accept(mp, methods);
}
}
for (RoleReference roleRef : ejb.getRoleReferences()) {
accept(roleRef);
}
for (Iterator e = ejb.getMethodContainerTransactions().keySet().iterator(); e.hasNext(); ) {
MethodDescriptor md = (MethodDescriptor) e.next();
ContainerTransaction ct = (ContainerTransaction) ejb.getMethodContainerTransactions().get(md);
accept(md, ct);
}
for (EnvironmentProperty envProp : ejb.getEnvironmentProperties()) {
accept(envProp);
}
for (ResourceReferenceDescriptor next : ejb.getResourceReferenceDescriptors()) {
accept(next);
}
for (ResourceEnvReferenceDescriptor next : ejb.getResourceEnvReferenceDescriptors()) {
accept(next);
}
for (MessageDestinationReferencer next : ejb.getMessageDestinationReferenceDescriptors()) {
accept(next);
}
// referencer as well.
if (ejb.getType().equals(EjbMessageBeanDescriptor.TYPE)) {
MessageDestinationReferencer msgDestReferencer = (MessageDestinationReferencer) ejb;
if (msgDestReferencer.getMessageDestinationLinkName() != null) {
accept(msgDestReferencer);
}
}
for (ServiceReferenceDescriptor sref : ejb.getServiceReferenceDescriptors()) {
accept(sref);
}
if (ejb instanceof EjbCMPEntityDescriptor) {
EjbCMPEntityDescriptor cmp = (EjbCMPEntityDescriptor) ejb;
PersistenceDescriptor persistenceDesc = cmp.getPersistenceDescriptor();
for (Object fd : persistenceDesc.getCMPFields()) {
accept((FieldDescriptor) fd);
}
for (Object o : persistenceDesc.getQueriedMethods()) {
if (o instanceof MethodDescriptor) {
QueryDescriptor qd = persistenceDesc.getQueryFor((MethodDescriptor) o);
accept(qd);
}
}
}
}
Aggregations