私は、認証にSpring MVCとSpring Securityを使用しています。ユーザー名とパスワードでログインしていますが、もう2つのパラメータを送信したいと思います。それを行う方法はありますか?複数のパラメータを持つSpringセキュリティログイン
これは、ログインフォームです:
<form action="#" th:action="@{/auth/login}" th:object="${loginBean}" method="post">
<input type="hidden" th:field="*{timezone}" th:value="*{timezone}" />
<input type="hidden" th:field="*{language}" th:value="*{language}" />
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" />
<input type="text" placeholder="Email" th:field="*{username}" required="required"
title="Email pattern does not match" pattern="^[_A-Za-z0-9-\+]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$"/>
<span th:if="${#fields.hasErrors('username')}" th:errors="*{username}">Email Error</span>
<input type="password" placeholder="Password" th:field="*{password}" required="required" />
<span th:if="${#fields.hasErrors('password')}" th:errors="*{password}">Password Error</span>
<button type="submit" id="login-button">Login</button>
</form>
私もログインしてタイムゾーンと言語をお送りしたいと思います。
そしてAuthenticationProvider
:
@Component
public class CustomAuthenticationProvider implements AuthenticationProvider {
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
String name = authentication.getName();
// You can get the password here
String password = authentication.getCredentials().toString();
TokenDTO t = new TokenDTO();
t.setIdioma("en-US");
//try {
CustomUserService userService = new CustomUserService();
UserDetails user = userService.loadUser(name, password);
if (user == null)
throw new BadCredentialsException("Username not found.");
Collection<? extends GrantedAuthority> authorities = user.getAuthorities();
Authentication auth = new UsernamePasswordAuthenticationToken(user, user.getPassword(), authorities);
return auth;
}
@Override
public boolean supports(Class<?> authentication) {
return authentication.equals(UsernamePasswordAuthenticationToken.class);
}
}
それが認証によりのparamsを送信することは可能ですか?
以下のリンクを参照してください: http://stackoverflow.com/questions/10074308/how-to-pass-an-additional-parameter-with-spring-security-login-page – nits