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