summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/gitblit/GitBlit.java
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2013-06-17 15:56:14 -0400
committerJames Moger <james.moger@gitblit.com>2013-06-17 15:56:14 -0400
commit9b54923f4ee5411966016f91224e4f4f545f1416 (patch)
treeab5d381f6aa1501fe351502fb2d88736414e354e /src/main/java/com/gitblit/GitBlit.java
parentde3474a1ddd9201dec8246d7fd81e240b98bb6a5 (diff)
downloadgitblit-9b54923f4ee5411966016f91224e4f4f545f1416.tar.gz
gitblit-9b54923f4ee5411966016f91224e4f4f545f1416.zip
Option to auto-create accounts based on authenticated container principals (issue-246)
Diffstat (limited to 'src/main/java/com/gitblit/GitBlit.java')
-rw-r--r--src/main/java/com/gitblit/GitBlit.java13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/main/java/com/gitblit/GitBlit.java b/src/main/java/com/gitblit/GitBlit.java
index c538acea..25ffaba8 100644
--- a/src/main/java/com/gitblit/GitBlit.java
+++ b/src/main/java/com/gitblit/GitBlit.java
@@ -827,13 +827,24 @@ public class GitBlit implements ServletContextListener {
Principal principal = httpRequest.getUserPrincipal();
if (principal != null) {
String username = principal.getName();
- if (StringUtils.isEmpty(username)) {
+ if (!StringUtils.isEmpty(username)) {
UserModel user = getUserModel(username);
if (user != null) {
+ // existing user
flagWicketSession(AuthenticationType.CONTAINER);
logger.debug(MessageFormat.format("{0} authenticated by servlet container principal from {1}",
user.username, httpRequest.getRemoteAddr()));
return user;
+ } else if (settings.getBoolean(Keys.realm.container.autoCreateAccounts, true)) {
+ // auto-create user from an authenticated container principal
+ user = new UserModel(username.toLowerCase());
+ user.displayName = username;
+ user.password = Constants.EXTERNAL_ACCOUNT;
+ userService.updateUserModel(user);
+ flagWicketSession(AuthenticationType.CONTAINER);
+ logger.debug(MessageFormat.format("{0} authenticated and created by servlet container principal from {1}",
+ user.username, httpRequest.getRemoteAddr()));
+ return user;
} else {
logger.warn(MessageFormat.format("Failed to find UserModel for {0}, attempted servlet container authentication from {1}",
principal.getName(), httpRequest.getRemoteAddr()));