Skip to content

Commit cf1f5a5

Browse files
committed
Add support for nameid formats
1 parent 47116ee commit cf1f5a5

File tree

8 files changed

+65
-3
lines changed

8 files changed

+65
-3
lines changed

lib/GADS.pm

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,10 +1595,23 @@ any ['get', 'post'] => '/user_export/?' => require_any_role [qw/useradmin supera
15951595

15961596
any ['get', 'post'] => '/authentication_providers/' => require_any_role [qw/useradmin superadmin/] => sub {
15971597

1598+
my @name_ids = (
1599+
{ label_plain => 'emailAddress', value => 'emailAddress' },
1600+
{ label_plain => 'unspecified', value => 'unspecified' },
1601+
{ label_plain => 'X509SubjectName', value => 'X509SubjectName' },
1602+
{ label_plain => 'WindowsDomainQualifiedName', value => 'WindowsDomainQualifiedName' },
1603+
{ label_plain => 'entity', value => 'entity' },
1604+
{ label_plain => 'transient', value => 'transient' },
1605+
{ label_plain => 'persistent', value => 'persistent' },
1606+
);
1607+
15981608
my $auth = GADS::Authentication->new(schema => schema);
15991609
template 'authentication/providers' => {
16001610
providers => $auth,
16011611
permissions => "permisission", #$auth->permissions,
1612+
values => {
1613+
saml2_nameid => \@name_ids,
1614+
},
16021615
page => 'system_settings',
16031616
};
16041617
};
@@ -1732,6 +1745,7 @@ any ['get', 'post'] => '/authentication_providers/:id' => require_any_role [qw/u
17321745
) : (),
17331746
saml2_relaystate => param('saml2_relaystate'),
17341747
saml2_groupname => param('saml2_groupname'),
1748+
saml2_nameid => param('saml2_nameid'),
17351749
enabled => param('enabled'),
17361750
);
17371751
# FIXME: Remove permissions below
@@ -1763,6 +1777,8 @@ any ['get', 'post'] => '/authentication_providers/:id' => require_any_role [qw/u
17631777
return forwardHome(
17641778
{ danger => "Cannot delete an enabled authentication provider" } )
17651779
if $usero->enabled;
1780+
# FIXME: Will panic here if a user is still associated with this provider
1781+
# timlegge - fix
17661782
if (process( sub { $usero->retire(current_user => logged_in_user) }))
17671783
{
17681784
#FIXME: fix audit
@@ -1777,12 +1793,23 @@ any ['get', 'post'] => '/authentication_providers/:id' => require_any_role [qw/u
17771793
{ 'label_plain' => 'builtin', value => 'builtin'},
17781794
);
17791795

1796+
my @name_ids = (
1797+
{ label_plain => 'emailAddress', value => 'emailAddress' },
1798+
{ label_plain => 'unspecified', value => 'unspecified' },
1799+
{ label_plain => 'X509SubjectName', value => 'X509SubjectName' },
1800+
{ label_plain => 'WindowsDomainQualifiedName', value => 'WindowsDomainQualifiedName' },
1801+
{ label_plain => 'entity', value => 'entity' },
1802+
{ label_plain => 'transient', value => 'transient' },
1803+
{ label_plain => 'persistent', value => 'persistent' },
1804+
);
1805+
17801806
# FIXME need to revise what is passed to the template
17811807
my $output = template 'authentication/provider_edit' => {
17821808
editprovider => $editProvider,
17831809
groups => GADS::Groups->new(schema => schema)->all,
17841810
values => {
17851811
type => \@types,
1812+
saml2_nameid => \@name_ids,
17861813
},
17871814
permissions => $userso->permissions,
17881815
page => 'admin',

lib/GADS/API.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,7 @@ sub _post_add_authentication_providers
789789
saml2_relaystate => $body->{saml2_relaystate},
790790
saml2_groupname => $body->{saml2_groupname},
791791
saml2_unique_id => $body->{saml2_unique_id},
792+
saml2_nameid => $body->{saml2_nameid},
792793
enabled => $body->{enabled},
793794
);
794795

lib/GADS/SAML.pm

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use Net::SAML2::IdP;
1111
use Net::SAML2::SP;
1212
use Net::SAML2::Protocol::Assertion;
1313
use Net::SAML2::Protocol::AuthnRequest;
14-
use URN::OASIS::SAML2 qw(:bindings :urn);
14+
use URN::OASIS::SAML2 qw(:bindings :urn :nameid);
1515

1616
use MIME::Base64;
1717

@@ -168,10 +168,25 @@ sub initiate
168168
unlink $cacert_fh->filename;
169169
my $sso_url = $idp->sso_url('urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect');
170170

171+
my %name_ids = (
172+
emailAddress => NAMEID_EMAIL,
173+
unspecified => NAMEID_UNSPECIFIED,
174+
X509SubjectName => NAMEID_X509_SUBJECT_NAME,
175+
WindowsDomainQualifiedName => NAMEID_WINDOWS_DOMAIN_QUALIFIED_NAME,
176+
entity => NAMEID_FORMAT_ENTITY,
177+
transient => NAMEID_TRANSIENT,
178+
persistent => NAMEID_PERSISTENT,
179+
);
180+
# saml2_nameid can be undefined, blank or a value. Undefined will result in
181+
# the previous behaviour of requesting the email address. Blank will not
182+
# send the format request ($nameid will be undefined)
183+
my $nameid = defined $self->authentication->saml2_nameid
184+
? $name_ids{$self->authentication->saml2_nameid} : NAMEID_EMAIL;
185+
171186
my $authnreq = Net::SAML2::Protocol::AuthnRequest->new(
172187
issuer => $self->authentication->sso_xml,
173188
destination => $sso_url,
174-
nameid_format => $idp->format('emailAddress') || undef,
189+
$nameid ? (nameidpolicy_format => $nameid) : (), # don't send nameidpolicy_format if $nameid is undefined
175190
assertion_url => $self->authentication->sso_url,
176191
);
177192

lib/GADS/Schema/Result/Authentication.pm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ __PACKAGE__->add_columns(
4646
{ data_type => "smallint", default_value => 0, is_nullable => 0 },
4747
"saml2_unique_id",
4848
{ data_type => "varchar", is_nullable => 1, size => 80 },
49+
"saml2_nameid",
50+
{ data_type => "varchar", is_nullable => 1, size => 30 },
4951
"error_messages",
5052
{ data_type => "text", is_nullable => 1 },
5153
);

lib/GADS/Schema/Result/Site.pm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,12 @@ sub provider_fields
323323
type => 'freetext',
324324
placeholder => 'http://schemas.xmlsoap.org/claims/Group',
325325
},
326+
{
327+
name => 'saml2_nameid',
328+
description => 'SAML NameID format',
329+
type => 'dropdown',
330+
is_required => 1,
331+
},
326332
{
327333
name => 'xml',
328334
description => 'Identity Provider Metadata XML',

lib/GADS/Schema/ResultSet/Authentication.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ sub create_provider
8181
saml2_unique_id => $params{saml2_unique_id},
8282
saml2_relaystate => $params{saml2_relaystate},
8383
saml2_groupname => $params{saml2_groupname},
84+
saml2_nameid => $params{saml2_nameid},
8485
});
8586

8687
my $audit = GADS::Audit->new(schema => $self->result_source->schema, user => $params{auth_provider_change});

views/authentication/provider_edit.tt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,16 @@
103103
{id = "1", name = "Enable Authentication Provider"},
104104
{id = "0", name = "Disable Authentication Provider"}
105105
];
106+
ELSIF field.type == "dropdown";
107+
INCLUDE fields/select.tt
108+
id = field.name
109+
name = field.name
110+
label = field.description
111+
placeholder = field.placeholder
112+
items = values.${field.name}
113+
filter = "html"
114+
sub_field = sub_field
115+
sub_params = sub_params;
106116

107117
END;
108118
%]

views/wizard/provider_add.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
firstFrameFields.push(field);
1212
ELSIF field.name == "entity_id" OR field.name == "saml2_firstname" OR
1313
field.name == "saml2_surname" OR field.name == "saml2_groupname" OR
14-
field.name == "xml" OR field.name == "saml2_relaystate";
14+
field.name == "xml" OR field.name == "saml2_relaystate" OR field.name == "saml2_nameid";
1515
secondFrameFields.push(field);
1616
ELSE;
1717
thirdFrameFields.push(field);

0 commit comments

Comments
 (0)