401로 봄 보안에서 페이지에 액세스 할 수 없습니다.

LowCool

일반 사용자 및 관리자 기능으로 기본 스프링 보안을 사용하려고합니다. 나는 기사를 따르고있다 . 하지만 401 unauthorize 오류가 계속 발생하고 우편 배달부와 curl 명령으로 시도했지만 도움이되지 않았습니다.

아래는 내 봄 구성 파일입니다.

package com.ebi.uk.config;

import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

public class SpringSecurityConfig extends WebSecurityConfigurerAdapter  {

        @Override
        protected void configure(AuthenticationManagerBuilder auth) throws Exception {
            auth.inMemoryAuthentication()
                    .withUser("user").password("{noop}password").roles("USER")
                    .and()
                    .withUser("admin").password("{noop}password").roles("USER", "ADMIN");

        }
        
        @Override
        protected void configure(HttpSecurity http) throws Exception {

            http
                    //HTTP Basic authentication
                    .httpBasic()
                    .and()
                    .authorizeRequests()
                    .antMatchers(HttpMethod.GET, "/persons/all").hasRole("ADMIN")
                    .antMatchers(HttpMethod.POST, "/persons/create").hasRole("USER")
                    
                    .antMatchers(HttpMethod.DELETE, "/persons/delete/**").hasRole("ADMIN")
                    .antMatchers(HttpMethod.PUT, "/persons/update/**").hasRole("ADMIN")
                    .and()
                    .csrf().disable()
                    .formLogin().disable();
        }

}

아래는 내 pom.xml입니다.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.ebi.uk</groupId>
    <artifactId>ebiProjectJava</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>ebiProjectJava</name>
    <description>Project for EBI UK</description>
    <properties>
        <java.version>1.8</java.version>
        <testcontainers.version>1.15.1</testcontainers.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
        </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <!--   <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency> -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <!-- spring security test -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <scope>test</scope>
        </dependency>
        
        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>junit-jupiter</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>mysql</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.testcontainers</groupId>
                <artifactId>testcontainers-bom</artifactId>
                <version>${testcontainers.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>

        </plugins>
    </build>

</project>

아래는 우편 배달부에서 전화를 걸 때 SS입니다. 여기에 이미지 설명 입력아래는 내 예외 메시지입니다. 2

021-02-13 14:53:27.308 DEBUG 17240 --- [nio-8080-exec-6] o.a.c.authenticator.AuthenticatorBase    : Security checking request GET /persons/all
2021-02-13 14:53:27.308 DEBUG 17240 --- [nio-8080-exec-6] org.apache.catalina.realm.RealmBase      :   No applicable constraints defined
2021-02-13 14:53:27.309 DEBUG 17240 --- [nio-8080-exec-6] o.a.c.authenticator.AuthenticatorBase    : Not subject to any constraint
2021-02-13 14:53:27.309 DEBUG 17240 --- [nio-8080-exec-6] o.s.security.web.FilterChainProxy        : Securing GET /persons/all
2021-02-13 14:53:27.309 DEBUG 17240 --- [nio-8080-exec-6] s.s.w.c.SecurityContextPersistenceFilter : Set SecurityContextHolder to empty SecurityContext
2021-02-13 14:53:27.678 DEBUG 17240 --- [nio-8080-exec-6] o.s.s.a.dao.DaoAuthenticationProvider    : Failed to find user 'admin'
2021-02-13 14:53:27.680 DEBUG 17240 --- [nio-8080-exec-6] o.s.s.w.a.www.BasicAuthenticationFilter  : Failed to process authentication request

org.springframework.security.authentication.BadCredentialsException: Bad credentials
    at org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider.authenticate(AbstractUserDetailsAuthenticationProvider.java:141) ~[spring-security-core-5.4.2.jar:5.4.2]
    at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:182) ~[spring-security-core-5.4.2.jar:5.4.2]
    at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:201) ~[spring-security-core-5.4.2.jar:5.4.2]
후안 BC

여기서 문제는 예제처럼 @Configuration 어노테이션으로 SpringSecurityConfig.java를 장식하지 않았으므로 무시된다는 것입니다. 이 경우 앱은 BASIC 인증으로 보호되지만 비밀번호가 무작위로 생성되고 콘솔의 로그에 메시지가 표시됩니다. 귀하의 경우 이미 언급했듯이 @Configuration을 클래스에 추가하십시오.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

내 봄 부팅 응용 프로그램 페이지에 액세스 할 수 없습니다.

분류에서Dev

봄 부팅 application.properties에 액세스 할 수 없습니다

분류에서Dev

보호 수준으로 인해 페이지 필드에 액세스 할 수 없습니다.

분류에서Dev

봄 부팅 2.1.1.RELEASE에 메시지 소스에 액세스 할 수 없습니다

분류에서Dev

IIS에서 로컬 Bonobo Git Server 홈 페이지에 액세스 할 수 없습니다.

분류에서Dev

