首页>代码>Spring Boot整合Spring Security OAuth2实现第三方用户登录授权实例,支持QQ,微信,微博等平台>/spring-security-oauth2/src/main/java/com/hellokoding/springboot/oauth2/SecurityConfig.java
package com.hellokoding.springboot.oauth2;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.csrf.CookieCsrfTokenRepository;

@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests(a -> a
                .antMatchers("/").permitAll()
                .anyRequest().authenticated())
            .csrf(c -> c.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()))
            .logout(l -> l.logoutSuccessUrl("/").permitAll())
            .oauth2Login(o -> o
                .successHandler((request, response, authentication) -> {
                    response.sendRedirect("/");
                }));
    }
}
最近下载更多
xsxtxbb  LV8 2022年10月10日
win1991  LV6 2022年7月6日
chen519168  LV9 2022年6月11日
237116624  LV15 2022年3月16日
xuan0422  LV6 2022年3月9日
史鹏丽  LV2 2021年11月3日
A13697876274  LV5 2021年8月17日
sinbero  LV8 2021年5月28日
1224183237  LV10 2021年4月24日
天险无涯  LV15 2021年4月13日
最近浏览更多
sjwc88  LV4 2024年12月15日
15578157792  LV7 2024年12月6日
citybird  LV4 2024年11月20日
dapeng0011  LV15 2024年8月25日
一位靓仔路过  LV5 2024年6月6日
周青松197  LV3 2024年3月7日
2206371875  LV7 2023年11月6日
libo1212  LV8 2023年6月1日
叁卍石  LV5 2023年5月19日
locklock  LV2 2023年3月13日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友