1 23 package com.sun.enterprise.tools.verifier.tests.ejb.elements; 24 25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest; 26 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck; 27 import java.util.*; 28 import com.sun.enterprise.deployment.*; 29 import com.sun.enterprise.tools.verifier.*; 30 import com.sun.enterprise.tools.verifier.tests.*; 31 32 36 public class MethodPermissionSecurityRoleExists extends EjbTest implements EjbCheck { 37 38 39 40 48 public Result check(EjbDescriptor descriptor) { 49 50 Result result = getInitializedResult(); 51 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 52 53 Map permissionedMethods = descriptor.getPermissionedMethodsByPermission(); 54 boolean oneFailed = false; 55 if (permissionedMethods.size() >0) { 56 for (Iterator e = permissionedMethods.keySet().iterator(); e.hasNext();) { 57 MethodPermission nextPermission = (MethodPermission) e.next(); 58 if (nextPermission.isRoleBased()) { 59 if (!descriptor.getEjbBundleDescriptor().getRoles().contains(nextPermission.getRole())) { 60 oneFailed =true; 61 result.addErrorDetails(smh.getLocalString 62 ("tests.componentNameConstructor", 63 "For [ {0} ]", 64 new Object [] {compName.toString()})); 65 result.addErrorDetails 66 (smh.getLocalString 67 (getClass().getName() + ".failed", 68 "Error: Method permissions role [ {0} ] must be one of the roles defined in bean [ {1} ]", 69 new Object [] {nextPermission.getRole().getName(), descriptor.getName()})); 70 } else { 71 result.addGoodDetails(smh.getLocalString 72 ("tests.componentNameConstructor", 73 "For [ {0} ]", 74 new Object [] {compName.toString()})); 75 result.addGoodDetails 76 (smh.getLocalString 77 (getClass().getName() + ".passed", 78 "Valid: Method permissions role [ {0} ] is defined as one of the roles defined in bean [ {1} ]", 79 new Object [] {nextPermission.getRole().getName(), descriptor.getName()})); 80 } 81 } else { 82 addNaDetails(result, compName); 83 result.notApplicable(smh.getLocalString 84 (getClass().getName() + ".notApplicable1", 85 "There are no role based method-permissions within this bean [ {0} ]", 86 new Object [] {descriptor.getName()})); 87 } 88 } 89 if (oneFailed) { 90 result.setStatus(Result.FAILED); 91 } else { 92 if(result.getStatus() != Result.NOT_APPLICABLE) 93 result.setStatus(Result.PASSED); 94 } 95 } else { 96 result.addNaDetails(smh.getLocalString 97 ("tests.componentNameConstructor", 98 "For [ {0} ]", 99 new Object [] {compName.toString()})); 100 result.notApplicable(smh.getLocalString 101 (getClass().getName() + ".notApplicable", 102 "There are no <method-permission> elements within this bean [ {0} ]", 103 new Object [] {descriptor.getName()})); 104 } 105 return result; 106 } 107 } 108 109 | Popular Tags |