added method to get client by its (new) Long id

pull/165/merge
Justin Richer 2012-08-10 16:28:56 -04:00
parent 480fb8e593
commit eb5a24690f
4 changed files with 17 additions and 6 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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 {

View File

@ -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");
}