diff --git a/src/main/java/hudson/security/LDAPSecurityRealm.java b/src/main/java/hudson/security/LDAPSecurityRealm.java
index bcbb974..f17b924 100644
--- a/src/main/java/hudson/security/LDAPSecurityRealm.java
+++ b/src/main/java/hudson/security/LDAPSecurityRealm.java
@@ -26,53 +26,18 @@ package hudson.security;
import groovy.lang.Binding;
import hudson.Extension;
-import static hudson.Util.fixNull;
-import static hudson.Util.fixEmptyAndTrim;
import static hudson.Util.fixEmpty;
-
+import static hudson.Util.fixEmptyAndTrim;
+import static hudson.Util.fixNull;
import hudson.model.AbstractDescribableImpl;
import hudson.model.Descriptor;
-import hudson.tasks.Mailer;
-import jenkins.model.Jenkins;
import hudson.model.User;
import hudson.tasks.MailAddressResolver;
+import hudson.tasks.Mailer;
import hudson.util.FormValidation;
+import hudson.util.ListBoxModel;
import hudson.util.Scrambler;
import hudson.util.spring.BeanBuilder;
-import org.acegisecurity.Authentication;
-import org.acegisecurity.AuthenticationManager;
-import org.acegisecurity.GrantedAuthority;
-import org.acegisecurity.AcegiSecurityException;
-import org.acegisecurity.AuthenticationException;
-import org.acegisecurity.GrantedAuthorityImpl;
-import org.acegisecurity.ldap.InitialDirContextFactory;
-import org.acegisecurity.ldap.LdapDataAccessException;
-import org.acegisecurity.ldap.LdapTemplate;
-import org.acegisecurity.ldap.LdapUserSearch;
-import org.acegisecurity.ldap.search.FilterBasedLdapUserSearch;
-import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
-import org.acegisecurity.providers.ldap.LdapAuthoritiesPopulator;
-import org.acegisecurity.providers.ldap.populator.DefaultLdapAuthoritiesPopulator;
-import org.acegisecurity.userdetails.UserDetails;
-import org.acegisecurity.userdetails.UserDetailsService;
-import org.acegisecurity.userdetails.UsernameNotFoundException;
-import org.acegisecurity.userdetails.ldap.LdapUserDetails;
-import org.acegisecurity.userdetails.ldap.LdapUserDetailsImpl;
-import org.apache.commons.collections.map.LRUMap;
-import org.apache.commons.io.input.AutoCloseInputStream;
-import org.apache.commons.lang.StringUtils;
-import org.kohsuke.stapler.DataBoundConstructor;
-import org.kohsuke.stapler.QueryParameter;
-import org.springframework.dao.DataAccessException;
-import org.springframework.web.context.WebApplicationContext;
-
-import javax.naming.Context;
-import javax.naming.NamingException;
-import javax.naming.directory.Attribute;
-import javax.naming.directory.Attributes;
-import javax.naming.directory.BasicAttributes;
-import javax.naming.directory.DirContext;
-import javax.naming.directory.InitialDirContext;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -94,7 +59,40 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.InitialDirContext;
+import jenkins.model.Jenkins;
+import org.acegisecurity.AcegiSecurityException;
+import org.acegisecurity.Authentication;
+import org.acegisecurity.AuthenticationException;
+import org.acegisecurity.AuthenticationManager;
+import org.acegisecurity.GrantedAuthority;
+import org.acegisecurity.GrantedAuthorityImpl;
+import org.acegisecurity.ldap.InitialDirContextFactory;
+import org.acegisecurity.ldap.LdapDataAccessException;
+import org.acegisecurity.ldap.LdapTemplate;
+import org.acegisecurity.ldap.LdapUserSearch;
+import org.acegisecurity.ldap.search.FilterBasedLdapUserSearch;
+import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
+import org.acegisecurity.providers.ldap.LdapAuthoritiesPopulator;
+import org.acegisecurity.providers.ldap.populator.DefaultLdapAuthoritiesPopulator;
+import org.acegisecurity.userdetails.UserDetails;
+import org.acegisecurity.userdetails.UserDetailsService;
+import org.acegisecurity.userdetails.UsernameNotFoundException;
+import org.acegisecurity.userdetails.ldap.LdapUserDetails;
+import org.acegisecurity.userdetails.ldap.LdapUserDetailsImpl;
+import org.apache.commons.collections.map.LRUMap;
+import org.apache.commons.io.input.AutoCloseInputStream;
+import org.apache.commons.lang.StringUtils;
+import org.kohsuke.stapler.DataBoundConstructor;
+import org.kohsuke.stapler.QueryParameter;
+import org.springframework.dao.DataAccessException;
+import org.springframework.web.context.WebApplicationContext;
/**
* {@link SecurityRealm} implementation that uses LDAP for authentication.
@@ -213,19 +211,17 @@ import java.util.regex.Pattern;
*
*
RFC 2256
*
- * Defines the meaning of several key datatypes used in the schemas with some explanations.
+ * Defines the meaning of several key datatypes used in the schemas with some explanations.
*
* Active Directory schema
*
* More navigable schema list, including core and MS extensions specific to Active Directory.
*
- *
+ *
* @author Kohsuke Kawaguchi
* @since 1.166
*/
public class LDAPSecurityRealm extends AbstractPasswordBasedSecurityRealm {
- private static final String DEFAULT_DISPLAYNAME_ATTRIBUTE_NAME = "displayname";
- private static final String DEFAULT_MAILADDRESS_ATTRIBUTE_NAME = "mail";
private static final boolean FORCE_USERNAME_LOWERCASE =
Boolean.getBoolean(LDAPSecurityRealm.class.getName() + ".forceUsernameLowercase");
/**
@@ -402,7 +398,7 @@ public class LDAPSecurityRealm extends AbstractPasswordBasedSecurityRealm {
this.rootDN = rootDN.trim();
this.userSearchBase = fixNull(userSearchBase).trim();
userSearch = fixEmptyAndTrim(userSearch);
- this.userSearch = userSearch!=null ? userSearch : "uid={0}";
+ this.userSearch = userSearch!=null ? userSearch : DescriptorImpl.DEFAULT_USER_SEARCH;
this.groupSearchBase = fixEmptyAndTrim(groupSearchBase);
this.groupSearchFilter = fixEmptyAndTrim(groupSearchFilter);
this.groupMembershipFilter = fixEmptyAndTrim(groupMembershipFilter);
@@ -412,9 +408,9 @@ public class LDAPSecurityRealm extends AbstractPasswordBasedSecurityRealm {
? null
: EnvironmentProperty.toMap(Arrays.asList(environmentProperties));
this.displayNameAttributeName = StringUtils.defaultString(fixEmptyAndTrim(displayNameAttributeName),
- DEFAULT_DISPLAYNAME_ATTRIBUTE_NAME);
+ DescriptorImpl.DEFAULT_DISPLAYNAME_ATTRIBUTE_NAME);
this.mailAddressAttributeName = StringUtils.defaultString(fixEmptyAndTrim(mailAddressAttributeName),
- DEFAULT_MAILADDRESS_ATTRIBUTE_NAME);
+ DescriptorImpl.DEFAULT_MAILADDRESS_ATTRIBUTE_NAME);
}
public String getServerUrl() {
@@ -522,11 +518,11 @@ public class LDAPSecurityRealm extends AbstractPasswordBasedSecurityRealm {
}
public String getDisplayNameAttributeName() {
- return StringUtils.defaultString(displayNameAttributeName, DEFAULT_DISPLAYNAME_ATTRIBUTE_NAME);
+ return StringUtils.defaultString(displayNameAttributeName, DescriptorImpl.DEFAULT_DISPLAYNAME_ATTRIBUTE_NAME);
}
public String getMailAddressAttributeName() {
- return StringUtils.defaultString(mailAddressAttributeName, DEFAULT_MAILADDRESS_ATTRIBUTE_NAME);
+ return StringUtils.defaultString(mailAddressAttributeName, DescriptorImpl.DEFAULT_MAILADDRESS_ATTRIBUTE_NAME);
}
public SecurityComponents createSecurityComponents() {
@@ -851,14 +847,18 @@ public class LDAPSecurityRealm extends AbstractPasswordBasedSecurityRealm {
@Extension
public static final class DescriptorImpl extends Descriptor {
+
+ public static final String DEFAULT_DISPLAYNAME_ATTRIBUTE_NAME = "displayname";
+ public static final String DEFAULT_MAILADDRESS_ATTRIBUTE_NAME = "mail";
+ public static final String DEFAULT_USER_SEARCH = "uid={0}";
+
public String getDisplayName() {
return Messages.LDAPSecurityRealm_DisplayName();
}
- public FormValidation doServerCheck(
- @QueryParameter final String server,
- @QueryParameter final String managerDN,
- @QueryParameter final String managerPassword) {
+ // note that this works better in 1.528+ (JENKINS-19124)
+ public FormValidation doCheckServer(@QueryParameter String value, @QueryParameter String managerDN, @QueryParameter String managerPassword) {
+ String server = value;
if(!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER))
return FormValidation.ok();
@@ -927,7 +927,7 @@ public class LDAPSecurityRealm extends AbstractPasswordBasedSecurityRealm {
public static String GROUP_SEARCH = System.getProperty(LDAPSecurityRealm.class.getName()+".groupSearch",
"(& (cn={0}) (| (objectclass=groupOfNames) (objectclass=groupOfUniqueNames) (objectclass=posixGroup)))");
- public static class CacheConfiguration {
+ public static class CacheConfiguration extends AbstractDescribableImpl {
private final int size;
private final int ttl;
@@ -944,6 +944,40 @@ public class LDAPSecurityRealm extends AbstractPasswordBasedSecurityRealm {
public int getTtl() {
return ttl;
}
+
+ @Extension public static class DescriptorImpl extends Descriptor {
+
+ @Override public String getDisplayName() {
+ return "";
+ }
+
+ public ListBoxModel doFillSizeItems() {
+ ListBoxModel m = new ListBoxModel();
+ m.add("10");
+ m.add("20");
+ m.add("50");
+ m.add("100");
+ m.add("200");
+ m.add("500");
+ m.add("1000");
+ return m;
+ }
+
+ public ListBoxModel doFillTtlItems() {
+ ListBoxModel m = new ListBoxModel();
+ // TODO use Messages (not that there were any translations before)
+ m.add("30 sec", "30");
+ m.add("1 min", "60");
+ m.add("2 min", "120");
+ m.add("5 min", "300");
+ m.add("10 min", "600");
+ m.add("15 min", "900");
+ m.add("30 min", "1800");
+ m.add("1 hour", "3600");
+ return m;
+ }
+
+ }
}
private static class CacheEntry {
diff --git a/src/main/resources/hudson/security/LDAPSecurityRealm/CacheConfiguration/config.jelly b/src/main/resources/hudson/security/LDAPSecurityRealm/CacheConfiguration/config.jelly
new file mode 100644
index 0000000..5d4de63
--- /dev/null
+++ b/src/main/resources/hudson/security/LDAPSecurityRealm/CacheConfiguration/config.jelly
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/resources/hudson/security/LDAPSecurityRealm/EnvironmentProperty/config.jelly b/src/main/resources/hudson/security/LDAPSecurityRealm/EnvironmentProperty/config.jelly
index e9309bb..57baef4 100644
--- a/src/main/resources/hudson/security/LDAPSecurityRealm/EnvironmentProperty/config.jelly
+++ b/src/main/resources/hudson/security/LDAPSecurityRealm/EnvironmentProperty/config.jelly
@@ -32,6 +32,7 @@ THE SOFTWARE.
+
diff --git a/src/main/resources/hudson/security/LDAPSecurityRealm/config.jelly b/src/main/resources/hudson/security/LDAPSecurityRealm/config.jelly
index 09aa132..55fd786 100644
--- a/src/main/resources/hudson/security/LDAPSecurityRealm/config.jelly
+++ b/src/main/resources/hudson/security/LDAPSecurityRealm/config.jelly
@@ -23,88 +23,51 @@ THE SOFTWARE.
-->
-
-
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/webapp/help-cache.html b/src/main/resources/hudson/security/LDAPSecurityRealm/help-cache.html
similarity index 100%
rename from src/main/webapp/help-cache.html
rename to src/main/resources/hudson/security/LDAPSecurityRealm/help-cache.html
diff --git a/src/main/webapp/help-displayNameAttributeName.html b/src/main/resources/hudson/security/LDAPSecurityRealm/help-displayNameAttributeName.html
similarity index 100%
rename from src/main/webapp/help-displayNameAttributeName.html
rename to src/main/resources/hudson/security/LDAPSecurityRealm/help-displayNameAttributeName.html
diff --git a/src/main/webapp/help-envprop.html b/src/main/resources/hudson/security/LDAPSecurityRealm/help-environmentProperties.html
similarity index 100%
rename from src/main/webapp/help-envprop.html
rename to src/main/resources/hudson/security/LDAPSecurityRealm/help-environmentProperties.html
diff --git a/src/main/webapp/help-groupMembershipFilter.html b/src/main/resources/hudson/security/LDAPSecurityRealm/help-groupMembershipFilter.html
similarity index 100%
rename from src/main/webapp/help-groupMembershipFilter.html
rename to src/main/resources/hudson/security/LDAPSecurityRealm/help-groupMembershipFilter.html
diff --git a/src/main/webapp/help-groupSearchFilter.html b/src/main/resources/hudson/security/LDAPSecurityRealm/help-groupSearchFilter.html
similarity index 100%
rename from src/main/webapp/help-groupSearchFilter.html
rename to src/main/resources/hudson/security/LDAPSecurityRealm/help-groupSearchFilter.html
diff --git a/src/main/webapp/help-mailAddressAttributeName.html b/src/main/resources/hudson/security/LDAPSecurityRealm/help-mailAddressAttributeName.html
similarity index 100%
rename from src/main/webapp/help-mailAddressAttributeName.html
rename to src/main/resources/hudson/security/LDAPSecurityRealm/help-mailAddressAttributeName.html
diff --git a/src/main/webapp/help-server.html b/src/main/resources/hudson/security/LDAPSecurityRealm/help-server.html
similarity index 100%
rename from src/main/webapp/help-server.html
rename to src/main/resources/hudson/security/LDAPSecurityRealm/help-server.html