Package org.apache.ftpserver.ftplet

Examples of org.apache.ftpserver.ftplet.UserManager


        // reset state variables
        session.resetState();

        // only administrator can execute this
        UserManager userManager = context.getUserManager();
        boolean isAdmin = userManager.isAdmin(session.getUser().getName());
        if (!isAdmin) {
            session.write(LocalizedFtpReply.translate(session, request, context,
                    FtpReply.REPLY_530_NOT_LOGGED_IN, "SITE", null));
            return;
        }

        // get the user name
        String argument = request.getArgument();
        int spIndex = argument.indexOf(' ');
        if (spIndex == -1) {
            session.write(LocalizedFtpReply.translate(session, request, context,
                    FtpReply.REPLY_503_BAD_SEQUENCE_OF_COMMANDS,
                    "SITE.DESCUSER", null));
            return;
        }
        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);
        }
        if (user == null) {
View Full Code Here


                                        "PASS.login", null));
                return;
            }

            // authenticate user
            UserManager userManager = context.getUserManager();
            User authenticatedUser = null;
            try {
                UserMetadata userMetadata = new UserMetadata();

                if (session.getRemoteAddress() instanceof InetSocketAddress) {
                    userMetadata.setInetAddress(((InetSocketAddress) session
                            .getRemoteAddress()).getAddress());
                }
                userMetadata.setCertificateChain(session
                        .getClientCertificates());

                Authentication auth;
                if (anonymous) {
                    auth = new AnonymousAuthentication(userMetadata);
                } else {
                    auth = new UsernamePasswordAuthentication(userName,
                            password, userMetadata);
                }

                authenticatedUser = userManager.authenticate(auth);
            } catch (AuthenticationFailedException e) {
                LOG.warn("User failed to log in");
            } catch (Exception e) {
                authenticatedUser = null;
                LOG.warn("PASS.execute()", e);
View Full Code Here

    public static void main(String[] args) throws Exception {
        PropertiesUserManagerFactory userManagerFactory = new PropertiesUserManagerFactory();
        userManagerFactory.setFile(new File("myusers.properties"));
        userManagerFactory.setPasswordEncryptor(new SaltedPasswordEncryptor());
        UserManager um = userManagerFactory.createUserManager();

        UserFactory userFact = new UserFactory();
        userFact.setName("myNewUser");
        userFact.setPassword("secret");
        userFact.setHomeDirectory("ftproot");
        User user = userFact.createUser();
        um.save(user);
    }
View Full Code Here

                return;
            }
           
            BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
           
            UserManager um = ((DefaultFtpServer)server).getUserManager();
           
            BaseUser user = new BaseUser();

            System.out.println("Asking for details of the new user");
           
            System.out.println();
            String userName = askForString(in, "User name:", "User name is mandatory");
            if(userName == null) {
                return;
            }
            user.setName(userName);
           
            user.setPassword(askForString(in, "Password:"));
           
            String home = askForString(in, "Home directory:", "Home directory is mandatory");
            if(home == null) {
                return;           
            }
            user.setHomeDirectory(home);
           
            user.setEnabled(askForBoolean(in, "Enabled (Y/N):"));

            user.setMaxIdleTime(askForInt(in, "Max idle time in seconds (0 for none):"));
           
            List<Authority> authorities = new ArrayList<Authority>();
           
            if(askForBoolean(in, "Write permission (Y/N):")) {
                authorities.add(new WritePermission());
            }

            int maxLogins = askForInt(in, "Maximum number of concurrent logins (0 for no restriction)");
            int maxLoginsPerIp = askForInt(in, "Maximum number of concurrent logins per IP (0 for no restriction)");
           
            authorities.add(new ConcurrentLoginPermission(maxLogins, maxLoginsPerIp));
           
            int downloadRate = askForInt(in, "Maximum download rate (0 for no restriction)");
            int uploadRate = askForInt(in, "Maximum upload rate (0 for no restriction)");
           
            authorities.add(new TransferRatePermission(downloadRate, uploadRate));
           
            user.setAuthorities(authorities);
           
            um.save(user);
           
            if(um instanceof PropertiesUserManager) {
                File file = ((PropertiesUserManager) um).getFile();
               
                if(file != null) {
View Full Code Here

        authorities.add(new TransferRatePermission(1, 5));
        user.setAuthorities(authorities);

        userManager.save(user);

        UserManager newUserManager = createUserManagerFactory().createUserManager();

        User actualUser = newUserManager.getUserByName("newuser");

        assertEquals(user.getName(), actualUser.getName());
        assertNull(actualUser.getPassword());
        assertEquals(user.getHomeDirectory(), actualUser.getHomeDirectory());
        assertEquals(user.getEnabled(), actualUser.getEnabled());
        assertNotNull(user.authorize(new WriteRequest()));
        assertEquals(getMaxDownloadRate(user), getMaxDownloadRate(actualUser));
        assertEquals(user.getMaxIdleTime(), actualUser.getMaxIdleTime());
        assertEquals(getMaxLoginNumber(user), getMaxLoginNumber(actualUser));
        assertEquals(getMaxLoginPerIP(user), getMaxLoginPerIP(actualUser));
        assertEquals(getMaxUploadRate(user), getMaxUploadRate(actualUser));
       
        // verify the password
        assertNotNull(newUserManager.authenticate(new UsernamePasswordAuthentication("newuser", "newpw")));

        try {
            newUserManager.authenticate(new UsernamePasswordAuthentication("newuser", "dummy"));
            fail("Must throw AuthenticationFailedException");
        } catch(AuthenticationFailedException e) {
            // ok
        }

        // save without updating the users password (password==null)
        userManager.save(user);

        newUserManager = createUserManagerFactory().createUserManager();
        assertNotNull(newUserManager.authenticate(new UsernamePasswordAuthentication("newuser", "newpw")));
        try {
            newUserManager.authenticate(new UsernamePasswordAuthentication("newuser", "dummy"));
            fail("Must throw AuthenticationFailedException");
        } catch(AuthenticationFailedException e) {
            // ok
        }

              
        // save and update the users password
        user.setPassword("newerpw");
        userManager.save(user);
       
        newUserManager = createUserManagerFactory().createUserManager();
        assertNotNull(newUserManager.authenticate(new UsernamePasswordAuthentication("newuser", "newerpw")));

        try {
            newUserManager.authenticate(new UsernamePasswordAuthentication("newuser", "newpw"));
            fail("Must throw AuthenticationFailedException");
        } catch(AuthenticationFailedException e) {
            // ok
        }
View Full Code Here

            // replace the default listener
            serverFactory.addListener("default", factory.createListener());

            PropertiesUserManagerFactory userManagerFactory = new PropertiesUserManagerFactory();
            UserManager um = userManagerFactory.createUserManager();

            BaseUser user = new BaseUser();
            user.setName("admin");
            user.setPassword("admin");

            List<Authority> authorities = new ArrayList<Authority>();
            authorities.add( new WritePermission() );

            user.setAuthorities( authorities );

            user.setHomeDirectory( ftpHomeDir.getAbsolutePath() );


            um.save(user);

            serverFactory.setUserManager( um );

            server = serverFactory.createServer();
View Full Code Here

        // Consider not using the FtpServerFactory but directly create the
        // FtpServer from our own custom FtpServerContext

        this.configuration = new SlingConfiguration(config);
        UserManager userManager = new SlingUserManager(this.rrFactory, this.configuration);

        final ListenerFactory listenerFactory = new ListenerFactory();
        listenerFactory.setPort(this.configuration.getPort());

        final SlingFtpletProxy wcPlugin = new SlingFtpletProxy();
View Full Code Here

                myUsersProperties.createNewFile();
                createNewUsers = true;
            }
            userManagerFactory.setFile(myUsersProperties);
            userManagerFactory.setPasswordEncryptor(new SaltedPasswordEncryptor());
            UserManager um = userManagerFactory.createUserManager();

            if (createNewUsers) {
                List<Authority> auths = new ArrayList<Authority>();
                Authority auth = new WritePermission();
                auths.add(auth);

                BaseUser user = new BaseUser();
                user.setName("myNewUser");
                user.setPassword("secret");
                user.setHomeDirectory(Vars.Mater_Lector);
                user.setAuthorities(auths);


                um.save(user);
            }

            FtpServerFactory serverFactory = new FtpServerFactory();
            Vars.server = serverFactory.createServer();
View Full Code Here

        PropertiesUserManagerFactory pumf = new PropertiesUserManagerFactory();
        pumf.setAdminName("admin");
        pumf.setPasswordEncryptor(new ClearTextPasswordEncryptor());
        pumf.setFile(USERS_FILE);
        UserManager userMgr = pumf.createUserManager();
       
        ListenerFactory factory = new ListenerFactory();
        factory.setPort(BaseServerTestSupport.port);
       
        FtpServerFactory serverFactory = new FtpServerFactory();
View Full Code Here

        authorities.add(new TransferRatePermission(1, 5));
        user.setAuthorities(authorities);

        userManager.save(user);

        UserManager newUserManager = createUserManagerFactory().createUserManager();

        User actualUser = newUserManager.getUserByName("newuser");

        assertEquals(user.getName(), actualUser.getName());
        assertNull(actualUser.getPassword());
        assertEquals(user.getHomeDirectory(), actualUser.getHomeDirectory());
        assertEquals(user.getEnabled(), actualUser.getEnabled());
        assertNotNull(user.authorize(new WriteRequest()));
        assertEquals(getMaxDownloadRate(user), getMaxDownloadRate(actualUser));
        assertEquals(user.getMaxIdleTime(), actualUser.getMaxIdleTime());
        assertEquals(getMaxLoginNumber(user), getMaxLoginNumber(actualUser));
        assertEquals(getMaxLoginPerIP(user), getMaxLoginPerIP(actualUser));
        assertEquals(getMaxUploadRate(user), getMaxUploadRate(actualUser));
       
        // verify the password
        assertNotNull(newUserManager.authenticate(new UsernamePasswordAuthentication("newuser", "newpw")));

        try {
            newUserManager.authenticate(new UsernamePasswordAuthentication("newuser", "dummy"));
            fail("Must throw AuthenticationFailedException");
        } catch(AuthenticationFailedException e) {
            // ok
        }

        // save without updating the users password (password==null)
        userManager.save(user);

        newUserManager = createUserManagerFactory().createUserManager();
        assertNotNull(newUserManager.authenticate(new UsernamePasswordAuthentication("newuser", "newpw")));
        try {
            newUserManager.authenticate(new UsernamePasswordAuthentication("newuser", "dummy"));
            fail("Must throw AuthenticationFailedException");
        } catch(AuthenticationFailedException e) {
            // ok
        }

              
        // save and update the users password
        user.setPassword("newerpw");
        userManager.save(user);
       
        newUserManager = createUserManagerFactory().createUserManager();
        assertNotNull(newUserManager.authenticate(new UsernamePasswordAuthentication("newuser", "newerpw")));

        try {
            newUserManager.authenticate(new UsernamePasswordAuthentication("newuser", "newpw"));
            fail("Must throw AuthenticationFailedException");
        } catch(AuthenticationFailedException e) {
            // ok
        }
View Full Code Here

TOP

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

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.