From 8cbdcfe75610f865917a0d371211e22dcc7a10e6 Mon Sep 17 00:00:00 2001 From: Josh Cummings Date: Thu, 18 Jun 2020 11:42:08 -0600 Subject: [PATCH] Document SAML Attribute Support Issue gh-8661 --- .../src/main/java/sample/IndexController.java | 11 +++++++++-- .../src/main/resources/templates/index.html | 13 ++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/samples/boot/saml2login/src/main/java/sample/IndexController.java b/samples/boot/saml2login/src/main/java/sample/IndexController.java index 0d859205c5..8da3c251eb 100644 --- a/samples/boot/saml2login/src/main/java/sample/IndexController.java +++ b/samples/boot/saml2login/src/main/java/sample/IndexController.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,14 +16,21 @@ package sample; +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.security.saml2.provider.service.authentication.Saml2AuthenticatedPrincipal; import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; @Controller public class IndexController { @GetMapping("/") - public String index() { + public String index(Model model, + @AuthenticationPrincipal Saml2AuthenticatedPrincipal principal) { + String emailAddress = principal.getFirstAttribute("emailAddress"); + model.addAttribute("emailAddress", emailAddress); + model.addAttribute("userAttributes", principal.getAttributes()); return "index"; } } diff --git a/samples/boot/saml2login/src/main/resources/templates/index.html b/samples/boot/saml2login/src/main/resources/templates/index.html index e278cbe73c..0fb8ad872a 100644 --- a/samples/boot/saml2login/src/main/resources/templates/index.html +++ b/samples/boot/saml2login/src/main/resources/templates/index.html @@ -19,6 +19,11 @@ Spring Security - SAML 2.0 Login +
@@ -30,6 +35,12 @@

SAML 2.0 Login with Spring Security

-
You are successfully logged in as
+

You are successfully logged in as

+

You're email address is

+

All Your Attributes

+
+
+
+