James Moger
2012-04-25 0aa8cf8606600d628b2c491e52e9e3c901f9cc80
Allow user services to control editing of display name and email address
8 files modified
143 ■■■■■ changed files
distrib/gitblit.properties 8 ●●●● patch | view | raw | blame | history
src/com/gitblit/ConfigUserService.java 22 ●●●●● patch | view | raw | blame | history
src/com/gitblit/FileUserService.java 22 ●●●●● patch | view | raw | blame | history
src/com/gitblit/GitBlit.java 20 ●●●●● patch | view | raw | blame | history
src/com/gitblit/GitblitUserService.java 10 ●●●●● patch | view | raw | blame | history
src/com/gitblit/IUserService.java 16 ●●●●● patch | view | raw | blame | history
src/com/gitblit/LdapUserService.java 35 ●●●● patch | view | raw | blame | history
src/com/gitblit/wicket/pages/EditUserPage.java 10 ●●●● patch | view | raw | blame | history
distrib/gitblit.properties
@@ -233,8 +233,8 @@
# SINCE 1.0.0
realm.ldap.admins= @Git_Admins
# Attribute(s) on the USER record that indicate their display (or full) name. Leave blank
# for no mapping available in LDAP
# Attribute(s) on the USER record that indicate their display (or full) name.
# Leave blank for no mapping available in LDAP.
#
# This may be a single attribute, or a string of multiple attributes.  Examples:
#  displayName - Uses the attribute 'displayName' on the user record
@@ -244,8 +244,8 @@
# SINCE 1.0.0
realm.ldap.displayName= displayName
# Attribute(s) on the USER record that indicate their email address.  Leave blank
# for no mapping available in LDAP
# Attribute(s) on the USER record that indicate their email address.
# Leave blank for no mapping available in LDAP.
#
# This may be a single attribute, or a string of multiple attributes.  Examples:
#  email - Uses the attribute 'email' on the user record
src/com/gitblit/ConfigUserService.java
@@ -114,6 +114,28 @@
        return true;
    }
    
    /**
     * Does the user service support changes to user display name?
     *
     * @return true or false
     * @since 1.0.0
     */
    @Override
    public boolean supportsDisplayNameChanges() {
        return true;
    }
    /**
     * Does the user service support changes to user email address?
     *
     * @return true or false
     * @since 1.0.0
     */
    @Override
    public boolean supportsEmailAddressChanges() {
        return true;
    }
    /**
     * Does the user service support changes to team memberships?
     * 
src/com/gitblit/FileUserService.java
@@ -85,6 +85,28 @@
    }
    /**
     * Does the user service support changes to user display name?
     *
     * @return true or false
     * @since 1.0.0
     */
    @Override
    public boolean supportsDisplayNameChanges() {
        return false;
    }
    /**
     * Does the user service support changes to user email address?
     *
     * @return true or false
     * @since 1.0.0
     */
    @Override
    public boolean supportsEmailAddressChanges() {
        return false;
    }
    /**
     * Does the user service support changes to team memberships?
     * 
     * @return true or false
src/com/gitblit/GitBlit.java
@@ -388,6 +388,22 @@
    /**
     * 
     * @return true if the user service supports display name changes
     */
    public boolean supportsDisplayNameChanges() {
        return userService.supportsDisplayNameChanges();
    }
    /**
     *
     * @return true if the user service supports email address changes
     */
    public boolean supportsEmailAddressChanges() {
        return userService.supportsEmailAddressChanges();
    }
    /**
     *
     * @return true if the user service supports team membership changes
     */
    public boolean supportsTeamMembershipChanges() {
@@ -1780,6 +1796,10 @@
     */
    private ServerSettings loadSettingModels() {
        ServerSettings settingsModel = new ServerSettings();
        settingsModel.supportsCredentialChanges = userService.supportsCredentialChanges();
        settingsModel.supportsDisplayNameChanges = userService.supportsDisplayNameChanges();
        settingsModel.supportsEmailAddressChanges = userService.supportsEmailAddressChanges();
        settingsModel.supportsTeamMembershipChanges = userService.supportsTeamMembershipChanges();
        try {
            // Read bundled Gitblit properties to extract setting descriptions.
            // This copy is pristine and only used for populating the setting
src/com/gitblit/GitblitUserService.java
@@ -118,6 +118,16 @@
    }
    @Override
    public boolean supportsDisplayNameChanges() {
        return serviceImpl.supportsDisplayNameChanges();
    }
    @Override
    public boolean supportsEmailAddressChanges() {
        return serviceImpl.supportsEmailAddressChanges();
    }
    @Override
    public boolean supportsTeamMembershipChanges() {
        return serviceImpl.supportsTeamMembershipChanges();
    }
src/com/gitblit/IUserService.java
@@ -46,6 +46,22 @@
     * @since 1.0.0
     */    
    boolean supportsCredentialChanges();
    /**
     * Does the user service support changes to user display name?
     *
     * @return true or false
     * @since 1.0.0
     */
    boolean supportsDisplayNameChanges();
    /**
     * Does the user service support changes to user email address?
     *
     * @return true or false
     * @since 1.0.0
     */
    boolean supportsEmailAddressChanges();
    
    /**
     * Does the user service support changes to team memberships?
src/com/gitblit/LdapUserService.java
@@ -106,6 +106,29 @@
    }
    
    /**
     * If no displayName pattern is defined then Gitblit can manage the display name.
     *
     * @return true if Gitblit can manage the user display name
     * @since 1.0.0
     */
    @Override
    public boolean supportsDisplayNameChanges() {
        return StringUtils.isEmpty(settings.getString(Keys.realm.ldap.displayName, ""));
    }
    /**
     * If no email pattern is defined then Gitblit can manage the email address.
     *
     * @return true if Gitblit can manage the user email address
     * @since 1.0.0
     */
    @Override
    public boolean supportsEmailAddressChanges() {
        return StringUtils.isEmpty(settings.getString(Keys.realm.ldap.email, ""));
    }
    /**
     * If the LDAP server will maintain team memberships then LdapUserService
     * will not allow team membership changes.  In this scenario all team
     * changes must be made on the LDAP server by the LDAP administrator.
@@ -194,10 +217,9 @@
        // Don't want visibility into the real password, make up a dummy
        user.password = "StoredInLDAP";
        
        // Get Attributes for full name / email
        String displayName = settings.getString(Keys.realm.ldap.displayName, "displayName");
        String email = settings.getString(Keys.realm.ldap.email, "email");
        // Get full name Attribute
        String displayName = settings.getString(Keys.realm.ldap.displayName, "");
        if (!StringUtils.isEmpty(displayName)) {
        // Replace embedded ${} with attributes
        if (displayName.contains("${")) {
            for (Attribute userAttribute : userEntry.getAttributes())
@@ -207,7 +229,11 @@
        } else {
            user.displayName = userEntry.getAttribute(displayName).getValue();
        }
        }
        
        // Get email address Attribute
        String email = settings.getString(Keys.realm.ldap.email, "");
        if (!StringUtils.isEmpty(email)) {
        if (email.contains("${")) {
            for (Attribute userAttribute : userEntry.getAttributes())
                email = StringUtils.replace(email, "${" + userAttribute.getName() + "}", userAttribute.getValue());
@@ -217,6 +243,7 @@
            user.emailAddress = userEntry.getAttribute(email).getValue();
        }
    }
    }
    private void getTeamsFromLdap(LDAPConnection ldapConnection, String simpleUsername, SearchResultEntry loggingInUser, UserModel user) {
        String loggingInUserDN = loggingInUser.getDN();
src/com/gitblit/wicket/pages/EditUserPage.java
@@ -210,6 +210,12 @@
        // not all user services support manipulating username and password
        boolean editCredentials = GitBlit.self().supportsCredentialChanges();
        // not all user services support manipulating display name
        boolean editDisplayName = GitBlit.self().supportsDisplayNameChanges();
        // not all user services support manipulating email address
        boolean editEmailAddress = GitBlit.self().supportsEmailAddressChanges();
        // not all user services support manipulating team memberships
        boolean editTeams = GitBlit.self().supportsTeamMembershipChanges();
@@ -222,8 +228,8 @@
                confirmPassword);
        confirmPasswordField.setResetPassword(false);
        form.add(confirmPasswordField.setEnabled(editCredentials));
        form.add(new TextField<String>("displayName").setEnabled(editCredentials));
        form.add(new TextField<String>("emailAddress").setEnabled(editCredentials));
        form.add(new TextField<String>("displayName").setEnabled(editDisplayName));
        form.add(new TextField<String>("emailAddress").setEnabled(editEmailAddress));
        form.add(new CheckBox("canAdmin"));
        form.add(new CheckBox("excludeFromFederation"));
        form.add(repositories);