1 19 20 package com.sslexplorer.networkplaces.store.cifs; 21 22 import java.io.IOException ; 23 import java.net.UnknownHostException ; 24 25 import jcifs.smb.SmbException; 26 27 import org.apache.commons.logging.Log; 28 import org.apache.commons.logging.LogFactory; 29 import org.apache.commons.vfs.FileObject; 30 import org.apache.commons.vfs.FileSystemException; 31 import org.apache.commons.vfs.FileType; 32 33 import com.sslexplorer.networkplaces.AbstractNetworkPlaceMount; 34 import com.sslexplorer.policyframework.LaunchSession; 35 import com.sslexplorer.security.PasswordCredentials; 36 import com.sslexplorer.vfs.VFSStore; 37 import com.sslexplorer.vfs.utils.URI; 38 import com.sslexplorer.vfs.utils.URI.MalformedURIException; 39 import com.sslexplorer.vfs.webdav.DAVAuthenticationRequiredException; 40 import com.sslexplorer.vfs.webdav.DAVUtilities; 41 42 51 public class CIFSMount extends AbstractNetworkPlaceMount { 52 53 final static Log log = LogFactory.getLog(CIFSMount.class); 54 55 62 public CIFSMount(LaunchSession launchSession, VFSStore store) { 63 super(launchSession, store); 64 } 65 66 public URI getRootVFSURI(String charset) throws MalformedURIException { 70 try { 71 return super.getRootVFSURI(charset); 72 } 73 catch(MalformedURIException muri) { 74 77 String npath ="smb://" + getNetworkPlace().getUsername() + ":" + getNetworkPlace().getPassword() + "@" + getNetworkPlace().getPath().replace("\\\\", "").replace("//", "").replace("\\", "/"); 78 return DAVUtilities.processAndEncodeURI(npath, getStore().getRepository().getSession(), charset); 79 } 80 } 81 82 88 public FileObject createVFSFileObject(String path, PasswordCredentials credentials) throws IOException , DAVAuthenticationRequiredException { 89 90 super.getStore().getName(); 91 92 URI uri = getRootVFSURI(System.getProperty("jcifs.encoding", "cp860")); 93 94 try { 95 uri.setScheme("smb"); 96 if (credentials != null) { 97 uri.setUserinfo(DAVUtilities.encodeURIUserInfo(credentials.getUsername() + (credentials.getPassword() != null ? ":" + new String (credentials.getPassword()) : ""))); 98 } 99 uri.setPath(uri.getPath() + (uri.getPath().endsWith("/") ? "" : "/") + DAVUtilities.encodePath(path, System.getProperty("jcifs.encoding", "cp860"))); 100 FileObject root = getStore().getRepository().getFileSystemManager().resolveFile(uri.toString()); 101 if (root.getType().equals(FileType.FOLDER)) { 102 root.getChildren(); 104 } 105 return root; 106 } catch (FileSystemException fse) { 107 if (fse.getCause().getClass().getName().equals("jcifs.smb.SmbAuthException")) { 108 throw new DAVAuthenticationRequiredException(getMountString(), true); 109 } 110 if (fse.getCause() != null && fse.getCause() instanceof SmbException && ((SmbException) fse.getCause()).getRootCause() != null 111 && "Connection timeout".equals(((SmbException) fse.getCause()).getRootCause().getMessage())) { 112 throw new UnknownHostException (uri.getHost()); 113 } 114 if(log.isDebugEnabled()) 115 log.debug("File system exception! ", fse); 116 throw fse; 117 } 118 } 119 } | Popular Tags |