AbstractLoginModule implements LoginModule { protected static void setAuthInfo(@NotNull AuthInfo authInfo, @NotNull Subject subject) { Set<AuthInfo> ais = subject.getPublicCredentials(AuthInfo.class); if (!ais.isEmpty()) { subject.getPublicCredentials().removeAll(ais); } subject.getPublicCredentials().add(authInfo); }  @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 testSetAuthInfo() { Subject subject = new Subject(); AuthInfo authInfo = new AuthInfoImpl("userid", null, null); AbstractLoginModule.setAuthInfo(authInfo, subject); Set<AuthInfo> fromSubject = subject.getPublicCredentials(AuthInfo.class); assertEquals(1, fromSubject.size()); assertSame(authInfo, fromSubject.iterator().next()); }
@Test public void testSetAuthInfoPreExisting() { Subject subject = new Subject(); subject.getPublicCredentials().add(new AuthInfoImpl(null, null, null)); AuthInfo authInfo = new AuthInfoImpl("userid", null, null); AbstractLoginModule.setAuthInfo(authInfo, subject); Set<AuthInfo> fromSubject = subject.getPublicCredentials(AuthInfo.class); assertEquals(1, fromSubject.size()); assertSame(authInfo, fromSubject.iterator().next()); }