Package org.apache.ftpserver.ftplet

Examples of org.apache.ftpserver.ftplet.User


        user.setPassword("newpw");
        userManager.save(user);
       
        UserManager newUserManager = createUserManager();
       
        User actualUser = newUserManager.getUserByName("newuser");
       
        assertEquals(user.getName(), actualUser.getName());
        assertNull(actualUser.getPassword());
        assertEquals("/", actualUser.getHomeDirectory());
        assertEquals(true, actualUser.getEnabled());
        assertNull(user.authorize(new WriteRequest()));
        assertEquals(0, getMaxDownloadRate(actualUser));
        assertEquals(0, actualUser.getMaxIdleTime());
        assertEquals(0, getMaxLoginNumber(actualUser));
        assertEquals(0, getMaxLoginPerIP(actualUser));
        assertEquals(0, getMaxUploadRate(actualUser));
    }
View Full Code Here


    /**
     * Get user object.
     */
    public synchronized User getUserByName(String name) throws FtpException {
       
        User user = null;
        try {
            String dn = getDN(name);
            LOG.info("Getting user object for " + dn);
            user = (User)adminContext.lookup(dn);
        }
View Full Code Here

           
            if(password == null) {
                password = "";
            }
           
            User user;
            try {
                user = getUserByName(login);
            } catch (FtpException e) {
                throw new AuthenticationFailedException("Authentication failed", e);
            }
           
            if(user != null && password.equals(user.getPassword())) {
                    return user;
            } else {
                    throw new AuthenticationFailedException("Authentication failed");
            }
        } else if(authentication instanceof AnonymousAuthentication) {
View Full Code Here

            String dn = getDN(name);
            BaseUser newUser = new BaseUser(user);
           
            // if password is not available,
            // do not change the existing password
            User existUser = getUserByName(name);
            if( (existUser != null) && (newUser.getPassword() == null) ) {
                newUser.setPassword(existUser.getPassword());
            }

            // set attributes
            Attributes attrs = new BasicAttributes(true);
            attrs.put(new BasicAttribute(CN, name));
View Full Code Here

        }
        String userName = argument.substring(spIndex + 1);
       
        // check the user existance
        UserManager usrManager = context.getUserManager();
        User user = null;
        try {
            if(usrManager.doesExist(userName)) {
                user = usrManager.getUserByName(userName);
            }
        }
        catch(FtpException ex) {
            LOG.debug("Exception trying to get user from user manager", ex);
            user = null;
        }
        if(user == null) {
            session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, "SITE.DESCUSER", userName));
            return;
        }
       
        // send the user information
        StringBuffer sb = new StringBuffer(128);
        sb.append("\n");
        sb.append("userid          : ").append(user.getName()).append("\n");
        sb.append("userpassword    : ********\n");
        sb.append("homedirectory   : ").append(user.getHomeDirectory()).append("\n");
        sb.append("writepermission : ").append(user.authorize(new WriteRequest())).append("\n");
        sb.append("enableflag      : ").append(user.getEnabled()).append("\n");
        sb.append("idletime        : ").append(user.getMaxIdleTime()).append("\n");
       
        TransferRateRequest transferRateRequest = new TransferRateRequest();
        transferRateRequest = (TransferRateRequest) session.getUser().authorize(transferRateRequest);
       
        if(transferRateRequest != null) {
View Full Code Here

            if(maxLogin != 0 && currLogin >= maxLogin) {
              session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_421_SERVICE_NOT_AVAILABLE_CLOSING_CONTROL_CONNECTION, "USER.login", null));
                return;
            }
           
            User configUser = context.getUserManager().getUserByName(userName);
            if(configUser != null){
                //user login limit check
               
              InetAddress address = null;
              if(session.getRemoteAddress() instanceof InetSocketAddress) {
                address = ((InetSocketAddress)session.getRemoteAddress()).getAddress();
              }
             
                ConcurrentLoginRequest loginRequest = new  ConcurrentLoginRequest(
                        stat.getCurrentUserLoginNumber(configUser) + 1,
                        stat.getCurrentUserLoginNumber(configUser, address) + 1);
               
                if(configUser.authorize(loginRequest) == null) {
                  session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_421_SERVICE_NOT_AVAILABLE_CLOSING_CONTROL_CONNECTION, "USER.login", null));
                    return;
                }
            }
           
View Full Code Here

            if(!managedSession.isLoggedIn()) {
                continue;
            }
           
            User tmpUsr = managedSession.getUser();
            sb.append( StringUtils.pad(tmpUsr.getName(), ' ', true, 16) );
           
            if(managedSession.getRemoteAddress() instanceof InetSocketAddress) {
              sb.append( StringUtils.pad(((InetSocketAddress)managedSession.getRemoteAddress()).getAddress().getHostAddress(), ' ', true, 16) );
            }
            sb.append( StringUtils.pad(DateUtils.getISO8601Date(managedSession.getLoginTime().getTime()), ' ', true, 20) );
View Full Code Here

     * New login.
     */
    public synchronized void setLogin(final FtpIoSession session) {
        currLogins.incrementAndGet();
        totalLogins.incrementAndGet();
        User user = session.getUser();
        if ("anonymous".equals(user.getName())) {
            currAnonLogins.incrementAndGet();
            totalAnonLogins.incrementAndGet();
        }

        synchronized (user) {// thread safety is needed. Since the login occurrs
                             // at low frequency, this overhead is endurable
            UserLogins statisticsTable = userLoginTable.get(user.getName());
            if (statisticsTable == null) {
                // the hash table that records the login information of the user
                // and its ip address.
               
                InetAddress address = null;
                if (session.getRemoteAddress() instanceof InetSocketAddress) {
                    address = ((InetSocketAddress) session.getRemoteAddress()).getAddress();
                }
                statisticsTable = new UserLogins(address);
                userLoginTable.put(user.getName(), statisticsTable);
            } else {
                statisticsTable.totalLogins.incrementAndGet();

                if (session.getRemoteAddress() instanceof InetSocketAddress) {
                    InetAddress address = ((InetSocketAddress) session.getRemoteAddress()).getAddress();
View Full Code Here

    /**
     * User logout
     */
    public synchronized void setLogout(final FtpIoSession session) {
        User user = session.getUser();
        if (user == null) {
            return;
        }

        currLogins.decrementAndGet();

        if ("anonymous".equals(user.getName())) {
            currAnonLogins.decrementAndGet();
        }

        synchronized (user) {
            UserLogins userLogins = userLoginTable.get(user.getName());

            if (userLogins != null) {
                userLogins.totalLogins.decrementAndGet();
                if (session.getRemoteAddress() instanceof InetSocketAddress) {
                    InetAddress address = ((InetSocketAddress) session.getRemoteAddress()).getAddress();
View Full Code Here

    private void notifyLogin(final FtpIoSession session) {
        StatisticsObserver observer = this.observer;
        if (observer != null) {

            // is anonymous login
            User user = session.getUser();
            boolean anonymous = false;
            if (user != null) {
                String login = user.getName();
                anonymous = (login != null) && login.equals("anonymous");
            }
            observer.notifyLogin(anonymous);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.ftpserver.ftplet.User

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.