James Moger
2013-09-06 578319a659fba918ba720d12ca4d4fc105918595
Remove obsolete and deprecated FileUserService

Change-Id: I92d1d742e286643e1e1ab47a410b3fda146d1741
1 files deleted
2 files modified
1221 ■■■■■ changed files
src/main/java/com/gitblit/FileUserService.java 1146 ●●●●● patch | view | raw | blame | history
src/main/java/com/gitblit/GitblitUserService.java 52 ●●●●● patch | view | raw | blame | history
src/test/java/com/gitblit/tests/UserServiceTest.java 23 ●●●● patch | view | raw | blame | history
src/main/java/com/gitblit/FileUserService.java
File was deleted
src/main/java/com/gitblit/GitblitUserService.java
@@ -33,25 +33,25 @@
/**
 * This class wraps the default user service and is recommended as the starting
 * point for custom user service implementations.
 *
 *
 * This does seem a little convoluted, but the idea is to allow IUserService to
 * evolve with new methods and implementations without breaking custom
 * authentication implementations.
 *
 *
 * The most common implementation of a custom IUserService is to only override
 * authentication and then delegate all other functionality to one of Gitblit's
 * user services. This class optimizes that use-case.
 *
 *
 * Extending GitblitUserService allows for authentication customization without
 * having to keep-up-with IUSerService API changes.
 *
 *
 * @author James Moger
 *
 *
 */
public class GitblitUserService implements IUserService {
    protected IUserService serviceImpl;
    private final Logger logger = LoggerFactory.getLogger(GitblitUserService.class);
    public GitblitUserService() {
@@ -64,13 +64,9 @@
        logger.info("GUS delegating to " + serviceImpl.toString());
    }
    @SuppressWarnings("deprecation")
    protected IUserService createUserService(File realmFile) {
        IUserService service = null;
        if (realmFile.getName().toLowerCase().endsWith(".properties")) {
            // v0.5.0 - v0.7.0 properties-based realm file
            service = new FileUserService(realmFile);
        } else if (realmFile.getName().toLowerCase().endsWith(".conf")) {
        if (realmFile.getName().toLowerCase().endsWith(".conf")) {
            // v0.8.0+ config-based realm file
            service = new ConfigUserService(realmFile);
        }
@@ -91,25 +87,9 @@
            service.updateUserModel(admin);
        }
        if (service instanceof FileUserService) {
            // automatically create a users.conf realm file from the original
            // users.properties file
            File usersConfig = new File(realmFile.getParentFile(), "users.conf");
            if (!usersConfig.exists()) {
                logger.info(MessageFormat.format("Automatically creating {0} based on {1}",
                        usersConfig.getAbsolutePath(), realmFile.getAbsolutePath()));
                ConfigUserService configService = new ConfigUserService(usersConfig);
                for (String username : service.getAllUsernames()) {
                    UserModel userModel = service.getUserModel(username);
                    configService.updateUserModel(userModel);
                }
            }
            // issue suggestion about switching to users.conf
            logger.warn("Please consider using \"users.conf\" instead of the deprecated \"users.properties\" file");
        }
        return service;
    }
    @Override
    public String toString() {
        return getClass().getSimpleName();
@@ -158,7 +138,7 @@
        setAccountType(user);
        return user;
    }
    @Override
    public void logout(UserModel user) {
        serviceImpl.logout(user);
@@ -187,7 +167,7 @@
            if (!model.isLocalAccount() && !supportsTeamMembershipChanges()) {
                //  teams are externally controlled - copy from original model
                UserModel existingModel = getUserModel(username);
                model = DeepCopier.copy(model);
                model.teams.clear();
                model.teams.addAll(existingModel.teams);
@@ -200,7 +180,7 @@
            if (!model.isLocalAccount() && !supportsTeamMembershipChanges()) {
                //  teams are externally controlled- copy from original model
                UserModel existingModel = getUserModel(username);
                model = DeepCopier.copy(model);
                model.teams.clear();
                model.teams.addAll(existingModel.teams);
@@ -231,7 +211,7 @@
        for (UserModel user : users) {
            setAccountType(user);
        }
        return users;
        return users;
    }
    @Override
@@ -275,7 +255,7 @@
        if (!supportsTeamMembershipChanges()) {
            // teams are externally controlled - copy from original model
            TeamModel existingModel = getTeamModel(teamname);
            model = DeepCopier.copy(model);
            model.users.clear();
            model.users.addAll(existingModel.users);
@@ -313,12 +293,12 @@
    public boolean deleteRepositoryRole(String role) {
        return serviceImpl.deleteRepositoryRole(role);
    }
    protected boolean isLocalAccount(String username) {
        UserModel user = getUserModel(username);
        return user != null && user.isLocalAccount();
    }
    protected void setAccountType(UserModel user) {
        if (user != null) {
            if (!StringUtils.isEmpty(user.password)
@@ -330,7 +310,7 @@
            }
        }
    }
    protected AccountType getAccountType() {
        return AccountType.LOCAL;
    }
src/test/java/com/gitblit/tests/UserServiceTest.java
@@ -26,23 +26,12 @@
import com.gitblit.ConfigUserService;
import com.gitblit.Constants.AccessRestrictionType;
import com.gitblit.FileUserService;
import com.gitblit.IUserService;
import com.gitblit.models.RepositoryModel;
import com.gitblit.models.TeamModel;
import com.gitblit.models.UserModel;
public class UserServiceTest {
    @Test
    public void testFileUserService() throws IOException {
        File file = new File("us-test.properties");
        file.delete();
        IUserService service = new FileUserService(file);
        testUsers(service);
        testTeams(service);
        file.delete();
    }
    @Test
    public void testConfigUserService() throws IOException {
@@ -62,13 +51,13 @@
        // add admin and admins team
        TeamModel admins = new TeamModel("admins");
        admins.mailingLists.add("admins@localhost.com");
        admin = new UserModel("admin");
        admin.password = "password";
        admin.canAdmin = true;
        admin.excludeFromFederation = true;
        admin.teams.add(admins);
        service.updateUserModel(admin);
        admin = null;
        admins = null;
@@ -125,7 +114,7 @@
        // confirm we have 1 team (admins)
        assertEquals(1, service.getAllTeamNames().size());
        assertEquals("admins", service.getAllTeamNames().get(0));
        RepositoryModel newrepo1 = new RepositoryModel("newrepo1", null, null, null);
        newrepo1.accessRestriction = AccessRestrictionType.VIEW;
        RepositoryModel NEWREPO1 = new RepositoryModel("NEWREPO1", null, null, null);
@@ -168,7 +157,7 @@
        newrepo2.accessRestriction = AccessRestrictionType.VIEW;
        RepositoryModel NEWREPO2 = new RepositoryModel("NEWREPO2", null, null, null);
        NEWREPO2.accessRestriction = AccessRestrictionType.VIEW;
        team.addRepositoryPermission(newrepo2.name);
        team.name = "testteam2";
        service.updateTeamModel("testteam", team);
@@ -233,11 +222,11 @@
        // delete both teams
        service.deleteTeam("testteam");
        service.deleteTeam("nextteam");
        // assert we still have the admins team
        assertEquals(1, service.getAllTeamNames().size());
        assertEquals("admins", service.getAllTeamNames().get(0));
        team = service.getTeamModel("admins");
        assertEquals(1, team.mailingLists.size());
        assertTrue(team.mailingLists.contains("admins@localhost.com"));