test_class.declarator: handler
test_class.modifier: private
test_class.original_string: private EncryCredentialAuthenticationHandler handler;
test_class.type: EncryCredentialAuthenticationHandler
test_class.var_name: handler
test_class.file: ki4so-core/src/test/java/com/github/ebnew/ki4so/core/authentication/handlers/EncryCredentialAuthenticationHandlerTest.java
test_class.identifier: EncryCredentialAuthenticationHandlerTest
test_case.body: @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));
  		
  		/**
  		 * 测试解密返回null的情况。
  		 */
  		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));
  	}
test_case.class_method_signature: EncryCredentialAuthenticationHandlerTest.testDoAuthentication()
test_case.full_signature: @Test public void testDoAuthentication()
test_case.identifier: testDoAuthentication
test_case.invocations: assertFalse authenticate mock assertFalse authenticate mock setEncryCredentialManager thenThrow when decrypt assertFalse authenticate reset thenReturn when decrypt assertFalse authenticate reset thenReturn when decrypt assertFalse authenticate reset thenReturn when decrypt thenReturn when checkEncryCredentialInfo assertTrue authenticate
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testDoAuthentication()
focal_class.declarator: encryCredentialManager
focal_class.modifier: @Autowired
  	private
focal_class.original_string: @Autowired
  	private EncryCredentialManager encryCredentialManager;
focal_class.type: EncryCredentialManager
focal_class.var_name: encryCredentialManager
focal_class.declarator: DEFAULT_CLASS = EncryCredential.class
focal_class.modifier: private static final
focal_class.original_string: private static final Class<EncryCredential> DEFAULT_CLASS = EncryCredential.class;
focal_class.type: Class<EncryCredential>
focal_class.var_name: DEFAULT_CLASS
focal_class.file: ki4so-core/src/main/java/com/github/ebnew/ki4so/core/authentication/handlers/EncryCredentialAuthenticationHandler.java
focal_class.identifier: EncryCredentialAuthenticationHandler
focal_class.class_method_signature: EncryCredentialAuthenticationHandler.setEncryCredentialManager(
  			EncryCredentialManager encryCredentialManager)
focal_class.full_signature: public void setEncryCredentialManager(
  			EncryCredentialManager encryCredentialManager)
focal_class.identifier: setEncryCredentialManager
focal_class.modifiers: public
focal_class.parameters: (
  			EncryCredentialManager encryCredentialManager)
focal_class.return: void
focal_class.signature: void setEncryCredentialManager(
  			EncryCredentialManager encryCredentialManager)
focal_class.class_method_signature: EncryCredentialAuthenticationHandler.supports(final Credential credential)
focal_class.full_signature: public final boolean supports(final Credential credential)
focal_class.identifier: supports
focal_class.modifiers: public final
focal_class.parameters: (final Credential credential)
focal_class.return: boolean
focal_class.signature: boolean supports(final Credential credential)
focal_class.class_method_signature: EncryCredentialAuthenticationHandler.doAuthentication(Credential credential)
focal_class.full_signature: @Override protected boolean doAuthentication(Credential credential)
focal_class.identifier: doAuthentication
focal_class.modifiers: @Override protected
focal_class.parameters: (Credential credential)
focal_class.return: boolean
focal_class.signature: boolean doAuthentication(Credential credential)
focal_class.superclass: extends
  		AbstractPreAndPostProcessingAuthenticationHandler
focal_method.body: @Override
  	protected boolean doAuthentication(Credential credential)
  			throws AuthenticationException {
  		//不支持的凭据直接返回false.
  		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;
  	}
focal_method.class_method_signature: EncryCredentialAuthenticationHandler.doAuthentication(Credential credential)
focal_method.full_signature: @Override protected boolean doAuthentication(Credential credential)
focal_method.identifier: doAuthentication
focal_method.invocations: supports decrypt setEncryCredentialInfo checkEncryCredentialInfo
focal_method.modifiers: @Override protected
focal_method.parameters: (Credential credential)
focal_method.return: boolean
focal_method.signature: boolean doAuthentication(Credential credential)