@@ -68,6 +68,11 @@ Next, define the rules that will prevent unauthenticated users to access our pro
68
68
``` java
69
69
// src/main/java/com/auth0/example/security/AppConfig.java
70
70
71
+ @Bean
72
+ public LogoutSuccessHandler logoutSuccessHandler() {
73
+ return new LogoutController ();
74
+ }
75
+
71
76
@Override
72
77
protected void configure(HttpSecurity http) throws Exception {
73
78
http. csrf(). disable();
@@ -76,7 +81,7 @@ protected void configure(HttpSecurity http) throws Exception {
76
81
.antMatchers(" /callback" , " /login" ). permitAll()
77
82
.antMatchers(" /**" ). authenticated()
78
83
.and()
79
- .logout(). permitAll();
84
+ .logout(). logoutSuccessHandler(logoutSuccessHandler()) . permitAll();
80
85
http. sessionManagement(). sessionCreationPolicy(SessionCreationPolicy . NEVER );
81
86
}
82
87
```
@@ -100,11 +105,15 @@ To authenticate the users you will redirect them to the login page which uses [L
100
105
101
106
@RequestMapping (value = " /login" , method = RequestMethod . GET )
102
107
protected String login(final HttpServletRequest req) {
103
- String redirectUri = req. getScheme() + " ://" + req. getServerName() + " :" + req. getServerPort() + " /callback" ;
104
- String authorizeUrl = controller. buildAuthorizeUrl(req, redirectUri)
105
- .withAudience(String . format(" https://%s/userinfo" , appConfig. getDomain()))
106
- .build();
107
- return " redirect:" + authorizeUrl;
108
+ String redirectUri = req. getScheme() + " ://" + req. getServerName();
109
+ if ((req. getScheme(). equals(" http" ) && req. getServerPort() != 80 ) || (req. getScheme(). equals(" https" ) && req. getServerPort() != 443 )) {
110
+ redirectUri += " :" + req. getServerPort();
111
+ }
112
+ redirectUri += " /callback" ;
113
+ String authorizeUrl = controller. buildAuthorizeUrl(req, redirectUri)
114
+ .withAudience(String . format(" https://%s/userinfo" , appConfig. getDomain()))
115
+ .build();
116
+ return " redirect:" + authorizeUrl;
108
117
}
109
118
```
110
119
0 commit comments