1 43 package net.jforum.view.admin; 44 45 import java.util.ArrayList ; 46 import java.util.Arrays ; 47 import java.util.Enumeration ; 48 import java.util.List ; 49 50 import net.jforum.ActionServletRequest; 51 import net.jforum.JForumExecutionContext; 52 import net.jforum.security.PermissionControl; 53 import net.jforum.security.Role; 54 import net.jforum.security.RoleValue; 55 import net.jforum.security.RoleValueCollection; 56 57 61 class PermissionProcessHelper 62 { 63 private PermissionControl pc; 64 private int id; 65 66 public PermissionProcessHelper(PermissionControl pc, int id, boolean isGroup) throws Exception 67 { 68 this.id = id; 69 this.pc = pc; 70 71 this.init(); 72 } 73 74 public PermissionProcessHelper(PermissionControl pc, int id) throws Exception 75 { 76 this(pc, id, false); 77 } 78 79 public void processData() throws Exception 80 { 81 ActionServletRequest request = JForumExecutionContext.getRequest(); 82 Enumeration e = request.getParameterNames(); 83 84 while (e.hasMoreElements()) { 85 String paramName = (String )e.nextElement(); 86 87 if (paramName.startsWith("perm_")) { 88 if (paramName.endsWith("$single")) { 89 String paramValue = request.getParameter(paramName); 90 91 paramName = paramName.substring(0, paramName.indexOf('$')); 92 93 Role role = new Role(); 94 role.setName(paramName); 95 96 if (paramValue.equals("deny")) { 97 role.setType(PermissionControl.ROLE_DENY); 98 } 99 else { 100 role.setType(PermissionControl.ROLE_ALLOW); 101 } 102 103 this.pc.addRole(this.id, role); 104 } 105 else { 106 String [] paramValues = request.getParameterValues(paramName); 107 108 RoleValueCollection roleValues = new RoleValueCollection(); 109 if (!"all".equals(paramValues[0])) { 110 for (int i = 0; i < paramValues.length; i++) { 112 roleValues.add(this.createRoleValue(paramValues[i], PermissionControl.ROLE_DENY)); 113 } 114 115 List allowList = new ArrayList (Arrays.asList(this.getSplitedValues("all" + paramName))); 117 allowList.removeAll(Arrays.asList(paramValues)); 118 119 this.addRoleValues(roleValues, allowList.toArray(), PermissionControl.ROLE_ALLOW); 120 } 121 else { 122 this.addRoleValues(roleValues, this.getSplitedValues("all" + paramName), 123 PermissionControl.ROLE_ALLOW); 124 } 125 126 Role role = new Role(); 127 role.setName(paramName); 128 this.pc.addRole(this.id, role, roleValues); 129 } 130 } 131 } 132 } 133 134 private String [] getSplitedValues(String paramName) 135 { 136 String [] allValues = JForumExecutionContext.getRequest().getParameter(paramName).split(";"); 137 String [] returnValues = new String [allValues.length]; 138 139 for (int i = 0, counter = 0; i < allValues.length; i++) { 140 if (allValues[i].trim().equals("")) { 141 continue; 142 } 143 144 returnValues[counter++] = allValues[i]; 145 } 146 147 return returnValues; 148 } 149 150 private void addRoleValues(RoleValueCollection roleValues, Object [] allValues, int permissionType) 151 { 152 for (int i = 0; i < allValues.length; i++) { 153 String value = (String )allValues[i]; 154 if (value == null || value.equals("")) { 155 continue; 156 } 157 158 roleValues.add(this.createRoleValue((String )allValues[i], permissionType)); 159 } 160 } 161 162 private RoleValue createRoleValue(String value, int type) 163 { 164 RoleValue rv = new RoleValue(); 165 rv.setType(type); 166 rv.setValue(value); 167 168 return rv; 169 } 170 171 private void init() throws Exception 172 { 173 this.pc.deleteAllRoles(this.id); 174 } 175 } 176 | Popular Tags |