// Path: ki4so-core/src/main/java/com/github/ebnew/ki4so/core/authentication/DefaultKnightUser.java
// public class DefaultKnightUser extends AbstractKnightUser {
// 
//     public DefaultKnightUser() {
//         super();
//     }
// 
//     public DefaultKnightUser(String id, Map<String, Object> attributes) {
//         super(id, attributes);
//     }
// }
// 
// Path: ki4so-common/src/main/java/com/github/ebnew/ki4so/core/authentication/KnightCredential.java
// public interface KnightCredential {
// 
// 
//     /**
//      * 是否是原始凭据，即未认证过的原始信息
//      *
//      * @return true ：原始凭据，false：加密后的凭据
//      */
//     public boolean isOriginal();
// }
// 
// Path: ki4so-core/src/main/java/com/github/ebnew/ki4so/core/authentication/KnightNamePasswordCredential.java
// public class KnightNamePasswordCredential extends KnightAbstractParameter implements KnightCredential{
//     /**
//      * 用户名
//      */
//     private String username;
// 
//     /**
//      * 密码
//      */
// 
//     private String password;
// 
//     public String getUsername() {
//         return username;
//     }
// 
//     public void setUsername(String username) {
//         this.username = username;
//     }
// 
//     public String getPassword() {
//         return password;
//     }
// 
//     public void setPassword(String password) {
//         this.password = password;
//     }
// 
//     @Override
//     public boolean isOriginal() {
//         return false;
//     }
// }
// 
// Path: ki4so-core/src/main/java/com/github/ebnew/ki4so/core/authentication/KnightUser.java
// public interface KnightUser {
// 
//     public Map<String,Object> getAttributes();
// 
//     public String getId();
// }


import com.github.ebnew.ki4so.core.authentication.DefaultKnightUser;
import com.github.ebnew.ki4so.core.authentication.KnightCredential;
import com.github.ebnew.ki4so.core.authentication.KnightNamePasswordCredential;
import com.github.ebnew.ki4so.core.authentication.KnightUser;

package com.github.ebnew.ki4so.core.authentication.resolvers;


public class UsernamePasswordCredentialToPrincipalResolver implements CredentialToPrincipalResolver{
	
	/** Default class to support if one is not supplied. */
	private static final Class<KnightNamePasswordCredential> DEFAULT_CLASS = KnightNamePasswordCredential.class;

	/** Class that this instance will support. */
	private Class<?> classToSupport = DEFAULT_CLASS;
	
	/**
	 * Boolean to determine whether to support subclasses of the class to
	 * support.
	 */
	private boolean supportSubClasses = true;

	public void setSupportSubClasses(boolean supportSubClasses) {
		this.supportSubClasses = supportSubClasses;
	}

	@Override
	public KnightUser resolvePrincipal(KnightCredential credential) {
		//若类型匹配，则进行转换。
		if(credential!=null && this.supports(credential)){
            KnightNamePasswordCredential usernamePasswordCredential = (KnightNamePasswordCredential)credential;
            DefaultKnightUser principal = new DefaultKnightUser();
			//设置用户名为唯一标识。
			principal.setId(usernamePasswordCredential.getUsername());
			//设置参数表为用户属性。
			principal.setAttributes(usernamePasswordCredential.getParameters());
			return principal;
		}
		return null;
	}

	@Override

// Path: ki4so-core/src/main/java/com/github/ebnew/ki4so/core/authentication/DefaultKnightUser.java
// public class DefaultKnightUser extends AbstractKnightUser {
// 
//     public DefaultKnightUser() {
//         super();
//     }
// 
//     public DefaultKnightUser(String id, Map<String, Object> attributes) {
//         super(id, attributes);
//     }
// }
// 
// Path: ki4so-common/src/main/java/com/github/ebnew/ki4so/core/authentication/KnightCredential.java
// public interface KnightCredential {
// 
// 
//     /**
//      * 是否是原始凭据，即未认证过的原始信息
//      *
//      * @return true ：原始凭据，false：加密后的凭据
//      */
//     public boolean isOriginal();
// }
// 
// Path: ki4so-core/src/main/java/com/github/ebnew/ki4so/core/authentication/KnightNamePasswordCredential.java
// public class KnightNamePasswordCredential extends KnightAbstractParameter implements KnightCredential{
//     /**
//      * 用户名
//      */
//     private String username;
// 
//     /**
//      * 密码
//      */
// 
//     private String password;
// 
//     public String getUsername() {
//         return username;
//     }
// 
//     public void setUsername(String username) {
//         this.username = username;
//     }
// 
//     public String getPassword() {
//         return password;
//     }
// 
//     public void setPassword(String password) {
//         this.password = password;
//     }
// 
//     @Override
//     public boolean isOriginal() {
//         return false;
//     }
// }
// 
// Path: ki4so-core/src/main/java/com/github/ebnew/ki4so/core/authentication/KnightUser.java
// public interface KnightUser {
// 
//     public Map<String,Object> getAttributes();
// 
//     public String getId();
// }


// Path: ki4so-core/src/main/java/com/github/ebnew/ki4so/core/authentication/resolvers/UsernamePasswordCredentialToPrincipalResolver.java
import com.github.ebnew.ki4so.core.authentication.DefaultKnightUser;
import com.github.ebnew.ki4so.core.authentication.KnightCredential;
import com.github.ebnew.ki4so.core.authentication.KnightNamePasswordCredential;
import com.github.ebnew.ki4so.core.authentication.KnightUser;

package com.github.ebnew.ki4so.core.authentication.resolvers;


public class UsernamePasswordCredentialToPrincipalResolver implements CredentialToPrincipalResolver{
	
	/** Default class to support if one is not supplied. */
	private static final Class<KnightNamePasswordCredential> DEFAULT_CLASS = KnightNamePasswordCredential.class;

	/** Class that this instance will support. */
	private Class<?> classToSupport = DEFAULT_CLASS;
	
	/**
	 * Boolean to determine whether to support subclasses of the class to
	 * support.
	 */
	private boolean supportSubClasses = true;

	public void setSupportSubClasses(boolean supportSubClasses) {
		this.supportSubClasses = supportSubClasses;
	}

	@Override
	public KnightUser resolvePrincipal(KnightCredential credential) {
		//若类型匹配，则进行转换。
		if(credential!=null && this.supports(credential)){
            KnightNamePasswordCredential usernamePasswordCredential = (KnightNamePasswordCredential)credential;
            DefaultKnightUser principal = new DefaultKnightUser();
			//设置用户名为唯一标识。
			principal.setId(usernamePasswordCredential.getUsername());
			//设置参数表为用户属性。
			principal.setAttributes(usernamePasswordCredential.getParameters());
			return principal;
		}
		return null;
	}

	@Override

	public boolean supports(KnightCredential credential) {
