Skip to content

Commit 02a8c41

Browse files
chschujzheaux
authored andcommitted
Add NameID to SAML 2.0 Authentication Info
Issue gh-10820
1 parent 36c7b91 commit 02a8c41

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

saml2/saml2-service-provider/src/main/java/org/springframework/security/saml2/provider/service/authentication/Saml2AuthenticatedPrincipal.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ default String getRelyingPartyRegistrationId() {
7777
return null;
7878
}
7979

80+
@Override
81+
default String getNameId() {
82+
return getName();
83+
}
84+
8085
@Override
8186
default List<String> getSessionIndexes() {
8287
return Collections.emptyList();

saml2/saml2-service-provider/src/main/java/org/springframework/security/saml2/provider/service/authentication/Saml2AuthenticationInfo.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.util.List;
2020

21+
import org.opensaml.saml.saml2.core.NameID;
2122
import org.opensaml.saml.saml2.core.SessionIndex;
2223

2324
import org.springframework.security.core.Authentication;
@@ -41,6 +42,12 @@ public interface Saml2AuthenticationInfo {
4142
*/
4243
String getRelyingPartyRegistrationId();
4344

45+
/**
46+
* Get the {@link NameID} value of the authenticated principal
47+
* @return the {@link NameID} value of the authenticated principal
48+
*/
49+
String getNameId();
50+
4451
/**
4552
* Get the {@link SessionIndex} values of the authenticated principal
4653
* @return the {@link SessionIndex} values of the authenticated principal

saml2/saml2-service-provider/src/main/java/org/springframework/security/saml2/provider/service/web/authentication/logout/BaseOpenSamlLogoutRequestResolver.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,16 +147,19 @@ public Saml2LogoutRequest resolve(HttpServletRequest request, Authentication aut
147147
issuer.setValue(entityId);
148148
logoutRequest.setIssuer(issuer);
149149
NameID nameId = this.nameIdBuilder.buildObject();
150-
nameId.setValue(authentication.getName());
151150
logoutRequest.setNameID(nameId);
152151
Saml2AuthenticationInfo info = Saml2AuthenticationInfo.fromAuthentication(authentication);
153152
if (info != null) {
153+
nameId.setValue(info.getNameId());
154154
for (String index : info.getSessionIndexes()) {
155155
SessionIndex sessionIndex = this.sessionIndexBuilder.buildObject();
156156
sessionIndex.setValue(index);
157157
logoutRequest.getSessionIndexes().add(sessionIndex);
158158
}
159159
}
160+
else {
161+
nameId.setValue(authentication.getName());
162+
}
160163
logoutRequest.setIssueInstant(Instant.now(this.clock));
161164
this.parametersConsumer
162165
.accept(new LogoutRequestParameters(request, registration, authentication, logoutRequest));

0 commit comments

Comments
 (0)