1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
rulescollection.php
См. документацию.
1
<?php
2
9
10
namespace
Bitrix\Main\Authentication\Policy;
11
12
use Bitrix\Main;
13
use Bitrix\Main\Type;
14
use Bitrix\Main\Text;
15
use Bitrix\Main\Localization\Loc;
16
43
class
RulesCollection
extends
Type\Dictionary
44
{
45
public
const
PRESET_DEFAULT
= 0;
46
public
const
PRESET_LOW
= 1;
47
public
const
PRESET_MIDDLE
= 2;
48
public
const
PRESET_HIGH
= 3;
49
53
public
function
__construct
()
54
{
55
// Default policy
56
$values
= [
57
'SESSION_TIMEOUT'
=>
new
LesserRule
(Loc::getMessage(
'GP_SESSION_TIMEOUT'
), ini_get(
'session.gc_maxlifetime'
) / 60),
58
'SESSION_IP_MASK'
=>
new
IpMaskRule
(Loc::getMessage(
'GP_SESSION_IP_MASK'
)),
59
'MAX_STORE_NUM'
=>
new
LesserRule
(Loc::getMessage(
'GP_MAX_STORE_NUM'
), 10),
60
'STORE_IP_MASK'
=>
new
IpMaskRule
(Loc::getMessage(
'GP_STORE_IP_MASK'
)),
61
'STORE_TIMEOUT'
=>
new
LesserRule
(Loc::getMessage(
'GP_STORE_TIMEOUT'
), 60*24*365),
62
'CHECKWORD_TIMEOUT'
=>
new
LesserRule
(Loc::getMessage(
'GP_CHECKWORD_TIMEOUT'
), 60*24*2),
63
'PASSWORD_LENGTH'
=>
new
GreaterRule
(Loc::getMessage(
'GP_PASSWORD_LENGTH'
), 6),
64
'PASSWORD_UPPERCASE'
=>
new
BooleanRule
(Loc::getMessage(
'GP_PASSWORD_UPPERCASE'
)),
65
'PASSWORD_LOWERCASE'
=>
new
BooleanRule
(Loc::getMessage(
'GP_PASSWORD_LOWERCASE'
)),
66
'PASSWORD_DIGITS'
=>
new
BooleanRule
(Loc::getMessage(
'GP_PASSWORD_DIGITS'
)),
67
'PASSWORD_PUNCTUATION'
=>
new
BooleanRule
(Loc::getMessage(
'GP_PASSWORD_PUNCTUATION'
, [
'#SPECIAL_CHARS#'
=> \CUser::PASSWORD_SPECIAL_CHARS])),
68
'PASSWORD_CHECK_WEAK'
=>
new
BooleanRule
(Loc::getMessage(
'GP_PASSWORD_CHECK_WEAK'
)),
69
'PASSWORD_CHECK_POLICY'
=>
new
BooleanRule
(Loc::getMessage(
'GP_PASSWORD_CHECK_POLICY'
)),
70
'PASSWORD_CHANGE_DAYS'
=>
new
LesserPositiveRule
(Loc::getMessage(
'GP_PASSWORD_CHANGE_DAYS'
)),
71
'PASSWORD_MIN_CHANGE_DAYS'
=>
new
GreaterRule
(Loc::getMessage(
'GP_PASSWORD_MIN_CHANGE_DAYS'
)),
72
'PASSWORD_UNIQUE_COUNT'
=>
new
GreaterRule
(Loc::getMessage(
'GP_PASSWORD_UNIQUE_COUNT'
)),
73
'LOGIN_ATTEMPTS'
=>
new
LesserPositiveRule
(Loc::getMessage(
'GP_LOGIN_ATTEMPTS'
)),
74
'BLOCK_LOGIN_ATTEMPTS'
=>
new
LesserPositiveRule
(Loc::getMessage(
'GP_BLOCK_LOGIN_ATTEMPTS'
)),
75
'BLOCK_TIME'
=>
new
GreaterRule
(Loc::getMessage(
'GP_BLOCK_TIME'
)),
76
];
77
78
parent::__construct(
$values
);
79
}
80
86
public
static
function
createByPreset
($preset = self::PRESET_DEFAULT)
87
{
88
$policy =
new
static
();
89
90
if
($preset >= self::PRESET_LOW)
91
{
92
$policy[
'SESSION_TIMEOUT'
]->assignValue(30);
93
$policy[
'STORE_IP_MASK'
]->assignValue(
'255.0.0.0'
);
94
$policy[
'STORE_TIMEOUT'
]->assignValue(60*24*90);
95
}
96
if
($preset >= self::PRESET_MIDDLE)
97
{
98
$policy[
'SESSION_TIMEOUT'
]->assignValue(20);
99
$policy[
'SESSION_IP_MASK'
]->assignValue(
'255.255.0.0'
);
100
$policy[
'MAX_STORE_NUM'
]->assignValue(5);
101
$policy[
'STORE_IP_MASK'
]->assignValue(
'255.255.0.0'
);
102
$policy[
'STORE_TIMEOUT'
]->assignValue(60*24*30);
103
$policy[
'CHECKWORD_TIMEOUT'
]->assignValue(60*24*1);
104
$policy[
'PASSWORD_LENGTH'
]->assignValue(8);
105
$policy[
'PASSWORD_UPPERCASE'
]->assignValue(
true
);
106
$policy[
'PASSWORD_LOWERCASE'
]->assignValue(
true
);
107
$policy[
'PASSWORD_DIGITS'
]->assignValue(
true
);
108
$policy[
'PASSWORD_CHECK_WEAK'
]->assignValue(
true
);
109
$policy[
'PASSWORD_CHANGE_DAYS'
]->assignValue(180);
110
$policy[
'PASSWORD_UNIQUE_COUNT'
]->assignValue(1);
111
$policy[
'LOGIN_ATTEMPTS'
]->assignValue(10);
112
}
113
if
($preset >= self::PRESET_HIGH)
114
{
115
$policy[
'SESSION_TIMEOUT'
]->assignValue(15);
116
$policy[
'SESSION_IP_MASK'
]->assignValue(
'255.255.255.255'
);
117
$policy[
'MAX_STORE_NUM'
]->assignValue(2);
118
$policy[
'STORE_IP_MASK'
]->assignValue(
'255.255.255.255'
);
119
$policy[
'STORE_TIMEOUT'
]->assignValue(60*24*7);
120
$policy[
'CHECKWORD_TIMEOUT'
]->assignValue(60);
121
$policy[
'PASSWORD_LENGTH'
]->assignValue(10);
122
$policy[
'PASSWORD_PUNCTUATION'
]->assignValue(
true
);
123
$policy[
'PASSWORD_CHECK_POLICY'
]->assignValue(
true
);
124
$policy[
'PASSWORD_CHANGE_DAYS'
]->assignValue(90);
125
$policy[
'PASSWORD_MIN_CHANGE_DAYS'
]->assignValue(1);
126
$policy[
'PASSWORD_UNIQUE_COUNT'
]->assignValue(3);
127
$policy[
'LOGIN_ATTEMPTS'
]->assignValue(3);
128
}
129
130
return
$policy;
131
}
132
137
public
function
getValues
()
138
{
139
$result
= [];
140
141
foreach
($this->values as
$code
=> $rule)
142
{
143
$value = $rule->getValue();
144
if
($rule instanceof
BooleanRule
)
145
{
146
$result
[
$code
] = ($value ?
'Y'
:
'N'
);
147
}
148
else
149
{
150
$result
[
$code
] = $value;
151
}
152
}
153
154
return
$result
;
155
}
156
162
public
function
compare
(
RulesCollection
$policy)
163
{
164
foreach
($this->values as
$code
=> $rule)
165
{
166
if
($rule->compare($policy[
$code
]->getValue()))
167
{
168
return
true
;
169
}
170
}
171
172
return
false
;
173
}
174
182
public
function
__call
(
$name
, $arguments)
183
{
184
if
(str_starts_with(
$name
,
"get"
))
185
{
186
$ruleName = substr(
$name
, 3);
187
$ruleName =
Text\StringHelper::camel2snake
($ruleName);
188
$ruleName = strtoupper($ruleName);
189
190
if
(isset($this->values[$ruleName]))
191
{
192
return
$this->values[$ruleName]->getValue();
193
}
194
}
195
196
throw
new
Main\SystemException
(sprintf(
197
'Unknown method `%s` for object `%s`'
,
$name
, get_called_class()
198
));
199
}
200
}
Bitrix\Main\Authentication\Policy\BooleanRule
Определения
booleanrule.php:13
Bitrix\Main\Authentication\Policy\GreaterRule
Определения
greaterrule.php:13
Bitrix\Main\Authentication\Policy\IpMaskRule
Определения
ipmaskrule.php:13
Bitrix\Main\Authentication\Policy\LesserPositiveRule
Определения
lesserpositiverule.php:13
Bitrix\Main\Authentication\Policy\LesserRule
Определения
lesserrule.php:13
Bitrix\Main\Authentication\Policy\RulesCollection
Определения
rulescollection.php:44
Bitrix\Main\Authentication\Policy\RulesCollection\__construct
__construct()
Определения
rulescollection.php:53
Bitrix\Main\Authentication\Policy\RulesCollection\__call
__call($name, $arguments)
Определения
rulescollection.php:182
Bitrix\Main\Authentication\Policy\RulesCollection\compare
compare(RulesCollection $policy)
Определения
rulescollection.php:162
Bitrix\Main\Authentication\Policy\RulesCollection\PRESET_DEFAULT
const PRESET_DEFAULT
Определения
rulescollection.php:45
Bitrix\Main\Authentication\Policy\RulesCollection\getValues
getValues()
Определения
rulescollection.php:137
Bitrix\Main\Authentication\Policy\RulesCollection\PRESET_LOW
const PRESET_LOW
Определения
rulescollection.php:46
Bitrix\Main\Authentication\Policy\RulesCollection\PRESET_MIDDLE
const PRESET_MIDDLE
Определения
rulescollection.php:47
Bitrix\Main\Authentication\Policy\RulesCollection\PRESET_HIGH
const PRESET_HIGH
Определения
rulescollection.php:48
Bitrix\Main\Authentication\Policy\RulesCollection\createByPreset
static createByPreset($preset=self::PRESET_DEFAULT)
Определения
rulescollection.php:86
Bitrix\Main\SystemException
Определения
SystemException.php:9
Bitrix\Main\Text\StringHelper\camel2snake
static camel2snake($str)
Определения
stringhelper.php:44
Bitrix\Main\Type\Dictionary
Определения
dictionary.php:6
Bitrix\Main\Type\Dictionary\$values
$values
Определения
dictionary.php:10
$result
$result
Определения
get_property_values.php:14
$code
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения
options.php:195
$name
$name
Определения
menu_edit.php:35
bitrix
modules
main
lib
authentication
policy
rulescollection.php
Создано системой
1.14.0