CompositeCredentialsSupport implements CredentialsSupport { @Override public boolean setAttributes(@NotNull Credentials credentials, @NotNull Map<String, ?> attributes) { boolean set = false; Collection<CredentialsSupport> all = this.credentialSupplier.get(); for (CredentialsSupport c : all) { set = c.setAttributes(credentials, attributes) || set; } return set; } private  CompositeCredentialsSupport(@NotNull Supplier<Collection<CredentialsSupport>> credentialSupplier); static CredentialsSupport newInstance(@NotNull Supplier<Collection<CredentialsSupport>> credentialSupplier); @Override @NotNull Set<Class> getCredentialClasses(); @Override @Nullable String getUserId(@NotNull Credentials credentials); @Override @NotNull Map<String, ?> getAttributes(@NotNull Credentials credentials); @Override boolean setAttributes(@NotNull Credentials credentials, @NotNull Map<String, ?> attributes);  }
@Test public void testSetAttributes() { SimpleCredentials sc = new SimpleCredentials("uid", new char[0]); TestCredentials tc = new TestCredentials(); Credentials dummy = new Credentials() { }; Map<String, ?> attributesS = credentialsSupport.getAttributes(sc); assertNotNull(attributesS); assertTrue(attributesS.isEmpty()); Map<String, ?> attributesT = credentialsSupport.getAttributes(tc); assertNotNull(attributesT); assertTrue(attributesT.isEmpty()); Map<String, ?> attributesD = credentialsSupport.getAttributes(dummy); assertNotNull(attributesD); assertTrue(attributesD.isEmpty()); Map<String, ?> expectedS = ImmutableMap.of("a", "a", "b", Boolean.TRUE, "c", new TestCredentials()); assertTrue(credentialsSupport.setAttributes(sc, expectedS)); Map<String, ?> expectedT = ImmutableMap.of("test", "Test1CredentialsSupport"); assertTrue(credentialsSupport.setAttributes(tc, expectedT)); assertFalse(credentialsSupport.setAttributes(dummy, ImmutableMap.of("none", "none"))); attributesS = credentialsSupport.getAttributes(sc); for (Map.Entry<String, ?> entry : expectedS.entrySet()) { assertEquals(entry.getValue(), attributesS.get(entry.getKey())); } attributesT = credentialsSupport.getAttributes(tc); for (Map.Entry<String, ?> entry : expectedT.entrySet()) { assertEquals(entry.getValue(), attributesT.get(entry.getKey())); } attributesD = credentialsSupport.getAttributes(dummy); assertNotNull(attributesD); assertTrue(attributesD.isEmpty()); }