Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[KARAF-4989] Changed parsing of jaas ldap login module role.mapping option #283

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -125,9 +125,9 @@ private Map<String, Set<String>> parseRoleMapping(String option) {
LOGGER.debug("Parse role mapping {}", option);
String[] mappings = option.split(";");
for (String mapping : mappings) {
String[] map = mapping.split("=", 2);
String ldapRole = map[0].trim();
String[] karafRoles = map[1].split(",");
int index = mapping.lastIndexOf("=");
String ldapRole = mapping.substring(0,index).trim();
String[] karafRoles = mapping.substring(index+1).split(",");
if (roleMapping.get(ldapRole) == null) {
roleMapping.put(ldapRole, new HashSet<String>());
}
Expand Down
Expand Up @@ -438,5 +438,55 @@ public void handle(Callback[] callbacks) throws IOException, UnsupportedCallback
assertTrue(module.logout());
assertEquals("Principals should be gone as the user has logged out", 0, subject.getPrincipals().size());
}

@Test
public void testRoleMappingFqdn() throws Exception {
Properties options = ldapLoginModuleOptions();
options.put(LDAPOptions.ROLE_MAPPING, "cn=admin,ou=groups,dc=example,dc=com=karaf;cn=admin,ou=mygroups,dc=example,dc=com=another");
options.put(LDAPOptions.ROLE_BASE_DN, "ou=groups,dc=example,dc=com");
options.put(LDAPOptions.ROLE_SEARCH_SUBTREE, "true");
options.put(LDAPOptions.ROLE_FILTER, "(member=%fqdn)");
options.put(LDAPOptions.ROLE_NAME_ATTRIBUTE, "description");
LDAPLoginModule module = new LDAPLoginModule();
CallbackHandler cb = new CallbackHandler() {
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (Callback cb : callbacks) {
if (cb instanceof NameCallback) {
((NameCallback) cb).setName("admin");
} else if (cb instanceof PasswordCallback) {
((PasswordCallback) cb).setPassword("admin123".toCharArray());
}
}
}
};
Subject subject = new Subject();
module.initialize(subject, cb, null, options);

assertEquals("Precondition", 0, subject.getPrincipals().size());
assertTrue(module.login());
assertTrue(module.commit());

assertEquals(2, subject.getPrincipals().size());

final List<String> roles = new ArrayList<String>(Arrays.asList("karaf"));

boolean foundUser = false;
boolean foundRole = false;
for (Principal principal : subject.getPrincipals()) {
if (principal instanceof UserPrincipal) {
assertEquals("admin", principal.getName());
foundUser = true;
} else if (principal instanceof RolePrincipal) {
assertTrue(roles.remove(principal.getName()));
foundRole = true;
}
}
assertTrue(foundUser);
assertTrue(foundRole);
assertTrue(roles.isEmpty());

assertTrue(module.logout());
assertEquals("Principals should be gone as the user has logged out", 0, subject.getPrincipals().size());
}
}

Expand Up @@ -34,6 +34,7 @@ dn: cn=admin,ou=groups,dc=example,dc=com
objectClass: top
objectClass: groupOfNames
cn: admin
description: cn=admin,ou=groups,dc=example,dc=com
member: cn=admin,ou=people,dc=example,dc=com

dn: cn=admin,ou=people,dc=example,dc=com
Expand All @@ -55,4 +56,3 @@ cn: cheese
sn: cheese
uid: cheese
userPassword: foodie

Expand Up @@ -34,6 +34,7 @@ dn: cn=admin,ou=groups,dc=example,dc=com
objectClass: top
objectClass: groupOfNames
cn: admin
description: cn=admin,ou=groups,dc=example,dc=com
member: cn=admin\,\=\+\<\>#\;\\,ou=people,dc=example,dc=com

dn: cn=admin\,\=\+\<\>#\;\\,ou=people,dc=example,dc=com
Expand Down