programing

'security.basic.enabled' 속성은 사용되지 않습니다.보안 자동 구성은 커스터마이즈할 수 없습니다.

bestprogram 2023. 2. 26. 16:24

'security.basic.enabled' 속성은 사용되지 않습니다.보안 자동 구성은 커스터마이즈할 수 없습니다.

Spring-boot-starter-parent 버전 2.0.1을 사용하여 Spring Cloud 프로젝트를 진행하고 있습니다.해방.

경고 이하를 받고 있습니다.

'security.basic.enabled' 속성은 사용되지 않습니다.보안 자동 설정은 커스터마이즈 할 수 없게 되었습니다.대신 자체 Web Security Configurer bean을 제공하십시오.

security: basic: enabled: 스프링보안 최신 버전에서는 false가 비활성화되어 있습니다.

대신 어떤 것을 사용하면 좋을까요?

application.yml

---
server:
  port: 8888

security:
  basic:
    enabled: false

spring:
  cloud:
    config:
      server:
        git:
          uri: https://github.com/rseroter/pluralsight-spring-cloudconfig-wa-tolls

          search-paths:
          - 'station*'
          repos:
            perf:
              pattern:
                - '*/perf'
              uri: https://github.com/rseroter/pluralsight-spring-cloudconfig-wa-tolls-perf
              search-paths:
               - 'station*'

pom.xml

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.1.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <spring-cloud.version>Finchley.BUILD-SNAPSHOT</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.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>

    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

여기에 이미지 설명 입력

여기는 저의 시험 수업입니다.

@RunWith(SpringRunner.class)
@SpringBootTest
public class PluralsightSpringcloudM2ConfigserverGitApplicationTests {

    @Test
    public void contextLoads() {
    }

}

그리고

다른 질문과는 상관없다.

Spring Boot 2.0에서는 자동 설정(일부 속성 포함)이 변경되어 Web Security Configurer Adapter를 추가하는 즉시 취소되는 단일 동작이 있습니다.디폴트 설정은 다음과 같습니다.

protected void configure(HttpSecurity http) throws Exception {
    http
        .authorizeRequests()
            .anyRequest().authenticated()
            .and()
        .formLogin()
            .and()
        .httpBasic();
}

디폴트에서는, 생성된 패스워드를 가지는 1명의 유저가 설정되어 있습니다.이 사용자를 사용자 정의하려면 아래의 속성을 사용하십시오.spring.security.user.

spring.security.user.name=user # Default user name.
spring.security.user.password= # Password for the default user name.
spring.security.user.roles= # Granted roles for the default user name.

다음 속성은 Spring Boot 2에서 삭제되었습니다.

security.basic.authorize-mode
security.basic.enabled
security.basic.path
security.basic.realm
security.enable-csrf
security.headers.cache
security.headers.content-security-policy
security.headers.content-security-policy-mode
security.headers.content-type
security.headers.frame
security.headers.hsts
security.headers.xss
security.ignored
security.require-ssl
security.sessions

대체품(존재하는 경우)은 부록 A에서 찾을 수 있습니다. 공통 응용 프로그램 속성

명확히 하자면:커스텀 Web Security Configurer Adapter 를 작성하면, 디폴트의 시큐러티 설정이 커스텀 설정으로 바뀝니다.

@EnableWebSecurity
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        // For example: Use only Http Basic and not form login.
        http
            .authorizeRequests()
                .anyRequest().authenticated()
                .and()
            .httpBasic();
    }
}

상세한 것에 대하여는, Spring 2.0 이행 가이드를 참조해 주세요.

왜냐하면 당신이 글을 쓸 때security.basic.enabled = false기본적으로 애플리케이션에는 보안에 신경 쓰지 않고 모든 요청을 허용한다고 말합니다.spring boot 2.0 이후, 앱을 안전하지 않게 만들기 위해 1개의 구성만 쓸 수는 없습니다.그러기 위해서는 몇 가지 코드를 쓸 필요가 있습니다.또는 다음을 복사할 수 있습니다.

package com.LockheedMartin.F22Simulator;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().anyRequest().permitAll();
    }
}

그나저나, 넌 이 모든 걸어야 해.security.basic.enabled = falseapplication.properties에서 다음과 같이 입력합니다.spring 2.*.*이 속성을 더 이상 이해하지 못합니다.Intelij가 올바르게 설정되어 있는 경우는, 다음과 같은 경고가 표시됩니다.'unsupported property'.

Spring Reactive Security를 사용하는 경우 다음과 같은 작업을 수행해야 합니다.

@Bean
  public SecurityWebFilterChain springWebFilterChain(ServerHttpSecurity http) {
    http.authorizeExchange().anyExchange().permitAll();
    return http.build();
  }

또 다른 stackoverflow 게시물이 있습니다.Spring boot 2.0은 기본 보안을 비활성화합니다.

저는 당신의 테스트 수업에서 다음을 시도합니다.

@SpringBootTest(properties=" spring.autoconfigure.framework.boot.autoconfigure를 선택합니다.보안.보안.자동 설정」)

는 테스트 클래스의 컨텍스트에서 spring-security 자동 설정을 디세블로 합니다.

EDIT: 테스트 클래스의 컨텍스트에 한정되지 않는 경우는, 같은 것을 다음의 경우에 적용할 수 있습니다.

@SpringBootApplication(제외="org.springframework.boot.autoconfigure).보안.보안.자동 설정」)

그렇지 않은 경우 application.syslogl에서 다음을 수행할 수 있습니다.

spring.autoconfigure.boot.autoconfigure=spring.framework.boot.autoc보안.보안.자동 설정

이렇게 해서 나는 이 문제를 해결할 수 있었다.잘 모르겠어요.방금 application.yml을 수정했습니다.

---
server:
  port: 8888


spring:
  cloud:
    config:
      server:
        git:
          uri: https://github.com/rseroter/pluralsight-spring-cloudconfig-wa-tolls

          search-paths:
          - 'station*'
          repos:
            perf:
              pattern:
                - '*/perf'
              uri: https://github.com/rseroter/pluralsight-spring-cloudconfig-wa-tolls-perf
              search-paths:
               - 'station*'
  security:
    user:
      name: test
      password: test

http://localhost:8888/s1rates/default 에 액세스 하면, 유저명과 패스워드를 입력하도록 요구되어 다음의 결과가 표시됩니다.

여기에 이미지 설명 입력

언급URL : https://stackoverflow.com/questions/49717573/property-security-basic-enabled-is-deprecated-the-security-auto-configuration