久久久久久久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的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習吧!

問題描述

我正在使用 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();
        }
    }

推薦答案

你快到了.這是一個簡單的修復(fù) - @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(使用線程逐塊處理文件)
主站蜘蛛池模板: 国产视频久久久久 | 久久久久国产精品一区二区 | av一区二区三区四区 | 男人天堂国产 | 美国一级黄色片 | 中文字幕在线观看国产 | 成人av免费在线观看 | 2021天天干夜夜爽 | 亚洲综合在线一区二区 | 国产精品免费视频一区 | 亚洲精品在线视频 | 久久爱综合 | 亚洲免费高清 | 男女在线网站 | 久久精品成人 | 日韩欧美精品一区 | 国产精品日韩欧美一区二区三区 | 日本一区不卡 | 雨宫琴音一区二区在线 | 国产亚洲成av人片在线观看桃 | 日本一区二区三区在线观看 | 丁香一区二区 | 一区二区三区精品在线 | 一本色道精品久久一区二区三区 | 亚洲精品中文字幕中文字幕 | 日本成年免费网站 | 欧美日韩国产一区二区三区 | 久久综合久久自在自线精品自 | 成人免费视频在线观看 | 在线成人一区 | 日本久久视频 | 国产aⅴ爽av久久久久久久 | 午夜精品久久久久久久久久久久 | 亚洲成人黄色 | 国产高清在线精品 | 亚洲一区亚洲二区 | 中文精品一区二区 | 一区二区三区网站 | 综合久久综合久久 | 成人免费在线视频 | 久久99久久久久 |