test_class.declarator: authenticationManager
test_class.original_string: AuthenticationManagerImpl authenticationManager;
test_class.type: AuthenticationManagerImpl
test_class.var_name: authenticationManager
test_class.file: ki4so-core/src/test/java/com/github/ebnew/ki4so/core/authentication/AuthenticationManagerImplTest.java
test_class.identifier: AuthenticationManagerImplTest
test_case.body: @Test
  	public void testAuthenticate() {
  		//测试情况1，当传入的凭据为null的情况，应该抛出异常。
  		try{
  			authenticationManager.authenticate(null);
  			fail("当参数为Null应该抛出异常信息");
  		}catch (EmptyCredentialException e) {
  			
  		}
  		
  		Credential credential = Mockito.mock(Credential.class);
  		
  		//测试情况2，测试当认证管理器中的认证处理器列表为null的情况。
  		try{
  			authenticationManager.authenticate(credential);
  			fail("当没有认证处理器应该抛出异常信息");
  		}catch (UnsupportedCredentialsException e) {
  			
  		}
  		
  		//测试情况3，测试当认证管理器中的认证处理器列表不为null但是是空列表的情况。
  		List<AuthenticationHandler> authenticationHandlers = null;
  		try{
  			authenticationHandlers = new ArrayList<AuthenticationHandler>();
  			authenticationManager.setAuthenticationHandlers(authenticationHandlers);
  			authenticationManager.authenticate(credential);
  			fail("当没有认证处理器应该抛出异常信息");
  		}catch (UnsupportedCredentialsException e) {
  			
  		}
  		
  		//测试情况4，测试当认证管理器中的认证处理器列表不为null，列表有一个认证处理器，但是不支持该凭据的情况。
  		AuthenticationHandler handler = Mockito.mock(AuthenticationHandler.class);
  		Mockito.when(handler.supports(credential)).thenReturn(false);
  		try{
  			authenticationHandlers = new ArrayList<AuthenticationHandler>();
  			authenticationHandlers.add(handler);
  			authenticationManager.setAuthenticationHandlers(authenticationHandlers);
  			authenticationManager.authenticate(credential);
  			fail("当没有认证处理器应该抛出异常信息");
  		}catch (UnsupportedCredentialsException e) {
  			
  		}
  		
  		
  		//测试情况5，测试存在合法的认证处理器的情况，但是无合法的凭据转换器。
  		handler = Mockito.mock(AuthenticationHandler.class);
  		Mockito.when(handler.supports(credential)).thenReturn(true);
  		Mockito.when(handler.authenticate(credential)).thenReturn(true);
  		try{
  			authenticationHandlers = new ArrayList<AuthenticationHandler>();
  			authenticationHandlers.add(handler);
  			authenticationManager.setAuthenticationHandlers(authenticationHandlers);
  			authenticationManager.authenticate(credential);
  			fail("当没有凭据转换器应该抛出异常信息");
  		}catch (UnsupportedCredentialsException e) {
  			
  		}
  		
  		
  		//测试情况6，测试存在合法的认证处理器的情况，但是凭据转换器列表不为空，但是集合中的元素为空。
  		List<CredentialToPrincipalResolver> resolvers = new ArrayList<CredentialToPrincipalResolver>();
  		handler = Mockito.mock(AuthenticationHandler.class);
  		Mockito.when(handler.supports(credential)).thenReturn(true);
  		Mockito.when(handler.authenticate(credential)).thenReturn(true);
  		try{
  			authenticationHandlers = new ArrayList<AuthenticationHandler>();
  			authenticationHandlers.add(handler);
  			authenticationManager.setAuthenticationHandlers(authenticationHandlers);
  			authenticationManager.setCredentialToPrincipalResolvers(resolvers);
  			authenticationManager.authenticate(credential);
  			fail("当没有凭据转换器应该抛出异常信息");
  		}catch (UnsupportedCredentialsException e) {
  			
  		}
  		
  		//测试情况7，测试存在合法的认证处理器的情况，但是凭据转换器列表不为空，但是集合中的元素不为空，认证后处理器对象是空。
  		handler = Mockito.mock(AuthenticationHandler.class);
  		Mockito.when(handler.supports(credential)).thenReturn(true);
  		Mockito.when(handler.authenticate(credential)).thenReturn(true);
  		CredentialToPrincipalResolver resolver = Mockito.mock(CredentialToPrincipalResolver.class);
  		Principal principal = Mockito.mock(Principal.class);
  		Mockito.when(resolver.supports(credential)).thenReturn(true);
  		Mockito.when(resolver.resolvePrincipal(credential)).thenReturn(principal);
  		try{
  			authenticationHandlers = new ArrayList<AuthenticationHandler>();
  			authenticationHandlers.add(handler);
  			authenticationManager.setAuthenticationHandlers(authenticationHandlers);
  			resolvers = new ArrayList<CredentialToPrincipalResolver>();
  			resolvers.add(resolver);
  			authenticationManager.setCredentialToPrincipalResolvers(resolvers);
  			authenticationManager.authenticate(credential);
  			fail("当没有认证后处理器应该抛出异常信息");
  		}catch (NoAuthenticationPostHandlerException e) {
  			
  		}
  		
  		//测试情况8，测试存在合法的认证处理器的情况，但是凭据转换器列表不为空，但是集合中的元素不为空，认证后处理器对象不是空。
  		handler = Mockito.mock(AuthenticationHandler.class);
  		Mockito.when(handler.supports(credential)).thenReturn(true);
  		Mockito.when(handler.authenticate(credential)).thenReturn(true);
  		resolver = Mockito.mock(CredentialToPrincipalResolver.class);
  		principal = Mockito.mock(Principal.class);
  		Mockito.when(resolver.supports(credential)).thenReturn(true);
  		Mockito.when(resolver.resolvePrincipal(credential)).thenReturn(principal);
  		AuthenticationPostHandler authenticationPostHandler = Mockito.mock(AuthenticationPostHandler.class);
  		Authentication authentication = Mockito.mock(Authentication.class);
  		Mockito.when(authenticationPostHandler.postAuthentication(credential, principal)).thenReturn(authentication);
  		authenticationHandlers = new ArrayList<AuthenticationHandler>();
  		authenticationHandlers.add(handler);
  		authenticationManager.setAuthenticationHandlers(authenticationHandlers);
  		resolvers = new ArrayList<CredentialToPrincipalResolver>();
  		resolvers.add(resolver);
  		authenticationManager.setCredentialToPrincipalResolvers(resolvers);
  		authenticationManager.setAuthenticationPostHandler(authenticationPostHandler);
  		authenticationManager.authenticate(credential);
  	}
