summaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2013-07-02 14:49:06 -0400
committerJames Moger <james.moger@gitblit.com>2013-07-02 14:49:06 -0400
commitb5798e1e6cf15da4eb33647190e127b53410c620 (patch)
tree5417cb5784d0a1dbecc5b3602be5b2ccdd2fe231 /src/main/java
parentaa7d215a9a174428f4f76244b932797d9b87b910 (diff)
downloadgitblit-b5798e1e6cf15da4eb33647190e127b53410c620.tar.gz
gitblit-b5798e1e6cf15da4eb33647190e127b53410c620.zip
Improvements to handling internal accounts (anonymous, federation user)
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/gitblit/AuthenticationFilter.java4
-rw-r--r--src/main/java/com/gitblit/GitBlit.java20
-rw-r--r--src/main/java/com/gitblit/utils/RefLogUtils.java2
-rw-r--r--src/main/java/com/gitblit/wicket/GitBlitWebApp.properties3
-rw-r--r--src/main/java/com/gitblit/wicket/panels/ReflogPanel.java4
5 files changed, 25 insertions, 8 deletions
diff --git a/src/main/java/com/gitblit/AuthenticationFilter.java b/src/main/java/com/gitblit/AuthenticationFilter.java
index 5319bf3a..388452e4 100644
--- a/src/main/java/com/gitblit/AuthenticationFilter.java
+++ b/src/main/java/com/gitblit/AuthenticationFilter.java
@@ -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() {
diff --git a/src/main/java/com/gitblit/GitBlit.java b/src/main/java/com/gitblit/GitBlit.java
index 6285733b..b6f7de46 100644
--- a/src/main/java/com/gitblit/GitBlit.java
+++ b/src/main/java/com/gitblit/GitBlit.java
@@ -725,6 +725,18 @@ public class GitBlit implements ServletContextListener {
}
/**
+ * 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.
*
* @see IUserService.authenticate(String, char[])
@@ -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
diff --git a/src/main/java/com/gitblit/utils/RefLogUtils.java b/src/main/java/com/gitblit/utils/RefLogUtils.java
index fed55cab..643fbc0f 100644
--- a/src/main/java/com/gitblit/utils/RefLogUtils.java
+++ b/src/main/java/com/gitblit/utils/RefLogUtils.java
@@ -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),
diff --git a/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties b/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties
index bca0dc0d..e550c936 100644
--- a/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties
+++ b/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties
@@ -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 \ No newline at end of file
+gb.noActivityToday = there has been no activity today
+gb.anonymousUser= anonymous \ No newline at end of file
diff --git a/src/main/java/com/gitblit/wicket/panels/ReflogPanel.java b/src/main/java/com/gitblit/wicket/panels/ReflogPanel.java
index 048ce1b0..b0a94790 100644
--- a/src/main/java/com/gitblit/wicket/panels/ReflogPanel.java
+++ b/src/main/java/com/gitblit/wicket/panels/ReflogPanel.java
@@ -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(),