EncryCredentialToPrincipalResolver implements CredentialToPrincipalResolver { @Override public Principal resolvePrincipal(Credential credential) { if (credential != null && this.supports(credential)) { EncryCredential encryCredential = (EncryCredential) credential; DefaultUserPrincipal principal = new DefaultUserPrincipal(); EncryCredentialInfo encryCredentialInfo = encryCredential.getEncryCredentialInfo(); if (encryCredentialInfo != null) { principal.setId(encryCredentialInfo.getUserId()); principal.setAttributes(encryCredential.getParameters()); } return principal; } return null; }  void setSupportSubClasses(boolean supportSubClasses); @Override Principal resolvePrincipal(Credential credential); @Override boolean supports(Credential 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()); }