@Test public void getEffective() { Set<String> allowedRealms = new HashSet<>(); String requestedRealm = "requestedRealm"; allowedRealms.add("testRealm1"); allowedRealms.add("testRealm2"); allowedRealms.add("testRealm3"); allowedRealms.add("requestedRealm"); Set<String> effective = RealmUtils.getEffective(allowedRealms, requestedRealm); assertEquals(allowedRealms, effective); }
public static Set<String> getEffective(final Set<String> allowedRealms, final String requestedRealm) { Set<String> allowed = RealmUtils.normalize(allowedRealms); Set<String> requested = new HashSet<>(); requested.add(requestedRealm); Set<String> effective = new HashSet<>(); effective.addAll(requested.stream().filter(new StartsWithPredicate(allowed)).collect(Collectors.toSet())); effective.addAll(allowed.stream().filter(new StartsWithPredicate(requested)).collect(Collectors.toSet())); if (allowedRealms != null) { effective.addAll(allowedRealms.stream().filter(new DynRealmsPredicate()).collect(Collectors.toSet())); } return effective; }
RealmUtils { public static Set<String> getEffective(final Set<String> allowedRealms, final String requestedRealm) { Set<String> allowed = RealmUtils.normalize(allowedRealms); Set<String> requested = new HashSet<>(); requested.add(requestedRealm); Set<String> effective = new HashSet<>(); effective.addAll(requested.stream().filter(new StartsWithPredicate(allowed)).collect(Collectors.toSet())); effective.addAll(allowed.stream().filter(new StartsWithPredicate(requested)).collect(Collectors.toSet())); if (allowedRealms != null) { effective.addAll(allowedRealms.stream().filter(new DynRealmsPredicate()).collect(Collectors.toSet())); } return effective; } }
RealmUtils { public static Set<String> getEffective(final Set<String> allowedRealms, final String requestedRealm) { Set<String> allowed = RealmUtils.normalize(allowedRealms); Set<String> requested = new HashSet<>(); requested.add(requestedRealm); Set<String> effective = new HashSet<>(); effective.addAll(requested.stream().filter(new StartsWithPredicate(allowed)).collect(Collectors.toSet())); effective.addAll(allowed.stream().filter(new StartsWithPredicate(requested)).collect(Collectors.toSet())); if (allowedRealms != null) { effective.addAll(allowedRealms.stream().filter(new DynRealmsPredicate()).collect(Collectors.toSet())); } return effective; } private  RealmUtils(); }
RealmUtils { public static Set<String> getEffective(final Set<String> allowedRealms, final String requestedRealm) { Set<String> allowed = RealmUtils.normalize(allowedRealms); Set<String> requested = new HashSet<>(); requested.add(requestedRealm); Set<String> effective = new HashSet<>(); effective.addAll(requested.stream().filter(new StartsWithPredicate(allowed)).collect(Collectors.toSet())); effective.addAll(allowed.stream().filter(new StartsWithPredicate(requested)).collect(Collectors.toSet())); if (allowedRealms != null) { effective.addAll(allowedRealms.stream().filter(new DynRealmsPredicate()).collect(Collectors.toSet())); } return effective; } private  RealmUtils(); static String getGroupOwnerRealm(final String realmPath, final String groupKey); static boolean normalizingAddTo(final Set<String> realms, final String newRealm); static Set<String> normalize(final Collection<String> realms); static Set<String> getEffective(final Set<String> allowedRealms, final String requestedRealm); }
RealmUtils { public static Set<String> getEffective(final Set<String> allowedRealms, final String requestedRealm) { Set<String> allowed = RealmUtils.normalize(allowedRealms); Set<String> requested = new HashSet<>(); requested.add(requestedRealm); Set<String> effective = new HashSet<>(); effective.addAll(requested.stream().filter(new StartsWithPredicate(allowed)).collect(Collectors.toSet())); effective.addAll(allowed.stream().filter(new StartsWithPredicate(requested)).collect(Collectors.toSet())); if (allowedRealms != null) { effective.addAll(allowedRealms.stream().filter(new DynRealmsPredicate()).collect(Collectors.toSet())); } return effective; } private  RealmUtils(); static String getGroupOwnerRealm(final String realmPath, final String groupKey); static boolean normalizingAddTo(final Set<String> realms, final String newRealm); static Set<String> normalize(final Collection<String> realms); static Set<String> getEffective(final Set<String> allowedRealms, final String requestedRealm);  }