JAASAuthenticationService extends GroupAdapterAuthorizationSource implements AuthenticationService { @Override public User getUser() { User user = userOnThisThread.get(); if (user == null) { return User.ANONYMOUS; } return user; } JAASAuthenticationService(String domain); @Override User login(final String username,
                      final String password); @Override void logout(); @Override User getUser(); @Override boolean isLoggedIn(); static final String DEFAULT_DOMAIN; }
@Test public void testNoLogin() throws Exception { assertEquals( User.ANONYMOUS, tested.getUser() ); }
@Test public void testGetUser() throws Exception { String username = "user1"; String password = "password1"; RoleRegistry.get().registerRole( "admin" ); Set<Principal> principals = mockPrincipals( "admin" ); Subject subject = new Subject(); subject.getPrincipals().addAll( principals ); LoginContext loginContext = mock( LoginContext.class ); when( loginContext.getSubject() ).thenReturn( subject ); doReturn( loginContext ).when( tested ).createLoginContext( anyString(), anyString() ); User user = tested.login( username, password ); User user1 = tested.getUser(); assertEquals( user, user1 ); }