봄 보안 봄 부팅 2.x는 엔드 포인트에서 토크 응용 프로그램 (A)

    봄 부팅 2.x를 크게 이제 당신은 단지 같은 간단한 작업이, 봄 부팅 많은 보안 문제를 회피 할 수 WebSecurityConfigurerAdapter 파생 클래스를 제공해야합니다, 많은 보안 관련 구성이 있다는 것을 말할 수 없습니다, 기본 보안 구성을 단순화합니다.

액추에이터는 더 이상 자신의 별도의 보안 설정이없는 (management.security합니다. * 구성이 취소되었습니다), 민감한 마커의 각 엔드 포인트는 취소됩니다 보안 구성이 명확하게되었다 있도록.

예를 들어 다음과 같은 구성이

엔드 포인트 : 
    정보 : 
        민감성 : 거짓 
    매핑 : 
        민감한 : 사실 
관리 : 
    보안 : 
        역할 : MY_ADMIN
지금, 당신은 이런 식으로 작업을 수행 할 수 있습니다 :
수입 org.springframework.security.config.annotation.web.builders.HttpSecurity;
수입 org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
수입 org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 

/ ** 
 * 이름 : TestWebSecurityConfigureAdapter 
 * 
 * @author aboruo 
 * 우리의 사용자 정의 WebSecurityConfigurerAdapter를 추가하는 방법에 대한 예는 @description 
 * 2019년 9월 9일 20시 50분에서 만든 @date. 
 * / 
@EnableWebSecurity 
공공  클래스 TestWebSecurityConfigureAdapter는 확장 WebSecurityConfigurerAdapter { 
    @Override를
    보호  무효 구성은 (HttpSecurity HTTP) 가 발생 예외 { 
        http.csrf (). (해제). authorizeRequests () 
                .antMatchers ( "/ 액추에이터 / 건강", "/ 액추에이터 / 정보" ) 
                .permitAll ()를 
                .antMatchers ( "/ 액츄에이터 / ** " ) 
                .hasRole ( "MY_ADMIN " ) 
                .and () httpBasic ().; 
    } 
}

 

기본 건강 정보에 의해, 2.X에 유의하시기 바랍니다 액세스 할 수 있습니다 (경우에 기본 자세한 건강 정보 디스플레이를 액세스 할 수 없습니다). 이 새 기본값을 유지에서, 건강 차 메이에 추가되었습니다.

봄 부팅 2.x에서 봄 보안, 엔드 포인트 구현을 소개하지 않는 경우 (계속하는)

spring.factories 파일의 스프링 부팅 자동 구성 1. 먼저 찾기 자동 클래스

 

 이 검토

/ ** 
 * { @link 봄 보안에 대한 EnableAutoConfiguration 자동 구성}. 
 * 
 * @author 데이브 Syer 
 * @author 앤디 윌킨슨 
 * @author Madhura Bhave에 
 * @since 1.0.0
  * / 
@Configuration 
@ConditionalOnClass (DefaultAuthenticationEventPublisher. 클래스 ) 
@EnableConfigurationProperties (SecurityProperties. 클래스 ) 
@Import ({SpringBootWebSecurityConfiguration. 클래스 , WebSecurityEnablerConfiguration. 클래스 , 
        SecurityDataConfiguration. 클래스})
 공용  클래스 SecurityAutoConfiguration { 

    @Bean 
    @ConditionalOnMissingBean (AuthenticationEventPublisher. 클래스 )
     공공 {DefaultAuthenticationEventPublisher authenticationEventPublisher (ApplicationEventPublisher 게시자)
         반환  ) DefaultAuthenticationEventPublisher (게시자; 
    } 

}
DefaultAuthenticationEventPublisher : 기본 권한 인증 이벤트 게시자
SecurityProperties : 시작 spring.security : 보안 설정이 등록 정보가 프로파일 
에 의해
SecurityAutoConfiguration 및 몇 가지 주요 구성 클래스의 도입
① SpringBootWebSecurityConfiguration
/ ** 
 * 웹 보안의 기본 구성. 그것은 봄 보안의에 의존 
 인증의 종류 사용할지 결정하기 위해 * 내용 협상 전략. 는 IF 
 * 사용자가 지정하는 자신의 { @link WebSecurityConfigurerAdapter}이 오프 백업합니다 
 * 완전하고 사용자가로 구성 할 모든 비트 지정해야 
 사용자 지정 보안 구성의 일부를 *. 
 * 
 * @author Madhura Bhave에 
 * @since 2.0.0
  * / 
