package com.kxs.common.security.service;

import com.kxs.common.security.model.KxsUser;
import org.springframework.core.Ordered;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;

/**
 * @author 没秃顶的码农
 * @date 2021/12/21
 */
public interface KxsUserDetailsService extends UserDetailsService, Ordered {

	/**
	 * 是否支持此客户端校验
	 * @param clientId 目标客户端
	 * @return true/false
	 */
	default boolean support(String clientId, String grantType) {
		return true;
	}

	/**
	 * 排序值 默认取最大的
	 * @return 排序值
	 */
	@Override
	default int getOrder() {
		return 0;
	}

	/**
	 * 通过用户实体查询
	 * @param kxsUser user
	 * @return 用户详细信息
	 */
	default UserDetails loadUserByUser(KxsUser kxsUser) {
		return this.loadUserByUsername(kxsUser.getUsername());
	}

}
