2016-05-19 7 views
1

私は2つのアプリケーションを実行して認証とルーティング(zuulプロキシを使用)とUIを管理する "ゲートウェイ" "/ admin")をゲートウェイの後ろに置きます。認証されていない場合、プロキシされたURLをzuulに戻す方法

"/ login"(またはゲートウェイ自体の他のエンドポイント)を押すと、 "login.html"ページにルーティングされ、資格情報を入力して正しく認証されます。その後、私は "/ admin"に問題なくアクセスできます。

私の問題は、認証前に「/ admin」を押すと、「/login.html」にルーティングされず、「基本認証」ポップアップで認証情報を要求するだけです欲しい。

ここはゲートウェイサーバー上の私の設定です。

@Override 
    protected void configure(HttpSecurity http) throws Exception { 
     http 
     .sessionManagement() 
      .maximumSessions(1) 
       .expiredUrl("/login") 
        .maxSessionsPreventsLogin(false) 
         .sessionRegistry(sessionRegistry()) 
     .and() 
      .sessionCreationPolicy(SessionCreationPolicy.ALWAYS) 
       .invalidSessionUrl("/login"); 
     http.addFilterBefore(new ApiKeyAuthenticationFilter(macSigner()), BasicAuthenticationFilter.class); 
     http.httpBasic().and() 
     .authorizeRequests() 
      .antMatchers("/", "/home", "/index","/support.html", "/about.html","/features.html","/fonts/**","/ws/**", 
        "/contacts.html","/img/**","/logos/**","/docs/**").permitAll() 
      .antMatchers("/admin**").hasRole("ADMIN") 
      .anyRequest().authenticated() 
      .and() 
     .formLogin() 
      .loginPage("/login") 
      .permitAll() 
      .and() 
       .csrf().ignoringAntMatchers("/resource/api/**","/api/**").csrfTokenRepository(csrfTokenRepository()) 
      .and() 
     .addFilterAfter(csrfHeaderFilter(), SessionManagementFilter.class) 
     .logout() 
      .logoutRequestMatcher(new AntPathRequestMatcher("/logout")) 
      .logoutSuccessUrl("/login") 
      .permitAll(); 
    } 

とここに私の管理サーバー

@Override 
     protected void configure(HttpSecurity http) throws Exception { 
      http.httpBasic().and().authorizeRequests().anyRequest().authenticated(); 
      http.csrf().disable(); 
     } 

上の設定で誰も私にしてください掘るする場所になど、いくつかのアドバイスを与えることはできますか?

答えて

1

authenticationEntryPointとLoginUrlAuthenticationEntryPointを使用してみてください。例えば

@Override 
    protected void configure(HttpSecurity http) throws Exception { 
     // @formatter:off 
     http 
       .httpBasic().and().exceptionHandling() 
       .authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/login")).and() 
       .logout().and() 
       .authorizeRequests() 
       .antMatchers("/index.html", "/login", "/").permitAll() 
       .anyRequest().authenticated() 
       .and() 
       .csrf() 
       .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()); 
     // @formatter:on 
    } 

    @RequestMapping("/login") 
    public String login() { 
     return "forward:/"; 
    } 
+0

これはあなたに感謝働きました! –

関連する問題