Revize 9ec6ad3a
Přidáno uživatelem Pavel Fidransky před více než 4 roky(ů)
server/src/main/java/org/danekja/ymanager/WebSecurityConfiguration.java | ||
---|---|---|
37 | 37 |
protected void configure(HttpSecurity http) throws Exception { |
38 | 38 |
http.cors() |
39 | 39 |
.and() |
40 |
.csrf().disable() |
|
41 |
.authorizeRequests() |
|
40 |
.csrf().disable() |
|
41 |
.logout().disable() |
|
42 |
.authorizeRequests() |
|
42 | 43 |
.mvcMatchers("/login/*").permitAll() |
43 | 44 |
.anyRequest().authenticated() |
44 | 45 |
.and() |
45 |
.exceptionHandling().authenticationEntryPoint(restAuthenticationEntryPoint) |
|
46 |
.exceptionHandling() |
|
47 |
.authenticationEntryPoint(restAuthenticationEntryPoint) |
|
46 | 48 |
.and() |
47 |
.oauth2Login()
|
|
49 |
.oauth2Login() |
|
48 | 50 |
.userInfoEndpoint().oidcUserService(googleOauthUserService); |
49 | 51 |
} |
50 | 52 |
|
server/src/main/java/org/danekja/ymanager/ws/rest/LoginController.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import org.danekja.ymanager.business.AuthorizationService; |
4 | 4 |
import org.springframework.beans.factory.annotation.Autowired; |
5 |
import org.springframework.security.core.Authentication; |
|
6 |
import org.springframework.security.core.context.SecurityContextHolder; |
|
7 |
import org.springframework.security.web.authentication.logout.LogoutHandler; |
|
8 |
import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler; |
|
5 | 9 |
import org.springframework.security.web.savedrequest.HttpSessionRequestCache; |
6 | 10 |
import org.springframework.security.web.savedrequest.RequestCache; |
7 | 11 |
import org.springframework.stereotype.Controller; |
... | ... | |
18 | 22 |
@Autowired |
19 | 23 |
private AuthorizationService authorizationService; |
20 | 24 |
|
21 |
private RequestCache requestCache = new HttpSessionRequestCache(); |
|
25 |
private final RequestCache requestCache = new HttpSessionRequestCache(); |
|
26 |
private final LogoutHandler logoutHandler = new SecurityContextLogoutHandler(); |
|
22 | 27 |
|
23 | 28 |
/** |
24 | 29 |
* Hackity way of providing connecting apps with means to say where to redirect after login. |
... | ... | |
51 | 56 |
|
52 | 57 |
} |
53 | 58 |
} |
59 |
|
|
60 |
@GetMapping("logout") |
|
61 |
public void logout(HttpServletRequest request, HttpServletResponse response) { |
|
62 |
Authentication auth = SecurityContextHolder.getContext().getAuthentication(); |
|
63 |
if (auth != null) { |
|
64 |
logoutHandler.logout(request, response, auth); |
|
65 |
} |
|
66 |
} |
|
54 | 67 |
} |
Také k dispozici: Unified diff
re #41 custom logout endpoint