ServletSecurityAuthenticationService extends GroupAdapterAuthorizationSource implements AuthenticationService { @Override public User login(String username, String password) { final HttpServletRequest request = getRequestForThread(); try { request.login(username, password); return getUser(); } catch (final ServletException e) { throw new FailedAuthenticationException("Failed to authenticate user " + username, e); } } ServletSecurityAuthenticationService(); @Override User login(String username,
                      String password); @Override boolean isLoggedIn(); @Override void logout(); @Override User getUser();  }
@Test public void testLogin() throws Exception { RoleRegistry.get().registerRole("admin"); RoleRegistry.get().registerRole("role1"); Set<Principal> principals = mockPrincipals("admin", "role1", "group1", null); Subject subject = new Subject(); subject.getPrincipals().addAll(principals); doReturn(subject).when(tested).getSubjectFromPolicyContext(); User user = tested.login(USERNAME, PASSWORD); assertNotNull(user); assertEquals(USERNAME, user.getIdentifier()); assertEquals(2, user.getRoles().size()); assertTrue(user.getRoles().contains(new RoleImpl("admin"))); assertTrue(user.getRoles().contains(new RoleImpl("role1"))); assertEquals(1, user.getGroups().size()); assertTrue(user.getGroups().contains(new GroupImpl("group1"))); }