Redo LDAP config in the main configuration and add role mappings

This commit is contained in:
Janne Heß
2022-01-21 21:20:02 +01:00
committed by Graham Christensen
parent 76b4b43ac5
commit 61d74a7194
4 changed files with 71 additions and 47 deletions

View File

@ -59,7 +59,9 @@ sub doLDAPLogin {
my $user = $c->find_user({ username => $username });
my $LDAPUser = $c->find_user({ username => $username }, 'ldap');
my @LDAPRoles = grep { (substr $_, 0, 6) eq "hydra_" } $LDAPUser->roles;
my @LDAPRoles = $LDAPUser->roles;
my %ldap_config = %{Hydra::Helper::Nix::getHydraConfig->{'ldap'}};
my %role_mapping = $ldap_config{'role_mapping'} ? %{$ldap_config{'role_mapping'}} : ();
if (!$user) {
$c->model('DB::Users')->create(
@ -79,8 +81,10 @@ sub doLDAPLogin {
});
}
$user->userroles->delete;
if (@LDAPRoles) {
$user->userroles->create({ role => (substr $_, 6) }) for @LDAPRoles;
foreach my $ldap_role (@LDAPRoles) {
if (%role_mapping{$ldap_role}) {
$user->userroles->create({ role => $role_mapping{$ldap_role} });
}
}
$c->set_authenticated($user);
}