Skip to content

Commit

Permalink
P4ADEV-1102 added removal impl
Browse files Browse the repository at this point in the history
  • Loading branch information
macacia committed Oct 24, 2024
1 parent beb2e03 commit 0f69b8f
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import java.util.List;

public interface ClientRepository extends MongoRepository<Client, String> {

public interface ClientRepository extends ClientRepositoryExt, MongoRepository<Client, String> {
List<Client> findAllByOrganizationIpaCode(String organizationIpaCode);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package it.gov.pagopa.payhub.auth.repository;

public interface ClientRepositoryExt {
void deleteClient(String organizationIpaCode, String clientId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package it.gov.pagopa.payhub.auth.repository;

import it.gov.pagopa.payhub.auth.model.Client;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

public class ClientRepositoryExtImpl implements ClientRepositoryExt {
private final MongoTemplate mongoTemplate;

public ClientRepositoryExtImpl(MongoTemplate mongoTemplate) {
this.mongoTemplate = mongoTemplate;
}

@Override
public void deleteClient(String organizationIpaCode, String clientId) {
//find User with clientId
Client client = mongoTemplate.findOne(Query.query(Criteria.where(Client.Fields.clientId).is(clientId)), Client.class);
//If exists delete Client
if(client != null)
mongoTemplate.remove(
Query.query(Criteria
.where(Client.Fields.organizationIpaCode).is(organizationIpaCode)
.and(Client.Fields.clientId).is(client.getClientId())), Client.class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,6 @@ public List<ClientNoSecretDTO> getClients(String organizationIpaCode) {

@Override
public void revokeClient(String organizationIpaCode, String clientId) {
//TODO implement revoke
clientService.revokeClient(organizationIpaCode, clientId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ public interface ClientService {
String getClientSecret(String organizationIpaCode, String clientId);
List<ClientNoSecretDTO> getClients(String organizationIpaCode);
Optional<Client> getClientByClientId(String clientId);
void revokeClient(String organizationIpaCode, String clientId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import it.gov.pagopa.payhub.auth.model.Client;
import it.gov.pagopa.payhub.auth.service.a2a.registration.ClientRegistrationService;
import it.gov.pagopa.payhub.auth.service.a2a.retrieve.ClientRetrieverService;
import it.gov.pagopa.payhub.auth.service.a2a.revoke.ClientRemovalService;
import it.gov.pagopa.payhub.model.generated.ClientDTO;
import it.gov.pagopa.payhub.model.generated.ClientNoSecretDTO;
import jakarta.transaction.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

Expand All @@ -15,12 +17,13 @@
@Service
@Slf4j
public class ClientServiceImpl implements ClientService {

private final ClientRemovalService clientRemovalService;
private final ClientRegistrationService clientRegistrationService;
private final ClientRetrieverService clientRetrieverService;
private final ClientMapper clientMapper;

public ClientServiceImpl(ClientRegistrationService clientRegistrationService, ClientRetrieverService clientRetrieverService, ClientMapper clientMapper) {
public ClientServiceImpl(ClientRemovalService clientRemovalService, ClientRegistrationService clientRegistrationService, ClientRetrieverService clientRetrieverService, ClientMapper clientMapper) {
this.clientRemovalService = clientRemovalService;
this.clientRegistrationService = clientRegistrationService;
this.clientRetrieverService = clientRetrieverService;
this.clientMapper = clientMapper;
Expand Down Expand Up @@ -49,4 +52,9 @@ public Optional<Client> getClientByClientId(String clientId) {
return clientRetrieverService.getClientByClientId(clientId);
}

@Override
public void revokeClient(String organizationIpaCode, String clientId) {
clientRemovalService.revokeClient(organizationIpaCode, clientId);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package it.gov.pagopa.payhub.auth.service.a2a.revoke;

import it.gov.pagopa.payhub.auth.repository.ClientRepository;
import jakarta.transaction.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class ClientRemovalService {

private final ClientRepository clientRepository;

public ClientRemovalService(ClientRepository clientRepository) {
this.clientRepository = clientRepository;
}

@Transactional
public void revokeClient(String organizationIpaCode, String clientId) {
clientRepository.deleteClient(organizationIpaCode, clientId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import it.gov.pagopa.payhub.auth.model.Client;
import it.gov.pagopa.payhub.auth.service.a2a.registration.ClientRegistrationService;
import it.gov.pagopa.payhub.auth.service.a2a.retrieve.ClientRetrieverService;
import it.gov.pagopa.payhub.auth.service.a2a.revoke.ClientRemovalService;
import it.gov.pagopa.payhub.model.generated.ClientDTO;
import it.gov.pagopa.payhub.model.generated.ClientNoSecretDTO;
import org.junit.jupiter.api.AfterEach;
Expand All @@ -22,6 +23,9 @@
@ExtendWith(MockitoExtension.class)
class ClientServiceTest {

@Mock
private ClientRemovalService clientRemovalServiceMock;

@Mock
private ClientRegistrationService clientRegistrationServiceMock;

Expand All @@ -35,12 +39,13 @@ class ClientServiceTest {

@BeforeEach
void init(){
service = new ClientServiceImpl(clientRegistrationServiceMock, clientRetrieverServiceMock, clientMapperMock);
service = new ClientServiceImpl(clientRemovalServiceMock, clientRegistrationServiceMock, clientRetrieverServiceMock, clientMapperMock);
}

@AfterEach
void verifyNotMoreInteractions(){
Mockito.verifyNoMoreInteractions(
clientRemovalServiceMock,
clientRegistrationServiceMock,
clientRetrieverServiceMock,
clientMapperMock
Expand Down

0 comments on commit 0f69b8f

Please sign in to comment.