UsernamePasswordCredentialToPrincipalResolver implements CredentialToPrincipalResolver { @Override public Principal resolvePrincipal(Credential credential) { if(credential!=null && this.supports(credential)){ UsernamePasswordCredential usernamePasswordCredential = (UsernamePasswordCredential)credential; DefaultUserPrincipal principal = new DefaultUserPrincipal(); principal.setId(usernamePasswordCredential.getUsername()); principal.setAttributes(usernamePasswordCredential.getParameters()); return principal; } return null; }  void setSupportSubClasses(boolean supportSubClasses); @Override Principal resolvePrincipal(Credential credential); @Override boolean supports(Credential credential);  }
@Test public void testResolvePrincipal(){ Assert.assertNull(resolver.resolvePrincipal(null)); Credential credential = Mockito.mock(Credential.class); Assert.assertNull(resolver.resolvePrincipal(credential)); String username = "admin"; UsernamePasswordCredential usernamePasswordCredential = new UsernamePasswordCredential(); usernamePasswordCredential.setUsername(username); DefaultUserPrincipal principal = (DefaultUserPrincipal)resolver.resolvePrincipal(usernamePasswordCredential); Assert.assertNotNull(principal); Assert.assertEquals(username, principal.getId()); }