Package cu.ftpd.user

Examples of cu.ftpd.user.User


                            numberOfUsersAlreadyInGroup++;
                        }
                    }
                }
                if (group.getSlots() <= numberOfUsersAlreadyInGroup) {
                    User user = addUser(username, password);
                    user.addGroup(groupname);
                    user.setPrimaryGroup(groupname);
                    return user;
                } else {
                    throw new GroupLimitReachedException("slots", group.getName());
                }
            } else {
                User user = addUser(username, password);
                user.addGroup(groupname);
                user.setPrimaryGroup(groupname);
                return user;
            }
        }
    }
View Full Code Here


        yes we can, by checking .lastModified() on the file with a timer, but why would we need it?
        the only one we'd be interested in watching is the permissions-file, but that is changed as soon as someone logs on, so that's not needed.
         */

        synchronized(groupLock) {
            User user = getUser(username);
            if (groupname == null) {
                groupname = "default";
            }
            if (checkAvailability) {
                if (leech) {
                    Group group = getGroup(groupname);
                    List<LeechEntry> l = leechers.getLeechersForGroup(groupname);
                    if (l.size() < group.getLeechSlots()) {
                        // we can add without a problem
                        leechers.addLeecher(new LeechEntry(username, groupname));
                    } else {
                        // we can't add
                        return false;
                        // we could have checked if the user was in the list, and returned true then, but it doesn't matter, so we just return false.
                    }
                } else {
                    leechers.removeLeecher(new LeechEntry(username, groupname));
                    return true;
                }
            } else {
                // this also implies that we are using the general or whole site 'group'
                if (leech) {
                    leechers.addLeecher(new LeechEntry(username, groupname));
                } else {
                    // remove the user from the leech users for the general group
                    leechers.removeLeecher(new LeechEntry(username, groupname));
                }
            }
            user.setLeech(leechers.hasLeech(username));
            leechers.save();
            return true;
        }
    }
