AbstractLoginModule implements LoginModule { @Nullable protected Credentials getSharedCredentials() { Credentials shared = null; if (sharedState.containsKey(SHARED_KEY_CREDENTIALS)) { Object sc = sharedState.get(SHARED_KEY_CREDENTIALS); if (sc instanceof Credentials) { shared = (Credentials) sc; } else { log.debug("Login: Invalid value for share state entry {}. Credentials expected.", SHARED_KEY_CREDENTIALS); } } return shared; }  @Override void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> options); @Override boolean logout(); @Override boolean abort(); static final String SHARED_KEY_CREDENTIALS; static final String SHARED_KEY_LOGIN_NAME; static final String SHARED_KEY_ATTRIBUTES; static final String SHARED_KEY_PRE_AUTH_LOGIN; }
@Test public void testGetSharedCredentials() { Map<String, Object> sharedState = new HashMap<>(); sharedState.put(SHARED_KEY_CREDENTIALS, new TestCredentials()); AbstractLoginModule lm = initLoginModule(TestCredentials.class, sharedState); assertTrue(lm.getSharedCredentials() instanceof TestCredentials); sharedState.put(SHARED_KEY_CREDENTIALS, new SimpleCredentials("test", "test".toCharArray())); lm = initLoginModule(TestCredentials.class, sharedState); assertTrue(lm.getSharedCredentials() instanceof SimpleCredentials); lm = initLoginModule(SimpleCredentials.class, sharedState); assertTrue(lm.getSharedCredentials() instanceof SimpleCredentials); sharedState.put(SHARED_KEY_CREDENTIALS, "no credentials object"); lm = initLoginModule(TestCredentials.class, sharedState); assertNull(lm.getSharedCredentials()); sharedState.clear(); lm = initLoginModule(TestCredentials.class, sharedState); assertNull(lm.getSharedCredentials()); }