forked from onewelcome/java-spring-oidc-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSampleSecuredController.java
36 lines (26 loc) · 1.26 KB
/
SampleSecuredController.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
package com.onegini.oidc;
import java.security.Principal;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import com.onegini.oidc.model.TokenDetails;
@Controller
public class SampleSecuredController {
public static final String PAGE_SECURED = "/secured";
@Resource
private SessionFrameService sessionFrameService;
@GetMapping(PAGE_SECURED)
public String userInfo(final Principal principal, final ModelMap modelMap, final HttpServletRequest request) {
if (principal instanceof PreAuthenticatedAuthenticationToken) {
final PreAuthenticatedAuthenticationToken authenticationToken = (PreAuthenticatedAuthenticationToken) principal;
final TokenDetails tokenDetails = (TokenDetails) authenticationToken.getDetails();
modelMap.addAttribute("jwtClaimsSet", tokenDetails.getJwtClaimsSet());
modelMap.addAttribute("userInfo", authenticationToken.getPrincipal());
sessionFrameService.addSessionFramesAttributes(modelMap, request);
}
return "secured";
}
}