1 17 package org.alfresco.filesys.server.auth.acl; 18 19 import java.util.Enumeration ; 20 21 import org.alfresco.config.ConfigElement; 22 import org.alfresco.filesys.server.SrvSession; 23 import org.alfresco.filesys.server.config.ServerConfiguration; 24 import org.alfresco.filesys.server.core.SharedDevice; 25 import org.alfresco.filesys.server.core.SharedDeviceList; 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 29 36 public class DefaultAccessControlManager implements AccessControlManager 37 { 38 39 41 private static final Log logger = LogFactory.getLog("org.alfresco.smb.protocol"); 42 43 45 private AccessControlFactory m_factory; 46 47 49 private boolean m_debug; 50 51 54 public DefaultAccessControlManager() 55 { 56 57 59 m_factory = new AccessControlFactory(); 60 } 61 62 69 public int checkAccessControl(SrvSession sess, SharedDevice share) 70 { 71 72 74 if (share.hasAccessControls() == false) 75 { 76 77 79 if (logger.isDebugEnabled() && hasDebug()) 80 logger.debug("Check access control for " + share.getName() + ", no ACLs"); 81 82 84 return AccessControl.ReadWrite; 85 } 86 87 89 AccessControlList acls = share.getAccessControls(); 90 int access = AccessControl.Default; 91 92 94 if (logger.isDebugEnabled() && hasDebug()) 95 logger.debug("Check access control for " + share.getName() + ", ACLs=" + acls.numberOfControls()); 96 97 for (int i = 0; i < acls.numberOfControls(); i++) 98 { 99 100 102 AccessControl acl = acls.getControlAt(i); 103 int curAccess = acl.allowsAccess(sess, share, this); 104 105 107 if (logger.isDebugEnabled() && hasDebug()) 108 logger.debug(" Check access ACL=" + acl + ", access=" + AccessControl.asAccessString(curAccess)); 109 110 112 if (curAccess != AccessControl.Default) 113 access = curAccess; 114 } 115 116 120 if (access == AccessControl.Default) 121 { 122 123 125 access = acls.getDefaultAccessLevel(); 126 127 129 if (logger.isDebugEnabled() && hasDebug()) 130 logger.debug("Access defaulted=" + AccessControl.asAccessString(access) + ", share=" + share); 131 } 132 else if (logger.isDebugEnabled() && hasDebug()) 133 logger.debug("Access allowed=" + AccessControl.asAccessString(access) + ", share=" + share); 134 135 137 return access; 138 } 139 140 148 public SharedDeviceList filterShareList(SrvSession sess, SharedDeviceList shares) 149 { 150 151 153 if (shares == null || shares.numberOfShares() == 0) 154 return shares; 155 156 158 if (logger.isDebugEnabled() && hasDebug()) 159 logger.debug("Filter share list for " + sess + ", shares=" + shares); 160 161 164 SharedDeviceList filterList = new SharedDeviceList(); 165 Enumeration <SharedDevice> enm = shares.enumerateShares(); 166 167 while (enm.hasMoreElements()) 168 { 169 170 172 SharedDevice share = enm.nextElement(); 173 174 176 if (share.hasAccessControls()) 177 { 178 179 181 int access = checkAccessControl(sess, share); 182 if (access != AccessControl.NoAccess) 183 filterList.addShare(share); 184 } 185 else 186 { 187 188 190 filterList.addShare(share); 191 } 192 } 193 194 196 if (logger.isDebugEnabled() && hasDebug()) 197 logger.debug("Filtered share list " + filterList); 198 199 201 return filterList; 202 } 203 204 210 public void initialize(ServerConfiguration config, ConfigElement params) 211 { 212 213 215 if (params != null && params.getChild("debug") != null) 216 setDebug(true); 217 218 220 addAccessControlType(new UserAccessControlParser()); 221 addAccessControlType(new ProtocolAccessControlParser()); 222 addAccessControlType(new DomainAccessControlParser()); 223 addAccessControlType(new IpAddressAccessControlParser()); 224 } 225 226 235 public AccessControl createAccessControl(String type, ConfigElement params) throws ACLParseException, 236 InvalidACLTypeException 237 { 238 239 241 return m_factory.createAccessControl(type, params); 242 } 243 244 249 public void addAccessControlType(AccessControlParser parser) 250 { 251 252 254 if (logger.isDebugEnabled() && hasDebug()) 255 logger.debug("AccessControlManager Add rule type " + parser.getType()); 256 257 259 m_factory.addParser(parser); 260 } 261 262 267 public final boolean hasDebug() 268 { 269 return m_debug; 270 } 271 272 277 public final void setDebug(boolean dbg) 278 { 279 m_debug = dbg; 280 } 281 } 282 | Popular Tags |