AbstractLoginModule implements LoginModule { @Nullable protected PreAuthenticatedLogin getSharedPreAuthLogin() { Object login = sharedState.get(SHARED_KEY_PRE_AUTH_LOGIN); if (login instanceof PreAuthenticatedLogin) { return (PreAuthenticatedLogin) login; } else { return null; } }  @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 testGetSharedPreAuthLoginEmptySharedState() { AbstractLoginModule loginModule = initLoginModule(TestCredentials.class, ImmutableMap.of()); assertNull(loginModule.getSharedPreAuthLogin()); }
@Test public void testGetSharedPreAuthLogin() { Map<String, PreAuthenticatedLogin> sharedState = new HashMap<>(); AbstractLoginModule loginModule = initLoginModule(TestCredentials.class, sharedState); PreAuthenticatedLogin preAuthenticatedLogin = new PreAuthenticatedLogin("userId"); sharedState.put(AbstractLoginModule.SHARED_KEY_PRE_AUTH_LOGIN, preAuthenticatedLogin); assertSame(preAuthenticatedLogin, loginModule.getSharedPreAuthLogin()); }
@Test public void testGetSharedPreAuthLoginWrongEntry() { Map<String, String> sharedState = new HashMap<>(); AbstractLoginModule loginModule = initLoginModule(TestCredentials.class, sharedState); sharedState.put(AbstractLoginModule.SHARED_KEY_PRE_AUTH_LOGIN, "wrongType"); assertNull(loginModule.getSharedPreAuthLogin()); }