这是我的代码。
clientService 实现 ClientDetailsService ,但找不到令牌存储。
如何在自定义(例如数据库)ClientDetailsService?
时存储和获取令牌答案 0 :(得分:0)
当我们有ClientDetailsService
的自定义实现时,我们基本上会覆盖其loadClientByClientId(..)
方法。此方法在参数中使用clientId
,即客户端的用户名。在该自定义实现类中,我们需要做的就是检查数据库中是否存在给定的客户端名称。如果它确实存在,则加载其所有数据并返回该对象。这个类需要注入DAO或Repository的依赖关系来与数据库通信。
@Override
public ClientDetails loadClientByClientId(final String clientId) throws ClientRegistrationException {
Objects.requireNonNull(clientId, "Client ID must not be null");
final com.ex.auth.domain.ClientDetails clientDetails = clientDetailsRepository.findOne(clientId);
if (clientDetails == null) {
throw new NoSuchClientException(String.format("Client %s does not exist.", clientId));
}
return convertToDmo(clientDetails);
}