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 getById(Long id);
|
||||||
|
|
||||||
public ClientDetailsEntity getClientById(String clientId);
|
public ClientDetailsEntity getClientByClientId(String clientId);
|
||||||
|
|
||||||
public ClientDetailsEntity saveClient(ClientDetailsEntity client);
|
public ClientDetailsEntity saveClient(ClientDetailsEntity client);
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,8 @@ import org.springframework.security.oauth2.provider.ClientDetailsService;
|
||||||
|
|
||||||
public interface ClientDetailsEntityService extends ClientDetailsService {
|
public interface ClientDetailsEntityService extends ClientDetailsService {
|
||||||
|
|
||||||
|
public ClientDetailsEntity getClientById(Long id);
|
||||||
|
|
||||||
public ClientDetailsEntity loadClientByClientId(String clientId) throws OAuth2Exception;
|
public ClientDetailsEntity loadClientByClientId(String clientId) throws OAuth2Exception;
|
||||||
|
|
||||||
public void deleteClient(ClientDetailsEntity client);
|
public void deleteClient(ClientDetailsEntity client);
|
||||||
|
|
|
@ -54,7 +54,7 @@ public class JpaOAuth2ClientRepository implements OAuth2ClientRepository {
|
||||||
* @see org.mitre.oauth2.repository.OAuth2ClientRepository#getClientById(java.lang.String)
|
* @see org.mitre.oauth2.repository.OAuth2ClientRepository#getClientById(java.lang.String)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ClientDetailsEntity getClientById(String clientId) {
|
public ClientDetailsEntity getClientByClientId(String clientId) {
|
||||||
TypedQuery<ClientDetailsEntity> query = manager.createNamedQuery("ClientDetailsEntity.getByClientId", ClientDetailsEntity.class);
|
TypedQuery<ClientDetailsEntity> query = manager.createNamedQuery("ClientDetailsEntity.getByClientId", ClientDetailsEntity.class);
|
||||||
query.setParameter("clientId", clientId);
|
query.setParameter("clientId", clientId);
|
||||||
return JpaUtil.getSingleResult(query.getResultList());
|
return JpaUtil.getSingleResult(query.getResultList());
|
||||||
|
@ -73,7 +73,7 @@ public class JpaOAuth2ClientRepository implements OAuth2ClientRepository {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void deleteClient(ClientDetailsEntity client) {
|
public void deleteClient(ClientDetailsEntity client) {
|
||||||
ClientDetailsEntity found = getClientById(client.getClientId());
|
ClientDetailsEntity found = getClientByClientId(client.getClientId());
|
||||||
if (found != null) {
|
if (found != null) {
|
||||||
manager.remove(found);
|
manager.remove(found);
|
||||||
} else {
|
} 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
|
@Override
|
||||||
public ClientDetailsEntity loadClientByClientId(String clientId) throws OAuth2Exception, InvalidClientException, IllegalArgumentException {
|
public ClientDetailsEntity loadClientByClientId(String clientId) throws OAuth2Exception, InvalidClientException, IllegalArgumentException {
|
||||||
if (!Strings.isNullOrEmpty(clientId)) {
|
if (!Strings.isNullOrEmpty(clientId)) {
|
||||||
ClientDetailsEntity client = clientRepository.getClientById(clientId);
|
ClientDetailsEntity client = clientRepository.getClientByClientId(clientId);
|
||||||
if (client == null) {
|
if (client == null) {
|
||||||
throw new InvalidClientException("Client with id " + clientId + " was not found");
|
throw new InvalidClientException("Client with id " + clientId + " was not found");
|
||||||
}
|
}
|
||||||
|
@ -75,7 +84,7 @@ public class DefaultOAuth2ClientDetailsEntityService implements ClientDetailsEnt
|
||||||
@Override
|
@Override
|
||||||
public void deleteClient(ClientDetailsEntity client) throws InvalidClientException {
|
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");
|
throw new InvalidClientException("Client with id " + client.getClientId() + " was not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue