diff options
author | Fabrice Bacchella <fbacchella@spamcop.net> | 2015-05-15 22:36:45 +0200 |
---|---|---|
committer | Fabrice Bacchella <fbacchella@spamcop.net> | 2015-05-15 22:36:45 +0200 |
commit | 2c0555f90ecb61a068754569e2624a6569b89a2c (patch) | |
tree | 765e84867c620d101728f4c61d5634d72d856d5f /src/main | |
parent | 2fdefced2aeecc7c12f3de50f89c1590a6a088fc (diff) | |
download | gitblit-2c0555f90ecb61a068754569e2624a6569b89a2c.tar.gz gitblit-2c0555f90ecb61a068754569e2624a6569b89a2c.zip |
A patch that allows to extract a new user informations from the HTTP session
if the webapp container can fill it.
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/distrib/data/defaults.properties | 16 | ||||
-rw-r--r-- | src/main/java/com/gitblit/manager/AuthenticationManager.java | 48 |
2 files changed, 64 insertions, 0 deletions
diff --git a/src/main/distrib/data/defaults.properties b/src/main/distrib/data/defaults.properties index 0857ccf6..7be50c80 100644 --- a/src/main/distrib/data/defaults.properties +++ b/src/main/distrib/data/defaults.properties @@ -1610,6 +1610,22 @@ federation.sets = # SINCE 1.3.0 realm.container.autoCreateAccounts = false +# A set of mapping used to map HTTP session attributes to user informations +# They are used if realm.container.autoCreateAccounts is set to true and +# the webapp container used can fill the session with user informations +# +# SINCE 1.7.0 +realm.container.autoAccounts.displayName = +realm.container.autoAccounts.emailAddress = +realm.container.autoAccounts.locale = + +# If the user's created by the webapp container is given this role, +# the user created will be a admin user. +# +# SINCE 1.7.0 +realm.container.autoAccounts.adminRole = + + # Allow or prohibit Windows guest account logins # # SINCE 1.3.0 diff --git a/src/main/java/com/gitblit/manager/AuthenticationManager.java b/src/main/java/com/gitblit/manager/AuthenticationManager.java index 29221e6f..cbf0a1bd 100644 --- a/src/main/java/com/gitblit/manager/AuthenticationManager.java +++ b/src/main/java/com/gitblit/manager/AuthenticationManager.java @@ -215,6 +215,29 @@ public class AuthenticationManager implements IAuthenticationManager { user.displayName = username; user.password = Constants.EXTERNAL_ACCOUNT; user.accountType = AccountType.CONTAINER; + + // Try to extract user's informations for the session + // it uses "realm.container.autoAccounts.*" as the attribute name to look for + HttpSession session = httpRequest.getSession(); + String emailAddress = resolveAttribute(session, Keys.realm.container.autoAccounts.emailAddress); + if(emailAddress != null) { + user.emailAddress = emailAddress; + } + String displayName = resolveAttribute(session, Keys.realm.container.autoAccounts.displayName); + if(displayName != null) { + user.displayName = displayName; + } + String userLocale = resolveAttribute(session, Keys.realm.container.autoAccounts.locale); + if(userLocale != null) { + user.getPreferences().setLocale(userLocale); + } + String adminRole = settings.getString(Keys.realm.container.autoAccounts.adminRole, null); + if(adminRole != null && ! adminRole.isEmpty()) { + if(httpRequest.isUserInRole(adminRole)) { + user.canAdmin = true; + } + } + userManager.updateUserModel(user); flagSession(httpRequest, AuthenticationType.CONTAINER); logger.debug(MessageFormat.format("{0} authenticated and created by servlet container principal from {1}", @@ -293,6 +316,31 @@ public class AuthenticationManager implements IAuthenticationManager { } return null; } + + /** + * Extract given attribute from the session and return it's content + * it return null if attributeMapping is empty, or if the value is + * empty + * + * @param session The user session + * @param attributeMapping + * @return + */ + private String resolveAttribute(HttpSession session, String attributeMapping) { + String attributeName = settings.getString(attributeMapping, null); + if(StringUtils.isEmpty(attributeName)) { + return null; + } + Object attributeValue = session.getAttribute(attributeName); + if(attributeValue == null) { + return null; + } + String value = attributeValue.toString(); + if(value.isEmpty()) { + return null; + } + return value; + } /** * Authenticate a user based on a public key. |