Browse Source

Remove obsolete and deprecated FileUserService

Change-Id: I92d1d742e286643e1e1ab47a410b3fda146d1741
tags/v1.4.0
James Moger 10 years ago
parent
commit
578319a659

+ 0
- 1146
src/main/java/com/gitblit/FileUserService.java
File diff suppressed because it is too large
View File


+ 16
- 36
src/main/java/com/gitblit/GitblitUserService.java View File

@@ -33,25 +33,25 @@ import com.gitblit.utils.StringUtils;
/**
* 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 @@ public class GitblitUserService implements IUserService {
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 @@ public class GitblitUserService implements IUserService {
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 @@ public class GitblitUserService implements IUserService {
setAccountType(user);
return user;
}
@Override
public void logout(UserModel user) {
serviceImpl.logout(user);
@@ -187,7 +167,7 @@ public class GitblitUserService implements IUserService {
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 @@ public class GitblitUserService implements IUserService {
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 @@ public class GitblitUserService implements IUserService {
for (UserModel user : users) {
setAccountType(user);
}
return users;
return users;
}
@Override
@@ -275,7 +255,7 @@ public class GitblitUserService implements IUserService {
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 class GitblitUserService implements IUserService {
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 @@ public class GitblitUserService implements IUserService {
}
}
}
protected AccountType getAccountType() {
return AccountType.LOCAL;
}

+ 6
- 17
src/test/java/com/gitblit/tests/UserServiceTest.java View File

@@ -26,7 +26,6 @@ import org.junit.Test;
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;
@@ -34,16 +33,6 @@ 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 {
File file = new File("us-test.conf");
@@ -62,13 +51,13 @@ public class UserServiceTest {
// 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 @@ public class UserServiceTest {
// 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 @@ public class UserServiceTest {
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 @@ public class UserServiceTest {
// 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"));

Loading…
Cancel
Save