• <th id="kadjp"></th>

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

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

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

                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。

                国产欧美在线观看,国产精品白浆冒出视频,91精品国产91热久久久福利,大伊香蕉在线精品视频97 国产精品美女久久福利 国产精品黄的免费观看
              • <th id="kadjp"></th>