2017-06-23 21 views
0

こんにちは私は異なったJSPページを持つ3種類のユーザーがあります。私は春ブーツと初心者だけど、私はこれが私のアプリケーション構造で切り抜いたユーザーと切り抜いた成功URLページ で認証を行う方法がわからない:enter image description here複数のユーザーと複数の成功URLを春のブートで

 package bootsample; 

import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.context.annotation.Bean; 
import org.springframework.context.annotation.ComponentScan; 
import org.springframework.context.annotation.Configuration; 
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 
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; 
import org.springframework.security.core.userdetails.UserDetailsService; 
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 
import org.springframework.security.crypto.password.PasswordEncoder; 

import bootsample.service.CustomUserDetailsService; 



@Configuration 
@EnableWebSecurity 
@ComponentScan(basePackageClasses = CustomUserDetailsService.class) 
public class WebSecurityConfig extends WebSecurityConfigurerAdapter { 

@Autowired 
private UserDetailsService userDetailsService; 

@Autowired 
public void configAuthentication(AuthenticationManagerBuilder auth) throws Exception {  
    auth.userDetailsService(userDetailsService).passwordEncoder(passwordencoder()); 
} 



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



    http.authorizeRequests() 

    .antMatchers("/supervisor/**").hasAuthority("ROLE_Supervisor") 

    .antMatchers("/admin/**").hasAuthority("ROLE_ADMIN") 
    .anyRequest().permitAll() 
    .and() 
    .formLogin().loginPage("/login") 
    .defaultSuccessUrl("/supervisor/hello") 
    .defaultSuccessUrl("/admin/hello") 
    .usernameParameter("username").passwordParameter("password") 
    .and() 
    .logout().logoutSuccessUrl("/login?logout") 
    .and() 
    .exceptionHandling().accessDeniedPage("/403") 
    .and() 
    .csrf().disable(); 
} 

@Bean(name="passwordEncoder") 
    public PasswordEncoder passwordencoder(){ 
    return new BCryptPasswordEncoder(); 
    } 
} 

が、私はこれをしようとしたが、それはしていません仕事

答えて

0

あなたの2番目のdefaultSuccessUrlが最初を上書きしています。 (使用して

実装は、彼らがやりたいことができますが、一般的な動作は、後続の宛先へ ナビゲーションを制御するために、次のようになります。その代わりdefaultSuccessUrlのは、おそらくのjavadocからAuthenticationSuccessHandler

 .successHandler(new AuthenticationSuccessHandler() { 
      @Override 
      public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, 
        Authentication authentication) throws IOException, ServletException { 

       response.sendRedirect(...); 
      } 
     }) 

を使用したいですリダイレクトまたはフォワード)。 D:例えば、 ユーザーがログインフォームを提出することにより、ログインした後に、アプリケーションは、彼らがその後にリダイレクトする必要があります

+0

は、それが動作すると考えて決定する必要があります – ibhar

関連する問題