LDAPUserDetailsContextMapperWithProfileSearchEnhanced extends AbstractLDAPUserDetailsContextMapper { public Profile getProfile(String pname) { if ((this.profileMapping != null) && (this.profileMapping.containsKey(pname))) return this.profileMapping.get(pname); Profile p = Profile.findProfileIgnoreCase(pname); return p; }  void setLdapRoleConverters(List<LDAPRoleConverter> vals); void setMembershipSearchStartObject(String membershipSearchStartObject); void setLdapMembershipQuery(String ldapMembershipQuery); String cn_short(Attributes atts); String cn_short(Map<String, ArrayList<String>> userInfo); String cn_long(Map<String, ArrayList<String>> userInfo); String escape(String str); Profile getProfile(String pname);  }
@Test @Transactional public void test_ldapUserDetailsService_groups_and_profiles_dblasby() throws NamingException { Group group = new Group().setName("GENERAL"); group = groupRepository.save(group); UserDetails details = ldapUserDetailsService.loadUserByUsername("dblasby@example.com"); assertNotNull(details); assertEquals(3, details.getAuthorities().size()); assertEquals(Profile.Guest.name(), details.getAuthorities().toArray(new GrantedAuthority[0])[0].getAuthority()); assertEquals(Profile.Editor.name(), details.getAuthorities().toArray(new GrantedAuthority[0])[1].getAuthority()); assertEquals(Profile.RegisteredUser.name(), details.getAuthorities().toArray(new GrantedAuthority[0])[2].getAuthority()); LDAPUser user1 = (LDAPUser) details; assertEquals(1, user1.getPrivileges().size()); assertTrue(user1.getPrivileges().containsKey("GENERAL")); assertEquals(1, user1.getPrivileges().get("GENERAL").toArray().length); assertEquals(Profile.Editor, user1.getPrivileges().get("GENERAL").toArray()[0]); User user = userRepository.findOneByUsername("dblasby@example.com"); assertNotNull(user); assertEquals("blasby", user.getSurname()); assertEquals(Profile.Editor, user.getProfile()); List<UserGroup> ug = userGroupRepository.findAll(UserGroupSpecs.hasUserId(user.getId())); assertNotNull(ug); assertEquals(1, ug.size()); assertEquals("GENERAL", ug.get(0).getGroup().getName()); }
@Test @Transactional public void test_ldapUserDetailsService_groups_and_profiles_admin() throws NamingException { Group group = new Group().setName("GENERAL"); group = groupRepository.save(group); UserDetails details = ldapUserDetailsService.loadUserByUsername("admin@example.com"); assertNotNull(details); LDAPUser user1 = (LDAPUser) details; assertEquals(1, user1.getPrivileges().size()); assertTrue(user1.getPrivileges().containsKey("GENERAL")); assertEquals(1, user1.getPrivileges().get("GENERAL").toArray().length); assertEquals(Profile.Administrator, user1.getPrivileges().get("GENERAL").toArray()[0]); User user = userRepository.findOneByUsername("admin@example.com"); assertNotNull(user); assertEquals("admin", user.getSurname()); assertEquals(Profile.Administrator, user.getProfile()); List<UserGroup> ug = userGroupRepository.findAll(UserGroupSpecs.hasUserId(user.getId())); assertNotNull(ug); assertEquals(1, ug.size()); assertEquals("GENERAL", ug.get(0).getGroup().getName()); }
@Test @Transactional public void test_ldapUserDetailsService_groups_and_profiles_jody() throws NamingException { Group group = new Group().setName("GENERAL"); group = groupRepository.save(group); UserDetails details = ldapUserDetailsService.loadUserByUsername("jgee@example.com"); assertNotNull(details); LDAPUser user1 = (LDAPUser) details; assertEquals(0, user1.getPrivileges().size()); User user = userRepository.findOneByUsername("jgee@example.com"); assertNotNull(user); assertEquals("gee", user.getSurname()); assertEquals(Profile.RegisteredUser, user.getProfile()); List<UserGroup> ug = userGroupRepository.findAll(UserGroupSpecs.hasUserId(user.getId())); assertNotNull(ug); assertEquals(0, ug.size()); }