@Configuration 
@ConditionalOnClass (WebSecurityConfigurerAdapter. 등급 ) 
@ConditionalOnMissingBean (WebSecurityConfigurerAdapter. 클래스) 
@ConditionalOnWebApplication (타입 = Type.SERVLET)
 공용  클래스 SpringBootWebSecurityConfiguration는 { 

    @Configuration 
    @Order (SecurityProperties.BASIC_AUTH_ORDER)는 
    정적  클래스 DefaultConfigurerAdapter는 연장 WebSecurityConfigurerAdapter { 

    } 

}

 

이것은 *이 스프링 안전 정책이 사용할 인증 결정하는 내용 협상에 따라, 스프링 부팅 기본 보안 구성 클래스입니다. 코드, 우리는 볼 수 있습니다 :
  • 사용자가 자신의 정의 때 때 WebSecurityConfigurerAdapter 클래스를 SpringBootWebSecurityConfiguration이 적용되지 않습니다;
  • 응용 프로그램은 웹 응용 프로그램 및 유형이 SERVLET의 유형 인 경우 적용되는 경우
 WebSecurityEnablerConfiguration 
이름에서 알 수 있듯이이 확인 클래스 구성은 다음과 같습니다 콩의 ApplicationContext의 WebSecurityConfigureAdapter 유형을 적용하는, 존재하는 경우,이 콩 플러스 @EnableWebSecurity 주석의 책임입니다.
/ ** 
 * 형 WebSecurityConfigurerAdapter의 콩이있는 경우, 이것은 추가 
 {* @link 주석 EnableWebSecurity을}. 이것은 주석이 있는지 확인합니다 
 * 기본 보안 자동 구성으로 현재와 사용자가 사용자 추가도 경우 
 * 보안과 주석을 추가 할 수 잊는다. {경우 @link EnableWebSecurity}는 이미 한 
 *이 추가되었습니다 또는 {이름이 빈 경우 @value BeanIds # SPRING_SECURITY_FILTER_CHAIN}이있다 
 * 사용자가 구성되고,이 백 오프를합니다. 
 * 
 * @author Madhura Bhave에 
 * @since 2.0.0
  * / 
@Configuration 
@ConditionalOnBean (WebSecurityConfigurerAdapter. 클래스 ) 
@ConditionalOnMissingBean (이름 = BeanIds.SPRING_SECURITY_FILTER_CHAIN) 
@ConditionalOnWebApplication (유형 = ConditionalOnWebApplication.Type.SERVLET) 
@EnableWebSecurity 
공공  클래스 WebSecurityEnablerConfiguration { 

}

 


③ SecurityDataConfiguration
경우가 SecurityEvaluationContextExtension 기반 응용 프로그램 환경, 봄 데이터 통합에 추가 된 봄 보안.
/ ** 
 * 자동 스프링 데이터 봄 보안의 통합을 추가합니다. 
 * 
 * @author 롭 윈치 
 * @since 1.3.0
  * / 
@Configuration 
@ConditionalOnClass (. SecurityEvaluationContextExtension 클래스 )
 공공  클래스 SecurityDataConfiguration { 

    @Bean 
    @ConditionalOnMissingBean 
    공공 SecurityEvaluationContextExtension securityEvaluationContextExtension () {
         반환  ) (SecurityEvaluationContextExtension을; 
    } 

}

 

우리는 추적합니다
SecurityRequestMatcherProviderAutoConfiguration
UserDetailsServiceAutoConfiguration
SecurityFilterAutoConfiguration
OAuth2ClientAutoConfiguration
OAuth2ResourceServerAutoConfiguration
이러한 클래스는 어떻게 작동하는지 이해하기 위해, 하나 하나 소개한다.

추천

출처www.cnblogs.com/aboruo/p/11494505.html