EncryCredentialAuthenticationHandler extends
		AbstractPreAndPostProcessingAuthenticationHandler { @Override protected boolean doAuthentication(Credential credential) throws AuthenticationException { if(!this.supports(credential)){ return false; } if(credential!=null && credential instanceof EncryCredential){ EncryCredential encryCredential = (EncryCredential)credential; try{ EncryCredentialInfo encryCredentialInfo = this.encryCredentialManager.decrypt(encryCredential); if(encryCredentialInfo!=null){ encryCredential.setEncryCredentialInfo(encryCredentialInfo); return this.encryCredentialManager.checkEncryCredentialInfo(encryCredentialInfo); } }catch (InvalidEncryCredentialException e) { return false; } } return false; }  void setEncryCredentialManager(
			EncryCredentialManager encryCredentialManager); final boolean supports(final Credential 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)); }