View Full Code Here

    }

    public void execute(String[] parameterList, Connection connection, User user, FileSystem fs) {
        if (user.hasPermission(UserPermission.USEREDIT) || currentUserIsGadminForUser(parameterList[1], user)) {
            try {
                User u = ServiceManager.getServices().getUserbase().getUser(parameterList[1]); // this means that we are doing the user lookup twice, but it doesn't really matter.
                String malformedIps = "";
                String addedIps = "";
                String invalidIps = "";
                for (int i = 2; i < parameterList.length; i++) {
                    if (ip.matcher(parameterList[i]).matches()) {
                        if (!u.getIps().contains(parameterList[i])) {
                            u.addIp(parameterList[i]);
                            addedIps += parameterList[i] + ' ';
                        } else {
                            invalidIps += parameterList[i] + ' ';
                        }
                    } else {
View Full Code Here

        }
    }

    protected boolean currentUserIsGadminForUser(String username, User user) {
        try {
            User u = ServiceManager.getServices().getUserbase().getUser(username);
            //current user is gadmin for any of the groups the specified user is a member of
            for (String gadminGroup : user.getGadminGroups()) { // this is generally a smaller set, so it makes sense to go over that first, since we abort early
                if (u.isMemberOfGroup(gadminGroup)) {
                    return true;
                }
            }
        } catch (NoSuchUserException e) {
            // you can't be the gadmin of a user that doesn't exist
View Full Code Here

        synchronized(groupLock) {
            if (allotment == 0) {
                allotments.removeAllotment(username, groupname);
                allotments.save();
            } else {
                User user = getUser(username);
                if (checkAvailability) {
                    // check the size of the allotment first
                    // then check if there are any allotment slots left in this group
                    Group group = getGroup(groupname);
                    if (allotment <= group.getMaxAllotment()) {
                        List<Allotment> l = allotments.getAllotmentsForGroup(groupname);
                        if (l.size() < group.getAllotmentSlots()) {
                            allotments.addAllotment(new Allotment(user.getUsername(), groupname, allotment));
                            allotments.save();
                        } else {
                            return false;
                        }
                    } else {
                        return false;
                    }
                } else {
                    // if we're not checking availability, we are implicitly saying that this is in the general group
                    // no, an admin can chose to add a user to one of the leech slots for a certain group
                    allotments.addAllotment(new Allotment(user.getUsername(), groupname, allotment));
                    allotments.save();
                }
            }
        }
        return true;
View Full Code Here

            Iterator<Allotment> i = allotments.getAllotments().iterator();
            // we use the iterator, since we might need to remove allotments if users have disappeared.
            while (i.hasNext()) {
                Allotment a = i.next();
                try {
                    User user = getUser(a.getUsername());


                    // there is a problem here, and that is that if a person has gotten alloted, then gets a new allotment, then the user will get that allotment next
                    // time the allotment is run, so some gadmin can just add and remove allotments to pump up someone's credits
                    // thus, we should keep a list of when users were alloted, rather than when a particular allotment happened (userfile or something general)
                    // AND it should be run something like every 6 hours or something. it could really be run every week, but since we don't know if people will be online all the time...

                    // we should probably put this value in the userfile. it's a simple place to put it. OR we put it in the allotment object that keeps track of everything, that's much better
                    // _todo: put the LAST_ALLOTED value at the top of allotments.conf, and remove the individual allotment times
                    // done


                    if (user.getCredits() < a.getAllotment()) {
                        user.setCredits(a.getAllotment());
                        //System.err.println("gave " + a.getAllotment() + " to user " + a.getUsername() + " in group " + a.getGroupname());
                    } else {
                        //System.err.println("skipping " + a.getUsername() + " since he already got credits this time around");
                    }
                } catch (NoSuchUserException e) {
View Full Code Here

        }
    }

    protected boolean currentUserIsGadminForUser(String username, User user) {
        try {
            User u = ServiceManager.getServices().getUserbase().getUser(username);
            //current user is gadmin for any of the groups the specified user is a member of
            for (String gadminGroup : user.getGadminGroups()) { // this is generally a smaller set, so it makes sense to go over that first, since we abort early
                if (u.isMemberOfGroup(gadminGroup)) {
                    return true;
                }
            }
        } catch (NoSuchUserException e) {
            // you can't be the gadmin of a user that doesn't exist
View Full Code Here

            connection.respond("500 Groupname contains illegal characters.");
        } else if (!parameterList[2].matches("[\\w-]+")) {
            connection.respond("500 Username contains illegal characters.");
        } else {
            try {
                User newuser;
                if (user.hasPermission(UserPermission.ADDUSER)) {
                    newuser = ServiceManager.getServices().getUserbase().gAddUser(parameterList[1], parameterList[2], parameterList[3], false);
                } else if (user.isGadminForGroup(parameterList[1])) {
                    newuser = ServiceManager.getServices().getUserbase().gAddUser(parameterList[1], parameterList[2], parameterList[3], true);
                } else {
                    connection.respond("531 Permission denied.");
                    return;
                }
                // add ips if there are any. A user with no ips cannot log in
                String wrongIps = "";
                for (int i = 4; i < parameterList.length; i++) {
                    if (ip.matcher(parameterList[i]).matches()) {
                        newuser.addIp(parameterList[i]);
                    } else {
                        wrongIps += parameterList[i] + ' ';
                    }
                }
                connection.respond("200 User " + parameterList[2] + " successfully added." + (wrongIps.length() > 0 ? " The following ips were wrong: " + wrongIps : ""));
View Full Code Here

    }

    protected boolean currentUserIsGadminForUser(String username, User user) {
        try {
            User u = ServiceManager.getServices().getUserbase().getUser(username);
            //current user is gadmin for any of the groups the specified user is a member of
            for (String gadminGroup : user.getGadminGroups()) { // this is generally a smaller set, so it makes sense to go over that first, since we abort early
                if (u.isMemberOfGroup(gadminGroup)) {
                    return true;
                }
            }
        } catch (NoSuchUserException e) {
            // you can't be the gadmin of a user that doesn't exist
View Full Code Here

    }

    public void execute(String[] parameterList, Connection connection, User user, FileSystem fs) {
        if (user.hasPermission(UserPermission.GROUPS)) { // gadmins can't remove users from their group
            try {
                User u = ServiceManager.getServices().getUserbase().getUser(parameterList[1]);
                u.removeGroup(parameterList[2]);
                // remove leech and allotments for the user in this group
                ServiceManager.getServices().getUserbase().setAllotmentForUser(0, u.getUsername(), parameterList[2], false);
                ServiceManager.getServices().getUserbase().setLeechForUser(false, u.getUsername(), parameterList[2], false);
                connection.respond("200 sucessfully removed user " + parameterList[1] + " from group " + parameterList[2] + '.');
            } catch (NoSuchUserException e) {
                connection.respond("500 " + e.getMessage());
            } catch (NoSuchGroupException e) {
                connection.respond("500 " + e.getMessage());
View Full Code Here

TOP

Related Classes of cu.ftpd.user.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.