EncryCredentialAuthenticationHandler extends
		AbstractPreAndPostProcessingAuthenticationHandler { @Override protected boolean doAuthentication(KnightCredential credential) throws AuthenticationException { if(!this.supports(credential)){ return false; } if(credential!=null && credential instanceof KnightEncryCredential){ KnightEncryCredential encryCredential = (KnightEncryCredential)credential; try{ KnightCredentialInfo encryCredentialInfo = this.encryCredentialManager.decrypt(encryCredential); if(encryCredentialInfo!=null){ encryCredential.setCredentialInfo(encryCredentialInfo); return this.encryCredentialManager.checkEncryCredentialInfo(encryCredentialInfo); } }catch (InvalidEncryCredentialException e) { return false; } } return false; }  void setEncryCredentialManager(
            KnightEncryCredentialManager encryCredentialManager); @Override boolean supports(KnightCredential credential);  }
@Test public void testDoAuthentication() { Assert.assertFalse(handler.authenticate(null)); Credential credential = Mockito.mock(Credential.class); Assert.assertFalse(handler.authenticate(credential)); EncryCredential encryCredential = new EncryCredential("sssddaf"); EncryCredentialManager encryCredentialManager = Mockito.mock(EncryCredentialManager.class); this.handler.setEncryCredentialManager(encryCredentialManager); Mockito.when(encryCredentialManager.decrypt(encryCredential)).thenThrow(InvalidEncryCredentialException.INSTANCE); Assert.assertFalse(handler.authenticate(encryCredential)); Mockito.reset(encryCredentialManager); Mockito.when(encryCredentialManager.decrypt(encryCredential)).thenReturn(null); Assert.assertFalse(handler.authenticate(encryCredential)); Mockito.reset(encryCredentialManager); EncryCredentialInfo encryCredentialInfo = new EncryCredentialInfo(); Mockito.when(encryCredentialManager.decrypt(encryCredential)).thenReturn(encryCredentialInfo); Assert.assertFalse(handler.authenticate(encryCredential)); Mockito.reset(encryCredentialManager); encryCredentialInfo = new EncryCredentialInfo(); Mockito.when(encryCredentialManager.decrypt(encryCredential)).thenReturn(encryCredentialInfo); Mockito.when(encryCredentialManager.checkEncryCredentialInfo(encryCredentialInfo)).thenReturn(true); Assert.assertTrue(handler.authenticate(encryCredential)); }