Skip to content

Commit

Permalink
feat: added azure key strategy and get token section (#13)
Browse files Browse the repository at this point in the history
Co-authored-by: Vitolo-Andrea <[email protected]>
Co-authored-by: DanieleRanaldo <[email protected]>
  • Loading branch information
3 people authored Dec 2, 2024
1 parent 2d91a5e commit 13846ba
Show file tree
Hide file tree
Showing 27 changed files with 1,380 additions and 177 deletions.
7 changes: 6 additions & 1 deletion .spectral.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ overrides:
- "src/main/resources/META-INF/openapi.yaml#/paths/~1.well-known~1jwks.json/get/security"
- "src/main/resources/META-INF/openapi.yaml#/paths/~1.well-known~1openid-configuration/get/security"
rules:
owasp:api2:2023-read-restricted: "off"
owasp:api2:2023-read-restricted: "off"
- files:
- "src/main/resources/META-INF/openapi.yaml"
rules:
owasp:api3:2023-no-additionalProperties: "off"
owasp:api3:2023-constrained-additionalProperties: "off"
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-security-keyvault-keys</artifactId>
<version>4.8.7</version>
</dependency>
</dependencies>

<dependencyManagement>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/it/gov/pagopa/tpp/EmdTpp.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package it.gov.pagopa.tpp;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@Slf4j
@SpringBootApplication(scanBasePackages = "it.gov.pagopa")
public class EmdTpp {

Expand Down
33 changes: 25 additions & 8 deletions src/main/java/it/gov/pagopa/tpp/controller/TppController.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package it.gov.pagopa.tpp.controller;

import it.gov.pagopa.tpp.dto.TppDTO;
import it.gov.pagopa.tpp.dto.TppIdList;
import it.gov.pagopa.tpp.dto.TppUpdateState;
import it.gov.pagopa.tpp.dto.*;
import jakarta.validation.Valid;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.util.List;

@RestController
@RequestMapping("/emd/tpp")
public interface TppController {
Expand All @@ -22,7 +21,6 @@ public interface TppController {
@PostMapping("/list")
Mono<ResponseEntity<List<TppDTO>>> getEnabledList(@Valid @RequestBody TppIdList tppIdList);


/**
* Update a tpp
*
Expand All @@ -41,17 +39,36 @@ public interface TppController {
@PostMapping("/save")
Mono<ResponseEntity<TppDTO>> save(@Valid @RequestBody TppDTO tppDTO);


@PutMapping("/update")
Mono<ResponseEntity<TppDTO>> update(@Valid @RequestBody TppDTO tppDTO);
Mono<ResponseEntity<TppDTOWithoutTokenSection>> updateTppDetails(@Valid @RequestBody TppDTOWithoutTokenSection tppDTOWithoutTokenSection);

/**
* Update TokenSection of a TPP
*
* @param tppId of the TPP to update
* @param tokenSectionDTO updated token section
* @return outcome of the update
*/
@PutMapping("/update/{tppId}/token")
Mono<ResponseEntity<TokenSectionDTO>> updateTokenSection(@Valid @PathVariable String tppId, @Valid @RequestBody TokenSectionDTO tokenSectionDTO);

/**
* Get a tpp
* Get a tpp (without token section)
*
* @param tppId to get
* @return outcome of getting tpp
* @return outcome of getting tpp
*/
@GetMapping("/{tppId}")
Mono<ResponseEntity<TppDTO>> get(@Valid @PathVariable String tppId);
Mono<ResponseEntity<TppDTOWithoutTokenSection>> getTppDetails(@Valid @PathVariable String tppId);

/**
* Get TokenSection of a TPP
*
* @param tppId to get token section
* @return outcome of getting token section
*/
@GetMapping("/{tppId}/token")
Mono<ResponseEntity<TokenSectionDTO>> getTokenSection(@Valid @PathVariable String tppId);

}
31 changes: 19 additions & 12 deletions src/main/java/it/gov/pagopa/tpp/controller/TppControllerImpl.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package it.gov.pagopa.tpp.controller;

import it.gov.pagopa.tpp.dto.TppDTO;
import it.gov.pagopa.tpp.dto.TppIdList;
import it.gov.pagopa.tpp.dto.TppUpdateState;
import it.gov.pagopa.tpp.dto.*;
import it.gov.pagopa.tpp.service.TppServiceImpl;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -20,36 +18,45 @@ public TppControllerImpl(TppServiceImpl tppService) {
this.tppService = tppService;
}


@Override
public Mono<ResponseEntity<List<TppDTO>>> getEnabledList(TppIdList tppIdList) {
return tppService.getEnabledList(tppIdList.getIds())
.map(ResponseEntity::ok);
}


@Override
public Mono<ResponseEntity<TppDTO>> updateState(TppUpdateState tppUpdateState) {
return tppService.updateState(tppUpdateState.getTppId(),tppUpdateState.getState())
return tppService.updateState(tppUpdateState.getTppId(), tppUpdateState.getState())
.map(ResponseEntity::ok);

}

@Override
public Mono<ResponseEntity<TppDTO>> save(TppDTO tppDTO) {
return tppService.createNewTpp(tppDTO, String.format("%s_%d", UUID.randomUUID(), System.currentTimeMillis()))
return tppService.createNewTpp(tppDTO, String.format("%s-%d", UUID.randomUUID(), System.currentTimeMillis()))
.map(ResponseEntity::ok);
}

@Override
public Mono<ResponseEntity<TppDTOWithoutTokenSection>> updateTppDetails(TppDTOWithoutTokenSection tppDTOWithoutTokenSection) {
return tppService.updateTppDetails(tppDTOWithoutTokenSection)
.map(ResponseEntity::ok);
}

@Override
public Mono<ResponseEntity<TokenSectionDTO>> updateTokenSection(String tppId, TokenSectionDTO tokenSectionDTO) {
return tppService.updateTokenSection(tppId, tokenSectionDTO)
.map(ResponseEntity::ok);
}

@Override
public Mono<ResponseEntity<TppDTO>> update(TppDTO tppDTO) {
return tppService.updateExistingTpp(tppDTO)
public Mono<ResponseEntity<TppDTOWithoutTokenSection>> getTppDetails(String tppId) {
return tppService.getTppDetails(tppId)
.map(ResponseEntity::ok);
}

@Override
public Mono<ResponseEntity<TppDTO>> get(String tppId) {
return tppService.get(tppId)
public Mono<ResponseEntity<TokenSectionDTO>> getTokenSection(String tppId) {
return tppService.getTokenSection(tppId)
.map(ResponseEntity::ok);
}

Expand Down
16 changes: 16 additions & 0 deletions src/main/java/it/gov/pagopa/tpp/dto/TokenSectionDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package it.gov.pagopa.tpp.dto;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.util.Map;

@Data
@SuperBuilder
@NoArgsConstructor
public class TokenSectionDTO {
private String contentType;
private Map<String, String> pathAdditionalProperties;
private Map<String, String> bodyAdditionalProperties;
}
1 change: 0 additions & 1 deletion src/main/java/it/gov/pagopa/tpp/dto/TppDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,4 @@ public class TppDTO {
private LocalDateTime lastUpdateDate;
private TokenSection tokenSection;


}
47 changes: 47 additions & 0 deletions src/main/java/it/gov/pagopa/tpp/dto/TppDTOWithoutTokenSection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package it.gov.pagopa.tpp.dto;

import it.gov.pagopa.tpp.enums.AuthenticationType;
import it.gov.pagopa.tpp.model.Contact;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.time.LocalDateTime;

@Data
@SuperBuilder
@NoArgsConstructor
public class TppDTOWithoutTokenSection {
private String tppId;

@NotBlank(message = "Entity ID must not be blank")
@Pattern(regexp = "^(\\d{11}|[A-Za-z0-9]{16})$", message = "Entity ID must be 11 digits or up to 16 alphanumeric characters")
private String entityId;

@NotBlank(message = "ID PSP must not be blank")
private String idPsp;

@NotBlank(message = "Business name must not be blank")
private String businessName;

@NotBlank(message = "Legal address must not be blank")
private String legalAddress;

@Pattern(regexp = "^(https?|ftp)://[^ /$.?#].[^ ]*$", message = "Message URL must be a valid URL")
private String messageUrl;

@Pattern(regexp = "^(https?|ftp)://[^ /$.?#].[^ ]*$", message = "Authentication URL must be a valid URL")
private String authenticationUrl;

@NotNull(message = "Authentication type must not be null")
private AuthenticationType authenticationType;

@NotNull(message = "Contact must not be null")
private Contact contact;
private Boolean state;
private LocalDateTime creationDate;
private LocalDateTime lastUpdateDate;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package it.gov.pagopa.tpp.dto.mapper;

import it.gov.pagopa.tpp.dto.TokenSectionDTO;
import it.gov.pagopa.tpp.model.TokenSection;
import org.springframework.stereotype.Service;

@Service
public class TokenSectionObjectToDTOMapper {

public TokenSectionDTO map(TokenSection tokenSection) {
return TokenSectionDTO.builder()
.contentType(tokenSection.getContentType())
.pathAdditionalProperties(tokenSection.getPathAdditionalProperties())
.bodyAdditionalProperties(tokenSection.getBodyAdditionalProperties())
.build();

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package it.gov.pagopa.tpp.dto.mapper;

import it.gov.pagopa.tpp.dto.TppDTOWithoutTokenSection;
import it.gov.pagopa.tpp.model.Tpp;
import org.springframework.stereotype.Service;

@Service
public class TppWithoutTokenSectionObjectToDTOMapper {

public TppDTOWithoutTokenSection map(Tpp tpp){
return TppDTOWithoutTokenSection.builder()
.state(tpp.getState())
.messageUrl(tpp.getMessageUrl())
.authenticationUrl(tpp.getAuthenticationUrl())
.authenticationType(tpp.getAuthenticationType())
.tppId(tpp.getTppId())
.idPsp(tpp.getIdPsp())
.legalAddress(tpp.getLegalAddress())
.businessName(tpp.getBusinessName())
.contact(tpp.getContact())
.entityId(tpp.getEntityId())
.creationDate(tpp.getCreationDate())
.lastUpdateDate(tpp.getLastUpdateDate())
.build();
}
}
3 changes: 3 additions & 0 deletions src/main/java/it/gov/pagopa/tpp/model/TokenSection.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.util.Map;

@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
public class TokenSection {
private String contentType;
private Map<String, String> pathAdditionalProperties;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/it/gov/pagopa/tpp/model/Tpp.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@

import it.gov.pagopa.tpp.enums.AuthenticationType;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.springframework.data.mongodb.core.mapping.Document;

import java.time.LocalDateTime;

@Document(collection = "tpp")
@Data
@NoArgsConstructor
@SuperBuilder
public class Tpp {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package it.gov.pagopa.tpp.model.mapper;

import it.gov.pagopa.tpp.dto.TokenSectionDTO;
import it.gov.pagopa.tpp.model.TokenSection;
import org.springframework.stereotype.Service;

@Service
public class TokenSectionDTOToObjectMapper {

public TokenSection map(TokenSectionDTO tokenSectionDTO) {
return new TokenSection(
tokenSectionDTO.getContentType(),
tokenSectionDTO.getPathAdditionalProperties(),
tokenSectionDTO.getBodyAdditionalProperties()
);
}
}
11 changes: 9 additions & 2 deletions src/main/java/it/gov/pagopa/tpp/service/TppService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package it.gov.pagopa.tpp.service;

import it.gov.pagopa.tpp.dto.TokenSectionDTO;
import it.gov.pagopa.tpp.dto.TppDTO;
import it.gov.pagopa.tpp.dto.TppDTOWithoutTokenSection;
import reactor.core.publisher.Mono;

import java.util.List;
Expand All @@ -11,9 +13,14 @@ public interface TppService {

Mono<TppDTO> createNewTpp(TppDTO tppDTO, String tppId);

Mono<TppDTO> updateExistingTpp(TppDTO tppDTO);
Mono<TppDTOWithoutTokenSection> updateTppDetails(TppDTOWithoutTokenSection tppDTOWithoutTokenSection);

Mono<TokenSectionDTO> updateTokenSection(String tppId, TokenSectionDTO tokenSectionDTO);

Mono<TppDTO> updateState(String tppId, Boolean state);

Mono<TppDTO> get(String tppId);
Mono<TppDTOWithoutTokenSection> getTppDetails(String tppId);

Mono<TokenSectionDTO> getTokenSection(String tppId);

}
Loading

0 comments on commit 13846ba

Please sign in to comment.