表題について
ログイン画面からparameterを3つ送りたいのです
・ユーザコード
・パスワード
・+α
しかしsecurityのデフォルトは2つのparameterしか受け取れないです。
カスタマイズできるっぽいのですが、やり方がわかりません。
わかる方、よろしくお願いいたします。
securityのjavaConfig
protected void configure(HttpSecurity http) throws Exception { // ログイン処理 http.authorizeRequests() .antMatchers("/js/**","css/**").permitAll() .antMatchers("/**").authenticated() .and().formLogin() .loginPage("/login") .usernameParameter("username") .passwordParameter("password") //ここでもう1つのパラメータを受け取りたい .failureUrl("/login").permitAll(); }
ログイン画面
<form th:action="@{/login}" method="post"> <table> <tr> <td></td> <td><input type="text" name="car"></td>//こいつもsessionに格納したい </tr> <tr> <td>ユーザーコード</td> <td><input type="text" name="username" /></td> </tr> <tr> <td>パスワード</td> <td><input type="password" name="password" /></td> </tr> </table> <br /><br /> <button type="submit">ログイン</button> </form>
追記
下記ベストアンサーを参考に実装してみたのですが
nullというエラーが出ました。
デバッグしてauthRequestああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああーめん
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException { if (!request.getMethod().equals("POST")) { throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod()); } // Obtain UserName, Password, CompanyId String username = super.obtainUsername(request); String password = super.obtainPassword(request); String carNo = obtainCarNo(request); request.setAttribute("carNo", carNo); // username required if (!StringUtils.hasText(username)) { throw new AuthenticationServiceException("UserName is required"); } // validate password, companyId // omitted other process CarNoUsernamePasswordAuthenticationToken authRequest = new CarNoUsernamePasswordAuthenticationToken(username, password, carNo); // Allow subclasses to set the "details" property setDetails(request, authRequest); return this.getAuthenticationManager().authenticate(authRequest); // ここでnull }
回答1件
あなたの回答
tips
プレビュー