1
1
package org .cloudfoundry .identity .samples .authcode ;
2
2
3
3
import java .io .IOException ;
4
+ import java .net .URL ;
4
5
import java .util .Arrays ;
5
6
import java .util .Map ;
6
7
@@ -55,6 +56,8 @@ public static void main(String[] args) {
55
56
// property set by spring-cloud-sso-connector
56
57
@ Value ("${ssoServiceUrl:placeholder}" )
57
58
private String ssoServiceUrl ;
59
+ @ Value ("${security.oauth2.client.clientId}" )
60
+ private String clientId ;
58
61
59
62
@ Autowired (required = false )
60
63
private OAuth2RestTemplate oauth2RestTemplate ;
@@ -81,16 +84,15 @@ public String index() {
81
84
}
82
85
83
86
@ RequestMapping ("/authorization_code" )
84
- public String authCode (Model model ) throws Exception {
87
+ public String authCode (Model model , HttpServletRequest request ) throws Exception {
85
88
if (ssoServiceUrl .equals ("placeholder" )) {
86
89
model .addAttribute ("header" , "Warning: You need to bind to the SSO service." );
87
90
model .addAttribute ("warning" , "Please bind your app to restore regular functionality" );
88
91
return "configure_warning" ;
89
92
}
90
- Map <?,?> userInfoResponse = oauth2RestTemplate .getForObject ("{ssoServiceUrl}/userinfo" , Map .class ,
91
- ssoServiceUrl );
93
+ Map <?,?> userInfoResponse = oauth2RestTemplate .getForObject ("{ssoServiceUrl}/userinfo" , Map .class , ssoServiceUrl );
92
94
model .addAttribute ("ssoServiceUrl" ,ssoServiceUrl );
93
- model .addAttribute ("response" ,toPrettyJsonString (userInfoResponse ));
95
+ model .addAttribute ("response" , toPrettyJsonString (userInfoResponse ));
94
96
95
97
OAuth2AccessToken accessToken = oauth2RestTemplate .getOAuth2ClientContext ().getAccessToken ();
96
98
if (accessToken != null ) {
@@ -101,12 +103,14 @@ public String authCode(Model model) throws Exception {
101
103
}
102
104
103
105
@ RequestMapping (value ="/logout" , method = GET )
104
- public String logout (HttpServletRequest request , HttpServletResponse response ) {
106
+ public String logout (HttpServletRequest request , HttpServletResponse response ) throws IOException {
105
107
Authentication auth = SecurityContextHolder .getContext ().getAuthentication ();
106
108
if (auth != null ){
107
109
new SecurityContextLogoutHandler ().logout (request , response , auth );
108
110
}
109
- return "redirect:" + ssoServiceUrl + "/logout.do" ;
111
+ URL url = new URL (request .getRequestURL ().toString ());
112
+ String urlStr = url .getProtocol () + "://" + url .getAuthority ();
113
+ return "redirect:" + ssoServiceUrl + "/logout.do?redirect=" + urlStr + "&clientId=" + clientId ;
110
114
}
111
115
112
116
private Map <String , ?> parseToken (String base64Token ) throws IOException {
0 commit comments