Skip to content

Commit 387f00d

Browse files
committed
Extend Saml2AuthenticationInfo to also provide the NameID value for SAML 2.0 Single Logout
Issue gh-10820
1 parent 55a66b9 commit 387f00d

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/OpenSamlLogoutRequestResolver.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,19 @@ Saml2LogoutRequest resolve(HttpServletRequest request, Authentication authentica
126126
issuer.setValue(registration.getEntityId());
127127
logoutRequest.setIssuer(issuer);
128128
NameID nameId = this.nameIdBuilder.buildObject();
129-
nameId.setValue(authentication.getName());
130129
logoutRequest.setNameID(nameId);
131130
Saml2AuthenticationInfo info = Saml2AuthenticationInfo.fromAuthentication(authentication);
132131
if (info != null) {
132+
nameId.setValue(info.getNameId());
133133
for (String index : info.getSessionIndexes()) {
134134
SessionIndex sessionIndex = this.sessionIndexBuilder.buildObject();
135135
sessionIndex.setSessionIndex(index);
136136
logoutRequest.getSessionIndexes().add(sessionIndex);
137137
}
138138
}
139+
else {
140+
nameId.setValue(authentication.getName());
141+
}
139142
logoutRequestConsumer.accept(registration, logoutRequest);
140143
if (logoutRequest.getID() == null) {
141144
logoutRequest.setID("LR" + UUID.randomUUID());

0 commit comments

Comments
 (0)