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

📄 davprocessor.java

📁 这是linux下ssl vpn的实现程序
💻 JAVA
字号:
/* ========================================================================== *
 * Copyright (C) 2004-2005 Pier Fumagalli <http://www.betaversion.org/~pier/> *
 *                            All rights reserved.                            *
 * ========================================================================== *
 *                                                                            *
 * Licensed under the  Apache License, Version 2.0  (the "License").  You may *
 * not use this file except in compliance with the License.  You may obtain a *
 * copy of the License at <http://www.apache.org/licenses/LICENSE-2.0>.       *
 *                                                                            *
 * Unless  required  by applicable  law or  agreed  to  in writing,  software *
 * distributed under the License is distributed on an  "AS IS" BASIS, WITHOUT *
 * WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied.  See the *
 * License for the  specific language  governing permissions  and limitations *
 * under the License.                                                         *
 *                                                                            *
 * ========================================================================== */
package com.sslexplorer.vfs.webdav;

import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

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

import com.sslexplorer.boot.Util;
import com.sslexplorer.security.SessionInfo;
import com.sslexplorer.vfs.webdav.methods.COPY;
import com.sslexplorer.vfs.webdav.methods.DELETE;
import com.sslexplorer.vfs.webdav.methods.GET;
import com.sslexplorer.vfs.webdav.methods.HEAD;
import com.sslexplorer.vfs.webdav.methods.MKCOL;
import com.sslexplorer.vfs.webdav.methods.MOVE;
import com.sslexplorer.vfs.webdav.methods.OPTIONS;
import com.sslexplorer.vfs.webdav.methods.PROPFIND;
import com.sslexplorer.vfs.webdav.methods.PROPPATCH;
import com.sslexplorer.vfs.webdav.methods.PUT;

/**
 * <p>The <a href="http://www.rfc-editor.org/rfc/rfc2518.txt">WebDAV</a>
 * transactions processor.</p> 
 *
 * @author <a href="http://www.betaversion.org/~pier/">Pier Fumagalli</a>
 */
public class DAVProcessor {
    final static Log log = LogFactory.getLog(DAVProcessor.class);

    /** <p>All the implemented methods, comma separated.</p> */
    public static final String METHODS = "COPY,DELETE,GET,HEAD,MKCOL,MOVE,OPTIONS,PROPFIND,PROPPATCH,PUT";

    private DAVRepository repository = null;
    private Map methods = null;
    private SessionInfo session;

    private static Map methodImpls = new HashMap();
    
    
    public static void addDAVMethod(Class cls) {
        
    	    methodImpls.put(Util.getSimpleClassName(cls), cls);
    }
    
    public static void removeDAVMethod(Class cls) {
    	    methodImpls.remove(Util.getSimpleClassName(cls));
    }
    
    /**
     * <p>Create a new {@link DAVProcessor} instance.</p>
     * @throws Exception 
     */
    public DAVProcessor(DAVRepository repository, SessionInfo session) {
        this.repository = repository;
        this.session = session;
        initialiseProcessor();
    }
    
    public void initialiseProcessor(){
        this.methods = new HashMap();
        this.methods.put("DELETE",    new DELETE());
        this.methods.put("GET",       new GET());
        this.methods.put("HEAD",      new HEAD());
        this.methods.put("MKCOL",     new MKCOL());
        this.methods.put("MOVE",      new MOVE());
        this.methods.put("OPTIONS",   new OPTIONS());
        this.methods.put("PROPFIND",  new PROPFIND());
        this.methods.put("PROPPATCH", new PROPPATCH());
        this.methods.put("PUT",       new PUT());
        this.methods.put("COPY",       new COPY());
        
        Map.Entry entry;
        for(Iterator it = methodImpls.entrySet().iterator(); it.hasNext();) {
        	   try {
				entry = (Map.Entry) it.next();
				this.methods.put(entry.getKey(), ((Class) entry.getValue()).newInstance());
			} catch (InstantiationException e) {
				log.error("Could not create DAVMethod implementation", e);
			} catch (IllegalAccessException e) {
				log.error("Could not create DAVMethod implementation", e);
			}
        }
    }
    
    /**
     * Get the session this processor is associated with
     * 
     * @return session
     */
    public SessionInfo getSession() {
        return session;
    }

    /**
     * <p>Process the specified {@link DAVTransaction} fully.</p>
     * @throws IOException
     */
    public void process(DAVTransaction transaction)
    throws Exception {

            String method = transaction.getMethod();
            if (this.methods.containsKey(method)) {
                String path = transaction.getPath(); 
                DAVResource resource = repository.getResource(path.replaceAll("%20", " "), transaction);                
                resource.start(transaction);

                /* This is to verify that we have access. We process the cause of the 
                 * exception to determine whether an authentication exception should be thrown
                 */
                resource.verifyAccess();                
                
                DAVMethod instance = ((DAVMethod)this.methods.get(method));
                instance.process(transaction, resource);
            } else {
                String message = "Method \"" + method + "\" not implemented";
                throw new DAVException(501, message);
            }
    }

    /**
     * @return
     */
    public DAVRepository getRepository() {
        return repository;
    }
}

⌨️ 快捷键说明

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