问题描述
我目前已经在不同页面上使用用户名和密码实现了自己的身份验证登录,如下所示: 第一步:获取登录用户名页面
@GetMapping("/loginForm")
public String loginForm(Model model,User user) {
model.addAttribute("user",user);
return "fragments/CMS/authentication/sign_in_username";
}
@PostMapping("/loginUsername")
public String login(@modelattribute User user,HttpServletRequest httpSession) throws UsernameNotFoundException {
//find user from the database using the username supplied by the user
User foundUser = userService.findByEmail(user.getUsEmail());
//if username was not found,throw a username not found exception
if (foundUser == null) {
//to do:- create an @Exception handler to throw the exception and
//return the user to the error page
throw new UsernameNotFoundException("The user was not found");
}
HttpSession session = httpSession.getSession();
session.setAttribute("dbPassword",foundUser.getUsPassword());
// session.setAttribute("userName",user.getUsUsername());
session.setAttribute("userEmail",foundUser.getUsEmail());
System.out.println("User passed db password: "+ foundUser.getUsPassword());
return "fragments/CMS/authentication/sign_in_password";
}
当我在类路径(依赖项)上添加spring security时,默认的spring security登录页面将以一种非常顽固的方式出现。我无法执行.formLogin("/sign_in_username")
,因为我大概在两个不同的页面中登录了工作流程。是否可以通过上述身份验证逻辑来使用Spring安全授权部分?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)