Skip to content

Commit 8cbdcfe

Browse files
committed
Document SAML Attribute Support
Issue gh-8661
1 parent 360db53 commit 8cbdcfe

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

samples/boot/saml2login/src/main/java/sample/IndexController.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,14 +16,21 @@
1616

1717
package sample;
1818

19+
import org.springframework.security.core.annotation.AuthenticationPrincipal;
20+
import org.springframework.security.saml2.provider.service.authentication.Saml2AuthenticatedPrincipal;
1921
import org.springframework.stereotype.Controller;
22+
import org.springframework.ui.Model;
2023
import org.springframework.web.bind.annotation.GetMapping;
2124

2225
@Controller
2326
public class IndexController {
2427

2528
@GetMapping("/")
26-
public String index() {
29+
public String index(Model model,
30+
@AuthenticationPrincipal Saml2AuthenticatedPrincipal principal) {
31+
String emailAddress = principal.getFirstAttribute("emailAddress");
32+
model.addAttribute("emailAddress", emailAddress);
33+
model.addAttribute("userAttributes", principal.getAttributes());
2734
return "index";
2835
}
2936
}

samples/boot/saml2login/src/main/resources/templates/index.html

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
<head>
2020
<title>Spring Security - SAML 2.0 Login</title>
2121
<meta charset="utf-8" />
22+
<style>
23+
span, dt {
24+
font-weight: bold;
25+
}
26+
</style>
2227
</head>
2328
<body>
2429
<div>
@@ -30,6 +35,12 @@
3035
</a>
3136
</div>
3237
<h1>SAML 2.0 Login with Spring Security</h1>
33-
<div>You are successfully logged in as <span sec:authentication="name"></span></div>
38+
<p>You are successfully logged in as <span sec:authentication="name"></span></p>
39+
<p>You're email address is <span th:text="${emailAddress}"></span></p>
40+
<h2>All Your Attributes</h2>
41+
<dl th:each="userAttribute : ${userAttributes}">
42+
<dt th:text="${userAttribute.key}"></dt>
43+
<dd th:text="${userAttribute.value}"></dd>
44+
</dl>
3445
</body>
3546
</html>

0 commit comments

Comments
 (0)