-
Notifications
You must be signed in to change notification settings - Fork 71
/
SampleController.java
58 lines (52 loc) · 2.38 KB
/
SampleController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.microsoft.azuresamples.msal4j.msidentityspringbootwebapp;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.security.oauth2.core.oidc.user.OidcUser;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
@Controller
public class SampleController {
/**
* Add HTML partial fragment from /templates/content folder to request and serve base html
* @param model Model used for placing user param and bodyContent param in request before serving UI.
* @param fragment used to determine which partial to put into UI
*/
private String hydrateUI(Model model, String fragment) {
model.addAttribute("bodyContent", String.format("content/%s.html", fragment));
return "base"; //base.html in /templates folder
}
/**
* Sign in status endpoint
* The page demonstrates sign-in status. For full details, see the src/main/webapp/content/status.html file.
*
* @param model Model used for placing bodyContent param in request before serving UI.
* @return String the UI.
*/
@GetMapping(value = {"/", "sign_in_status", "/index"})
public String status(Model model) {
return hydrateUI(model, "status");
}
/**
* Token details endpoint
* Demonstrates how to extract and make use of token details
* For full details, see method: Utilities.filterclaims(OidcUser principal)
*
* @param model Model used for placing claims param and bodyContent param in request before serving UI.
* @param principal OidcUser this object contains all ID token claims about the user. See utilities file.
* @return String the UI.
*/
@GetMapping(path = "/token_details")
public String tokenDetails(Model model, @AuthenticationPrincipal OidcUser principal) {
model.addAttribute("claims", Utilities.filterClaims(principal));
return hydrateUI(model, "token");
}
// survey endpoint - did the sample address your needs?
// not an integral a part of this tutorial.
@GetMapping(path = "/survey")
public String survey(Model model) {
return hydrateUI(model, "survey");
}
}