1 package com.sun.enterprise.tools.verifier.tests.ejb.runtime;2 3 /*4 * The contents of this file are subject to the terms 5 * of the Common Development and Distribution License 6 * (the License). You may not use this file except in7 * compliance with the License.8 * 9 * You can obtain a copy of the license at 10 * https://glassfish.dev.java.net/public/CDDLv1.0.html or11 * glassfish/bootstrap/legal/CDDLv1.0.txt.12 * See the License for the specific language governing 13 * permissions and limitations under the License.14 * 15 * When distributing Covered Code, include this CDDL 16 * Header Notice in each file and include the License file 17 * at glassfish/bootstrap/legal/CDDLv1.0.txt. 18 * If applicable, add the following below the CDDL Header, 19 * with the fields enclosed by brackets [] replaced by20 * you own identifying information: 21 * "Portions Copyrighted [year] [name of copyright owner]"22 * 23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.24 */25 26 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;27 import java.util.*;28 import com.sun.enterprise.deployment.EjbDescriptor;29 import com.sun.enterprise.deployment.EjbSessionDescriptor;30 import com.sun.enterprise.tools.verifier.*;31 import com.sun.enterprise.tools.verifier.tests.*;32 33 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;34 35 import com.sun.enterprise.deployment.EjbEntityDescriptor;36 import com.sun.enterprise.deployment.EjbSessionDescriptor;37 import java.lang.reflect.*;38 39 /** ias-ejb-jar40 * security-role-mapping [0,n]41 * role-name [String]42 * principal-name [String] | group-name [String]43 *44 * The element defines the security role mappings for the bean.45 * The role-name should not be an empty string46 * The role-name should be desclared in the assembly-descriptor in the ejb-jar.xml47 * file.48 * The principal-name and group-name should not be empty strings.49 *50 * @author Irfan Ahmed51 */52 public class ASSecurityRoleMapping extends EjbTest implements EjbCheck { 53 //hs NO API for security-role-mapping element from sun-ejb-jar.xml54 //hs DOL Issue - information missing55 56 public Result check(EjbDescriptor descriptor)57 {58 Result result = getInitializedResult();59 /*60 * 61 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();62 boolean oneFailed = false;63 SunEjbJar ejbJar = descriptor.getEjbBundleDescriptor().getIasEjbObject();64 65 if(descriptor.getEjbBundleDescriptor().getTestsDone().contains(getClass().getName()))66 {67 result.setStatus(Result.NOT_RUN);68 result.addGoodDetails(smh.getLocalString("iasEjbJar.allReadyRun",69 "NOT RUN [AS-EJB ias-ejb-jar] security-role-mapping is a JAR Level Test. This test has already been run once"));70 return result;71 }72 descriptor.getEjbBundleDescriptor().setTestsDone(getClass().getName());73 74 if(ejbJar!=null)75 {76 SecurityRoleMapping secRoleMapping[] = ejbJar.getSecurityRoleMapping();77 if(secRoleMapping.length>0)78 {79 for(int i=0;i<secRoleMapping.length;i++)80 {81 String roleName = secRoleMapping[i].getRoleName();82 if(roleName.length()==0)83 {84 oneFailed = true;85 result.failed(smh.getLocalString(getClass().getName()+".failed",86 "FAILED [AS-EJB security-role-mapping] : role-name cannot be an empty string",87 new Object[]{new Integer(i)}));88 }89 else90 {91 boolean roleNameFound = false;92 Set roles = descriptor.getEjbBundleDescriptor().getRoles();93 Iterator it = roles.iterator();94 while(it.hasNext())95 {96 Role role = (Role)it.next();97 if(role.getName().equals(roleName))98 {99 roleNameFound = true;100 break;101 }102 }103 if(roleNameFound)104 {105 result.passed(smh.getLocalString(getClass().getName()+".passed",106 "PASSED [AS-EJB security-role-mapping] : role-name {1} verified with ejb-jar.xml",107 new Object[]{new Integer(i), roleName}));108 }109 else110 {111 oneFailed = true;112 //<addition> srini@sun.com Bug: 4721914113 //result.failed(smh.getLocalString(getClass().getName()+".failed",114 result.failed(smh.getLocalString(getClass().getName()+".failed1",115 "FAILED [AS-EJB security-role-mapping] : role-name {1} could not be located in ejb-jar.xml",116 new Object[]{new Integer(i), roleName}));117 //<addition>118 }119 }120 121 String pName[] = secRoleMapping[i].getPrincipalName();122 for(int j=0;j<pName.length;j++)123 {124 if(pName[j].length()==0)125 {126 oneFailed = true;127 //<addition> srini@sun.com Bug: 4721914128 //result.failed(smh.getLocalString(getClass().getName()+".failed",129 result.failed(smh.getLocalString(getClass().getName()+".failed2",130 "FAILED [AS-EJB security-role-mapping] : principal-name cannot be empty string",131 new Object[]{new Integer(i)}));132 //<addition>133 }134 else135 {136 //<addition> srini@sun.com Bug: 4721914137 //result.passed(smh.getLocalString(getClass().getName()+".passed",138 result.passed(smh.getLocalString(getClass().getName()+".passed1",139 "PASSED [AS-EJB security-role-mapping] : principal-name is {1}",140 new Object[]{new Integer(i),pName[j]}));141 //<addition>142 }143 }144 145 pName = secRoleMapping[i].getGroupName();146 for(int j=0;j<pName.length;j++)147 {148 if(pName[j].length()==0)149 {150 oneFailed = true;151 //<addition> srini@sun.com Bug: 4721914152 //result.failed(smh.getLocalString(getClass().getName()+".failed",153 result.failed(smh.getLocalString(getClass().getName()+".failed3",154 "FAILED [AS-EJB security-role-mapping] : group-name cannot be empty string",155 new Object[]{new Integer(i)}));156 //<addition>157 }158 else159 {160 //<addition> srini@sun.com Bug: 4721914161 //result.passed(smh.getLocalString(getClass().getName()+".passed",162 result.passed(smh.getLocalString(getClass().getName()+".passed2",163 "PASSED [AS-EJB security-role-mapping] : group-name is {1}",164 new Object[]{new Integer(i),pName[j]}));165 //<addition>166 }167 }168 }169 }170 else171 {172 result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable",173 "NOT APPLICABLE [AS-EJB] : security-role-mapping element is not defined"));174 }175 if(oneFailed)176 result.setStatus(Result.FAILED);177 }178 else179 {180 result.addErrorDetails(smh.getLocalString181 ("tests.componentNameConstructor",182 "For [ {0} ]",183 new Object[] {compName.toString()}));184 result.addErrorDetails(smh.getLocalString185 (getClass().getName() + ".notRun",186 "NOT RUN [AS-EJB] : Could not create an SunEjbJar object"));187 }188 */189 return result;190 }191 }192 193