EncryCredentialToPrincipalResolver implements CredentialToPrincipalResolver { public KnightUser resolvePrincipal(KnightCredential credential) { if (credential != null && this.supports(credential)) { KnightEncryCredential encryCredential = (KnightEncryCredential) credential; DefaultKnightUser principal = new DefaultKnightUser(); KnightCredentialInfo encryCredentialInfo = encryCredential.getCredentialInfo(); if (encryCredentialInfo != null) { principal.setId(encryCredentialInfo.getUserId()); principal.setAttributes(encryCredential.getParameters()); } return principal; } return null; }  void setSupportSubClasses(boolean supportSubClasses); KnightUser resolvePrincipal(KnightCredential credential); boolean supports(KnightCredential credential);  }
@Test public void testResolvePrincipal() { assertNull(this.resolver.resolvePrincipal(null)); Credential credential = Mockito.mock(Credential.class); assertNull(this.resolver.resolvePrincipal(credential)); String userId = "test"; EncryCredential encryCredential = new EncryCredential("ddd"); Map<String, Object> param = new HashMap<String, Object>(); encryCredential.setParameters(param); EncryCredentialInfo encryCredentialInfo = new EncryCredentialInfo(); encryCredentialInfo.setUserId(userId); encryCredential.setEncryCredentialInfo(encryCredentialInfo); Principal principal = this.resolver.resolvePrincipal(encryCredential); assertNotNull(principal); assertEquals(userId, principal.getId()); assertEquals(param, principal.getAttributes()); }