Browse Source

Improvements to handling internal accounts (anonymous, federation user)

tags/v1.3.0
James Moger 11 years ago
parent
commit
b5798e1e6c

+ 2
- 2
src/main/java/com/gitblit/AuthenticationFilter.java View File

@@ -36,6 +36,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.gitblit.models.UserModel;
import com.gitblit.utils.DeepCopier;
import com.gitblit.utils.StringUtils;
/**
@@ -151,8 +152,7 @@ public abstract class AuthenticationFilter implements Filter {
public AuthenticatedRequest(HttpServletRequest req) {
super(req);
user = new UserModel("anonymous");
user.isAuthenticated = false;
user = DeepCopier.copy(UserModel.ANONYMOUS);
}
UserModel getUser() {

+ 16
- 4
src/main/java/com/gitblit/GitBlit.java View File

@@ -724,6 +724,18 @@ public class GitBlit implements ServletContextListener {
return (user != null && user.isLocalAccount()) || userService.supportsTeamMembershipChanges();
}

/**
* Returns true if the username represents an internal account
*
* @param username
* @return true if the specified username represents an internal account
*/
protected boolean isInternalAccount(String username) {
return !StringUtils.isEmpty(username)
&& (username.equalsIgnoreCase(Constants.FEDERATION_USER)
|| username.equalsIgnoreCase(UserModel.ANONYMOUS.username));
}

/**
* Authenticate a user based on a username and password.
*
@@ -836,6 +848,7 @@ public class GitBlit implements ServletContextListener {
if (principal != null) {
String username = principal.getName();
if (!StringUtils.isEmpty(username)) {
boolean internalAccount = isInternalAccount(username);
UserModel user = getUserModel(username);
if (user != null) {
// existing user
@@ -844,7 +857,7 @@ public class GitBlit implements ServletContextListener {
user.username, httpRequest.getRemoteAddr()));
return user;
} else if (settings.getBoolean(Keys.realm.container.autoCreateAccounts, false)
&& !username.equalsIgnoreCase(Constants.FEDERATION_USER)) {
&& !internalAccount) {
// auto-create user from an authenticated container principal
user = new UserModel(username.toLowerCase());
user.displayName = username;
@@ -854,7 +867,7 @@ public class GitBlit implements ServletContextListener {
logger.debug(MessageFormat.format("{0} authenticated and created by servlet container principal from {1}",
user.username, httpRequest.getRemoteAddr()));
return user;
} else {
} else if (!internalAccount) {
logger.warn(MessageFormat.format("Failed to find UserModel for {0}, attempted servlet container authentication from {1}",
principal.getName(), httpRequest.getRemoteAddr()));
}
@@ -2933,8 +2946,7 @@ public class GitBlit implements ServletContextListener {
String cloneUrl = sb.toString();

// Retrieve all available repositories
UserModel user = new UserModel(Constants.FEDERATION_USER);
user.canAdmin = true;
UserModel user = getFederationUser();
List<RepositoryModel> list = getRepositoryModels(user);

// create the [cloneurl, repositoryModel] map

+ 1
- 1
src/main/java/com/gitblit/utils/RefLogUtils.java View File

@@ -184,7 +184,7 @@ public class RefLogUtils {
PersonIdent ident;
if (UserModel.ANONYMOUS.equals(user)) {
// anonymous push
ident = new PersonIdent("anonymous", "anonymous");
ident = new PersonIdent(user.username + "/" + user.username, user.username);
} else {
// construct real pushing account
ident = new PersonIdent(MessageFormat.format("{0}/{1}", user.getDisplayName(), user.username),

+ 2
- 1
src/main/java/com/gitblit/wicket/GitBlitWebApp.properties View File

@@ -500,4 +500,5 @@ gb.starredAndOwned = starred & owned
gb.reviewPatchset = review {0} patchset {1}
gb.todaysActivityStats = today / {1} commits by {2} authors
gb.todaysActivityNone = today / none
gb.noActivityToday = there has been no activity today
gb.noActivityToday = there has been no activity today
gb.anonymousUser= anonymous

+ 4
- 0
src/main/java/com/gitblit/wicket/panels/ReflogPanel.java View File

@@ -37,6 +37,7 @@ import com.gitblit.Keys;
import com.gitblit.models.RefLogEntry;
import com.gitblit.models.RepositoryCommit;
import com.gitblit.models.RepositoryModel;
import com.gitblit.models.UserModel;
import com.gitblit.utils.RefLogUtils;
import com.gitblit.utils.StringUtils;
import com.gitblit.utils.TimeUtils;
@@ -163,6 +164,9 @@ public class ReflogPanel extends BasePanel {
if (change.user.username.equals(change.user.emailAddress) && change.user.emailAddress.indexOf('@') > -1) {
// username is an email address - 1.2.1 push log bug
changeItem.add(new Label("whoChanged", change.user.getDisplayName()));
} else if (change.user.username.equals(UserModel.ANONYMOUS.username)) {
// anonymous change
changeItem.add(new Label("whoChanged", getString("gb.anonymousUser")));
} else {
// link to user account page
changeItem.add(new LinkPanel("whoChanged", null, change.user.getDisplayName(),

Loading…
Cancel
Save