/**
  * {@inheritdoc}
  */
 public function select(EmailFolder $folder, OroEntityManager $em)
 {
     /** @var UserEmailOrigin $origin */
     $origin = $folder->getOrigin();
     $config = new ImapConfig($origin->getImapHost(), $origin->getImapPort(), $origin->getImapEncryption(), $origin->getUser(), $this->encryptor->decryptData($origin->getPassword()), $this->imapEmailGoogleOauth2Manager->getAccessTokenWithCheckingExpiration($origin));
     return new ImapEmailFlagManager($this->connectorFactory->createImapConnector($config), $em);
 }
 /**
  * {@inheritdoc}
  */
 public function select(EmailFolder $folder, OroEntityManager $em)
 {
     /** @var ImapEmailOrigin $origin */
     $origin = $folder->getOrigin();
     $config = new ImapConfig($origin->getHost(), $origin->getPort(), $origin->getSsl(), $origin->getUser(), $this->encryptor->decryptData($origin->getPassword()));
     return new ImapEmailFlagManager($this->connectorFactory->createImapConnector($config), $em);
 }
Пример #3
0
 public function testEncodeDecodeDifferentInstances()
 {
     $someData = 'someValue';
     $encrypted = $this->encryptor->encryptData($someData);
     $newInstance = $this->getInstance();
     $this->assertEquals($someData, $newInstance->decryptData($encrypted));
 }
Пример #4
0
 /**
  * @param array      $formData
  * @param array|bool $expectedViewData
  * @param array      $expectedModelData
  *
  * @dataProvider setDataProvider
  */
 public function testBindValidData($formData, $expectedViewData, $expectedModelData)
 {
     $type = new ChoiceAccountType($this->translator);
     $form = $this->factory->create($type);
     if ($expectedViewData) {
         $form->submit($formData);
         foreach ($expectedViewData as $name => $value) {
             $this->assertEquals($value, $form->get($name)->getData());
         }
         $entity = $form->getData();
         foreach ($expectedModelData as $name => $value) {
             if ($name === 'userEmailOrigin') {
                 $userEmailOrigin = $this->readAttribute($entity, $name);
                 if ($userEmailOrigin) {
                     $passowrd = $this->encryptor->decryptData($userEmailOrigin->getPassword());
                     $userEmailOrigin->setPassword($passowrd);
                 }
                 $this->assertAttributeEquals($userEmailOrigin, $name, $entity);
             } else {
                 $this->assertAttributeEquals($value, $name, $entity);
             }
         }
     } else {
         $form->submit($formData);
         $this->assertNull($form->getData());
     }
 }
Пример #5
0
 /**
  * Pre submit event listener
  * Encrypt passwords and populate if empty
  * Populate websites choices from hidden fields
  *
  * @param FormEvent $event
  */
 public function preSubmit(FormEvent $event)
 {
     $data = (array) $event->getData();
     $form = $event->getForm();
     $oldPassword = $form->get('apiKey')->getData();
     if (empty($data['apiKey']) && $oldPassword) {
         // populate old password
         $data['apiKey'] = $oldPassword;
     } elseif (isset($data['apiKey'])) {
         $data['apiKey'] = $this->encryptor->encryptData($data['apiKey']);
     }
     // first time all websites comes from frontend(when run sync action)
     // otherwise loaded from entity
     if (!empty($data['websites'])) {
         $websites = $data['websites'];
         // reverseTransform, but not set back to event
         if (!is_array($websites)) {
             $websites = json_decode($websites, true);
         }
         $modifier = $this->getModifierWebsitesList($websites);
         $modifier($form);
     }
     $this->muteFields($form);
     $event->setData($data);
 }
Пример #6
0
 /**
  * @dataProvider keyDataProvider
  * @param string $key
  */
 public function testEncodeDecodeDifferentInstances($key)
 {
     $someData = 'someValue';
     $encryptor = new Mcrypt($key);
     $encrypted = $encryptor->encryptData($someData);
     $this->assertNotEquals($someData, $encrypted);
     $newInstance = new Mcrypt($key);
     $this->assertEquals($someData, $newInstance->decryptData($encrypted));
 }
 public function testBuildForm()
 {
     // test encrypted password
     $encPassword = base64_encode('test');
     $this->encryptor->expects($this->once())->method('encryptData')->will($this->returnValue($encPassword));
     $form = $this->factory->create($this->formType);
     $form->submit('test');
     $this->assertEquals($encPassword, $form->getData());
     // test empty password with old password defined
     $form = $this->factory->create($this->formType, 'test');
     $form->submit('');
     $this->assertEquals('test', $form->getData());
 }
Пример #8
0
 /**
  * {@inheritdoc}
  */
 public function init(Transport $transportEntity)
 {
     parent::init($transportEntity);
     $wsiMode = $this->settings->get('wsi_mode', false);
     $apiUser = $this->settings->get('api_user', false);
     $apiKey = $this->settings->get('api_key', false);
     $apiKey = $this->encoder->decryptData($apiKey);
     if (!$apiUser || !$apiKey) {
         throw new InvalidConfigurationException("Magento SOAP transport require 'api_key' and 'api_user' settings to be defined.");
     }
     // revert initial state
     $this->isExtensionInstalled = null;
     $this->isWsiMode = $wsiMode;
     /** @var string sessionId returned by Magento API login method */
     $this->sessionId = $this->call('login', ['username' => $apiUser, 'apiKey' => $apiKey]);
 }
Пример #9
0
 /**
  * @param array $options
  *
  * @return callable
  */
 protected function getEncryptClosure($options)
 {
     $enc = $this->encryptor;
     $isEncode = !empty($options['encode']) && $options['encode'];
     return function (FormEvent $event) use($enc, $isEncode) {
         $form = $event->getForm();
         $password = $event->getData();
         $oldPassword = $form->getData();
         if (empty($password) && $oldPassword) {
             // populate old password
             $password = $oldPassword;
         } elseif (!empty($password) && $isEncode) {
             $password = $this->encryptor->encryptData($password);
         }
         $event->setData($password);
     };
 }
Пример #10
0
 /**
  * Set password on form reload
  *
  * @param FormEvent $event
  */
 public function postSet(FormEvent $event)
 {
     /** @var Mailbox $data */
     $data = $event->getData();
     $form = $event->getForm();
     if ($data instanceof Mailbox && $data->getOrigin() && $form->has('passwordHolder')) {
         $form->get('passwordHolder')->setData($this->encryptor->decryptData($data->getOrigin()->getPassword()));
     }
 }
 /**
  * @param $request
  * $param sting $formParentName
  * @return FormInterface
  */
 public function getCheckGmailConnectionForm($request, $formParentName)
 {
     $form = $this->formFactory->create('oro_imap_configuration_gmail', null, ['csrf_protection' => false]);
     $form->submit($request);
     if (!$form->isValid()) {
         throw new Exception("Incorrect setting for IMAP authentication");
     }
     /** @var UserEmailOrigin $origin */
     $origin = $form->getData();
     $password = $this->mcrypt->decryptData($origin->getPassword());
     $config = new ImapConfig($origin->getImapHost(), $origin->getImapPort(), $origin->getImapEncryption(), $origin->getUser(), $password, $origin->getAccessToken());
     $connector = $this->imapConnectorFactory->createImapConnector($config);
     /** @var EntityManager $entityManager */
     $entityManager = $this->doctrine->getManager();
     $manager = new ImapEmailFolderManager($connector, $entityManager, $origin);
     $emailFolders = $manager->getFolders();
     $origin->setFolders($emailFolders);
     $accountTypeModel = $this->createAccountModel(AccountTypeModel::ACCOUNT_TYPE_GMAIL, $origin);
     return $this->prepareForm($formParentName, $accountTypeModel);
 }
Пример #12
0
 /**
  * {@inheritdoc}
  */
 public function loadEmailBody(EmailFolder $folder, Email $email, EntityManager $em)
 {
     /** @var UserEmailOrigin $origin */
     $origin = $folder->getOrigin();
     $config = new ImapConfig($origin->getImapHost(), $origin->getImapPort(), $origin->getImapEncryption(), $origin->getUser(), $this->encryptor->decryptData($origin->getPassword()), $this->imapEmailGoogleOauth2Manager->getAccessTokenWithCheckingExpiration($origin));
     $manager = new ImapEmailManager($this->connectorFactory->createImapConnector($config));
     $manager->selectFolder($folder->getFullName());
     $repo = $em->getRepository('OroImapBundle:ImapEmail');
     $query = $repo->createQueryBuilder('e')->select('e.uid')->innerJoin('e.imapFolder', 'if')->where('e.email = ?1 AND if.folder = ?2')->setParameter(1, $email)->setParameter(2, $folder)->getQuery();
     $loadedEmail = $manager->findEmail($query->getSingleScalarResult());
     if (null === $loadedEmail) {
         throw new EmailBodyNotFoundException($email);
     }
     $builder = new EmailBodyBuilder();
     $builder->setEmailBody($loadedEmail->getBody()->getContent(), $loadedEmail->getBody()->getBodyIsText());
     foreach ($loadedEmail->getAttachments() as $attachment) {
         $builder->addEmailAttachment($attachment->getFileName(), $attachment->getContent(), $attachment->getContentType(), $attachment->getContentTransferEncoding(), $attachment->getContentId());
     }
     return $builder->getEmailBody();
 }
Пример #13
0
 /**
  * Modify transport smtp settings
  *
  * @param UserEmailOrigin $userEmailOrigin
  */
 protected function modifySmtpSettings(UserEmailOrigin $userEmailOrigin)
 {
     $transport = $this->mailer->getTransport();
     if ($transport instanceof \Swift_Transport_EsmtpTransport) {
         $transport->setHost($userEmailOrigin->getSmtpHost());
         $transport->setPort($userEmailOrigin->getSmtpPort());
         $transport->setUsername($userEmailOrigin->getUser());
         $transport->setPassword($this->encryptor->decryptData($userEmailOrigin->getPassword()));
         if ($userEmailOrigin->getSmtpEncryption()) {
             $transport->setEncryption($userEmailOrigin->getSmtpEncryption());
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function loadEmailBody(Email $email, EntityManager $em)
 {
     /** @var ImapEmailOrigin $origin */
     $origin = $email->getFolder()->getOrigin();
     $config = new ImapConfig($origin->getHost(), $origin->getPort(), $origin->getSsl(), $origin->getUser(), $this->encryptor->decryptData($origin->getPassword()));
     $manager = new ImapEmailManager($this->connectorFactory->createImapConnector($config));
     $manager->selectFolder($email->getFolder()->getFullName());
     $repo = $em->getRepository('OroImapBundle:ImapEmail');
     $query = $repo->createQueryBuilder('e')->select('e.uid')->where('e.email = ?1')->setParameter(1, $email)->getQuery();
     /** @var ImapEmail $imapEmail */
     $imapEmail = $query->getSingleResult();
     $loadedEmail = $manager->findEmail($imapEmail['uid']);
     if ($loadedEmail === null) {
         throw new \RuntimeException(sprintf('Cannot find a body for "%s" email.', $email->getSubject()));
     }
     $builder = new EmailBodyBuilder();
     $builder->setEmailBody($loadedEmail->getBody()->getContent(), $loadedEmail->getBody()->getBodyIsText());
     foreach ($loadedEmail->getAttachments() as $attachment) {
         $builder->addEmailAttachment($attachment->getFileName(), $attachment->getContent(), $attachment->getContentType(), $attachment->getContentTransferEncoding());
     }
     return $builder->getEmailBody();
 }
Пример #15
0
 /**
  * @param array      $formData
  * @param array|bool $expectedViewData
  *
  * @param array      $expectedModelData
  *
  * @dataProvider setDataProvider
  */
 public function testBindValidData($formData, $expectedViewData, $expectedModelData)
 {
     $type = new ConfigurationType($this->encryptor);
     $form = $this->factory->create($type);
     if ($expectedViewData) {
         $form->submit($formData);
         foreach ($expectedViewData as $name => $value) {
             $this->assertEquals($value, $form->get($name)->getData());
         }
         $entity = $form->getData();
         foreach ($expectedModelData as $name => $value) {
             if ($name == 'password') {
                 $encodedPass = $this->readAttribute($entity, $name);
                 $this->assertEquals($this->encryptor->decryptData($encodedPass), $value);
             } else {
                 $this->assertAttributeEquals($value, $name, $entity);
             }
         }
     } else {
         $form->submit($formData);
         $this->assertNull($form->getData());
     }
 }
Пример #16
0
 /**
  * {@inheritdoc}
  */
 public function init(Transport $transportEntity)
 {
     /**
      * Cache WSDL and force transport entity to use it instead of original URL.
      * This should be done before parent::init as settings will be cached there.
      */
     if ($transportEntity instanceof MagentoSoapTransport) {
         $wsdlUrl = $transportEntity->getWsdlUrl();
         // Save auth information to be able to perform requests.
         $urlParts = parse_url($wsdlUrl);
         if (isset($urlParts['user'], $urlParts['pass'])) {
             $this->auth['login'] = $urlParts['user'];
             $this->auth['password'] = $urlParts['pass'];
         }
         // Load WSDL to local cache.
         if (!$this->wsdlManager->isCacheLoaded($wsdlUrl)) {
             $this->wsdlManager->loadWsdl($wsdlUrl);
         }
         // Set cached WSDL path to transport entity.
         $transportEntity->setWsdlCachePath($this->wsdlManager->getCachedWsdlPath($wsdlUrl));
     }
     parent::init($transportEntity);
     $wsiMode = $this->settings->get('wsi_mode', false);
     $apiUser = $this->settings->get('api_user', false);
     $apiKey = $this->settings->get('api_key', false);
     $apiKey = $this->encoder->decryptData($apiKey);
     if (!$apiUser || !$apiKey) {
         throw new InvalidConfigurationException("Magento SOAP transport require 'api_key' and 'api_user' settings to be defined.");
     }
     // revert initial state
     $this->isExtensionInstalled = null;
     $this->adminUrl = null;
     $this->isWsiMode = $wsiMode;
     /** @var string sessionId returned by Magento API login method */
     $this->sessionId = null;
     $this->sessionId = $this->call('login', ['username' => $apiUser, 'apiKey' => $apiKey]);
     $this->checkExtensionFunctions();
 }
Пример #17
0
 /**
  * Creates a processor is used to synchronize emails
  *
  * @param UserEmailOrigin $origin
  * @return ImapEmailSynchronizationProcessor
  */
 protected function createSynchronizationProcessor($origin)
 {
     $config = new ImapConfig($origin->getImapHost(), $origin->getImapPort(), $origin->getImapEncryption(), $origin->getUser(), $this->encryptor->decryptData($origin->getPassword()), $this->imapEmailGoogleOauth2Manager->getAccessTokenWithCheckingExpiration($origin));
     return $this->syncProcessorFactory->create(new ImapEmailManager($this->connectorFactory->createImapConnector($config)), $this->getKnownEmailAddressChecker());
 }
Пример #18
0
 /**
  * @param UserEmailOrigin $origin
  *
  * @return ImapEmailFolderManager
  */
 protected function createManager(UserEmailOrigin $origin)
 {
     $config = new ImapConfig($origin->getImapHost(), $origin->getImapPort(), $origin->getImapEncryption(), $origin->getUser(), $this->mcrypt->decryptData($origin->getPassword()), $this->imapEmailGoogleOauth2Manager->getAccessTokenWithCheckingExpiration($origin));
     $connector = $this->connectorFactory->createImapConnector($config);
     return new ImapEmailFolderManager($connector, $this->doctrine->getManager(), $origin);
 }
Пример #19
0
 /**
  * Creates a processor is used to synchronize emails
  *
  * @param ImapEmailOrigin $origin
  * @return ImapEmailSynchronizationProcessor
  */
 protected function createSynchronizationProcessor($origin)
 {
     $config = new ImapConfig($origin->getHost(), $origin->getPort(), $origin->getSsl(), $origin->getUser(), $this->encryptor->decryptData($origin->getPassword()));
     return $this->syncProcessorFactory->create(new ImapEmailManager($this->connectorFactory->createImapConnector($config)), $this->getKnownEmailAddressChecker());
 }
Пример #20
0
 /**
  * @param ImapEmailOrigin $origin
  *
  * @return ImapEmailFolderManager
  */
 protected function createManager(ImapEmailOrigin $origin)
 {
     $config = new ImapConfig($origin->getHost(), $origin->getPort(), $origin->getSsl(), $origin->getUser(), $this->mcrypt->decryptData($origin->getPassword()));
     $connector = $this->connectorFactory->createImapConnector($config);
     return new ImapEmailFolderManager($connector, $this->doctrine->getManager(), $origin);
 }
Пример #21
0
 /**
  * Creates a processor is used to synchronize emails
  *
  * @param ImapEmailOrigin $origin
  * @return ImapEmailSynchronizationProcessor
  */
 protected function createSynchronizationProcessor($origin)
 {
     $config = new ImapConfig($origin->getHost(), $origin->getPort(), $origin->getSsl(), $origin->getUser(), $this->encryptor->decryptData($origin->getPassword()));
     return new ImapEmailSynchronizationProcessor($this->log, $this->getEntityManager(), $this->emailEntityBuilder, $this->emailAddressManager, $this->knownEmailAddressChecker, new ImapEmailManager($this->connectorFactory->createImapConnector($config)));
 }