saml: allow to keep existing roles on login (#3440)
This commit is contained in:
@@ -46,6 +46,11 @@ final class SamlConfiguration implements SamlConfigurationInterface
|
|||||||
return $this->configuration->getSamlRolesMapping();
|
return $this->configuration->getSamlRolesMapping();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isRolesResetOnLogin(): bool
|
||||||
|
{
|
||||||
|
return $this->configuration->isSamlRolesResetOnLogin();
|
||||||
|
}
|
||||||
|
|
||||||
public function getConnection(): array
|
public function getConnection(): array
|
||||||
{
|
{
|
||||||
return $this->configuration->getSamlConnection();
|
return $this->configuration->getSamlConnection();
|
||||||
|
|||||||
@@ -21,5 +21,7 @@ interface SamlConfigurationInterface
|
|||||||
|
|
||||||
public function getRolesMapping(): array;
|
public function getRolesMapping(): array;
|
||||||
|
|
||||||
|
public function isRolesResetOnLogin(): bool;
|
||||||
|
|
||||||
public function getConnection(): array;
|
public function getConnection(): array;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,6 +86,11 @@ class SystemConfiguration implements SystemBundleConfiguration
|
|||||||
return (array) $this->find('saml.roles.mapping');
|
return (array) $this->find('saml.roles.mapping');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isSamlRolesResetOnLogin(): bool
|
||||||
|
{
|
||||||
|
return (bool) $this->find('saml.roles.resetOnLogin');
|
||||||
|
}
|
||||||
|
|
||||||
public function getSamlConnection(): array
|
public function getSamlConnection(): array
|
||||||
{
|
{
|
||||||
return (array) $this->find('saml.connection');
|
return (array) $this->find('saml.connection');
|
||||||
|
|||||||
@@ -885,6 +885,9 @@ class Configuration implements ConfigurationInterface
|
|||||||
->arrayNode('roles')
|
->arrayNode('roles')
|
||||||
->addDefaultsIfNotSet()
|
->addDefaultsIfNotSet()
|
||||||
->children()
|
->children()
|
||||||
|
->booleanNode('resetOnLogin')
|
||||||
|
->defaultTrue()
|
||||||
|
->end()
|
||||||
->scalarNode('attribute')
|
->scalarNode('attribute')
|
||||||
->defaultNull()
|
->defaultNull()
|
||||||
->end()
|
->end()
|
||||||
|
|||||||
@@ -56,7 +56,13 @@ final class SamlUserFactory
|
|||||||
$roles[] = $groupMap[$groupName];
|
$roles[] = $groupMap[$groupName];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$user->setRoles($roles);
|
if ($this->configuration->isRolesResetOnLogin()) {
|
||||||
|
$user->setRoles($roles);
|
||||||
|
} else {
|
||||||
|
foreach ($roles as $role) {
|
||||||
|
$user->addRole($role);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$mappingConfig = $this->configuration->getAttributeMapping();
|
$mappingConfig = $this->configuration->getAttributeMapping();
|
||||||
|
|||||||
@@ -451,6 +451,7 @@ class ConfigurationTest extends TestCase
|
|||||||
'activate' => false,
|
'activate' => false,
|
||||||
'title' => 'Login with SAML',
|
'title' => 'Login with SAML',
|
||||||
'roles' => [
|
'roles' => [
|
||||||
|
'resetOnLogin' => true,
|
||||||
'attribute' => null,
|
'attribute' => null,
|
||||||
'mapping' => []
|
'mapping' => []
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user