複数の認証によるSpring Security

アリレザ:

こんにちは私は私のコントローラーとrestControllerのこの注文をどのように使用できるか...のように-> HTMLビューの注文1と残りのAPIの注文2

複数のHTTP要素を持つ複数のエントリポイント

私はコントローラークラスで順序を使用する必要があると思います!

@Configuration
@EnableWebMvcSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    UserDetailsService userDetailsService;

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(userDetailsService);
    }

    @Configuration
    @Order(1)
    public static class ApiWebSecurityConfig extends WebSecurityConfigurerAdapter {

        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http.authorizeRequests()
                    .antMatchers("/").permitAll()
                    .antMatchers("/user/**").hasRole("EMPLOYEE")
                    .anyRequest().authenticated()
                    .and()
                    .formLogin()
                    .loginPage("/LoginPage")
                    .loginProcessingUrl("/authenticateTheUser")
                    .successHandler(customAuthenticationSuccessHandler)
                    .permitAll()
                    .and()
                    .logout().permitAll() `enter code here`
                    .and()
                    .exceptionHandling().accessDeniedPage("/access-denied");
        }
    }

    @Configuration
    @Order(2)
    public class ApiWebSecurityConfig extends WebSecurityConfigurerAdapter {

        @Override
        protected void configure(AuthenticationManagerBuilder auth) throws Exception {
            auth.authenticationProvider(m.authenticationProvider());
        }

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

            http.authorizeRequests()
                    .antMatchers(HttpMethod.GET, "/api/**").hasRole("EMPLOYEE")
                    .and()
                    .httpBasic()
                    .and()
                    .csrf().disable()
                    .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);

        }

    }

}
アリレザ:

私はこの問題に取り組み、これがために、セキュリティ出て一つのプロジェクトでそれらを使用することは容易である、単一のプロジェクトで春のREST APIと春のMVCを使用するための方法を見つける春の残りのセキュリティ春のMVCのセキュリティログインページ基本認証registeryを休まプロジェクトにhttpBasic()を使用する必要があります

URLの使用のため

http:// username:password @ localhost:8080 / api / members /

@Configuration
@EnableWebSecurity
public class MultipleEntryPointsSecurityConfig extends WebSecurityConfigurerAdapter {

   @Autowired
   private UserService userService;

   @Autowired
   private CustomAuthenticationSuccessHandler customAuthenticationSuccessHandler;

   @Override
   protected void configure(AuthenticationManagerBuilder auth) throws Exception {
       auth.authenticationProvider(authenticationProvider());
   }

// this is filter for mappings for api and mvc mappings
// http://username:password@localhost:8080/api/members/
   @Override
   protected void configure(HttpSecurity http) throws Exception {

       http.authorizeRequests()
               .antMatchers("/").hasRole("EMPLOYEE")
               .antMatchers("/leaders/**").hasRole("MANAGER")
               .antMatchers("/systems/**").hasRole("ADMIN")
               .antMatchers(HttpMethod.GET, "/api/**").hasRole("EMPLOYEE")
               .and()

               .httpBasic()
               .and()

               .formLogin()
               .loginPage("/showMyLoginPage")
               .loginProcessingUrl("/authenticateTheUser")
               .successHandler(customAuthenticationSuccessHandler)
               .permitAll()
               .and()
               .logout().permitAll()
               .and()
               .exceptionHandling().accessDeniedPage("/access-denied");

   }

   @Bean
   public BCryptPasswordEncoder passwordEncoder() {
       return new BCryptPasswordEncoder();
   }

   @Bean
   public DaoAuthenticationProvider authenticationProvider() {
       DaoAuthenticationProvider auth = new DaoAuthenticationProvider();
       auth.setUserDetailsService(userService); //set the custom user details service
       auth.setPasswordEncoder(passwordEncoder()); //set the password encoder - bcrypt
       return auth;
   }

}

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Spring Securityによる認証

分類Dev

Spring WebFlux Securityで複数の認証方法を実装するにはどうすればよいですか?

分類Dev

Spring Security + Spring data + MongoDBによる認証

分類Dev

複数の認証メカニズムを接続するSpring Boot Security

分類Dev

複数の認証プロバイダーLDAP認証とJPAをサポートするSpring Security

分類Dev

ユーザーによるSpring Security認証

分類Dev

Spring SecurityおよびJavaConfigで認証するときのPartialResultException

分類Dev

