<code id="qf3hh"></code>
  • <menuitem id="qf3hh"></menuitem>
  • <strike id="qf3hh"><label id="qf3hh"></label></strike>

  • ?
      開發(fā)技術(shù) / Technology

      如何使用Shiro實(shí)現(xiàn)用戶注冊(cè)成功后自動(dòng)登錄?

      日期:2015年4月8日  作者:zhjw  來源:互聯(lián)網(wǎng)    點(diǎn)擊:1598

      10

      如何使用Shiro實(shí)現(xiàn)用戶注冊(cè)成功后自動(dòng)登錄?15

      之前用戶注冊(cè)后是先跳到登錄頁面: 
      Java代碼  收藏代碼
      1. @RequestMapping(method = RequestMethod.POST)  
      2. public String register(@Valid User user, RedirectAttributes redirectAttributes) {  
      3.     accountService.registerUser(user);  
      4.     redirectAttributes.addFlashAttribute("username",  
      5. user.getLoginName());  
      6.     return "redirect:/login";  
      7. }  

      現(xiàn)在要求用戶注冊(cè)成功后自動(dòng)登錄,改寫如下: 
      Java代碼  收藏代碼
      1. @RequestMapping(method = RequestMethod.POST)  
      2. public String register(@Valid User user, RedirectAttributes redirectAttributes) {  
      3.     accountService.registerUser(user);  
      4.     UsernamePasswordToken token = new UsernamePasswordToken();  
      5.     token.setUsername(user.getLoginName());  
      6.     token.setPassword(user.getPassword().toCharArray());  
      7.     SecurityUtils.getSubject().login(token);  
      8.     return "redirect:/";  
      9. }  

      結(jié)果報(bào)錯(cuò): 
      Java代碼  收藏代碼
      1. org.apache.shiro.authc.IncorrectCredentialsException: Submitted credentials for token [org.apache.shiro.authc.UsernamePasswordToken - user01, rememberMe=false] did not match the expected credentials.  

      問題補(bǔ)充:問題解決了,改寫成token.setPassword(user.getPlainPassword().toCharArray()); 就可以了。因?yàn)槲业膗ser的plainPassword是明文,user的password是hash。

      国产一级婬片AAA毛,无码中文精品视视在线观看,欧美日韩a人成v在线动漫,五月丁香青草久久
      <code id="qf3hh"></code>
    • <menuitem id="qf3hh"></menuitem>
    • <strike id="qf3hh"><label id="qf3hh"></label></strike>