1 26 27 package org.objectweb.jonas_web.deployment.api; 28 29 import java.util.ArrayList ; 30 import java.util.HashMap ; 31 import java.util.Iterator ; 32 import java.util.List ; 33 import java.util.Map ; 34 35 39 public class MethodsDesc { 40 41 44 private Map httpMethods = null; 45 46 49 public static final String [] METHODS = new String [] { 50 "DELETE", "GET", "HEAD", "OPTIONS", "POST", "PUT", "TRACE" 51 }; 52 53 56 private static final int ALL_ACTIONS_LENGTH = 38; 57 58 62 public MethodsDesc() { 63 httpMethods = new HashMap (); 64 for (int m = 0; m < METHODS.length; m++) { 65 httpMethods.put(METHODS[m], new MethodDesc(METHODS[m])); 66 } 67 } 68 69 75 public void addMethods(String [] methods, String transportGuarantee, boolean isExcluded) { 76 MethodDesc method = null; 77 for (int m = 0; m < methods.length; m++) { 78 method = getMethod(methods[m]); 79 method.addTransportGuarantee(transportGuarantee); 80 if (isExcluded) { 81 method.setExcluded(); 82 } else { 83 method.setUnchecked(); 84 } 85 } 86 } 87 88 94 public void addMethodsOnRole(String [] methods, String role, String transportGuarantee) { 95 for (int m = 0; m < methods.length; m++) { 96 getMethod(methods[m]).addRole(role, transportGuarantee); 97 } 98 } 99 100 101 106 private MethodDesc getMethod(String methodName) { 107 MethodDesc m = (MethodDesc) httpMethods.get(methodName.toUpperCase()); 108 if (m == null) { 109 throw new IllegalStateException ("No such method named '" + methodName + "'."); 110 } else { 111 return m; 112 } 113 } 114 115 116 117 121 public String getExcludedActions() { 122 StringBuffer actions = new StringBuffer (); 123 MethodDesc method = null; 124 for (Iterator it = httpMethods.values().iterator(); it.hasNext();) { 125 method = (MethodDesc) it.next(); 126 if (method.isExcluded() && !method.hasRole()) { 127 if (actions.length() > 0) { 129 actions.append(","); 130 } 131 actions.append(method.getName()); 132 } 133 } 134 return actions.toString(); 135 } 136 137 138 142 public String getUncheckedActions() { 143 StringBuffer actions = new StringBuffer (); 144 MethodDesc method = null; 145 for (Iterator it = httpMethods.values().iterator(); it.hasNext();) { 146 method = (MethodDesc) it.next(); 147 if (method.isUnchecked() && !method.hasRole()) { 148 if (actions.length() > 0) { 150 actions.append(","); 151 } 152 actions.append(method.getName()); 153 } 154 } 155 if (actions.length() == ALL_ACTIONS_LENGTH) { 157 return null; 158 } else { 159 return actions.toString(); 160 } 161 } 162 163 167 public Map getRoleMapActions() { 168 MethodDesc method = null; 169 Map rolesMap = new HashMap (); 170 for (Iterator it = httpMethods.values().iterator(); it.hasNext();) { 171 method = (MethodDesc) it.next(); 172 if (method.hasRole()) { 173 for (Iterator itRoles = method.getRolesIterator(); itRoles.hasNext();) { 174 175 String roleName = (String ) itRoles.next(); 176 String actions = (String ) rolesMap.get(roleName); 177 if (actions == null) { 178 actions = method.getName(); 179 } else { 180 actions += ","; 181 actions += method.getName(); 182 } 183 rolesMap.put(roleName, actions); 184 } 185 } 186 } 187 return rolesMap; 188 } 189 190 191 197 public List getUncheckedWebUserDataActionsRoleList() { 198 199 MethodDesc method = null; 200 StringBuffer nones = null; 202 StringBuffer confidentials = null; 203 StringBuffer integrals = null; 204 205 for (Iterator it = httpMethods.values().iterator(); it.hasNext();) { 207 method = (MethodDesc) it.next(); 208 String methodName = method.getName(); 209 if (method.isUnchecked() && method.hasRole()) { 211 if (method.getTransportGuarantee().hasNone()) { 213 if (nones == null) { 214 nones = new StringBuffer (methodName); 215 } else { 216 nones.append(","); 217 nones.append(methodName); 218 } 219 } 220 if (method.getTransportGuarantee().isIntegral()) { 222 if (integrals == null) { 223 integrals = new StringBuffer (methodName); 224 } else { 225 integrals.append(","); 226 integrals.append(methodName); 227 } 228 } 229 230 if (method.getTransportGuarantee().isConfidential()) { 232 if (confidentials == null) { 233 confidentials = new StringBuffer (methodName); 234 } else { 235 confidentials.append(","); 236 confidentials.append(methodName); 237 } 238 } 239 } 240 } 241 242 246 List unchecked = new ArrayList (); 247 if (nones != null) { 248 unchecked.add(nones.toString()); 249 } 250 if (integrals != null) { 251 integrals.append(":"); 252 integrals.append(TransportGuaranteeDesc.INTEGRAL_TRANSPORT); 253 unchecked.add(integrals.toString()); 254 } 255 if (confidentials != null) { 256 confidentials.append(":"); 257 confidentials.append(TransportGuaranteeDesc.CONFIDENTIAL_TRANSPORT); 258 unchecked.add(confidentials.toString()); 259 } 260 261 return unchecked; 262 } 263 264 265 266 } 267 | Popular Tags |