亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? ldapusermanager.java

?? 一個利用Java語言實現(xiàn)的ftp程序
?? JAVA
字號:
/*
 * Copyright (C) The Apache Software Foundation. All rights reserved.
 *
 * This software is published under the terms of the Apache Software License
 * version 1.1, a copy of which has been included with this distribution in
 * the LICENSE file.
 */
package server.ftp.usermanager;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Properties;

import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttribute;
import javax.naming.directory.BasicAttributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.ModificationItem;
import javax.naming.directory.SearchResult;

import server.ftp.FtpConfig;
import util.StringUtils;

/**
 * Ldap based user manager class. Tested using Netscape Directory Server 4.1.
 * The LDAP requires the password to be nonempty for simple authentication. So
 * instead of using empty string password (""), we will be using single space (" ").
 * <br>
 * The required LDAP attribute types:
 * <ul>
 *   <li>memberuid</li>
 *   <li>uid</li>
 *   <li>cn</li>
 *   <li>sn</li>
 *   <li>userpassword</li>
 *   <li>objectclass</li>
 *   <li>enableflag (created by ftp-db.ldif file)</li>
 *   <li>homedirectory</li>
 *   <li>writepermission (created by ftp-db.ldif file)</li>
 *   <li>idletime (created by ftp-db.ldif file)</li>
 *   <li>uploadrate (created by ftp-db.ldif file)</li>
 *   <li>downloadrate (created by ftp-db.ldif file)</li>
 * </ul>
 * 
 * Some of the above mentioned attribute types are created by ftd-db.ldif schema file.
 * The schema file also creates an object class called ftpUsers derived from 
 * inetOrgPerson and have all these attributes.<br>
 * Assumed LDAP objectclass hierarchy:<br>
 * <pre>
 *        top
 *         |
 *       person
 *         |
 * organizationalPerson
 *         |
 *    inetOrgPerson
 *         |
 *      ftpUsers
 * </pre>
 * 
 * @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
 */
public
class LdapUserManager extends UserManager {
    
    
    // LDAP attributes
    private final static String LOGIN      = "memberuid";
    private final static String UID        = "uid";
    private final static String CN         = "cn";
    private final static String SN         = "sn";
    private final static String PASSWORD   = "userpassword";
    private final static String OBJ_CLASS  = "objectclass";
    private final static String ENABLE     = "enableflag";
    private final static String ROOT_DIR   = "homedirectory";
    private final static String WRITE_PERM = "writepermission";
    private final static String IDLE_TIME  = "idletime";
    private final static String UP_RATE    = "uploadrate";
    private final static String DOWN_RATE  = "downloadrate";
    
    private final static String[] ALL_ATTRS = {
        UID,
        ENABLE,
        ROOT_DIR,
        WRITE_PERM,
        IDLE_TIME,
        UP_RATE,
        DOWN_RATE
    };
    
