Config.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Security\Model;
  7. use Magento\Framework\App\Config\ScopeConfigInterface;
  8. use Magento\Framework\Config\ScopeInterface;
  9. use Magento\Store\Model\ScopeInterface as StoreScopeInterface;
  10. /**
  11. * Security config
  12. */
  13. class Config implements ConfigInterface
  14. {
  15. /**
  16. * Period of time which will be used to limit frequency of password reset requests
  17. */
  18. const LIMITATION_TIME_PERIOD = 3600;
  19. /**
  20. * Configuration path to admin area
  21. */
  22. const XML_PATH_ADMIN_AREA = 'admin/security/';
  23. /**
  24. * Configuration path to frontend area
  25. */
  26. const XML_PATH_FRONTEND_AREA = 'customer/password/';
  27. /**
  28. * Configuration path to fronted area
  29. * @deprecated
  30. * @see \Magento\Security\Model\Config::XML_PATH_FRONTEND_AREA
  31. */
  32. const XML_PATH_FRONTED_AREA = self::XML_PATH_FRONTEND_AREA;
  33. /**
  34. * Configuration path to admin account sharing
  35. */
  36. const XML_PATH_ADMIN_ACCOUNT_SHARING = 'admin/security/admin_account_sharing';
  37. /**
  38. * Configuration key to limit password reset requests method
  39. */
  40. const XML_PATH_PASSWORD_RESET_PROTECTION_TYPE = 'password_reset_protection_type';
  41. /**
  42. * Configuration key to max number password reset requests
  43. */
  44. const XML_PATH_MAX_NUMBER_PASSWORD_RESET_REQUESTS = 'max_number_password_reset_requests';
  45. /**
  46. * Configuration key to minimum time between password reset requests
  47. */
  48. const XML_PATH_MIN_TIME_BETWEEN_PASSWORD_RESET_REQUESTS = 'min_time_between_password_reset_requests';
  49. /**
  50. * Recipient email config path
  51. */
  52. const XML_PATH_EMAIL_RECIPIENT = 'contact/email/recipient_email';
  53. /**
  54. * @var ScopeConfigInterface
  55. */
  56. private $scopeConfig;
  57. /**
  58. * @var ScopeInterface
  59. */
  60. private $scope;
  61. /**
  62. * SecurityConfig constructor.
  63. *
  64. * @param ScopeConfigInterface $scopeConfig
  65. * @param ScopeInterface $scope
  66. */
  67. public function __construct(
  68. ScopeConfigInterface $scopeConfig,
  69. ScopeInterface $scope
  70. ) {
  71. $this->scopeConfig = $scopeConfig;
  72. $this->scope = $scope;
  73. }
  74. /**
  75. * {@inheritDoc}
  76. *
  77. * @return string
  78. */
  79. public function getCustomerServiceEmail()
  80. {
  81. return $this->scopeConfig->getValue(
  82. self::XML_PATH_EMAIL_RECIPIENT,
  83. StoreScopeInterface::SCOPE_STORE
  84. );
  85. }
  86. /**
  87. * {@inheritDoc}
  88. *
  89. * @return int
  90. */
  91. public function getLimitationTimePeriod()
  92. {
  93. return self::LIMITATION_TIME_PERIOD;
  94. }
  95. /**
  96. * {@inheritDoc}
  97. *
  98. * @return bool
  99. */
  100. public function isAdminAccountSharingEnabled()
  101. {
  102. return $this->scopeConfig->isSetFlag(
  103. self::XML_PATH_ADMIN_ACCOUNT_SHARING,
  104. StoreScopeInterface::SCOPE_STORE
  105. );
  106. }
  107. /**
  108. * {@inheritDoc}
  109. *
  110. * @return int
  111. */
  112. public function getAdminSessionLifetime()
  113. {
  114. return (int) $this->scopeConfig->getValue(\Magento\Backend\Model\Auth\Session::XML_PATH_SESSION_LIFETIME);
  115. }
  116. /**
  117. * {@inheritDoc}
  118. *
  119. * @return string
  120. */
  121. protected function getXmlPathPrefix()
  122. {
  123. if ($this->scope->getCurrentScope() == \Magento\Framework\App\Area::AREA_ADMINHTML) {
  124. return self::XML_PATH_ADMIN_AREA;
  125. }
  126. return self::XML_PATH_FRONTEND_AREA;
  127. }
  128. /**
  129. * {@inheritdoc}
  130. *
  131. * @return int
  132. */
  133. public function getPasswordResetProtectionType()
  134. {
  135. return (int) $this->scopeConfig->getValue(
  136. $this->getXmlPathPrefix() . self::XML_PATH_PASSWORD_RESET_PROTECTION_TYPE,
  137. StoreScopeInterface::SCOPE_STORE
  138. );
  139. }
  140. /**
  141. * {@inheritDoc}
  142. *
  143. * @param int $scope
  144. * @return int
  145. */
  146. public function getMaxNumberPasswordResetRequests()
  147. {
  148. return (int) $this->scopeConfig->getValue(
  149. $this->getXmlPathPrefix() . self::XML_PATH_MAX_NUMBER_PASSWORD_RESET_REQUESTS,
  150. StoreScopeInterface::SCOPE_STORE
  151. );
  152. }
  153. /**
  154. * {@inheritDoc}
  155. *
  156. * @param int $scope
  157. * @return int
  158. */
  159. public function getMinTimeBetweenPasswordResetRequests()
  160. {
  161. $timeInMin = $this->scopeConfig->getValue(
  162. $this->getXmlPathPrefix() . self::XML_PATH_MIN_TIME_BETWEEN_PASSWORD_RESET_REQUESTS,
  163. StoreScopeInterface::SCOPE_STORE
  164. );
  165. return $timeInMin * 60;
  166. }
  167. }