1 17 package org.alfresco.filesys.server.auth.acl; 18 19 import java.util.StringTokenizer ; 20 21 import org.alfresco.filesys.server.SrvSession; 22 import org.alfresco.filesys.server.core.SharedDevice; 23 24 29 public abstract class AccessControl 30 { 31 32 34 public final static int NoAccess = 0; 35 public final static int ReadOnly = 1; 36 public final static int ReadWrite = 2; 37 38 public final static int MaxLevel = 2; 39 40 42 public final static int Default = -1; 43 44 46 private final static String [] _accessType = { "None", "Read", "Write" }; 47 48 50 private String m_name; 51 private String m_type; 52 53 55 private int m_access; 56 57 64 protected AccessControl(String name, String type, int access) 65 { 66 setName(name); 67 setType(type); 68 69 m_access = access; 70 } 71 72 77 public final String getName() 78 { 79 return m_name; 80 } 81 82 87 public final String getType() 88 { 89 return m_type; 90 } 91 92 97 public final int getAccess() 98 { 99 return m_access; 100 } 101 102 107 public final String getAccessString() 108 { 109 return _accessType[m_access]; 110 } 111 112 120 public abstract int allowsAccess(SrvSession sess, SharedDevice share, AccessControlManager mgr); 121 122 130 protected final static int indexFromList(String val, String [] valid, boolean caseSensitive) 131 { 132 133 135 if (val == null || val.length() == 0) 136 return -1; 137 138 140 for (int i = 0; i < valid.length; i++) 141 { 142 143 145 if (caseSensitive) 146 { 147 if (valid[i].equals(val)) 148 return i; 149 } 150 else if (valid[i].equalsIgnoreCase(val)) 151 return i; 152 } 153 154 156 return -1; 157 } 158 159 165 protected final static String [] listFromString(String str) 166 { 167 168 170 if (str == null || str.length() == 0) 171 return null; 172 173 175 StringTokenizer token = new StringTokenizer (str, ","); 176 int numStrs = token.countTokens(); 177 if (numStrs == 0) 178 return null; 179 180 String [] list = new String [numStrs]; 181 182 184 int i = 0; 185 186 while (token.hasMoreTokens()) 187 list[i++] = token.nextToken(); 188 189 191 return list; 192 } 193 194 199 protected final void setType(String typ) 200 { 201 m_type = typ; 202 } 203 204 209 protected final void setName(String name) 210 { 211 m_name = name; 212 } 213 214 220 public static final String asAccessString(int access) 221 { 222 if (access == Default) 223 return "Default"; 224 return _accessType[access]; 225 } 226 227 232 public String toString() 233 { 234 StringBuffer str = new StringBuffer (); 235 236 str.append("["); 237 str.append(getType()); 238 str.append(":"); 239 str.append(getName()); 240 str.append(","); 241 str.append(getAccessString()); 242 str.append("]"); 243 244 return str.toString(); 245 } 246 } 247 | Popular Tags |