test_case.class_method_signature: AuthenticationManagerImplTest.testAuthenticate()
test_case.full_signature: @Test public void testAuthenticate()
test_case.identifier: testAuthenticate
test_case.invocations: authenticate fail mock authenticate fail setAuthenticationHandlers authenticate fail mock thenReturn when supports add setAuthenticationHandlers authenticate fail mock thenReturn when supports thenReturn when authenticate add setAuthenticationHandlers authenticate fail mock thenReturn when supports thenReturn when authenticate add setAuthenticationHandlers setCredentialToPrincipalResolvers authenticate fail mock thenReturn when supports thenReturn when authenticate mock mock thenReturn when supports thenReturn when resolvePrincipal add setAuthenticationHandlers add setCredentialToPrincipalResolvers authenticate fail mock thenReturn when supports thenReturn when authenticate mock mock thenReturn when supports thenReturn when resolvePrincipal mock mock thenReturn when postAuthentication add setAuthenticationHandlers add setCredentialToPrincipalResolvers setAuthenticationPostHandler authenticate
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testAuthenticate()
focal_class.declarator: authenticationHandlers
focal_class.modifier: private
focal_class.original_string: private List<AuthenticationHandler> authenticationHandlers;
focal_class.type: List<AuthenticationHandler>
focal_class.var_name: authenticationHandlers
focal_class.declarator: credentialToPrincipalResolvers
focal_class.modifier: private
focal_class.original_string: private List<CredentialToPrincipalResolver> credentialToPrincipalResolvers;
focal_class.type: List<CredentialToPrincipalResolver>
focal_class.var_name: credentialToPrincipalResolvers
focal_class.declarator: authenticationPostHandler
focal_class.modifier: private
focal_class.original_string: private AuthenticationPostHandler authenticationPostHandler;
focal_class.type: AuthenticationPostHandler
focal_class.var_name: authenticationPostHandler
focal_class.file: ki4so-core/src/main/java/com/github/ebnew/ki4so/core/authentication/AuthenticationManagerImpl.java
focal_class.identifier: AuthenticationManagerImpl
focal_class.interfaces: implements AuthenticationManager
focal_class.class_method_signature: AuthenticationManagerImpl.setAuthenticationPostHandler(
  			AuthenticationPostHandler authenticationPostHandler)
focal_class.full_signature: public void setAuthenticationPostHandler(
  			AuthenticationPostHandler authenticationPostHandler)
focal_class.identifier: setAuthenticationPostHandler
focal_class.modifiers: public
focal_class.parameters: (
  			AuthenticationPostHandler authenticationPostHandler)
focal_class.return: void
focal_class.signature: void setAuthenticationPostHandler(
  			AuthenticationPostHandler authenticationPostHandler)
