Пример #1
0
  @Test // if parts user Details are Encrypted
  public void testValidatedUserDetailsEncryption() {

    CustomerDTO validatingUser = new CustomerDTO();
    validatingUser.setDateOfBirth(
        DateUtil.formatDate(ApplicationContants.DATE_OF_BIRTH_FORMAT, "12/12/1979"));
    PaymentDetailsDTO validatingPaymentsDTO = new PaymentDetailsDTO();
    validatingPaymentsDTO.setPaymentType(PaymentType.CREDIT_CARD.getPaymentType());
    validatingPaymentsDTO.setValue("111111111111");
    validatingUser.setPaymentDetails(validatingPaymentsDTO);

    validatingUser.setEncryptionModule(encryptionModule);

    customer.encryptUserInformation();
    validatingUser.encryptUserInformation();

    ApplicationSpecification<CustomerDTO> userDetailsSpecification =
        new EncryptedUserInformationSpecification(customer);
    assertTrue(
        "User details not encrypted properly",
        userDetailsSpecification.isSatisfiedBy(validatingUser));
  }
Пример #2
0
  // Scenario Registration Customer
  @Before
  public void init() {

    // initializeSpring
    context = new ClassPathXmlApplicationContext("res/spring/application-context-test.xml");
    customer = context.getBean(CustomerDTO.class);
    logonCredentialsDTO = context.getBean(CapturedCredentialsDTO.class);
    encryptionModule = context.getBean(EncryptionModule.class);
    paymentDetailsDTO = context.getBean(PaymentDetailsDTO.class);
    contactInforMationDTO = context.getBean(ContactInformationDTO.class);
    customerRepository = context.getBean(CustomerRepository.class);

    customer.setFirstName("Samuel");
    customer.setLastname("Sam");
    customer.setDateOfBirth(
        DateUtil.formatDate(ApplicationContants.DATE_OF_BIRTH_FORMAT, "12/12/1979"));

    // customer payment details
    paymentDetailsDTO.setPaymentType(PaymentType.CREDIT_CARD.getPaymentType());
    paymentDetailsDTO.setValue("111111111111");
    customer.setPaymentDetails(paymentDetailsDTO);

    contactInforMationDTO.setContactType(ContactType.EMAIL.getContactType());
    contactInforMationDTO.setContactValue("*****@*****.**");
    customer.setContactDetails(contactInforMationDTO);

    // set Encryption model
    customer.setEncryptionModule(encryptionModule);

    // Captured Credentials to validate Password and Captured Password;
    logonCredentialsDTO.setUserName("userName");
    logonCredentialsDTO.setPassword("password");
    logonCredentialsDTO.setConfirmPasword("p@ssword!");

    // Use a dynamic proxy to lookup for interface
    userManagerImpl = new UserManagerImpl(customerRepository);
    userManager = new APSMockObjectGenerator<UserManagerImpl>().mock(userManagerImpl);
  }
