如何解决如何在我的自定义身份验证代码中使用Spring安全授权?
我目前已经在不同页面上使用用户名和密码实现了自己的身份验证登录,如下所示: 第一步:获取登录用户名页面
@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 举报,一经查实,本站将立刻删除。