// Path: ki4so-common/src/main/java/com/github/ebnew/ki4so/core/exception/NoKi4soKeyException.java
// public class NoKi4soKeyException extends AuthenticationException{
// 
// 	/**
// 	 * 
// 	 */
// 	private static final long serialVersionUID = 115935182258831210L;
// 
// 	public static final NoKi4soKeyException INSTANCE = new NoKi4soKeyException();
// 	
// 	/**
// 	 * 异常代码值。
// 	 */
// 	public static final String CODE = "NO.KI4SO.KEY.CODE";
// 	
// 	/**
// 	 * 异常信息键值，要转换为具体的语言值。
// 	 */
// 	public static final String MSG_KEY = "NO.KI4SO.KEY.MSG";
// 	
// 	public NoKi4soKeyException(String code, String msgKey) {
// 		super(code, msgKey);
// 	}
// 	
// 	public NoKi4soKeyException() {
// 		super(CODE, MSG_KEY);
// 	}
// 
// }
// 
// Path: ki4so-common/src/main/java/com/github/ebnew/ki4so/web/utils/WebConstants.java
// public interface WebConstants {
// 	
// 	/**
// 	 * ki4so中心认证服务器写入到用户web客户端cookie中的认证加密后的凭据的键名称。
// 	 */
// 	public static final String KI4SO_SERVER_ENCRYPTED_CREDENTIAL_COOKIE_KEY = "KI4SO_SERVER_EC";
// 	
// 	/**
// 	 * ki4so客户端应用服务器写入到用户web客户端cookie中的认证加密后的凭据的键名称。
// 	 */
// 	public static final String KI4SO_CLIENT_ENCRYPTED_CREDENTIAL_COOKIE_KEY = "KI4SO_CLIENT_EC";
// 	
// 	/**
// 	 * 目的服务地址service的参数名。
// 	 */
// 	public static final String SERVICE_PARAM_NAME = "service";
// 	
// 	/**
// 	 * 目的服务地址存储在session中的key值。
// 	 */
// 	public static final String KI4SO_SERVICE_KEY_IN_SESSION = "KI4SO_SERVICE_KEY";
// 	
// 	/**
// 	 * 用户标识的参数名。
// 	 */
// 	public static final String USER_ID_PARAM_NAME = "userId";
// 
// }


import com.github.ebnew.ki4so.core.app.App;
import com.github.ebnew.ki4so.core.app.AppService;
import com.github.ebnew.ki4so.core.authentication.status.UserLoggedStatusStore;
import com.github.ebnew.ki4so.core.exception.NoKi4soKeyException;
import com.github.ebnew.ki4so.core.key.KeyService;
import com.github.ebnew.ki4so.core.key.Ki4soKey;
import com.github.ebnew.ki4so.core.model.EncryCredentialInfo;
import com.github.ebnew.ki4so.web.utils.WebConstants;
import java.util.HashMap;
import java.util.Map;
import junit.framework.Assert;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
import org.mockito.Mockito;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.github.ebnew.ki4so.core.authentication;


/**
 *
 * @author bidlink
 */
public class DefaultAuthenticationPostHandlerTest {

    private DefaultAuthenticationPostHandler handler;

    public DefaultAuthenticationPostHandlerTest() {
    }

    @BeforeClass
    public static void setUpClass() {

    }

    @AfterClass
    public static void tearDownClass() {
    }

    @Before
    public void setUp() {
        handler = new DefaultAuthenticationPostHandler();
    }

    @After
    public void tearDown() {
    }

