matrix.business.oauth2.service.impl.DefaultClientDetailServiceImpl Maven / Gradle / Ivy
package matrix.business.oauth2.service.impl;
import matrix.boot.based.utils.WebUtil;
import matrix.business.common.utils.SqlUtil;
import matrix.business.oauth2.dto.DefaultClientDetailDto;
import matrix.business.oauth2.service.DefaultClientDetailService;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.security.oauth2.provider.ClientRegistrationException;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* 默认的客户端验证器
*
* @author wangcheng
* date 2021/8/30
*/
public class DefaultClientDetailServiceImpl implements DefaultClientDetailService {
@Override
public ClientDetails loadClientByClientId(String clientId) throws ClientRegistrationException {
List list = getByClientIds(Collections.singletonList(clientId));
if (CollectionUtils.isEmpty(list)) {
throw new ClientRegistrationException(clientId + " not found");
}
return list.get(0);
}
@Override
public List getByClientIds(List clientIds) {
if (CollectionUtils.isEmpty(clientIds)) {
return new ArrayList<>();
}
//获取执行模板
JdbcTemplate jdbcTemplate = WebUtil.getBean(JdbcTemplate.class);
//组装sql
String querySql = String.format("%s WHERE client_id IN (%s)",
SqlUtil.getSql("select_oauth2_client_table.sql"), String.join(",", SqlUtil.getPlaceholder(clientIds.size())));
return jdbcTemplate.query(querySql, new BeanPropertyRowMapper<>(DefaultClientDetailDto.class), clientIds.toArray());
}
}