2016-03-29 4 views
0

webappがあり、Spring Securityを使用しています。私が午前問題は常にこれです@RequestMapping(value="/login", method=RequestMethod.GET)代わりの@RequestMapping(value="/login", method=RequestMethod.POST)にマッピングされますSpring Security.config - ログインページが正常に動作しない

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

    http 
     .csrf().disable() 
     .authorizeRequests() 
      .antMatchers("/static/**").permitAll() 
      .antMatchers("/settings/api/**").permitAll() 
      .antMatchers("/api/**").permitAll() 
      .anyRequest().authenticated() 
     .and() 
     .formLogin() 
      .loginPage("/login").permitAll() 
      .defaultSuccessUrl("/", true); 
} 

:私はとsecurity.configの私の春のセキュリティconfigure機能を持っています。だから私はHTTPリクエストからユーザー名とパスワードを取得しようとしているときはnullと出てきます。 POSTメソッドにマップするにはどうすればよいですか?

私はformloginと

@RequestMapping(value="/login", method=RequestMethod.POST) 
public String login(HttpServletRequest request, HttpServletResponse response) { 
    String username = request.getParameter("username"); 
    String password = request.getParameter("password"); 
    boolean f = false; 
    f = customAuthenticationProvider.verifyUser(username,password,request); 
    if(f == false) 
     return "loginError"; 
    else 
     return "index"; 
} 

答えて

0

として私のポストコントローラを(持っている)、あなたはそれがUsernamePasswordAuthenticationFilter上のスプリングによっての世話をされています、POSTコントローラを提供する必要はありません。あなたが設定しているのはloginアクション(/ login)にフォームを追加してユーザ名とパスワードの入力を追加するloginPage( "/ login")です。このような

何か:

<form action="login" method="post"> 
    <div> 
     <label for="username">Username:</label> 
     <input type="text" class="form-control" id="username" name="username"/> 
    </div> 
    <div> 
     <label for="password">Password:</label> 
     <input type="password" class="form-control" id="password" name="password"/> 
    </div> 
    <button type="submit">Submit</button> 
</form> 
+0

あなたは私は私はあなたが働く提案するものとは思わないその内側から関数を呼び出しています見ることができるように私はちょうど私のポストのコントローラを追加しました。私はこれに非常に新しいですので、どんな助けも素敵です。お気軽に –

+0

これは私があなたに伝えるように動作します、これをチェックしてください:http://docs.spring.io/spring-security/site/docs/3.2.x/guides/ form.html – Ulises

+0

ありがとうございます。しかし、それは動作していません。おそらく私は別の場所に問題があります。私は一度それを見つけると更新されます。 –

関連する問題