protected function KeycloakRoleMatcher::getEvalPattern in Keycloak OpenID Connect 8
Return a regex evaluation pattern for user group role rules.
Parameters
string $pattern: User entered search pattern.
string $operation: Evaluation operation to conduct.
bool $case_sensitive: Whether the resulting pattern shall be case-sensitive.
Return value
string PCRE pattern for role rule evaluation.
1 call to KeycloakRoleMatcher::getEvalPattern()
- KeycloakRoleMatcher::evalRoleRule in src/
Service/ KeycloakRoleMatcher.php - Check, if the given rule matches the user groups.
File
- src/
Service/ KeycloakRoleMatcher.php, line 324
Class
- KeycloakRoleMatcher
- Role matcher service.
Namespace
Drupal\keycloak\ServiceCode
protected function getEvalPattern($pattern, $operation = 'equal', $case_sensitive = TRUE) {
// Quote regular expression characters in regular pattern string.
if ($operation != 'regex' && $operation != 'not_regex') {
$pattern = preg_quote($pattern, '/');
}
// Construct a PCRE pattern for the given operation.
switch ($operation) {
case 'starts_with':
case 'starts_not_with':
$pattern = '/^' . $pattern . '/';
break;
case 'ends_with':
case 'ends_not_with':
$pattern = '/' . $pattern . '$/';
break;
case 'contains':
case 'contains_not':
case 'regex':
case 'not_regex':
$pattern = '/' . $pattern . '/';
break;
case 'not_equal':
default:
$pattern = '/^' . $pattern . '$/';
break;
}
// Whether the pattern shall not be case sensitive.
if (!$case_sensitive) {
$pattern = $pattern . 'i';
}
return $pattern;
}