DefaultAuthenticationPostHandler implements
		AuthenticationPostHandler { @Override public Authentication postAuthentication(Credential credential, Principal principal){ Date createTime = new Date(); AuthenticationImpl authentication = new AuthenticationImpl(); authentication.setAuthenticatedDate(createTime); authentication.setPrincipal(principal); encryCredentialWithKi4soKey(authentication, credential, principal); encryCredentialWithAppKey(authentication, credential, principal); return authentication; }  void setUserLoggedStatusStore(UserLoggedStatusStore userLoggedStatusStore); AppService getAppService(); void setAppService(AppService appService); KeyService getKeyService(); void setKeyService(KeyService keyService); EncryCredentialManager getEncryCredentialManager(); void setEncryCredentialManager(
			EncryCredentialManager encryCredentialManager); @Override Authentication postAuthentication(Credential credential, Principal principal);  }
@Test public void testPostAuthentication() { Authentication authentication = this.handler.postAuthentication(null, null); assertNotNull(authentication); Assert.assertNull(authentication.getPrincipal()); String username = "test"; String password = "pwdsssss"; UsernamePasswordCredential credential = new UsernamePasswordCredential(username, password); DefaultUserPrincipal principal = new DefaultUserPrincipal(); principal.setId(username); AppService appService = Mockito.mock(AppService.class); Mockito.when(appService.findKi4soServerApp()).thenReturn(null); this.handler.setAppService(appService); try { this.handler.postAuthentication(credential, principal); fail("应该抛出异常"); } catch (NoKi4soKeyException e) { } String appId = "1000"; String app2Id = "1001"; String keyId = "1000000"; String encStringValue = "ssssdafdsafdsafdsafdasfdsafdsa"; String service = "http: Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put(WebConstants.SERVICE_PARAM_NAME, service); credential.setParameters(parameters); App app = new App(); app.setAppId(appId); App clientApp = new App(); clientApp.setAppId(app2Id); Ki4soKey key = new Ki4soKey(); key.setKeyId(keyId); Mockito.when(appService.findKi4soServerApp()).thenReturn(app); Mockito.when(appService.findAppByHost(service)).thenReturn(clientApp); KeyService keyService = Mockito.mock(KeyService.class); Mockito.when(keyService.findKeyByAppId(appId)).thenReturn(key); Mockito.when(keyService.findKeyByAppId(app2Id)).thenReturn(key); this.handler.setKeyService(keyService); EncryCredentialManager encryCredentialManager = Mockito.mock(EncryCredentialManager.class); Mockito.when(encryCredentialManager.encrypt(Mockito.any(EncryCredentialInfo.class))).thenReturn(encStringValue); this.handler.setEncryCredentialManager(encryCredentialManager); UserLoggedStatusStore userLoggedStatusStore = Mockito.mock(UserLoggedStatusStore.class); this.handler.setUserLoggedStatusStore(userLoggedStatusStore); authentication = this.handler.postAuthentication(credential, principal); assertNotNull(authentication); }