I'm using Spring MVC and Spring Security for the authentication. I'm doing the login with username and password but I would like to send two more parameters. Is there any way to do that?
This is the login form:
<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>
I would like to send the timezone and language in the login too.
And the 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);
}
}
Is it possible to send more params in the authentications?