久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

盡管 authorizeRequests().anyRequest().permitAll() spring-se

spring-security returns 401 despite authorizeRequests().anyRequest().permitAll()(盡管 authorizeRequests().anyRequest().permitAll() spring-security 返回 401)
本文介紹了盡管 authorizeRequests().anyRequest().permitAll() spring-security 返回 401的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在使用 spring-securityspring-security-oauth2(JWT 訪問令牌)進行身份驗證和授權(quán).這個想法是讓所有請求通過,但能夠區(qū)分經(jīng)過身份驗證的用戶和未經(jīng)身份驗證的用戶.一旦我啟用 @EnableResourceServer 我配置的 HttpSecurity 似乎被忽略.并且請求返回 401:

I'm using spring-security and spring-security-oauth2 (JWT access tokens) for authentication and authorization. The idea is to let all requests through, but to be able to distinguish between authenticated users and unauthenticated users. As soon as I enable @EnableResourceServer my configured HttpSecurity seems to get ignored. And requests return 401:

{
    "error": "unauthorized",
    "error_description": "Full authentication is required to access this resource"
}

這是配置:

@SpringBootApplication
@EnableJpaRepositories
@ComponentScan
@EntityScan
@EnableWebSecurity
public class Application {

    public static void main(final String[] args) {
        new SpringApplicationBuilder(Application.class).bannerMode(Banner.Mode.OFF).run(args);
    }

    @EnableResourceServer
    public static class SecurityConfig extends WebSecurityConfigurerAdapter implements JwtAccessTokenConverterConfigurer {

        @Override
        protected void configure(final HttpSecurity http) throws Exception {
            http.csrf().disable();
            http.authorizeRequests().anyRequest().permitAll();
        }

        @Override
        public void configure(final JwtAccessTokenConverter converter) {
            final DefaultAccessTokenConverter conv = new DefaultAccessTokenConverter();
            conv.setUserTokenConverter(userAuthenticationConverter());
            converter.setAccessTokenConverter(conv);

        }

        @Bean
        public UserAuthenticationConverter userAuthenticationConverter() {
            return new ResourceAuthenticationConverter();
        }
    }

推薦答案

你快到了.這是一個簡單的修復 - @EnableResourceServer 的 javadoc 提供了答案:

You're almost there. It's an easy fix - the javadoc of @EnableResourceServer provides the answer:

用戶應(yīng)該添加這個注解并提供一個@Bean 類型ResourceServerConfigurer(例如,通過 ResourceServerConfigurerAdapter)指定資源的詳細信息(URL 路徑和資源id).

Users should add this annotation and provide a @Bean of type ResourceServerConfigurer (e.g. via ResourceServerConfigurerAdapter) that specifies the details of the resource (URL paths and resource id).

但是,您使用的是 WebSecurityConfigurerAdapter.只需將其改為ResourceServerConfigurerAdapter,增強configure的可見性:

You're using a WebSecurityConfigurerAdapter however. Just change it to ResourceServerConfigurerAdapter and enhance the visibility of configure:

@EnableResourceServer
public static class SecurityConfig extends ResourceServerConfigurerAdapter implements JwtAccessTokenConverterConfigurer {
// snip
        @Override
        public void configure(final HttpSecurity http) throws Exception {
            http.csrf().disable();
            http.authorizeRequests().anyRequest().permitAll();
        }
// snip

這篇關(guān)于盡管 authorizeRequests().anyRequest().permitAll() spring-security 返回 401的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環(huán)繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數(shù)據(jù)庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 欧美在线a| 日韩一区二区三区av | 国产精品久久二区 | 天天操夜夜拍 | 欧美一区二区另类 | 欧美日韩国产在线观看 | 亚洲国产成人精品女人 | 日韩免费视频 | 亚洲综合色 | 日韩美香港a一级毛片免费 国产综合av | 欧美日韩视频在线播放 | 日韩www | 国产在线精品一区二区 | 91在线看视频 | 日韩精品一区二区三区免费视频 | 久久最新| 国产一区二区三区不卡av | 成人久久久久 | 欧美精品一区二区在线观看 | 91看片视频 | 九九亚洲精品 | 国产欧美日韩综合精品一 | 天色综合网 | 在线婷婷 | 99精品视频免费观看 | 天天艹日日干 | 91观看| 免费国产黄网站在线观看视频 | 91一区二区三区在线观看 | 精品久久久久久久人人人人传媒 | 波多野结衣精品 | 久久这里有精品 | a国产一区二区免费入口 | 国内久久精品 | 91av在线免费播放 | 国产精品日韩 | 综合在线视频 | 国产成人高清成人av片在线看 | 成人国产精品久久 | 国产在线精品一区二区 | 99久久国产免费 |