|
1 | 1 | /*
|
2 | 2 | * The MIT License
|
3 |
| - * |
| 3 | + * |
4 | 4 | * Copyright (c) 2004-2010, Sun Microsystems, Inc., Kohsuke Kawaguchi, Seiji Sogabe,
|
5 | 5 | * Olivier Lamy
|
6 | 6 | * Copyright (c) 2017 CloudBees, Inc.
|
7 |
| - * |
| 7 | + * |
8 | 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
9 | 9 | * of this software and associated documentation files (the "Software"), to deal
|
10 | 10 | * in the Software without restriction, including without limitation the rights
|
11 | 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12 | 12 | * copies of the Software, and to permit persons to whom the Software is
|
13 | 13 | * furnished to do so, subject to the following conditions:
|
14 |
| - * |
| 14 | + * |
15 | 15 | * The above copyright notice and this permission notice shall be included in
|
16 | 16 | * all copies or substantial portions of the Software.
|
17 |
| - * |
| 17 | + * |
18 | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19 | 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20 | 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
70 | 70 | import org.springframework.security.ldap.userdetails.LdapAuthoritiesPopulator;
|
71 | 71 | import org.springframework.security.ldap.userdetails.LdapUserDetails;
|
72 | 72 | import org.springframework.security.ldap.userdetails.LdapUserDetailsImpl;
|
| 73 | + |
| 74 | +import com.iwombat.util.StringUtil; |
| 75 | + |
73 | 76 | import org.apache.commons.collections.map.LRUMap;
|
74 | 77 | import org.apache.commons.io.IOUtils;
|
75 | 78 | import org.apache.commons.lang.StringUtils;
|
@@ -293,7 +296,7 @@ public class LDAPSecurityRealm extends AbstractPasswordBasedSecurityRealm {
|
293 | 296 | justification = "This public field is exposed to the plugin's API")
|
294 | 297 | @Deprecated @Restricted(NoExternalUse.class)
|
295 | 298 | public transient String userSearch;
|
296 |
| - |
| 299 | + |
297 | 300 | /**
|
298 | 301 | * This defines the organizational unit that contains groups.
|
299 | 302 | *
|
@@ -326,7 +329,7 @@ public class LDAPSecurityRealm extends AbstractPasswordBasedSecurityRealm {
|
326 | 329 | * @deprecated use {@link #groupMembershipStrategy}
|
327 | 330 | */
|
328 | 331 | @Deprecated @Restricted(NoExternalUse.class)
|
329 |
| - @SuppressFBWarnings(value = "UUF_UNUSED_PUBLIC_OR_PROTECTED_FIELD", |
| 332 | + @SuppressFBWarnings(value = "UUF_UNUSED_PUBLIC_OR_PROTECTED_FIELD", |
330 | 333 | justification = "This public field is exposed to the plugin's API")
|
331 | 334 | public transient String groupMembershipFilter;
|
332 | 335 |
|
@@ -363,7 +366,7 @@ group target (CN is a reasonable default)
|
363 | 366 | public transient String managerDN;
|
364 | 367 |
|
365 | 368 | @Deprecated @Restricted(NoExternalUse.class)
|
366 |
| - @SuppressFBWarnings(value = "UUF_UNUSED_PUBLIC_OR_PROTECTED_FIELD", |
| 369 | + @SuppressFBWarnings(value = "UUF_UNUSED_PUBLIC_OR_PROTECTED_FIELD", |
367 | 370 | justification = "This public field is exposed to the plugin's API")
|
368 | 371 | private transient String managerPassword;
|
369 | 372 |
|
@@ -1391,10 +1394,15 @@ public static final class AuthoritiesPopulatorImpl extends DefaultLdapAuthoritie
|
1391 | 1394 | boolean convertToUpperCase = true;
|
1392 | 1395 | private GrantedAuthority defaultRole = null;
|
1393 | 1396 |
|
1394 |
| - public AuthoritiesPopulatorImpl(ContextSource contextSource, String groupSearchBase) { |
| 1397 | + public AuthoritiesPopulatorImpl(ContextSource contextSource, String groupSearchBase, LDAPGroupMembershipStrategy ldapGroupMembershipStrategy) { |
1395 | 1398 | super(contextSource, fixNull(groupSearchBase));
|
1396 |
| - |
1397 | 1399 | super.setRolePrefix("");
|
| 1400 | + if (ldapGroupMembershipStrategy instanceof FromGroupSearchLDAPGroupMembershipStrategy) { |
| 1401 | + FromGroupSearchLDAPGroupMembershipStrategy fromGroupSearchLDAPGroupMembershipStrategy = (FromGroupSearchLDAPGroupMembershipStrategy) ldapGroupMembershipStrategy; |
| 1402 | + if (StringUtils.isNotBlank(fromGroupSearchLDAPGroupMembershipStrategy.getAttribute())) { |
| 1403 | + super.setGroupRoleAttribute(fromGroupSearchLDAPGroupMembershipStrategy.getAttribute()); |
| 1404 | + } |
| 1405 | + } |
1398 | 1406 | super.setConvertToUpperCase(false);
|
1399 | 1407 | }
|
1400 | 1408 |
|
@@ -1524,7 +1532,7 @@ public FormValidation doValidate(StaplerRequest req) throws Exception {
|
1524 | 1532 | String user = json.getString("testUser");
|
1525 | 1533 | String password = json.getString("testPassword");
|
1526 | 1534 | JSONObject realmCfg = json.getJSONObject("securityRealm");
|
1527 |
| - |
| 1535 | + |
1528 | 1536 | // instantiate the realm
|
1529 | 1537 | LDAPSecurityRealm realm = req.bindJSON(LDAPSecurityRealm.class, realmCfg);
|
1530 | 1538 | return validate(realm, user, password);
|
|
0 commit comments