亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

shiro的問題

shiro的問題

qq_那一眸的風情_03788798 2016-11-02 17:43:37
報錯:Submitted credentials for token [org.apache.shiro.authc.UsernamePasswordToken - admin, rememberMe=true] did not match the expected credentials.controller:@RequestMapping(value = "login.do", method = RequestMethod.POST) @ResponseBody public ModelMap login() throws Exception { logger.info("進入了userController"); String username = request.getParameter("username"); String password =request.getParameter("password") ; String verifycode = request.getParameter("code"); String sessioncode = (String) session.getAttribute("code"); logger.info("接收的信息:"+username+password+verifycode+sessioncode); ModelMap parmars=new ModelMap(); UsernamePasswordToken token =new UsernamePasswordToken(username,password); Subject CurrentUser =SecurityUtils.getSubject(); try{ if (verifycode.equalsIgnoreCase(sessioncode)) { if (!CurrentUser.isAuthenticated()) { //token.setRememberMe(true); CurrentUser.login(token); logger.info(token.getUsername() + "登錄成功"); } else { parmars.put("code", Code.USERNAMEORPASSWORD_WRONG); } } else { parmars.put("code", Code.CODE_WRONG); } } catch (Exception e) { e.printStackTrace(); parmars.put("code", Code.UNKOWN_WRONG); } return ?parmars; }Myrealm:public class Myrealm extends AuthorizingRealm{ @SuppressWarnings("unused") private static final Logger logger = LoggerFactory.getLogger(Myrealm.class); @Autowired private UserService userService; public Myrealm(){ super(); } /* * (non-Javadoc) * @see org.apache.shiro.realm.AuthenticatingRealm#doGetAuthenticationInfo(org.apache.shiro.authc.AuthenticationToken) * 認證回調函數,登錄時調用 */ @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException { UsernamePasswordToken token =(UsernamePasswordToken) authcToken; User user=userService.getUserbyusername(token.getUsername()); if (user!=null) { return ?new ?SimpleAuthenticationInfo(user.getUsername(),user.getPassword(),getName()); }else { throw new AuthenticationException("該用戶不存在"); } } /* * (non-Javadoc) * @see org.apache.shiro.realm.AuthorizingRealm#doGetAuthorizationInfo(org.apache.shiro.subject.PrincipalCollection) * 授權查詢回調函數,無用戶授權信息是調用 */ @Override protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection)throws AuthenticationException { String username=(String) principalCollection.getPrimaryPrincipal(); //獲取角色相關信息 List<Role> Rolelist=userService.getUserbyusername(username).getRole(); //角色名集合 Set<String> RoleSet=new HashSet<String>(); //權限名集合 Set<String> PermissionSet =new HashSet<String>(); for (Role role : Rolelist) { RoleSet.add(role.getRolename()); for (Menu menu : role.getMenu()) { PermissionSet.add(menu.getMenuname()); } } SimpleAuthorizationInfo authorization=new SimpleAuthorizationInfo(); authorization.addRoles(RoleSet); authorization.addStringPermissions(PermissionSet); return authorization; } /* *更新用戶授權信息緩存 */ public void clearCacheAuthenticationInfo(String principals ){ @SuppressWarnings("unused") SimplePrincipalCollection info=new SimplePrincipalCollection(principals,getName()); clearCacheAuthenticationInfo(principals); } /* * 清除所有用戶授權信息緩存 */ public void clearAllCacheauthenticationInfo(){ Cache<Object, AuthorizationInfo> cache=getAuthorizationCache(); if (cache!=null) { for(Object key :cache.keys()){ cache.remove(key); } } }}
查看完整描述

2 回答

?
慕粉1853512859

TA貢獻1條經驗 獲得超0個贊

你的密碼是明文,加密下就行了

查看完整回答
反對 回復 2017-07-06
?
qq_那一眸的風情_03788798

TA貢獻11條經驗 獲得超4個贊

求教?。。?/p>


查看完整回答
反對 回復 2016-11-02
  • 2 回答
  • 1 關注
  • 3318 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號