1 17 18 package org.alfresco.filesys.server.filesys; 19 20 import java.util.Enumeration ; 21 22 import org.alfresco.config.ConfigElement; 23 import org.alfresco.filesys.server.SrvSession; 24 import org.alfresco.filesys.server.auth.ClientInfo; 25 import org.alfresco.filesys.server.auth.InvalidUserException; 26 import org.alfresco.filesys.server.config.InvalidConfigurationException; 27 import org.alfresco.filesys.server.config.ServerConfiguration; 28 import org.alfresco.filesys.server.core.ShareMapper; 29 import org.alfresco.filesys.server.core.ShareType; 30 import org.alfresco.filesys.server.core.SharedDevice; 31 import org.alfresco.filesys.server.core.SharedDeviceList; 32 import org.alfresco.filesys.smb.server.repo.ContentContext; 33 import org.apache.commons.logging.Log; 34 import org.apache.commons.logging.LogFactory; 35 36 44 public class HomeShareMapper implements ShareMapper 45 { 46 48 private static final Log logger = LogFactory.getLog("org.alfresco.smb.protocol"); 49 50 52 public static final String HOME_FOLDER_SHARE = "HOME"; 53 54 56 private ServerConfiguration m_config; 57 58 60 private String m_homeShareName = HOME_FOLDER_SHARE; 61 62 64 private boolean m_debug; 65 66 69 public HomeShareMapper() 70 { 71 } 72 73 80 public void initializeMapper(ServerConfiguration config, ConfigElement params) throws InvalidConfigurationException 81 { 82 84 m_config = config; 85 86 88 String homeName = params.getAttribute("name"); 89 if ( homeName != null && homeName.length() > 0) 90 m_homeShareName = homeName; 91 92 94 if (params != null && params.getChild("debug") != null) 95 m_debug = true; 96 } 97 98 103 public final boolean hasDebug() 104 { 105 return m_debug; 106 } 107 108 113 public final String getHomeFolderName() 114 { 115 return m_homeShareName; 116 } 117 118 126 public SharedDeviceList getShareList(String host, SrvSession sess, boolean allShares) 127 { 128 131 if ( sess != null && sess.hasClientInformation() && sess.hasDynamicShares() == false) 132 { 133 ClientInfo client = sess.getClientInformation(); 134 if ( client.hasHomeFolder()) 135 { 136 138 DiskSharedDevice homeShare = createHomeDiskShare(client); 139 sess.addDynamicShare(homeShare); 140 141 143 if ( logger.isDebugEnabled()) 144 logger.debug("Added " + getHomeFolderName() + " share to list of shares for " + client.getUserName()); 145 } 146 } 147 148 150 SharedDeviceList shrList = new SharedDeviceList(m_config.getShares()); 151 152 if ( sess != null && sess.hasDynamicShares()) { 153 154 156 shrList.addShares(sess.getDynamicShareList()); 157 } 158 159 161 if ( allShares == false) 162 shrList.removeUnavailableShares(); 163 return shrList; 164 } 165 166 177 public SharedDevice findShare(String tohost, String name, int typ, SrvSession sess, boolean create) 178 throws Exception 179 { 180 181 183 SharedDevice share = null; 184 185 if (( typ == ShareType.DISK || typ == ShareType.UNKNOWN) && name.equalsIgnoreCase(getHomeFolderName()) && 186 sess.getClientInformation() != null) { 187 188 190 ClientInfo client = sess.getClientInformation(); 191 192 194 if ( logger.isDebugEnabled()) 195 logger.debug("Map share " + name + ", type=" + ShareType.TypeAsString(typ) + ", client=" + client); 196 197 199 if ( client != null && client.hasHomeFolder()) { 200 201 203 if ( sess.hasDynamicShares()) { 204 205 207 share = sess.getDynamicShareList().findShare(name, typ, false); 208 209 211 if ( logger.isDebugEnabled()) 212 logger.debug(" Reusing existing dynamic share for " + name); 213 } 214 215 217 if ( share == null && create == true) { 218 219 221 DiskSharedDevice diskShare = createHomeDiskShare(client); 222 223 225 sess.addDynamicShare(diskShare); 226 share = diskShare; 227 228 230 if (logger.isDebugEnabled()) 231 logger.debug(" Mapped share " + name + " to " + client.getHomeFolder()); 232 } 233 } 234 else 235 throw new InvalidUserException("No home directory"); 236 } 237 else { 238 239 242 share = m_config.getShares().findShare(name, typ, false); 243 244 if ( share == null) { 245 246 248 share = m_config.getShares().findShare(name, typ, true); 249 } 250 } 251 252 254 if ( share != null && share.getContext() != null && share.getContext().isAvailable() == false) 255 share = null; 256 257 259 return share; 260 } 261 262 267 public void deleteShares(SrvSession sess) 268 { 269 270 272 if ( sess.hasDynamicShares() == false) 273 return; 274 275 277 SharedDeviceList shares = sess.getDynamicShareList(); 278 Enumeration <SharedDevice> enm = shares.enumerateShares(); 279 280 while ( enm.hasMoreElements()) { 281 282 284 SharedDevice shr = (SharedDevice) enm.nextElement(); 285 286 288 shr.getContext().CloseContext(); 289 290 292 if (logger.isDebugEnabled()) 293 logger.debug("Deleted dynamic share " + shr); 294 } 295 296 298 shares.removeAllShares(); 299 } 300 301 304 public void closeMapper() 305 { 306 308 } 309 310 316 private final DiskSharedDevice createHomeDiskShare(ClientInfo client) 317 { 318 320 DiskInterface diskDrv = m_config.getDiskInterface(); 321 DiskDeviceContext diskCtx = new ContentContext("", "", client.getHomeFolder()); 322 323 325 diskCtx.setDiskInformation(new SrvDiskInfo(2560, 64, 512, 2304)); 326 327 329 return new DiskSharedDevice(getHomeFolderName(), diskDrv, diskCtx, SharedDevice.Temporary); 330 } 331 } 332 | Popular Tags |