    // TODO add test methods here.
    // The methods must be annotated with annotation @Test. For example:
    //
    @Test
    public void testPostAuthentication() {

        /**
         * 测试传入错误参数的情况。
         */
        Authentication authentication = this.handler.postAuthentication(null, null);
        assertNotNull(authentication);
        Assert.assertNull(authentication.getPrincipal());

        /**
         * 测试参数正确的情况，但是ki4so 服务器的app对象为空的情况。
         */
        String username = "test";
        String password = "pwdsssss";
        UsernamePasswordCredential credential = new UsernamePasswordCredential(username, password);

// Path: ki4so-common/src/main/java/com/github/ebnew/ki4so/core/exception/NoKi4soKeyException.java
// public class NoKi4soKeyException extends AuthenticationException{
// 
// 	/**
// 	 * 
// 	 */
// 	private static final long serialVersionUID = 115935182258831210L;
// 
// 	public static final NoKi4soKeyException INSTANCE = new NoKi4soKeyException();
// 	
// 	/**
// 	 * 异常代码值。
// 	 */
// 	public static final String CODE = "NO.KI4SO.KEY.CODE";
// 	
// 	/**
// 	 * 异常信息键值，要转换为具体的语言值。
// 	 */
// 	public static final String MSG_KEY = "NO.KI4SO.KEY.MSG";
// 	
// 	public NoKi4soKeyException(String code, String msgKey) {
// 		super(code, msgKey);
// 	}
// 	
// 	public NoKi4soKeyException() {
// 		super(CODE, MSG_KEY);
// 	}
// 
// }
// 
// Path: ki4so-common/src/main/java/com/github/ebnew/ki4so/web/utils/WebConstants.java
// public interface WebConstants {
// 	
// 	/**
// 	 * ki4so中心认证服务器写入到用户web客户端cookie中的认证加密后的凭据的键名称。
// 	 */
// 	public static final String KI4SO_SERVER_ENCRYPTED_CREDENTIAL_COOKIE_KEY = "KI4SO_SERVER_EC";
// 	
// 	/**
// 	 * ki4so客户端应用服务器写入到用户web客户端cookie中的认证加密后的凭据的键名称。
// 	 */
// 	public static final String KI4SO_CLIENT_ENCRYPTED_CREDENTIAL_COOKIE_KEY = "KI4SO_CLIENT_EC";
// 	
// 	/**
// 	 * 目的服务地址service的参数名。
// 	 */
// 	public static final String SERVICE_PARAM_NAME = "service";
// 	
// 	/**
// 	 * 目的服务地址存储在session中的key值。
// 	 */
// 	public static final String KI4SO_SERVICE_KEY_IN_SESSION = "KI4SO_SERVICE_KEY";
// 	
// 	/**
// 	 * 用户标识的参数名。
// 	 */
// 	public static final String USER_ID_PARAM_NAME = "userId";
// 
// }


// Path: ki4so-core/src/test/java/com/github/ebnew/ki4so/core/authentication/DefaultAuthenticationPostHandlerTest.java
import com.github.ebnew.ki4so.core.app.App;
import com.github.ebnew.ki4so.core.app.AppService;
import com.github.ebnew.ki4so.core.authentication.status.UserLoggedStatusStore;
import com.github.ebnew.ki4so.core.exception.NoKi4soKeyException;
import com.github.ebnew.ki4so.core.key.KeyService;
import com.github.ebnew.ki4so.core.key.Ki4soKey;
import com.github.ebnew.ki4so.core.model.EncryCredentialInfo;
import com.github.ebnew.ki4so.web.utils.WebConstants;
import java.util.HashMap;
import java.util.Map;
import junit.framework.Assert;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
import org.mockito.Mockito;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.github.ebnew.ki4so.core.authentication;


/**
 *
 * @author bidlink
 */
public class DefaultAuthenticationPostHandlerTest {

    private DefaultAuthenticationPostHandler handler;

    public DefaultAuthenticationPostHandlerTest() {
    }

    @BeforeClass
    public static void setUpClass() {

    }

    @AfterClass
    public static void tearDownClass() {
    }

    @Before
    public void setUp() {
        handler = new DefaultAuthenticationPostHandler();
    }

    @After
    public void tearDown() {
    }

    // TODO add test methods here.
    // The methods must be annotated with annotation @Test. For example:
    //
    @Test
    public void testPostAuthentication() {

        /**
         * 测试传入错误参数的情况。
         */
        Authentication authentication = this.handler.postAuthentication(null, null);
        assertNotNull(authentication);
        Assert.assertNull(authentication.getPrincipal());

        /**
         * 测试参数正确的情况，但是ki4so 服务器的app对象为空的情况。
         */
        String username = "test";
        String password = "pwdsssss";
        UsernamePasswordCredential credential = new UsernamePasswordCredential(username, password);

        DefaultUserPrincipal principal = new DefaultUserPrincipal();
