Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support for mapping remote user auth claims to user attributes #365

Open
wants to merge 2 commits into
base: stable
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions lib/RT/Interface/Web.pm
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,35 @@ sub WebRemoteUserAutocreateInfo {
$user_info{'Comments'} = $comments if defined $comments;
$user_info{'RealName'} = $realname if defined $realname;

# Get and populate RT-fields with attributes, set in environment variables, from
# the webserver that provide user authentication via REMOTE_USER.
if (RT->Config->Get('WebRemoteUserAuth')) {
my $remote_user = RequestENV("REMOTE_USER");
$RT::Logger->info("Remote user is $remote_user \n");

# Get the mapping configuration for RemoteUserHeaders
my $mapping = RT->Config->Get('RemoteUserHeaders')->{'attributes_map'};

# Iterate over the keys of the mapping configuration
for (keys(%{$mapping})) {
my $rtVar = $_;
my @envVar = @{ $mapping->{$_} }; # Array of environment variables associated with the RT variable

for(my $i=0; $i < scalar(@envVar); $i++) {
my $value = RequestENV("$envVar[$i]");
$RT::Logger->info("Found header: $envVar[$i] with value <$value> Mapped to RT variable: $rtVar \n");

# Make sure header is not empty before adding it, if empty; see if there's another mapping
if ((defined($value) and length($value)) and (not defined($user_info{"$rtVar"}))) {
$user_info{"$rtVar"} = $value;
$RT::Logger->info("RT variable $rtVar set to <$value> taken from header $envVar[$i]\n");
} elsif (defined($user_info{"$rtVar"})) {
$RT::Logger->info("RT variable $rtVar is already set to $user_info{\"$rtVar\"} so skipping header $envVar[$i]\n");
}
}
}
}

# and return the wad of stuff
return {%user_info};
}
Expand Down