Пример #3
0
  @Test // test if insertion happened successfully and the insert Specification is met
  public void testRegisterUser() throws ApplicationException {

    ApplicationSpecification<CapturedCredentialsDTO> capturedCredentials =
        new CapturedCredentialsSpecification(logonCredentialsDTO);
    CapturedCredentialsDTO validationCredentials = new CapturedCredentialsDTO();
    validationCredentials.setUserName("userName");
    validationCredentials.setPassword("password");
    validationCredentials.setConfirmPasword("password");

    try {
      Thread.currentThread();
      Thread.sleep(1000);
    } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    System.out.println(
        "***************************** 1. User Registration Process *****************************");
    System.out.println("   ");
    System.out.println("1. Validating Password and Confirm Password   ");
    System.out.println("");
    System.out.println("Password         = "******"Confirm Password = "******"");
    System.out.println("Appliying validate captured credentials specification");
    System.out.println();
    System.out.println(
        "Validation Results = " + capturedCredentials.isSatisfiedBy(validationCredentials));
    System.out.println("");
    System.out.println("");
    System.out.println("Correcting the Confirm Password");
    System.out.println("");
    logonCredentialsDTO.setConfirmPasword(validationCredentials.getConfirmPasword());
    System.out.println("Uptated the Confirm Password");
    System.out.println("");
    System.out.println("Password         = "******"Confirm Password = "******"");
    System.out.println("Appliying validate captured credentials specification again.");
    System.out.println("");
    System.out.println(
        "Validation Results = " + capturedCredentials.isSatisfiedBy(validationCredentials));
    System.out.println("");
    System.out.println("");

    // For Presentation
    // 1.  Validate captured Password and CapturedPassword.
    if (capturedCredentials.isSatisfiedBy(logonCredentialsDTO)) {
      System.out.println("Captured Password and Confirm Password are valid");

      System.out.println("");
      System.out.println(
          "*********************************************************************************");
      System.out.println("");
      System.out.println(
          "**************** 2. User Information Encryption Process **************************");
      System.out.println("");
      System.out.println("Unencrypted data ");
      System.out.println("");

      CustomerDTO validatingUser = new CustomerDTO();
      validatingUser.setDateOfBirth(
          DateUtil.formatDate(ApplicationContants.DATE_OF_BIRTH_FORMAT, "12/12/1979"));

      System.out.println("Dateof Birth    = " + validatingUser.getStringDateOfBirth());
      System.out.println("CreditCard Info = " + validatingUser.getPaymentDetails().getValue());
      System.out.println(" ");

      try {
        Thread.currentThread();
        Thread.sleep(2000);
      } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      PaymentDetailsDTO validatingPaymentsDTO = new PaymentDetailsDTO();
      validatingPaymentsDTO.setPaymentType(PaymentType.CREDIT_CARD.getPaymentType());
      validatingPaymentsDTO.setValue("111111111111");
      validatingUser.setPaymentDetails(validatingPaymentsDTO);
      validatingUser.setEncryptionModule(encryptionModule);
      customer.encryptUserInformation();

      System.out.println("Encrypting user sensetiveinformation");
      System.out.println(" ");

      validatingUser.encryptUserInformation();

      System.out.println(" ");
      System.out.println(" Done ");
      System.out.println(" ");
      System.out.println(" Displaying encrypted Information ");
      System.out.println(" ");
      System.out.println("Dateof Birth    = " + validatingUser.getStringDateOfBirth());
      System.out.println("CreditCard Info = " + validatingUser.getPaymentDetails().getValue());
      System.out.println(" ");
      System.out.println(" Applying encryption Specification ");
      System.out.println(" ");

      ApplicationSpecification<CustomerDTO> userDetailsSpecification =
          new EncryptedUserInformationSpecification(customer);

      System.out.println(" ");
      System.out.println(
          " Is usert data encrypted = " + userDetailsSpecification.isSatisfiedBy(validatingUser));
      System.out.println(" ");

      try {
        Thread.currentThread();
        Thread.sleep(2000);
      } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      // For Presentation
      // 2.  Validate captured Date of Birth and and Payment details are encrypted.
      if (userDetailsSpecification.isSatisfiedBy(validatingUser)) {
        System.out.println("User details have been encrypted properly");

        System.out.println(" ");
        System.out.println(
            "********************************************************************************************** ");
        System.out.println(" ");
        System.out.println(
            "*********************** 2. User Credentials Encryption Process *******************************");
        System.out.println(" ");

        credentialDTO = new CredentialsDTO();
        credentialDTO.setUserName(logonCredentialsDTO.getUserName());
        credentialDTO.setPassword(logonCredentialsDTO.getPassword());
        customer.setCredentials(credentialDTO);
        customer.getCredentials().setEncryptionModule(encryptionModule);

        System.out.println("Displaying username and pasword in clear text");
        System.out.println(" ");

        CredentialsDTO credentialDTOEncrypt = new CredentialsDTO();
        credentialDTOEncrypt.setUserName("userName");
        credentialDTOEncrypt.setPassword("password");
        credentialDTOEncrypt.setEncryptionModule(encryptionModule);

        System.out.println("Username = "******"Password = "******" ");
        System.out.println(" Encrypting the credentials");
        System.out.println(" ");

        credentialDTO = customer.getCredentials().encryptCredentials();
        credentialDTOEncrypt.encryptCredentials();
        System.out.println(" ");
        System.out.println("Done ...");
        System.out.println(" ");
        System.out.println(" Encrypted the credentials");
        System.out.println(" ");
        System.out.println("Username = "******"Password = "******" ");
        System.out.println("Applying encrption check specification");
        System.out.println(" ");

        ApplicationSpecification<CredentialsDTO> encryptSpecification =
            new EncryptedCredentialsSpecification(credentialDTO);

        System.out.println(
            "Are credentials encrypted = "
                + encryptSpecification.isSatisfiedBy(credentialDTOEncrypt));
        System.out.println(" ");

        try {
          Thread.currentThread();
          Thread.sleep(2000);
        } catch (InterruptedException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }

        // For Presentation
        // 3.  Validate userEntry.
        if (encryptSpecification.isSatisfiedBy(credentialDTOEncrypt)) {
          System.out.println("UserName and password are  Encrypted");

          System.out.println(" ");
          System.out.println(
              " *************************************************************************************");
          System.out.println(" ");
          System.out.println(
              " ******************* Registering user in the Database ********************************");
          System.out.println(" ");

          CustomerDTO responseCutomer = userManager.updateUser(customer);
          CustomerDTO insertedUser = userManager.selectCustomer(responseCutomer);

          System.out.println("User successfully registered new id = " + insertedUser.getId());

          assertNotNull("Failed to Insert User", insertedUser);
          try {
            Thread.currentThread();
            Thread.sleep(2000);
          } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
          System.out.println(
              " ******************* Registeration process is complete  ********************************");
          System.out.println(" ");
        }
      }
    }
  }