Spring SecurityでWebSocketの認証をオフにする方法は?

分類Dev

Spring Security4.0.2-複数認証マネージャー-「org.springframework.security.filterChainProxy」という名前のBeanの作成中にエラーが発生しました

分類Dev

認証後にJSON応答を返すようにSpring Securityを構成する

分類Dev

Spring Security複数のAuthenticationProviders

分類Dev

Spring Security + Spring Sessionで認証をtrueに設定する

分類Dev

Spring SecurityとLDAP認証

分類Dev

Spring Security:認証userdaoがnull

分類Dev

Spring Security WebFlux-認証付きの本体

分類Dev

Spring Security Rest APIに対するAndroidデバイスからの認証

分類Dev

FacebookAppでFacebook認証をSpring Securityに統合する

分類Dev

Spring Security認証プロセスにフックする方法は?

分類Dev

認証前のSpring Security + Spring Boot MVCインデックスページはHTMLのように見えます

分類Dev

認証なしでSwagger URLにアクセスできるようにSpring Securityを構成する方法

分類Dev

Spring Securityを使用して、Active Directoryサーバーに対してどのように認証しますか?

分類Dev

認証後にURLにアクセスしようとすると、Spring Securityログインの問題が発生する

分類Dev

Spring SecurityのAuthenticationSuccessHandler

分類Dev

Spring Security 5.1.1Spring-security-oauth2認証サーバーに接続するOAuth2クライアント

分類Dev

Spring Security OAuth-このリソースにアクセスするには完全な認証が必要です

分類Dev

Spring Boot Security2.0で2つの異なる認証方法を使用する方法

分類Dev

Spring Securityで認証が失敗した後、元のページにリダイレクトする

分類Dev

ブラウザの基本認証ポップアップを無効にする方法-Angular 5 + Spring Security

分類Dev

Spring Boot + Spring Security:基本認証フォームを抑制する方法

Related 関連記事

  1. 1

    Spring Securityによる認証

  2. 2

    Spring WebFlux Securityで複数の認証方法を実装するにはどうすればよいですか?

  3. 3

    Spring Security + Spring data + MongoDBによる認証

  4. 4

    複数の認証メカニズムを接続するSpring Boot Security

  5. 5

    複数の認証プロバイダーLDAP認証とJPAをサポートするSpring Security

  6. 6

    ユーザーによるSpring Security認証

  7. 7

    Spring SecurityおよびJavaConfigで認証するときのPartialResultException

  8. 8

    Spring SecurityでWebSocketの認証をオフにする方法は?

  9. 9

    Spring Security4.0.2-複数認証マネージャー-「org.springframework.security.filterChainProxy」という名前のBeanの作成中にエラーが発生しました

  10. 10

    認証後にJSON応答を返すようにSpring Securityを構成する

  11. 11

    Spring Security複数のAuthenticationProviders

  12. 12

    Spring Security + Spring Sessionで認証をtrueに設定する

  13. 13

    Spring SecurityとLDAP認証

  14. 14

    Spring Security:認証userdaoがnull

  15. 15

    Spring Security WebFlux-認証付きの本体

  16. 16

    Spring Security Rest APIに対するAndroidデバイスからの認証

  17. 17

    FacebookAppでFacebook認証をSpring Securityに統合する

  18. 18

    Spring Security認証プロセスにフックする方法は?

  19. 19

    認証前のSpring Security + Spring Boot MVCインデックスページはHTMLのように見えます

  20. 20

    認証なしでSwagger URLにアクセスできるようにSpring Securityを構成する方法

  21. 21

    Spring Securityを使用して、Active Directoryサーバーに対してどのように認証しますか?

  22. 22

    認証後にURLにアクセスしようとすると、Spring Securityログインの問題が発生する

  23. 23

    Spring SecurityのAuthenticationSuccessHandler

  24. 24

    Spring Security 5.1.1Spring-security-oauth2認証サーバーに接続するOAuth2クライアント

  25. 25

    Spring Security OAuth-このリソースにアクセスするには完全な認証が必要です

  26. 26

    Spring Boot Security2.0で2つの異なる認証方法を使用する方法

  27. 27

    Spring Securityで認証が失敗した後、元のページにリダイレクトする

  28. 28

    ブラウザの基本認証ポップアップを無効にする方法-Angular 5 + Spring Security

  29. 29

    Spring Boot + Spring Security:基本認証フォームを抑制する方法

ホットタグ

アーカイブ