|
22 | 22 | import org.springframework.boot.autoconfigure.SpringBootApplication;
|
23 | 23 | import org.springframework.http.HttpStatus;
|
24 | 24 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
25 |
| -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; |
| 25 | +import org.springframework.context.annotation.Bean; |
26 | 26 | import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
27 | 27 | import org.springframework.security.oauth2.core.user.OAuth2User;
|
| 28 | +import org.springframework.security.web.SecurityFilterChain; |
28 | 29 | import org.springframework.security.web.authentication.HttpStatusEntryPoint;
|
29 | 30 | import org.springframework.web.bind.annotation.GetMapping;
|
30 | 31 | import org.springframework.web.bind.annotation.RestController;
|
31 | 32 |
|
32 | 33 | @SpringBootApplication
|
33 | 34 | @RestController
|
34 |
| -public class SocialApplication extends WebSecurityConfigurerAdapter { |
| 35 | +public class SocialApplication { |
35 | 36 |
|
36 | 37 | @GetMapping("/user")
|
37 | 38 | public Map<String, Object> user(@AuthenticationPrincipal OAuth2User principal) {
|
38 | 39 | return Collections.singletonMap("name", principal.getAttribute("name"));
|
39 | 40 | }
|
40 | 41 |
|
41 |
| - @Override |
42 |
| - protected void configure(HttpSecurity http) throws Exception { |
| 42 | + @Bean |
| 43 | + public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { |
43 | 44 | // @formatter:off
|
44 | 45 | http
|
45 |
| - .authorizeRequests(a -> a |
46 |
| - .antMatchers("/", "/error", "/webjars/**").permitAll() |
47 |
| - .anyRequest().authenticated() |
48 |
| - ) |
49 |
| - .exceptionHandling(e -> e |
50 |
| - .authenticationEntryPoint(new HttpStatusEntryPoint(HttpStatus.UNAUTHORIZED)) |
51 |
| - ) |
52 |
| - .oauth2Login(); |
| 46 | + .authorizeRequests(a -> a |
| 47 | + .antMatchers("/", "/error", "/webjars/**").permitAll() |
| 48 | + .anyRequest().authenticated() |
| 49 | + ) |
| 50 | + .exceptionHandling(e -> e |
| 51 | + .authenticationEntryPoint(new HttpStatusEntryPoint(HttpStatus.UNAUTHORIZED)) |
| 52 | + ) |
| 53 | + .oauth2Login(); |
| 54 | + return http.build(); |
53 | 55 | // @formatter:on
|
54 | 56 | }
|
55 |
| - |
56 | 57 | public static void main(String[] args) {
|
57 | 58 | SpringApplication.run(SocialApplication.class, args);
|
58 | 59 | }
|
|
0 commit comments