欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

如何解決springboot2集成oauth2踩坑的問(wèn)題

如何解決springboot2集成oauth2踩坑的問(wèn)題,相信很多沒(méi)有經(jīng)驗(yàn)的人對(duì)此束手無(wú)策,為此本文總結(jié)了問(wèn)題出現(xiàn)的原因和解決方法,通過(guò)這篇文章希望你能解決這個(gè)問(wèn)題。

成都創(chuàng)新互聯(lián)公司堅(jiān)信:善待客戶(hù),將會(huì)成為終身客戶(hù)。我們能堅(jiān)持多年,是因?yàn)槲覀円恢笨芍档眯刨?lài)。我們從不忽悠初訪客戶(hù),我們用心做好本職工作,不忘初心,方得始終。10多年網(wǎng)站建設(shè)經(jīng)驗(yàn)成都創(chuàng)新互聯(lián)公司是成都老牌網(wǎng)站營(yíng)銷(xiāo)服務(wù)商,為您提供做網(wǎng)站、成都做網(wǎng)站、網(wǎng)站設(shè)計(jì)、H5場(chǎng)景定制、網(wǎng)站制作、品牌網(wǎng)站建設(shè)、小程序定制開(kāi)發(fā)服務(wù),給眾多知名企業(yè)提供過(guò)好品質(zhì)的建站服務(wù)。

剛開(kāi)始用springboot1.5集成oauth3沒(méi)問(wèn)題,現(xiàn)在升級(jí)成springboot2.1踩了不少坑,下面列舉下:

問(wèn)題一
Possible CSRF detected - state parameter was required but no state could be found

客戶(hù)端代碼

@EnableOAuth3Sso
@Configuration
public class UiSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http.antMatcher("/**")
                .authorizeRequests()
                .antMatchers("/", "/login**")
                .permitAll()
                .anyRequest()
                .authenticated();
    }

}

在獲取到code后一直停留在登陸頁(yè)面上 如何解決springboot2集成oauth2踩坑的問(wèn)題 在網(wǎng)上找了下有以下方案: 1、配置server.servlet.session.cookie.name=UPSESSIONID 但是這個(gè)試了沒(méi)效果 2、設(shè)置code策略authCodeProvider.setStateMandatory(false); 這里改動(dòng)了很多代碼

@Configuration
@EnableOAuth3Client
@EnableGlobalMethodSecurity(prePostEnabled=true)//開(kāi)啟@PreAuthorize注解
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Autowired
    private OAuth3ClientContext oauth3ClientContext;
    @Override
    protected void configure(HttpSecurity http) throws Exception {
//        // @formatter:off
        http.authorizeRequests()
                .anyRequest().authenticated().and()
                .formLogin().loginPage("/login").permitAll().and()
                .exceptionHandling().and()
                .logout().logoutSuccessUrl("/login").permitAll()
                .and().headers().frameOptions().sameOrigin()
                .and().csrf()
                .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()).and()
                .addFilterBefore(ssoFilter(), BasicAuthenticationFilter.class);//這里需要配置在basic前
    }
    @Bean
    public FilterRegistrationBean oauth3ClientFilterRegistration(OAuth3ClientContextFilter filter) {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(filter);
        registration.setOrder(-100);
        return registration;
    }

    @Bean
    @ConfigurationProperties("security.oauth3")
    public ClientResources trina() {
        return new ClientResources();
    }

    private Filter ssoFilter() {
        CompositeFilter filter = new CompositeFilter();
        List<filter> filters = new ArrayList<filter>();
        filters.add(ssoFilter(trina(), "/login"));
        filter.setFilters(filters);
        return filter;
    }
    private Filter ssoFilter(ClientResources client, String path) {
        OAuth3ClientAuthenticationProcessingFilter oAuth3ClientAuthenticationFilter = new OAuth3ClientAuthenticationProcessingFilter(
                path);
        OAuth3RestTemplate oAuth3RestTemplate = new OAuth3RestTemplate(client.getClient(), this.oauth3ClientContext);
        oAuth3ClientAuthenticationFilter.setRestTemplate(oAuth3RestTemplate);
        AuthorizationCodeAccessTokenProvider authCodeProvider = new AuthorizationCodeAccessTokenProvider();
        authCodeProvider.setStateMandatory(false);
        AccessTokenProviderChain provider = new AccessTokenProviderChain(
                Arrays.asList(authCodeProvider));
        oAuth3RestTemplate.setAccessTokenProvider(provider);
        UserInfoTokenServices tokenServices = new UserInfoTokenServices(client.getResource().getUserInfoUri(),
                client.getClient().getClientId());
        tokenServices.setRestTemplate(oAuth3RestTemplate);
        oAuth3ClientAuthenticationFilter.setTokenServices(tokenServices);
        return oAuth3ClientAuthenticationFilter;
    }

}

class ClientResources {

    @NestedConfigurationProperty
    private AuthorizationCodeResourceDetails client = new AuthorizationCodeResourceDetails();

    @NestedConfigurationProperty
    private ResourceServerProperties resource = new ResourceServerProperties();

    public AuthorizationCodeResourceDetails getClient() {
        return client;
    }

    public ResourceServerProperties getResource() {
        return resource;
    }
}

修改后訪問(wèn)呢連接,登陸后成功跳轉(zhuǎn)到指定頁(yè)面。

看完上述內(nèi)容,你們掌握如何解決springboot2集成oauth2踩坑的問(wèn)題的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!

新聞名稱(chēng):如何解決springboot2集成oauth2踩坑的問(wèn)題
URL地址:http://chinadenli.net/article28/gpdpjp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供、品牌網(wǎng)站設(shè)計(jì)、動(dòng)態(tài)網(wǎng)站、品牌網(wǎng)站建設(shè)、網(wǎng)站改版、App開(kāi)發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

綿陽(yáng)服務(wù)器托管
欧美成人高清在线播放| a久久天堂国产毛片精品| 九九九热视频最新在线| 国产精品日韩欧美第一页| 亚洲精品成人午夜久久| 中文字日产幕码三区国产| 日韩午夜福利高清在线观看| 九九热在线视频精品免费| 欧美国产精品区一区二区三区| 欧美一区二区在线日韩| 女人精品内射国产99| 国产精品一级香蕉一区| 黄色美女日本的美女日人| 情一色一区二区三区四| 在线免费观看一二区视频| 午夜国产精品国自产拍av| 日韩欧美三级视频在线| 黄片在线免费观看全集| 亚洲综合香蕉在线视频| 高中女厕偷拍一区二区三区| 国产高清一区二区不卡| 色一情一乱一区二区三区码| 粉嫩国产美女国产av| 日韩一级毛一欧美一级乱| 青青操成人免费在线视频| 高清一区二区三区大伊香蕉| 一区二区三区免费公开| 国产精品一区二区三区日韩av | 中国少妇精品偷拍视频| 国产伦精品一一区二区三区高清版| 男人和女人黄 色大片| 国产又粗又硬又大又爽的视频| 暴力性生活在线免费视频| 91偷拍与自偷拍精品| 国产又大又黄又粗又免费| 国产又粗又长又爽又猛的视频| 麻豆最新出品国产精品| 国产一级精品色特级色国产| 99视频精品免费视频播放| 国产精品香蕉在线的人| 在线播放欧美精品一区|