2017-10-27 5 views
1

デフォルトでは、春のブートWebセキュリティを使用してトークンを生成し、ログインしてトークンを生成します。しかし、私はそれを行うには/user/loginエンドポイントが必要です。私WebSecurityConfigは、次のようになります。JWTトークンを生成するためのエンドポイントアドレスを変更する方法

protected void configure(HttpSecurity http) throws Exception { 
    http.cors().and().csrf().disable().authorizeRequests() 
      .antMatchers(HttpMethod.POST, SIGN_UP_URL).permitAll() 
      .anyRequest().authenticated() 
      .and() 
      .addFilter(new JWTAuthenticationFilter(authenticationManager())) 
      .addFilter(new JWTAuthorizationFilter(authenticationManager())) 
      // this disables session creation on Spring Security 
      .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS); 
} 

私はJWTのトークンを生成するためのエンドポイントのアドレスを変更する方法を知りたいと思いましたか?前もって感謝します!

答えて

0

このように.loginPage()のパラメータを変更できます。

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

    http.csrf().disable() 
      .authorizeRequests() 
      .antMatchers("/", "/home", "/about").permitAll() 
      .antMatchers("/admin/**").hasAnyRole("ADMIN") 
      .antMatchers("/user/**").hasAnyRole("USER") 
      .anyRequest().authenticated() 
      .and() 
      .formLogin() 
      .loginPage("/user/login") 
      .permitAll() 
      .and() 
      .logout() 
      .permitAll() 
      .and() 
      .exceptionHandling().accessDeniedHandler(accessDeniedHandler); 
} 
+0

は答えてくれてありがとうしかしformLoginは()ログインページを生成するため、これは、問題を解決していないと私はそれを避けるためにしたいと思います。私はちょうどデフォルトエンドポイント '/ login'を '/ user/login'に変更したいと思っています – Jacek

+0

私の間違い申し訳ありません。これをチェックしてください:[link](http://www.svlada.com/jwt-token-authentication-with-spring-boot/) – Habil

0

私は少し調査を行なったし、私は私自身のフィルター(JWTAuthenticationFilter)を使用するトークンを生成するためには、それを行うことは不可能です。そのフィルタはUsernamePasswordAuthenticationFilterから延びており、コンストラクタでハードコードされたエンドポイントがあります:

public UsernamePasswordAuthenticationFilter() { 
    super(new AntPathRequestMatcher("/login", "POST")); 
} 
関連する問題