1 17 package org.alfresco.web.ui.repo.component.evaluator; 18 19 import java.util.StringTokenizer ; 20 21 import javax.faces.context.FacesContext; 22 import javax.faces.el.ValueBinding; 23 24 import org.alfresco.service.cmr.repository.NodeRef; 25 import org.alfresco.service.cmr.security.AccessStatus; 26 import org.alfresco.service.cmr.security.PermissionService; 27 import org.alfresco.web.bean.repository.Node; 28 import org.alfresco.web.bean.repository.Repository; 29 import org.alfresco.web.ui.common.component.evaluator.BaseEvaluator; 30 31 36 public class PermissionEvaluator extends BaseEvaluator 37 { 38 48 public boolean evaluate() 49 { 50 boolean result = false; 51 52 54 try 55 { 56 Object obj = getValue(); 57 if (obj instanceof Node) 58 { 59 String [] allow = getAllowPermissions(); 63 if (allow.length != 0) 64 { 65 result = true; 66 for (int i=0; i<allow.length; i++) 67 { 68 result = result & ((Node)obj).hasPermission(allow[i]); 69 } 70 } 71 } 72 else if (obj instanceof NodeRef) 73 { 74 PermissionService service = Repository.getServiceRegistry(getFacesContext()).getPermissionService(); 76 String [] allow = getAllowPermissions(); 77 if (allow.length != 0) 78 { 79 result = true; 80 for (int i=0; i<allow.length; i++) 81 { 82 result = result & (AccessStatus.ALLOWED == service.hasPermission(((NodeRef)obj), allow[i])); 83 } 84 } 85 } 86 } 87 catch (Exception err) 88 { 89 s_logger.debug("Error during PermissionEvaluator evaluation: " + err.getMessage()); 91 } 92 93 return result; 94 } 95 96 99 public void restoreState(FacesContext context, Object state) 100 { 101 Object values[] = (Object [])state; 102 super.restoreState(context, values[0]); 104 this.allow = (String )values[1]; 105 this.deny = (String )values[2]; 106 } 107 108 111 public Object saveState(FacesContext context) 112 { 113 Object values[] = new Object [3]; 114 values[0] = super.saveState(context); 116 values[1] = this.allow; 117 values[2] = this.deny; 118 return (values); 119 } 120 121 124 private String [] getAllowPermissions() 125 { 126 String [] allowPermissions; 127 128 String allow = getAllow(); 129 if (allow != null) 130 { 131 if (allow.indexOf(',') == -1) 132 { 133 allowPermissions = new String [1]; 135 allowPermissions[0] = allow; 136 } 137 else 138 { 139 StringTokenizer t = new StringTokenizer (allow, ","); 141 allowPermissions = new String [t.countTokens()]; 142 for (int i=0; i<allowPermissions.length; i++) 143 { 144 allowPermissions[i] = t.nextToken(); 145 } 146 } 147 } 148 else 149 { 150 allowPermissions = new String [0]; 151 } 152 153 return allowPermissions; 154 } 155 156 161 public String getAllow() 162 { 163 ValueBinding vb = getValueBinding("allow"); 164 if (vb != null) 165 { 166 this.allow = (String )vb.getValue(getFacesContext()); 167 } 168 169 return this.allow; 170 } 171 172 177 public void setAllow(String allow) 178 { 179 this.allow = allow; 180 } 181 182 187 public String getDeny() 188 { 189 ValueBinding vb = getValueBinding("deny"); 190 if (vb != null) 191 { 192 this.deny = (String )vb.getValue(getFacesContext()); 193 } 194 195 return this.deny; 196 } 197 198 203 public void setDeny(String deny) 204 { 205 this.deny = deny; 206 } 207 208 209 210 private String deny = null; 211 212 213 private String allow = null; 214 } 215 | Popular Tags |