成功登录后,我需要执行一个操作(即更新用户表中的字段)。但是我找不到登录数据的处理位置。
有关此表单的登录视图部分如下所示:
<form th:action="@{/login}" th:object="${user}" method="post" role="login">
<h2 class="text-center" th:text="${companyName}"></h2>
<input type="email" id="username" name="username" autocomplete="username" th:placeholder="|Email@${clientEmailDomain}|" required class="form-control input-lg" />
<input type="password" class="form-control input-lg" id="password" name="password" autocomplete="current-password" placeholder="Password" required="" />
<button type="submit" class="btn btn-lg btn-primary btn-block">Log in</button>
</form>
WebSecurityConfigAdapter
包括:
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/",
"/css/**",
"/fonts/**",
"/img/**",
"/js/**",
"/register",
"/resetPassword",
).permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.defaultSuccessUrl("/search/" + clientOsVersion)
.permitAll()
.and()
.logout()
.permitAll();
// THIS IS ONLY DURING DEV to access to the database
http.csrf().disable();
http.headers().frameOptions().disable();
// END OF DEV ONLY
}
在登录控制器中,永远不会调用以下方法(尽管会调用其对应的“ get”方法):
@PostMapping("/login")
public ModelAndView processLoginForm(ModelAndView modelAndView,
@Valid User user
) {
System.err.println("Processing login data"); // This line is NEVER printed!!!
// Here I need to update a user's attribute.
modelAndView.addObject("clientEmailDomain",
clientEmailDomain);
modelAndView.addObject("companyName",
companyName);
return modelaAndView;
}
我该怎么做才能使用我的processLoginForm
方法,或者在到达/search
路由之前,我应该在哪里放置我的代码以成功登录后完成一些工作,因为我只想要这份工作每个会话一次(不是用户每次搜索都要做一次)?
任何帮助表示赞赏,