GCP Secret Manager에서 보안 비밀에 액세스 할 수 없습니다.

분류에서Dev

프로토 타입에서 액세스 할 수 없습니다.

분류에서Dev

IP로 웹에 액세스 할 수 있지만 DNS 이름으로는 액세스 할 수 없습니다.

분류에서Dev

/ 이외의 경로에 액세스 할 수 없습니다.

분류에서Dev

Codeigniter에서 내 웹 페이지에 액세스 할 수 없습니다.

분류에서Dev

Vagrant nginx에서 laravel 페이지에 액세스 할 수 없습니다.

분류에서Dev

"로컬 디스크"에 액세스 할 수 없습니다.

분류에서Dev

"로컬 디스크"에 액세스 할 수 없습니다.

분류에서Dev

페이지로드시 생성 된 입력 텍스트 필드에 액세스 할 수 없습니다.

분류에서Dev

Java의 자격 증명으로 웹 페이지에 액세스 할 수 없습니다.

분류에서Dev

마스터 페이지의 컨트롤에 액세스 할 수 없습니다.

분류에서Dev

다른 라우터 설정 페이지에 액세스 할 수 없습니다.

분류에서Dev

다른 라우터 설정 페이지에 액세스 할 수 없습니다.

분류에서Dev

Apache 오류 로그에 액세스 할 수 없습니다.

분류에서Dev

getelementbyid로 ID에 액세스 할 수 없습니다.

분류에서Dev

PHP 개체에 배열로 액세스 할 수 없습니다.

분류에서Dev

.desktop으로 .jar 파일에 액세스 할 수 없습니다.

분류에서Dev

업로드 된 파일에 액세스 할 수 없습니다.

분류에서Dev

로컬 웹 및 phpMyAdmin에 액세스 할 수 없습니다.

분류에서Dev

ID로 캐 러셀에 액세스 할 수 없습니다.

분류에서Dev

게터에 제대로 액세스 할 수 없습니다

분류에서Dev

iPhone으로 내 웹 앱에 액세스 할 수 없습니다.

분류에서Dev

Zencart로 db에 액세스 할 수 없습니다.

분류에서Dev

Cloud Functions로 Datasnapshot 값에 액세스 할 수 없습니다.

Related 관련 기사

  1. 1

    내 봄 부팅 응용 프로그램 페이지에 액세스 할 수 없습니다.

  2. 2

    봄 부팅 application.properties에 액세스 할 수 없습니다

  3. 3

    보호 수준으로 인해 페이지 필드에 액세스 할 수 없습니다.

  4. 4

    봄 부팅 2.1.1.RELEASE에 메시지 소스에 액세스 할 수 없습니다

  5. 5

    IIS에서 로컬 Bonobo Git Server 홈 페이지에 액세스 할 수 없습니다.

  6. 6

    GCP Secret Manager에서 보안 비밀에 액세스 할 수 없습니다.

  7. 7

    프로토 타입에서 액세스 할 수 없습니다.

  8. 8

    IP로 웹에 액세스 할 수 있지만 DNS 이름으로는 액세스 할 수 없습니다.

  9. 9

    / 이외의 경로에 액세스 할 수 없습니다.

  10. 10

    Codeigniter에서 내 웹 페이지에 액세스 할 수 없습니다.

  11. 11

    Vagrant nginx에서 laravel 페이지에 액세스 할 수 없습니다.

  12. 12

    "로컬 디스크"에 액세스 할 수 없습니다.

  13. 13

    "로컬 디스크"에 액세스 할 수 없습니다.

  14. 14

    페이지로드시 생성 된 입력 텍스트 필드에 액세스 할 수 없습니다.

  15. 15

    Java의 자격 증명으로 웹 페이지에 액세스 할 수 없습니다.

  16. 16

    마스터 페이지의 컨트롤에 액세스 할 수 없습니다.

  17. 17

    다른 라우터 설정 페이지에 액세스 할 수 없습니다.

  18. 18

    다른 라우터 설정 페이지에 액세스 할 수 없습니다.

  19. 19

    Apache 오류 로그에 액세스 할 수 없습니다.

  20. 20

    getelementbyid로 ID에 액세스 할 수 없습니다.

  21. 21

    PHP 개체에 배열로 액세스 할 수 없습니다.

  22. 22

    .desktop으로 .jar 파일에 액세스 할 수 없습니다.

  23. 23

    업로드 된 파일에 액세스 할 수 없습니다.

  24. 24

    로컬 웹 및 phpMyAdmin에 액세스 할 수 없습니다.

  25. 25

    ID로 캐 러셀에 액세스 할 수 없습니다.

  26. 26

    게터에 제대로 액세스 할 수 없습니다

  27. 27

    iPhone으로 내 웹 앱에 액세스 할 수 없습니다.

  28. 28

    Zencart로 db에 액세스 할 수 없습니다.

  29. 29

    Cloud Functions로 Datasnapshot 값에 액세스 할 수 없습니다.

뜨겁다태그

보관