春のブート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 * @descriptionたとえば、当社のカスタムWebSecurityConfigurerAdapter追加について * @Dateは2019年9月9日午後08時50分に作成します。 * / @EnableWebSecurity パブリック クラス TestWebSecurityConfigureAdapterは延びWebSecurityConfigurerAdapter { @Overrideを 保護された ボイドのconfigure(HttpSecurity HTTP)は、スロー例外{ http.csrf()。無効にします()。authorizeRequests() .antMatchers( "/アクチュエータ/健康"、 "/アクチュエータ/情報" ) .permitAll() .antMatchers(「/アクチュエータを/ **」) .hasRole( "MY_ADMIN" ) .AND()httpBasic()。 } }
(場合のデフォルト詳しい健康情報を表示してアクセスすることはできません)2.xでは、デフォルトの健康や情報にアクセスできることに注意してください。これらの新しい既定値に合わせて、健康は主メイザーに追加されました。
春のブート2.xは春のセキュリティ、エンドポイント実装を導入しない場合には(続きます)
1.まずspring.factoriesファイルの春・ブート・自動設定で自動設定クラスを見つけます
これを確認します
/ ** * { @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
/ ** * Webセキュリティのデフォルト設定。これは、春のセキュリティのに依存して 使用する認証の種類を決定するために*コンテンツネゴシエーション戦略。場合 *ユーザーが指定し、独自の{ @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は有効になりません。
- アプリケーションは、Webアプリケーションとタイプは、サーブレットのタイプである場合に有効になるように、ある場合には
② 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
これらのクラスは、それがどのように機能するかを理解するために、一つ一つを紹介しています。