SimpleCredentialsSupport implements CredentialsSupport { @Override public boolean setAttributes(@NotNull Credentials credentials, @NotNull Map<String, ?> attributes) { if (credentials instanceof SimpleCredentials) { SimpleCredentials sc = (SimpleCredentials) credentials; for (Map.Entry<String, ?> entry : attributes.entrySet()) { sc.setAttribute(entry.getKey(), entry.getValue()); } return true; } else { return false; } } private  SimpleCredentialsSupport(); static CredentialsSupport getInstance(); @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() { Map<String, ?> attributes = credentialsSupport.getAttributes(new TestCredentials()); assertNotNull(attributes); assertTrue(attributes.isEmpty()); SimpleCredentials sc = new SimpleCredentials("uid", new char[0]); Map<String, ?> expected = ImmutableMap.of("a", "a", "b", Boolean.TRUE, "c", new TestCredentials()); credentialsSupport.setAttributes(sc, expected); for (Map.Entry<String, ?> entry : expected.entrySet()) { assertEquals(entry.getValue(), sc.getAttribute(entry.getKey())); } attributes = credentialsSupport.getAttributes(sc); assertNotNull(attributes); assertEquals(3, attributes.size()); assertEquals(expected, attributes); }
@Test public void testSetAttributesFalse() { assertFalse(credentialsSupport.setAttributes(new Credentials() {}, ImmutableMap.of("a", "value"))); }