Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions src/main/java/com/mastercard/app/petstore/PetstoreApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,6 @@ public class PetstoreApplication {
@Autowired
EmployeeFlowExample employeeFlowExample;

@Bean
PetFlowExample petFlowExample() {
petFlowExample = new PetFlowExample();
return petFlowExample;
}

@Bean
AdoptionFlowExample adoptionFlowExample() {
adoptionFlowExample = new AdoptionFlowExample();
return adoptionFlowExample;
}

@Bean
EmployeeFlowExample employeeFlowExample() {
employeeFlowExample = new EmployeeFlowExample();
return employeeFlowExample;
}

@Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,27 @@
* The type Adoption flow example.
*/

@ComponentScan(basePackages = {"com.mastercard.app.petstore.utils"})
@Component("AdoptionFLowExample")
public class AdoptionFlowExample {

@Autowired
private AdoptionsService adoptionsService;
@Autowired
private CatService catService;

/**
* Constructs an instance of {@code AdoptionFlowExample} with required dependencies.
* <p>
* This constructor is annotated with {@link org.springframework.beans.factory.annotation.Autowired}
* so that Spring can automatically inject the required beans at runtime.
* </p>
*
* @param adoptionsService the service responsible for handling adoption operations
* @param catService the service responsible for managing cat-related operations
*/
@Autowired
public AdoptionFlowExample(AdoptionsService adoptionsService, CatService catService){
this.adoptionsService = adoptionsService;
this.catService = catService;
}
/**
* Adoption use case. Shows a typical adding an adoption, adopting pet, updating status and then removing it
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,26 @@
/**
* The type Employee flow example.
*/

@ComponentScan(basePackages = {"com.mastercard.app.petstore.utils"})
@Component("EmployeeFlowExample")
public class EmployeeFlowExample {

@Autowired
private EmployeeService employeeService;

/**
* Constructs a new {@code EmployeeFlowExample} with the required service dependency.
* <p>
* This constructor is annotated with {@link org.springframework.beans.factory.annotation.Autowired},
* allowing Spring to automatically inject the {@link EmployeeService} bean at runtime.
* The service is then used to perform operations related to employees within the flow example.
* </p>
*
* @param employeeService the service responsible for managing employee-related operations
*/
@Autowired
public EmployeeFlowExample(EmployeeService employeeService){
this.employeeService = employeeService;
}

/**
* Employee use case. Show add a new employee, searching for their information, then removing them.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,28 @@
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;

@ComponentScan(basePackages = {"com.mastercard.app.petstore.utils"})
@Component("PetFlowExample")
public class PetFlowExample {

@Autowired
private CatService catService;
@Autowired
private PetService petService;

/**
* Constructs a new {@code PetFlowExample} with the required service dependencies.
* <p>
* This constructor is annotated with {@link org.springframework.beans.factory.annotation.Autowired},
* allowing Spring to automatically inject the {@link CatService} and {@link PetService} beans
* at runtime. These services are then used to perform operations related to cats and pets
* within the flow example.
* </p>
*
* @param catService the service responsible for managing cat-related operations
* @param petService the service responsible for managing general pet-related operations
*/
@Autowired
public PetFlowExample(CatService catService, PetService petService){
this.catService = catService;
this.petService=petService;
}
/**
* Pet use case flow. Shows creating a cat, updating their status and then removing them
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.mastercard.developer.encryption.EncryptionException;
import com.mastercard.developer.encryption.JweConfigBuilder;
import com.mastercard.developer.utils.EncryptionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;

Expand All @@ -15,15 +16,39 @@
@org.springframework.context.annotation.Configuration
public class JweEncryptionUtils {

@Value("${mastercard.encryption.encryptionCert}")
private String encryptionCertificateFilePath;
@Value("${mastercard.encryption.decryptionKeys}")
private String decryptionKeyFilePath;
@Value("${mastercard.encryption.decryptionKeyAlias}")
private String decryptionKeyAlias;
@Value("${mastercard.encryption.decryptionKeyPassword}")
private String decryptionKeyPassword;
private final String encryptionCertificateFilePath;

private final String decryptionKeyFilePath;

private final String decryptionKeyAlias;

private final String decryptionKeyPassword;

@Autowired
public JweEncryptionUtils(
@Value("${mastercard.encryption.encryptionCert}") String encryptionCertificateFilePath,
@Value("${mastercard.encryption.decryptionKeys") String decryptionKeyFilePath,
@Value("${mastercard.encryption.decryptionKeyAlias}") String decryptionKeyAlias,
@Value("${mastercard.encryption.decryptionKeyPassword}") String decryptionKeyPassword
)
{
if (encryptionCertificateFilePath.isEmpty()){
throw new IllegalArgumentException("encryptionCert in application.properties is empty");
}
this.encryptionCertificateFilePath = encryptionCertificateFilePath;
if (decryptionKeyFilePath.isEmpty()){
throw new IllegalArgumentException("decryptionKeys in application.properties is empty");
}
this.decryptionKeyFilePath = decryptionKeyFilePath;
if (decryptionKeyAlias.isEmpty()){
throw new IllegalArgumentException("decryptionKeyAlias in application.properties is empty");
}
this.decryptionKeyAlias = decryptionKeyAlias;
if (decryptionKeyPassword.isEmpty()){
throw new IllegalArgumentException("decryptionKeyPassword in application.properties is empty");
}
this.decryptionKeyPassword = decryptionKeyPassword;
}
/**
* Sets field level encryption config for adoptions.
*
Expand All @@ -35,7 +60,6 @@ public class JweEncryptionUtils {
*/
@Bean
public EncryptionConfig fieldLevelEncryptionConfigForAdoptions() throws EncryptionException, GeneralSecurityException, IOException {
checkProperties();
Certificate encryptionCertificate = EncryptionUtils.loadEncryptionCertificate(encryptionCertificateFilePath);
PrivateKey decryptionKey = EncryptionUtils.loadDecryptionKey(decryptionKeyFilePath, decryptionKeyAlias, decryptionKeyPassword);

Expand All @@ -59,7 +83,6 @@ public EncryptionConfig fieldLevelEncryptionConfigForAdoptions() throws Encrypti
*/
@Bean
public EncryptionConfig fullBodyEncryptionConfig() throws EncryptionException, GeneralSecurityException, IOException {
checkProperties();
Certificate encryptionCertificate = EncryptionUtils.loadEncryptionCertificate(encryptionCertificateFilePath);
PrivateKey decryptionKey = EncryptionUtils.loadDecryptionKey(decryptionKeyFilePath, decryptionKeyAlias, decryptionKeyPassword);

Expand All @@ -70,19 +93,4 @@ public EncryptionConfig fullBodyEncryptionConfig() throws EncryptionException, G
.withDecryptionKey(decryptionKey)
.build();
}

private void checkProperties() {
if (encryptionCertificateFilePath.isEmpty()){
throw new IllegalArgumentException("encryptionCert in application.properties is empty");
}
if (decryptionKeyFilePath.isEmpty()){
throw new IllegalArgumentException("decryptionKeys in application.properties is empty");
}
if (decryptionKeyAlias.isEmpty()){
throw new IllegalArgumentException("decryptionKeyAlias in application.properties is empty");
}
if (decryptionKeyPassword.isEmpty()){
throw new IllegalArgumentException("decryptionKeyPassword in application.properties is empty");
}
}
}