    private final static String[] UID_ATTRS = {
        UID
    };
    
    
    // Currently we are using only one connection.
    // So all the methods are synchronized.
    private DirContext mAdminContext;
    private Properties mAdminEnv;
    private String mstRoot;
    private String mstDnPrefix;
    private String mstDnSuffix;
    private Attribute mObjClassAttr;
    
    
    /**
     * Instantiate LDAP based <code>UserManager</code> implementation.
     */
    public LdapUserManager(FtpConfig cfg) throws Exception { 
        super(cfg);
        
        // get ldap parameters
        String url      = cfg.getProperty(FtpConfig.PREFIX + "ldap.url");
        String admin    = cfg.getProperty(FtpConfig.PREFIX + "ldap.admin");
        String password = cfg.getProperty(FtpConfig.PREFIX + "ldap.password");
        String auth     = cfg.getProperty(FtpConfig.PREFIX + "ldap.authentication");
        
        mstRoot     = cfg.getProperty(FtpConfig.PREFIX + "ldap.root");
        mstDnPrefix = cfg.getProperty(FtpConfig.PREFIX + "ldap.dn.prefix");
        mstDnSuffix = cfg.getProperty(FtpConfig.PREFIX + "ldap.dn.suffix");
        
        
        // create connection
        mAdminEnv = new Properties();
        mAdminEnv.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
        mAdminEnv.setProperty(Context.PROVIDER_URL, url);
        mAdminEnv.setProperty(Context.SECURITY_AUTHENTICATION, auth);             
        mAdminEnv.setProperty(Context.SECURITY_PRINCIPAL, admin);             
        mAdminEnv.setProperty(Context.SECURITY_CREDENTIALS, password);                     
        mAdminContext = new InitialDirContext(mAdminEnv);
        
        
        // create objectClass attribute
        mObjClassAttr = new BasicAttribute(OBJ_CLASS, false);
        mObjClassAttr.add("ftpUsers");
        mObjClassAttr.add("inetOrgPerson");
        mObjClassAttr.add("organizationalPerson");
        mObjClassAttr.add("person");
        mObjClassAttr.add("top");
        
        getConfig().getLogger().info("LDAP user manager opened.");
    }
    
    
    /**
     * Get all user names.
     */
    public synchronized Collection getAllUserNames() {
        ArrayList allUsers = new ArrayList();
        
        try {
            Attributes matchAttrs = new BasicAttributes(true);
            matchAttrs.put(mObjClassAttr);
            NamingEnumeration answers = mAdminContext.search(mstRoot, matchAttrs, UID_ATTRS);
            while (answers.hasMore()) {
                SearchResult sr = (SearchResult)answers.next();
                String uid = sr.getAttributes().get(UID).get().toString();
                allUsers.add(uid);
            }
        }
        catch(Exception ex) {
            getConfig().getLogger().error(ex);
        }
        
        Collections.sort(allUsers);
        return allUsers;
    } 
    
    
    /**
     * Get user object.
     */
    public synchronized User getUserByName(String name) {
        User user = null;
        
        try {
            String dn = getDN(name);
            Attributes attrs = mAdminContext.getAttributes(dn, ALL_ATTRS);
                        
            user = new User();
            user.setName(attrs.get(UID).get().toString());
            user.getVirtualDirectory().setRootDirectory(new File(attrs.get(ROOT_DIR).get().toString()));
            user.setEnabled(Boolean.TRUE.toString().equals(attrs.get(ENABLE).get().toString()));
            user.getVirtualDirectory().setWritePermission(Boolean.TRUE.toString().equals(attrs.get(WRITE_PERM).get().toString()));  
            user.setMaxIdleTime( Integer.parseInt(attrs.get(IDLE_TIME).get().toString()) );
            user.setMaxUploadRate( Integer.parseInt(attrs.get(UP_RATE).get().toString()) );
            user.setMaxDownloadRate( Integer.parseInt(attrs.get(DOWN_RATE).get().toString()) );
        }
        catch(Exception ex) {
            getConfig().getLogger().error(ex);
            user = null;
        }
        
        return user;
    }
    
    
    /**
     * User authentication.
     */
    public boolean authenticate(String login, String password) {
        
        // empty password string is not allowed
        if (password == null) {
            password = " ";
        }
        if (password.equals("")) {
            password = " ";
        }
        
        try {
            if( doesExist(login) ) {
                Properties userProp = (Properties)mAdminEnv.clone();
                String dn = getDN(login);
                userProp.setProperty(Context.SECURITY_PRINCIPAL, dn);             
                userProp.setProperty(Context.SECURITY_CREDENTIALS, password);
                
                DirContext userContext = new InitialDirContext(userProp);
                userContext.close(); 
                return true;
            }
        }
        catch(NamingException ex) {   
        }
        return false;
    }
    
    
    /**
     * Save user
     */
    public synchronized void save(User user) throws NamingException {
        if ( doesExist(user.getName()) ) {
            update(user);
        }
        else {
            add(user);
        }
    }
    
    
    /**
     * Add a new user
     */
    private synchronized void add(User user) throws NamingException {
        
        // empty password is not allowed
        if (user.getPassword() == null) {
            user.setPassword(" ");
        }
        if (user.getPassword().equals("")) {
            user.setPassword(" ");
        }
        
        String dn = getDN(user.getName());
        
        Attributes attrs = new BasicAttributes(true);
        attrs.put(new BasicAttribute(LOGIN, user.getName()));
        attrs.put(new BasicAttribute(UID, user.getName()));
        attrs.put(new BasicAttribute(CN, user.getName()));
        attrs.put(new BasicAttribute(SN, user.getName()));
        attrs.put(new BasicAttribute(PASSWORD, user.getPassword()));
        
        attrs.put(mObjClassAttr);
        
        attrs.put(new BasicAttribute(ENABLE, String.valueOf(user.getEnabled())));
        attrs.put(new BasicAttribute(ROOT_DIR, user.getVirtualDirectory().getRootDirectory()));
        attrs.put(new BasicAttribute(WRITE_PERM, String.valueOf(user.getVirtualDirectory().getWritePermission())));
        attrs.put(new BasicAttribute(IDLE_TIME, String.valueOf(user.getMaxIdleTime())));
        attrs.put(new BasicAttribute(UP_RATE, String.valueOf(user.getMaxUploadRate())));
        attrs.put(new BasicAttribute(DOWN_RATE, String.valueOf(user.getMaxDownloadRate())));
        
        mAdminContext.bind(dn, null, attrs);
    }
    
    
    /**
     * Update an existing user
     */
    private synchronized void update(User user) throws NamingException {
        String dn = getDN(user.getName());
        ArrayList mods = new ArrayList();
        
        if (user.getPassword() != null) {
            if (user.getPassword().equals("")) {
                user.setPassword(" ");
            }
            mods.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(PASSWORD, user.getPassword())));
        }
        mods.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(ENABLE, String.valueOf(user.getEnabled()))));
        mods.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(ROOT_DIR, user.getVirtualDirectory().getRootDirectory())));
        mods.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(WRITE_PERM, String.valueOf(user.getVirtualDirectory().getWritePermission()))));
        mods.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(IDLE_TIME, String.valueOf(user.getMaxIdleTime()))));
        mods.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(UP_RATE, String.valueOf(user.getMaxUploadRate()))));
        mods.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(DOWN_RATE, String.valueOf(user.getMaxDownloadRate()))));
        
        
        ModificationItem modArr[] = new ModificationItem[mods.size()];
        for(int i=0; i<modArr.length; i++) {
            modArr[i] = (ModificationItem)mods.get(i);
        }
        mAdminContext.modifyAttributes(dn, modArr);
    }
    
    
    /**
     * User existance check
     */
    public synchronized boolean doesExist(String name) {
        boolean bExist = false;
        try {
            String dn = getDN(name);
            mAdminContext.getAttributes(dn, UID_ATTRS);
            bExist = true;
        }
        catch(NamingException ex) {
        }
        return bExist;
    }
    
    
    /**
     * Delete user
     */
    public synchronized void delete(String userName) throws NamingException {
        String dn = getDN(userName);
        mAdminContext.unbind(dn);
    }
    
    
    /**
     * Close user manager
     */
    public synchronized void dispose() {
        if (mAdminContext != null) {
            try {
                mAdminContext.close();
            }
            catch(NamingException ex) {
            }
            mAdminContext = null;
        }
    }
    
    /**
     * Get the distinguished name (DN) for this user name
     */
    private String getDN(String userName) throws NamingException {
        
        //escape special characters
        userName = StringUtils.replaceString(userName, "\\", "\\\\");
        userName = StringUtils.replaceString(userName, ",", "\\,");        
        userName = StringUtils.replaceString(userName, "+", "\\+");
        userName = StringUtils.replaceString(userName, "\"", "\\\"");
        userName = StringUtils.replaceString(userName, "<", "\\<");
        userName = StringUtils.replaceString(userName, ">", "\\>");
        userName = StringUtils.replaceString(userName, ";", "\\;"); 
        
        return mstDnPrefix + userName + mstDnSuffix;
    }   
        
}    

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
最新欧美精品一区二区三区| 91在线视频播放| 欧美一级日韩不卡播放免费| 亚洲电影一级片| 欧美精品自拍偷拍动漫精品| 日本女优在线视频一区二区| 91麻豆精品国产自产在线| 日本美女一区二区三区| 日韩视频免费观看高清完整版在线观看 | 亚洲国产精品麻豆| 欧美日韩大陆在线| 麻豆高清免费国产一区| 日韩情涩欧美日韩视频| 国产成人综合在线观看| 亚洲丝袜制服诱惑| 制服丝袜亚洲色图| 国产一区不卡精品| 亚洲欧美视频在线观看视频| 欧美日韩国产免费一区二区| 久久成人18免费观看| 欧美国产一区二区在线观看| 色婷婷久久一区二区三区麻豆| 亚洲成a人片综合在线| 日韩精品一区二区三区蜜臀| 大白屁股一区二区视频| 亚洲香肠在线观看| 久久久久久久av麻豆果冻| 色综合天天综合网天天狠天天| 亚洲电影在线播放| 久久久久久久久99精品| 色先锋资源久久综合| 麻豆91精品视频| 亚洲美腿欧美偷拍| 久久无码av三级| 欧美色老头old∨ideo| 国产麻豆精品theporn| 亚洲永久精品国产| 欧美韩国日本不卡| 91精品国产全国免费观看| 不卡一区二区三区四区| 男人的天堂亚洲一区| 亚洲欧洲成人精品av97| 欧美v日韩v国产v| 欧美在线观看视频一区二区| 国产成人一区二区精品非洲| 亚洲五码中文字幕| 国产精品网站一区| 精品少妇一区二区三区| 欧美日韩精品一区二区三区蜜桃| 国产成a人亚洲精品| 久久99久久精品欧美| 亚洲午夜私人影院| 成人欧美一区二区三区视频网页 | 精品99一区二区三区| 日本高清不卡在线观看| 懂色一区二区三区免费观看| 蜜臀av性久久久久蜜臀av麻豆| 一区二区三区日韩欧美| 国产精品久久久久久久久图文区| 欧美不卡在线视频| 91精品午夜视频| 欧美色爱综合网| 一本大道综合伊人精品热热| 成人一道本在线| 国产精品一区免费视频| 久久激情五月婷婷| 美日韩一区二区三区| 日本免费新一区视频| 石原莉奈一区二区三区在线观看| 一区二区三区产品免费精品久久75| 国产精品理论在线观看| 中文字幕精品一区二区三区精品| 久久影视一区二区| 26uuu久久天堂性欧美| 欧美成人猛片aaaaaaa| 日韩欧美国产一区二区在线播放| 777色狠狠一区二区三区| 欧美情侣在线播放| 欧美一区二区三区四区在线观看| 欧美日韩一区中文字幕| 欧美日韩在线直播| 在线不卡中文字幕播放| 欧美喷潮久久久xxxxx| 欧美一区二区女人| 日韩欧美的一区二区| 精品剧情在线观看| 国产校园另类小说区| 国产欧美一区二区三区在线老狼| 国产日韩影视精品| 国产午夜亚洲精品不卡| 中文字幕亚洲综合久久菠萝蜜| 专区另类欧美日韩| 一区二区三区久久| 日韩和欧美的一区| 麻豆成人在线观看| 国产乱一区二区| 不卡的看片网站| 一本一道综合狠狠老| 欧美日韩一区二区三区四区五区| 欧美午夜电影网| 日韩欧美123| 中文字幕免费在线观看视频一区| 亚洲精品少妇30p| 日韩制服丝袜av| 国产成人av影院| 在线视频综合导航| 日韩欧美一区二区三区在线| 欧美国产97人人爽人人喊| 一区二区三区在线观看视频| 天天操天天综合网| 国产精品亚洲综合一区在线观看| 99久久精品免费看国产| 色成人在线视频| 精品国产一区a| 亚洲欧美激情小说另类| 秋霞午夜鲁丝一区二区老狼| 国产综合色产在线精品| 色狠狠一区二区| 26uuu欧美| 一区二区欧美国产| 国产一区二区三区最好精华液| eeuss鲁片一区二区三区在线观看| 欧洲av在线精品| 久久久www成人免费毛片麻豆 | 欧美猛男超大videosgay| 欧美精品一区二区三区一线天视频 | 欧美精品第1页| 国产精品久99| 美美哒免费高清在线观看视频一区二区 | 色综合亚洲欧洲| 2021久久国产精品不只是精品| 亚洲美女屁股眼交| 国产又黄又大久久| 欧美日韩一区二区三区四区五区| 国产夜色精品一区二区av| 亚洲成人自拍偷拍| 风间由美一区二区三区在线观看| 欧美日韩在线播| 亚洲视频图片小说| 国产成人亚洲综合a∨婷婷图片| 精品污污网站免费看| 国产精品久久久久久久第一福利| 激情综合网av| 69堂亚洲精品首页| 一区二区三区不卡视频| 99久久99久久精品免费观看| 久久女同性恋中文字幕| 视频一区在线视频| 欧美在线你懂得| 亚洲色欲色欲www| 成人精品小蝌蚪| 久久这里只有精品6| 久久电影网站中文字幕 | 欧美本精品男人aⅴ天堂| 亚洲成人av电影| 欧美影院精品一区| 亚洲视频免费看| 97se狠狠狠综合亚洲狠狠| 国产欧美一区二区精品仙草咪| 精品一区二区在线播放| 欧美一区二区视频网站| 性欧美疯狂xxxxbbbb| 欧美一a一片一级一片| 亚洲欧美日韩中文播放| 97久久超碰国产精品| 中文字幕中文乱码欧美一区二区| 国产成人免费在线视频| 亚洲精品一区在线观看| 国产呦精品一区二区三区网站| 欧美tickling网站挠脚心| 日韩经典一区二区| 欧美一区二区二区| 精品一区二区免费在线观看| 精品国产免费一区二区三区香蕉| 美女任你摸久久| 久久精品视频免费| 国产一区二三区| 国产亲近乱来精品视频| 成人黄色国产精品网站大全在线免费观看 | 精品剧情v国产在线观看在线| 麻豆国产欧美一区二区三区| 精品久久久网站| 国产成人亚洲精品狼色在线| 国产精品久久久一区麻豆最新章节| 成人激情开心网| 亚洲一区在线视频| 777久久久精品| 国模大尺度一区二区三区| 国产欧美精品日韩区二区麻豆天美| 成人网在线播放| 一区二区三区成人| 欧美电影免费观看高清完整版在| 国产精品资源在线| 亚洲女同ⅹxx女同tv| 欧美色爱综合网| 国产一区二区网址| 亚洲激情校园春色| 日韩欧美国产成人一区二区| 国产大片一区二区| 亚洲图片欧美综合|