From cca01e704d022ebbf8a8b16db2e321a251fcd8b5 Mon Sep 17 00:00:00 2001 From: kohsuke Date: Thu, 24 Sep 2009 18:02:30 +0000 Subject: [PATCH] Merged revisions 22092 via svnmerge from https://svn.dev.java.net/svn/hudson/branches/rc ........ r22092 | kohsuke | 2009-09-24 10:13:43 -0700 (Thu, 24 Sep 2009) | 1 line Because Util.fixNull() is overloaded, Groovy won't be able to find the right version. Also added a regression test. ........ git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@22093 71c3de6d-444a-0410-be80-ed276b4c234a Originally-Committed-As: 9b981befbe3dad8f07d9a03ec04141780d036c1d --- .../hudson/security/LDAPSecurityRealm.java | 20 +++++---- .../security/LDAPSecurityRealmTest.groovy | 42 +++++++++++++++++++ .../security/LDAPBindSecurityRealm.groovy | 2 +- 3 files changed, 54 insertions(+), 10 deletions(-) create mode 100644 test/src/test/groovy/hudson/security/LDAPSecurityRealmTest.groovy diff --git a/core/src/main/java/hudson/security/LDAPSecurityRealm.java b/core/src/main/java/hudson/security/LDAPSecurityRealm.java index 6944688..c037ac6 100644 --- a/core/src/main/java/hudson/security/LDAPSecurityRealm.java +++ b/core/src/main/java/hudson/security/LDAPSecurityRealm.java @@ -25,7 +25,9 @@ package hudson.security; import groovy.lang.Binding; import hudson.Extension; -import hudson.Util; +import static hudson.Util.fixNull; +import static hudson.Util.fixEmptyAndTrim; +import static hudson.Util.fixEmpty; import hudson.model.Descriptor; import hudson.model.Hudson; import hudson.model.User; @@ -274,14 +276,14 @@ public class LDAPSecurityRealm extends SecurityRealm { @DataBoundConstructor public LDAPSecurityRealm(String server, String rootDN, String userSearchBase, String userSearch, String groupSearchBase, String managerDN, String managerPassword) { this.server = server.trim(); - this.managerDN = Util.fixEmpty(managerDN); - this.managerPassword = Scrambler.scramble(Util.fixEmpty(managerPassword)); - if(Util.fixEmptyAndTrim(rootDN)==null) rootDN=Util.fixNull(inferRootDN(server)); + this.managerDN = fixEmpty(managerDN); + this.managerPassword = Scrambler.scramble(fixEmpty(managerPassword)); + if(fixEmptyAndTrim(rootDN)==null) rootDN= fixNull(inferRootDN(server)); this.rootDN = rootDN.trim(); - this.userSearchBase = userSearchBase.trim(); - userSearch = Util.fixEmptyAndTrim(userSearch); + this.userSearchBase = fixNull(userSearchBase).trim(); + userSearch = fixEmptyAndTrim(userSearch); this.userSearch = userSearch!=null ? userSearch : "uid={0}"; - this.groupSearchBase = Util.fixEmptyAndTrim(groupSearchBase); + this.groupSearchBase = fixEmptyAndTrim(groupSearchBase); } public String getServerUrl() { @@ -326,7 +328,7 @@ public class LDAPSecurityRealm extends SecurityRealm { } public String getLDAPURL() { - return getServerUrl()+'/'+Util.fixNull(rootDN); + return getServerUrl()+'/'+ fixNull(rootDN); } public SecurityComponents createSecurityComponents() { @@ -449,7 +451,7 @@ public class LDAPSecurityRealm extends SecurityRealm { String rolePrefix; boolean convertToUpperCase; public AuthoritiesPopulatorImpl(InitialDirContextFactory initialDirContextFactory, String groupSearchBase) { - super(initialDirContextFactory, groupSearchBase); + super(initialDirContextFactory, fixNull(groupSearchBase)); // These match the defaults in acegi 1.0.5; set again to store in non-private fields: setRolePrefix("ROLE_"); setConvertToUpperCase(true); diff --git a/test/src/test/groovy/hudson/security/LDAPSecurityRealmTest.groovy b/test/src/test/groovy/hudson/security/LDAPSecurityRealmTest.groovy new file mode 100644 index 0000000..a0d7c79 --- /dev/null +++ b/test/src/test/groovy/hudson/security/LDAPSecurityRealmTest.groovy @@ -0,0 +1,42 @@ +/* + * The MIT License + * + * Copyright (c) 2004-2009, Sun Microsystems + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package hudson.security + +import org.jvnet.hudson.test.HudsonTestCase + +/** + * + * + * @author Kohsuke Kawaguchi + */ +public class LDAPSecurityRealmTest extends HudsonTestCase { + /** + * This minimal test still causes the 'LDAPBindSecurityRealm.groovy' to be parsed, allowing us to catch + * basic syntax errors and such. + */ + void testGroovyBeanDef() { + hudson.securityRealm = new LDAPSecurityRealm("ldap.itd.umich.edu",null,null,null,null,null,null); + println hudson.securityRealm.securityComponents // force the component creation + } +} \ No newline at end of file diff --git a/war/resources/WEB-INF/security/LDAPBindSecurityRealm.groovy b/war/resources/WEB-INF/security/LDAPBindSecurityRealm.groovy index 589270d..ee0edca 100644 --- a/war/resources/WEB-INF/security/LDAPBindSecurityRealm.groovy +++ b/war/resources/WEB-INF/security/LDAPBindSecurityRealm.groovy @@ -61,7 +61,7 @@ bindAuthenticator(BindAuthenticator2,initialDirContextFactory) { userSearch = ldapUserSearch; } -authoritiesPopulator(AuthoritiesPopulatorImpl, initialDirContextFactory, Util.fixNull(instance.groupSearchBase)) { +authoritiesPopulator(AuthoritiesPopulatorImpl, initialDirContextFactory, instance.groupSearchBase) { // see DefaultLdapAuthoritiesPopulator for other possible configurations searchSubtree = true; groupSearchFilter = "(| (member={0}) (uniqueMember={0}) (memberUid={1}))";