Package org.apache.ftpserver.usermanager.impl

Examples of org.apache.ftpserver.usermanager.impl.BaseUser


           
            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();
View Full Code Here


    private FileSystemView fileSystemView;

    @Override
    protected void setUp() throws Exception {
        BaseUser baseUser = new BaseUser();
        baseUser.setHomeDirectory(ROOT_DIR.getAbsolutePath());
        fileSystemView = new NativeFileSystemView(baseUser) {
        };
        directoryLister = new DirectoryLister();

        assertTrue(ROOT_DIR.mkdirs());
View Full Code Here

            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 );
View Full Code Here

  private static final String TEST_PASSWORD = "demo";

  public TestUserManager(String homeDirectory) {
    super("admin", new ClearTextPasswordEncryptor());

    testUser = new BaseUser();
    testUser.setAuthorities(Arrays.asList(new Authority[] {new ConcurrentLoginPermission(1, 1), new WritePermission()}));
    testUser.setEnabled(true);
    testUser.setHomeDirectory(homeDirectory);
    testUser.setMaxIdleTime(10000);
    testUser.setName(TEST_USERNAME);
    testUser.setPassword(TEST_PASSWORD);

    anonUser = new BaseUser(testUser);
    anonUser.setName("anonymous");
  }
View Full Code Here

            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);
            }
View Full Code Here

    private DirectoryLister directoryLister;

    private FileSystemView fileSystemView;

    protected void setUp() throws Exception {
        BaseUser baseUser = new BaseUser();
        baseUser.setHomeDirectory(ROOT_DIR.getAbsolutePath());
        fileSystemView = new NativeFileSystemView(baseUser) {
        };
        directoryLister = new DirectoryLister();

        assertTrue(ROOT_DIR.mkdirs());
View Full Code Here

            return 0;
        }
    }

    public void testSave() throws Exception {
        BaseUser user = new BaseUser();
        user.setName("newuser");
        user.setPassword("newpw");
        user.setHomeDirectory("newhome");
        user.setEnabled(false);
        user.setMaxIdleTime(2);

        List<Authority> authorities = new ArrayList<Authority>();
        authorities.add(new WritePermission());
        authorities.add(new ConcurrentLoginPermission(3, 4));
        authorities.add(new TransferRatePermission(1, 5));
        user.setAuthorities(authorities);

        userManager.save(user);

        User actualUser = userManager.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(userManager.authenticate(new UsernamePasswordAuthentication("newuser", "newpw")));

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

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

        assertNotNull(userManager.authenticate(new UsernamePasswordAuthentication("newuser", "newpw")));
        try {
            userManager.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);
       
        assertNotNull(userManager.authenticate(new UsernamePasswordAuthentication("newuser", "newerpw")));

        try {
View Full Code Here

        }

    }

    public void testSavePersistent() throws Exception {
        BaseUser user = new BaseUser();
        user.setName("newuser");
        user.setPassword("newpw");
        user.setHomeDirectory("newhome");
        user.setEnabled(false);
        user.setMaxIdleTime(2);

        List<Authority> authorities = new ArrayList<Authority>();
        authorities.add(new WritePermission());
        authorities.add(new ConcurrentLoginPermission(3, 4));
        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")));
View Full Code Here

    }

   
    public void testSaveWithExistingUser() throws Exception {
        BaseUser user = new BaseUser();
        user.setName("user2");
        user.setHomeDirectory("newhome");
        userManager.save(user);

        User actualUser = userManager.getUserByName("user2");

        assertEquals("user2", actualUser.getName());
        assertNull(actualUser.getPassword());
        assertEquals("newhome", actualUser.getHomeDirectory());
        assertEquals(0, getMaxDownloadRate(actualUser));
        assertEquals(0, actualUser.getMaxIdleTime());
        assertEquals(0, getMaxLoginNumber(actualUser));
        assertEquals(0, getMaxLoginPerIP(actualUser));
        assertEquals(0, getMaxUploadRate(actualUser));
        assertNull(user.authorize(new WriteRequest()));
        assertTrue(actualUser.getEnabled());
    }
View Full Code Here

        assertNull(user.authorize(new WriteRequest()));
        assertTrue(actualUser.getEnabled());
    }

    public void testSaveWithDefaultValues() throws Exception {
        BaseUser user = new BaseUser();
        user.setName("newuser");
        user.setPassword("newpw");
        userManager.save(user);

        User actualUser = userManager.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

TOP

Related Classes of org.apache.ftpserver.usermanager.impl.BaseUser

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.