shiro 认证失败 ,但是用户有权限
后端代码
usersController
package com.graduate.twentyone.controller;
import com.graduate.twentyone.diman.RestDate;
import com.graduate.twentyone.diman.Users;
import org.apache.catalina.User;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.Map;
@Controller
@ResponseBody
@CrossOrigin
public class UsersController {
/***
*@methodName userslogin
*@方法功能描述
*@params
* @param users
*@return com.graduate.twentyone.diman.RestDate
*@exception
*@author $風~$
*@Date 2021/3/22
*/
@RequestMapping(value = "userlogin" ,method = RequestMethod.POST)
// @GetMapping("/userlogin")
public RestDate userslogin(@RequestBody Users users) {
String uname = users.getUname();
String pwd = users.getPwd();
System.out.println( " 222 uname " + uname);
System.out.println(" 333 pwd " + pwd);
Subject subject = SecurityUtils.getSubject();
RestDate<Object> restDate = new RestDate<>(800, "error", "返回的数据");
String authToken1 = (String) subject.getSession().getId();
System.out.println(authToken1+" authtoken");
Map map = new HashMap();
map.put("authToken",authToken1);
try {
subject.login(new UsernamePasswordToken(uname, pwd));
} catch (IncorrectCredentialsException incorrectCredentialsException) {
restDate = new RestDate<>(2, "密码错误", "返回的数据");
return restDate;
} catch (UnknownAccountException UnknownAccountException) {
restDate = new RestDate<>(1, "账号错误", "返回的数据");
return restDate;
} catch (NullPointerException nullPointerException) {
restDate = new RestDate<>(0, "未输入信息", "返回的数据");
return restDate;
}
if (subject.isAuthenticated()) {
restDate = new RestDate<>(-1, "success",map);
return restDate;
}
return restDate;
}
}
foodController
package com.graduate.twentyone.controller;
import com.graduate.twentyone.diman.Food;
import com.graduate.twentyone.diman.RestDate;
import com.graduate.twentyone.service.FoodService;
import org.apache.shiro