added method to get client by its (new) Long id
parent
480fb8e593
commit
eb5a24690f
|
@ -23,7 +23,7 @@ public interface OAuth2ClientRepository {
|
|||
|
||||
public ClientDetailsEntity getById(Long id);
|
||||
|
||||
public ClientDetailsEntity getClientById(String clientId);
|
||||
public ClientDetailsEntity getClientByClientId(String clientId);
|
||||
|
||||
public ClientDetailsEntity saveClient(ClientDetailsEntity client);
|
||||
|
||||
|
|
|
@ -25,6 +25,8 @@ import org.springframework.security.oauth2.provider.ClientDetailsService;
|
|||
|
||||
public interface ClientDetailsEntityService extends ClientDetailsService {
|
||||
|
||||
public ClientDetailsEntity getClientById(Long id);
|
||||
|
||||
public ClientDetailsEntity loadClientByClientId(String clientId) throws OAuth2Exception;
|
||||
|
||||
public void deleteClient(ClientDetailsEntity client);
|
||||
|
|
|
@ -54,7 +54,7 @@ public class JpaOAuth2ClientRepository implements OAuth2ClientRepository {
|
|||
* @see org.mitre.oauth2.repository.OAuth2ClientRepository#getClientById(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public ClientDetailsEntity getClientById(String clientId) {
|
||||
public ClientDetailsEntity getClientByClientId(String clientId) {
|
||||
TypedQuery<ClientDetailsEntity> query = manager.createNamedQuery("ClientDetailsEntity.getByClientId", ClientDetailsEntity.class);
|
||||
query.setParameter("clientId", clientId);
|
||||
return JpaUtil.getSingleResult(query.getResultList());
|
||||
|
@ -73,7 +73,7 @@ public class JpaOAuth2ClientRepository implements OAuth2ClientRepository {
|
|||
*/
|
||||
@Override
|
||||
public void deleteClient(ClientDetailsEntity client) {
|
||||
ClientDetailsEntity found = getClientById(client.getClientId());
|
||||
ClientDetailsEntity found = getClientByClientId(client.getClientId());
|
||||
if (found != null) {
|
||||
manager.remove(found);
|
||||
} else {
|
||||
|
|
|
@ -52,12 +52,21 @@ public class DefaultOAuth2ClientDetailsEntityService implements ClientDetailsEnt
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the client for the given ID
|
||||
* Get the client by its internal ID
|
||||
*/
|
||||
public ClientDetailsEntity getClientById(Long id) {
|
||||
ClientDetailsEntity client = clientRepository.getById(id);
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the client for the given ClientID
|
||||
*/
|
||||
@Override
|
||||
public ClientDetailsEntity loadClientByClientId(String clientId) throws OAuth2Exception, InvalidClientException, IllegalArgumentException {
|
||||
if (!Strings.isNullOrEmpty(clientId)) {
|
||||
ClientDetailsEntity client = clientRepository.getClientById(clientId);
|
||||
ClientDetailsEntity client = clientRepository.getClientByClientId(clientId);
|
||||
if (client == null) {
|
||||
throw new InvalidClientException("Client with id " + clientId + " was not found");
|
||||
}
|
||||
|
@ -75,7 +84,7 @@ public class DefaultOAuth2ClientDetailsEntityService implements ClientDetailsEnt
|
|||
@Override
|
||||
public void deleteClient(ClientDetailsEntity client) throws InvalidClientException {
|
||||
|
||||
if (clientRepository.getClientById(client.getClientId()) == null) {
|
||||
if (clientRepository.getClientByClientId(client.getClientId()) == null) {
|
||||
throw new InvalidClientException("Client with id " + client.getClientId() + " was not found");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue