123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Security\Model;
- use Magento\Framework\App\Config\ScopeConfigInterface;
- use Magento\Framework\Config\ScopeInterface;
- use Magento\Store\Model\ScopeInterface as StoreScopeInterface;
- /**
- * Security config
- */
- class Config implements ConfigInterface
- {
- /**
- * Period of time which will be used to limit frequency of password reset requests
- */
- const LIMITATION_TIME_PERIOD = 3600;
- /**
- * Configuration path to admin area
- */
- const XML_PATH_ADMIN_AREA = 'admin/security/';
- /**
- * Configuration path to frontend area
- */
- const XML_PATH_FRONTEND_AREA = 'customer/password/';
- /**
- * Configuration path to fronted area
- * @deprecated
- * @see \Magento\Security\Model\Config::XML_PATH_FRONTEND_AREA
- */
- const XML_PATH_FRONTED_AREA = self::XML_PATH_FRONTEND_AREA;
- /**
- * Configuration path to admin account sharing
- */
- const XML_PATH_ADMIN_ACCOUNT_SHARING = 'admin/security/admin_account_sharing';
- /**
- * Configuration key to limit password reset requests method
- */
- const XML_PATH_PASSWORD_RESET_PROTECTION_TYPE = 'password_reset_protection_type';
- /**
- * Configuration key to max number password reset requests
- */
- const XML_PATH_MAX_NUMBER_PASSWORD_RESET_REQUESTS = 'max_number_password_reset_requests';
- /**
- * Configuration key to minimum time between password reset requests
- */
- const XML_PATH_MIN_TIME_BETWEEN_PASSWORD_RESET_REQUESTS = 'min_time_between_password_reset_requests';
- /**
- * Recipient email config path
- */
- const XML_PATH_EMAIL_RECIPIENT = 'contact/email/recipient_email';
- /**
- * @var ScopeConfigInterface
- */
- private $scopeConfig;
- /**
- * @var ScopeInterface
- */
- private $scope;
- /**
- * SecurityConfig constructor.
- *
- * @param ScopeConfigInterface $scopeConfig
- * @param ScopeInterface $scope
- */
- public function __construct(
- ScopeConfigInterface $scopeConfig,
- ScopeInterface $scope
- ) {
- $this->scopeConfig = $scopeConfig;
- $this->scope = $scope;
- }
- /**
- * {@inheritDoc}
- *
- * @return string
- */
- public function getCustomerServiceEmail()
- {
- return $this->scopeConfig->getValue(
- self::XML_PATH_EMAIL_RECIPIENT,
- StoreScopeInterface::SCOPE_STORE
- );
- }
- /**
- * {@inheritDoc}
- *
- * @return int
- */
- public function getLimitationTimePeriod()
- {
- return self::LIMITATION_TIME_PERIOD;
- }
- /**
- * {@inheritDoc}
- *
- * @return bool
- */
- public function isAdminAccountSharingEnabled()
- {
- return $this->scopeConfig->isSetFlag(
- self::XML_PATH_ADMIN_ACCOUNT_SHARING,
- StoreScopeInterface::SCOPE_STORE
- );
- }
- /**
- * {@inheritDoc}
- *
- * @return int
- */
- public function getAdminSessionLifetime()
- {
- return (int) $this->scopeConfig->getValue(\Magento\Backend\Model\Auth\Session::XML_PATH_SESSION_LIFETIME);
- }
- /**
- * {@inheritDoc}
- *
- * @return string
- */
- protected function getXmlPathPrefix()
- {
- if ($this->scope->getCurrentScope() == \Magento\Framework\App\Area::AREA_ADMINHTML) {
- return self::XML_PATH_ADMIN_AREA;
- }
- return self::XML_PATH_FRONTEND_AREA;
- }
- /**
- * {@inheritdoc}
- *
- * @return int
- */
- public function getPasswordResetProtectionType()
- {
- return (int) $this->scopeConfig->getValue(
- $this->getXmlPathPrefix() . self::XML_PATH_PASSWORD_RESET_PROTECTION_TYPE,
- StoreScopeInterface::SCOPE_STORE
- );
- }
- /**
- * {@inheritDoc}
- *
- * @param int $scope
- * @return int
- */
- public function getMaxNumberPasswordResetRequests()
- {
- return (int) $this->scopeConfig->getValue(
- $this->getXmlPathPrefix() . self::XML_PATH_MAX_NUMBER_PASSWORD_RESET_REQUESTS,
- StoreScopeInterface::SCOPE_STORE
- );
- }
- /**
- * {@inheritDoc}
- *
- * @param int $scope
- * @return int
- */
- public function getMinTimeBetweenPasswordResetRequests()
- {
- $timeInMin = $this->scopeConfig->getValue(
- $this->getXmlPathPrefix() . self::XML_PATH_MIN_TIME_BETWEEN_PASSWORD_RESET_REQUESTS,
- StoreScopeInterface::SCOPE_STORE
- );
- return $timeInMin * 60;
- }
- }
|