focal_class.class_method_signature: AuthenticationManagerImpl.setCredentialToPrincipalResolvers(
  			List<CredentialToPrincipalResolver> credentialToPrincipalResolvers)
focal_class.full_signature: public void setCredentialToPrincipalResolvers(
  			List<CredentialToPrincipalResolver> credentialToPrincipalResolvers)
focal_class.identifier: setCredentialToPrincipalResolvers
focal_class.modifiers: public
focal_class.parameters: (
  			List<CredentialToPrincipalResolver> credentialToPrincipalResolvers)
focal_class.return: void
focal_class.signature: void setCredentialToPrincipalResolvers(
  			List<CredentialToPrincipalResolver> credentialToPrincipalResolvers)
focal_class.class_method_signature: AuthenticationManagerImpl.setAuthenticationHandlers(
  			List<AuthenticationHandler> authenticationHandlers)
focal_class.full_signature: public void setAuthenticationHandlers(
  			List<AuthenticationHandler> authenticationHandlers)
focal_class.identifier: setAuthenticationHandlers
focal_class.modifiers: public
focal_class.parameters: (
  			List<AuthenticationHandler> authenticationHandlers)
focal_class.return: void
focal_class.signature: void setAuthenticationHandlers(
  			List<AuthenticationHandler> authenticationHandlers)
focal_class.class_method_signature: AuthenticationManagerImpl.AuthenticationManagerImpl()
focal_class.full_signature: public  AuthenticationManagerImpl()
focal_class.identifier: AuthenticationManagerImpl
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.signature:  AuthenticationManagerImpl()
focal_class.class_method_signature: AuthenticationManagerImpl.authenticate(Credential credential)
focal_class.full_signature: public Authentication authenticate(Credential credential)
focal_class.identifier: authenticate
focal_class.modifiers: public
focal_class.parameters: (Credential credential)
focal_class.return: Authentication
focal_class.signature: Authentication authenticate(Credential credential)
focal_method.body: public Authentication authenticate(Credential credential) throws InvalidCredentialException{
  		//是否找到支持的凭据认证处理器。
  		boolean foundSupported = false;
  		//是否认证通过。
          boolean authenticated = false;
  		//若凭据为空，则跑出异常。
  		if(credential==null){
  			throw new EmptyCredentialException();
  		}
  		
  		//初始化的认证异常信息。
  		AuthenticationException unAuthSupportedHandlerException = InvalidCredentialException.INSTANCE; 
  		
  		//循环调用所有的认证处理器。
  		if(authenticationHandlers!=null && authenticationHandlers.size()>0){
  			for(AuthenticationHandler handler:authenticationHandlers){
  				//认证处理器是否支持该凭据。
  				if(handler.supports(credential)){
  					foundSupported = true;
  					try {
  						authenticated = handler.authenticate(credential);
  						//若认证成功，则跳出循环。
  						if(authenticated){
  							break;
  						}
  					}catch (AuthenticationException e) {
  						unAuthSupportedHandlerException = e;
  					}
  					
  				}
  			}
  		}
  		//未找到支持的认证处理器。
  		if(!foundSupported){
  			throw new UnsupportedCredentialsException();
  		}
  		
  		//若未认证通过，则抛出最后一个异常信息。
  		if(!authenticated){
  			throw unAuthSupportedHandlerException;
  		}
  		
  		Principal principal = null;
  		//初始化是否找到合适的凭据转换器。
  		foundSupported = false;
  		//循环调用所有的用户凭据解析器。
  		if(credentialToPrincipalResolvers!=null && credentialToPrincipalResolvers.size()>0){
  			for(CredentialToPrincipalResolver resolver:credentialToPrincipalResolvers){
  				//用户凭据解析器是否支持该凭据。
  				if(resolver.supports(credential)){
  					foundSupported = true;
  					principal = resolver.resolvePrincipal(credential);
  					//若解析成功，则跳出循环。
  					if(principal!=null){
  						break;
  					}
  				}
  			}
  		}
  		//未找到支持的用户凭据解析器。
  		if(!foundSupported){
  			throw new UnsupportedCredentialsException();
  		}
  		//若认证后处理器对象为空，则抛出异常。
  		if(authenticationPostHandler==null){
  			throw new NoAuthenticationPostHandlerException();
  		}
  		
  		//交由认证后处理器进行处理。
  		return authenticationPostHandler.postAuthentication(credential, principal);
  	}
focal_method.class_method_signature: AuthenticationManagerImpl.authenticate(Credential credential)
focal_method.full_signature: public Authentication authenticate(Credential credential)
focal_method.identifier: authenticate
focal_method.invocations: size supports authenticate size supports resolvePrincipal postAuthentication
focal_method.modifiers: public
focal_method.parameters: (Credential credential)
focal_method.return: Authentication
focal_method.signature: Authentication authenticate(Credential credential)