@Test public void expandFilterTest1() { LdapUser ldapUser = new LdapUser(); ldapUser.setAttribute("mail", new TreeSet<>(Collections.singletonList("james@bond"))); ldapUser.setAttribute("uid", new TreeSet<>(Collections.singletonList("bondjame"))); ldapUser.setAttribute("ou", new TreeSet<>(Arrays.asList("MI6", "MI7"))); User user = new User("007", "123", null, true); assertEquals("(objectclass=james@bond)", plugin.expandFilter("(objectclass=%mail%)", ldapUser, user)); assertEquals("(objectclass=bondjame)", plugin.expandFilter("(objectclass=%uid%)", ldapUser, user)); assertEquals("(objectclass=007)", plugin.expandFilter("(objectclass=%username%)", ldapUser, user)); assertEquals("(objectclass=123)", plugin.expandFilter("(objectclass=%guid%)", ldapUser, user)); ldapUser.setAttribute("role", new TreeSet<>(Collections.singletonList("agent"))); assertEquals("(objectclass=agent)", plugin.expandFilter("(objectclass=%role%)", ldapUser, user)); ldapUser.setAttribute("role", new TreeSet<>(Arrays.asList("agent", "double-agent"))); assertEquals("(objectclass=%role%)", plugin.expandFilter("(objectclass=%role%)", ldapUser, user)); }
String expandFilter(String filter, LdapUser ldapUser, User user) { filter = expandUserFilter(user, filter, transforms); for (Entry<String, Set<String>> entry : ldapUser.getAttributes().entrySet()) { if (entry.getValue().size() == 1) { try { filter = replace(filter, entry.getKey(), entry.getValue().iterator().next(), transforms); } catch (PatternSyntaxException ex) { LOGGER.log(Level.WARNING, "The pattern for expanding is not valid", ex); } } } filter = filter.replaceAll("\\\\%", "%"); return filter; }
LdapFilterPlugin extends AbstractLdapPlugin { String expandFilter(String filter, LdapUser ldapUser, User user) { filter = expandUserFilter(user, filter, transforms); for (Entry<String, Set<String>> entry : ldapUser.getAttributes().entrySet()) { if (entry.getValue().size() == 1) { try { filter = replace(filter, entry.getKey(), entry.getValue().iterator().next(), transforms); } catch (PatternSyntaxException ex) { LOGGER.log(Level.WARNING, "The pattern for expanding is not valid", ex); } } } filter = filter.replaceAll("\\\\%", "%"); return filter; } }
LdapFilterPlugin extends AbstractLdapPlugin { String expandFilter(String filter, LdapUser ldapUser, User user) { filter = expandUserFilter(user, filter, transforms); for (Entry<String, Set<String>> entry : ldapUser.getAttributes().entrySet()) { if (entry.getValue().size() == 1) { try { filter = replace(filter, entry.getKey(), entry.getValue().iterator().next(), transforms); } catch (PatternSyntaxException ex) { LOGGER.log(Level.WARNING, "The pattern for expanding is not valid", ex); } } } filter = filter.replaceAll("\\\\%", "%"); return filter; } LdapFilterPlugin(); }
LdapFilterPlugin extends AbstractLdapPlugin { String expandFilter(String filter, LdapUser ldapUser, User user) { filter = expandUserFilter(user, filter, transforms); for (Entry<String, Set<String>> entry : ldapUser.getAttributes().entrySet()) { if (entry.getValue().size() == 1) { try { filter = replace(filter, entry.getKey(), entry.getValue().iterator().next(), transforms); } catch (PatternSyntaxException ex) { LOGGER.log(Level.WARNING, "The pattern for expanding is not valid", ex); } } } filter = filter.replaceAll("\\\\%", "%"); return filter; } LdapFilterPlugin(); @Override void load(Map<String, Object> parameters); @Override void fillSession(HttpServletRequest req, User user); @Override boolean checkEntity(HttpServletRequest request, Project project); @Override boolean checkEntity(HttpServletRequest request, Group group); }
LdapFilterPlugin extends AbstractLdapPlugin { String expandFilter(String filter, LdapUser ldapUser, User user) { filter = expandUserFilter(user, filter, transforms); for (Entry<String, Set<String>> entry : ldapUser.getAttributes().entrySet()) { if (entry.getValue().size() == 1) { try { filter = replace(filter, entry.getKey(), entry.getValue().iterator().next(), transforms); } catch (PatternSyntaxException ex) { LOGGER.log(Level.WARNING, "The pattern for expanding is not valid", ex); } } } filter = filter.replaceAll("\\\\%", "%"); return filter; } LdapFilterPlugin(); @Override void load(Map<String, Object> parameters); @Override void fillSession(HttpServletRequest req, User user); @Override boolean checkEntity(HttpServletRequest request, Project project); @Override boolean checkEntity(HttpServletRequest request, Group group);  }