UsernamePasswordCredentialToPrincipalResolver implements CredentialToPrincipalResolver { @Override public KnightUser resolvePrincipal(KnightCredential credential) { if(credential!=null && this.supports(credential)){ KnightNamePasswordCredential usernamePasswordCredential = (KnightNamePasswordCredential)credential; DefaultKnightUser principal = new DefaultKnightUser(); principal.setId(usernamePasswordCredential.getUsername()); principal.setAttributes(usernamePasswordCredential.getParameters()); return principal; } return null; }  void setSupportSubClasses(boolean supportSubClasses); @Override KnightUser resolvePrincipal(KnightCredential credential); @Override boolean supports(KnightCredential 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()); }