我用nutz 做了一个应用,分了三层为dao,service,rest 前端用vue.js写的,前端ajax请求登录后shiro怎么做权限控制?
//测试shiro注解
@At
@Filters(@By(type=CrossOriginFilter.class))
@GET
@RequiresAuthentication
public boolean updateAccount(){
log.debug("测试shiro注解");
return true;
}
@At
@GET
@Filters(@By(type=CrossOriginFilter.class))
@RequiresGuest
public boolean signUp(){
log.debug("测试shiro注解 Guest 权限");
return false;
}
登录
@At
@AdaptBy(type=JsonAdaptor.class)
@Filters(@By(type=CrossOriginFilter.class)) // 覆盖UserModule类的@Filter设置,因为登陆可不能要求是个已经登陆的Session
@POST
@Ok("json") //输出用json格式
public boolean login(@Param("username") String username,
@Param("password") String password ){
if (Strings.isBlank(username) || Strings.isBlank(password)){
log.debug("username or password is null");
return false;
}
int userId = userService.fetch(username, password);
if (userId < 0){
log.debug("no such user = " + username);
return false;
} else {
//添加token为后来的权限做验证
SecurityUtils.getSubject().login(new SimpleShiroToken(userId));
return true;
}
}