Document SAML Attribute Support

Issue gh-8661
This commit is contained in:
Josh Cummings 2020-06-18 11:42:08 -06:00
parent 360db53dd2
commit 8cbdcfe756
No known key found for this signature in database
GPG Key ID: 49EF60DD7FF83443
2 changed files with 21 additions and 3 deletions

View File

@ -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";
}
}

View File

@ -19,6 +19,11 @@
<head>
<title>Spring Security - SAML 2.0 Login</title>
<meta charset="utf-8" />
<style>
span, dt {
font-weight: bold;
}
</style>
</head>
<body>
<div>
@ -30,6 +35,12 @@
</a>
</div>
<h1>SAML 2.0 Login with Spring Security</h1>
<div>You are successfully logged in as <span sec:authentication="name"></span></div>
<p>You are successfully logged in as <span sec:authentication="name"></span></p>
<p>You're email address is <span th:text="${emailAddress}"></span></p>
<h2>All Your Attributes</h2>
<dl th:each="userAttribute : ${userAttributes}">
<dt th:text="${userAttribute.key}"></dt>
<dd th:text="${userAttribute.value}"></dd>
</dl>
</body>
</html>