]> git.argeo.org Git - lgpl/argeo-commons.git/blob - ArgeoLdapAuthoritiesPopulator.java
9df6ed4a7bc2ee1067d707e95845e489510d7046
[lgpl/argeo-commons.git] / ArgeoLdapAuthoritiesPopulator.java
1 package org.argeo.security.ldap;
2
3 import org.springframework.ldap.core.ContextSource;
4 import org.springframework.security.ldap.populator.DefaultLdapAuthoritiesPopulator;
5
6 /** TODO: notify Spring Security to open this class more. */
7 public class ArgeoLdapAuthoritiesPopulator extends
8 DefaultLdapAuthoritiesPopulator {
9
10 /* Hacked from parent class */
11 private String groupRoleAttribute = "cn";
12 private final String groupSearchBase;
13 private String rolePrefix = "ROLE_";
14 private boolean convertToUpperCase = true;
15
16 public ArgeoLdapAuthoritiesPopulator(ContextSource contextSource,
17 String groupSearchBase) {
18 super(contextSource, groupSearchBase);
19 this.groupSearchBase = groupSearchBase;
20 }
21
22 @Override
23 public void setConvertToUpperCase(boolean convertToUpperCase) {
24 super.setConvertToUpperCase(convertToUpperCase);
25 this.convertToUpperCase = convertToUpperCase;
26 }
27
28 @Override
29 public void setGroupRoleAttribute(String groupRoleAttribute) {
30 super.setGroupRoleAttribute(groupRoleAttribute);
31 this.groupRoleAttribute = groupRoleAttribute;
32 }
33
34 @Override
35 public void setRolePrefix(String rolePrefix) {
36 super.setRolePrefix(rolePrefix);
37 this.rolePrefix = rolePrefix;
38 }
39
40 /** Hacked from parent class. */
41 public String convertGroupToRole(String groupName) {
42 if (convertToUpperCase) {
43 groupName = groupName.toUpperCase();
44 }
45
46 return rolePrefix + groupName;
47 }
48
49 public String getGroupRoleAttribute() {
50 return groupRoleAttribute;
51 }
52
53 public String getGroupSearchBase() {
54 return groupSearchBase;
55 }
56
57 }