LdapHelper { List<String> parseLdapIdResponse(List<String> uidGidGroupsLines) { Pattern uidGidGroupsPattern = Pattern.compile(".*groups=(.*)"); Pattern groupPattern = Pattern.compile("[0-9]*\\((.*)\\)"); List<String> accu = new ArrayList<>(); for (String line : uidGidGroupsLines) { Matcher groupMatcher = uidGidGroupsPattern.matcher(line.trim()); if (groupMatcher.matches()) { for (String groupIdAndName : groupMatcher.group(1).split(",")) { Matcher matcher = groupPattern.matcher(groupIdAndName); if (matcher.matches()) { accu.add(matcher.group(1)); } } } } return accu; }  boolean isRegistered(String remoteUserName); void register(String remoteUserName);  }
@Test public void parseLdapResponseTest() { ArrayList<String> response = new ArrayList<>(); response.add("uid=10230(tep_amarin) gid=10118(calwps) groups=10118(calwps),20009(tep_coreteam)\r"); List<String> groups = new LdapHelper().parseLdapIdResponse(response); assertEquals("calwps", groups.get(0)); assertEquals("tep_coreteam", groups.get(1)); response.add("uid=10272(tep_arose) gid=20009(tep_coreteam) groups=10118(calwps),20009(tep_coreteam)"); groups = new LdapHelper().parseLdapIdResponse(response); assertEquals("calwps", groups.get(0)); assertEquals("tep_coreteam", groups.get(1)); }