⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cifsstore.java

📁 这是linux下ssl vpn的实现程序
💻 JAVA
字号:
package com.sslexplorer.vfs.store.cifs;

import jcifs.Config;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.sslexplorer.core.CoreServlet;
import com.sslexplorer.security.SessionInfo;
import com.sslexplorer.vfs.NetworkPlace;
import com.sslexplorer.vfs.utils.URI;
import com.sslexplorer.vfs.utils.URI.MalformedURIException;
import com.sslexplorer.vfs.webdav.AbstractNetworkPlaceMount;
import com.sslexplorer.vfs.webdav.AbstractNetworkPlaceStore;
import com.sslexplorer.vfs.webdav.DAVTransaction;

/**
 * CIFS implementation of a {@link AbstractNetworkPlaceStore}.
 * 
 * @author Brett Smith <a href="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
 * @version $Revision: 1.20 $
 */
public class CIFSStore extends AbstractNetworkPlaceStore {
    final static Log log = LogFactory.getLog(CIFSStore.class);

    /**
     * Constructor.
     */
    public CIFSStore() {
        super("cifs", System.getProperty("jcifs.encoding", "cp860"));
        try {
            setIfNotEmpty("jcifs.netbios.wins", null);
            setIfNotEmpty("jcifs.netbios.baddr", null);
            setIfNotEmpty("jcifs.netbios.scope", null);
            setIfNotEmpty("jcifs.smb.client.laddr", null);
            setIfNotEmpty("jcifs.netbios.laddr", null);
            setIfNotEmpty("jcifs.netbios.lmhosts", null);
            setIfNotEmpty("jcifs.smb.client.disablePlainTextPasswords", null);
            setIfNotEmpty("jcifs.netbios.hostname", null);
            setIfNotEmpty("jcifs.netbios.soTimeout", null);
            setIfNotEmpty("jcifs.netbios.retryCount", null);
            setIfNotEmpty("jcifs.netbios.retryTimeout", null);
            setIfNotEmpty("jcifs.resolveOrder", null);
            setIfNotEmpty("jcifs.smb.client.responseTimeout", null);
            setIfNotEmpty("jcifs.smb.client.soTimeout", null);

            String guestUser = CoreServlet.getServlet().getPropertyDatabase().getProperty(0, null, "cifs.guestUser").replace('\\', ';').replace('/', ';');
            String guestPassword = CoreServlet.getServlet().getPropertyDatabase().getProperty(0, null, "cifs.guestPassword");
            if(!guestUser.equals("")) {
                Config.setProperty("cifs.guestUser", guestUser);                
            }
            if(!guestPassword.equals("")) {
                Config.setProperty("cifs.guestUser", guestPassword);                
            }
        } catch (Exception e) {
            log.error("Failed to configure JCIFS. CIFS browsing may not act as expected.", e);
        }

    }

    static void setIfNotEmpty(String name, Integer profileId) throws Exception {
        String val = CoreServlet.getServlet().getPropertyDatabase().getProperty(profileId == null ? 0 : profileId.intValue(),
                        null, name).trim();
        if (!val.equals("")) {
            Config.setProperty(name, val);
        }

    }
    
    /* (non-Javadoc)
     * @see com.sslexplorer.vfs.webdav.AbstractStore#willHandle(java.lang.String)
     */
    public boolean willHandle(String scheme) {
        return super.willHandle(scheme) || scheme.equals("smb");
    }

    /* (non-Javadoc)
     * @see com.sslexplorer.vfs.webdav.DAVStore#validateUserEnteredPath(java.lang.String)
     */
    public String validateUserEnteredPath(String path) throws IllegalArgumentException {
		try {
			URI uri = new URI(path) ;
			if (uri.getScheme() != null && uri.getScheme().startsWith("smb")){
				return uri.getScheme();
			}
		} catch (MalformedURIException e) {
			if(path.startsWith("\\\\")) {
				return "smb";
			}
		}
        throw new IllegalArgumentException();
	}

    /* (non-Javadoc)
     * @see com.sslexplorer.vfs.webdav.AbstractNetworkPlaceStore#createMount(com.sslexplorer.vfs.NetworkPlace, com.sslexplorer.security.SessionInfo)
     */
    protected AbstractNetworkPlaceMount createMount(NetworkPlace networkPlace, SessionInfo session) throws Exception {
        return new CIFSMount(networkPlace, this);
    }
    
    /* (non-Javadoc)
     * @see com.sslexplorer.vfs.webdav.AbstractNetworkPlaceStore#getGuestUsername(com.sslexplorer.vfs.webdav.DAVTransaction)
     */
    public String getGuestUsername(DAVTransaction transaction) {
        try {
            return CoreServlet.getServlet().getPropertyDatabase().getProperty(0, null, "cifs.guestUser");
        }
        catch(Exception e) {            
        }
        return null;
    }
    
    /* (non-Javadoc)
     * @see com.sslexplorer.vfs.webdav.AbstractNetworkPlaceStore#getGuestPassword(com.sslexplorer.vfs.webdav.DAVTransaction)
     */
    public char[] getGuestPassword(DAVTransaction transaction) {
        try {
            return CoreServlet.getServlet().getPropertyDatabase().getProperty(0, null, "cifs.guestPassword").toCharArray();
        }
        catch(Exception e) {            
        }
        return null;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -