use of com.zyd.blog.framework.exception.ZhydException in project OneBlog by zhangyd-c.
the class ShiroServiceImpl method loadFilterChainDefinitions.
/**
* 初始化权限
*/
@Override
public Map<String, String> loadFilterChainDefinitions() {
/*
配置访问权限
- anon:所有url都都可以匿名访问
- authc: 需要认证才能进行访问(此处指所有非匿名的路径都需要登录才能访问)
- user:配置记住我或认证通过可以访问
*/
Map<String, String> filterChainDefinitionMap = new LinkedHashMap<String, String>();
// 配置退出过滤器,其中的具体的退出代码Shiro已经替我们实现了
filterChainDefinitionMap.put("/passport/logout", "logout");
filterChainDefinitionMap.put("/passport/login", "anon");
filterChainDefinitionMap.put("/passport/signin", "anon");
filterChainDefinitionMap.put("/websocket", "anon");
filterChainDefinitionMap.put("/favicon.ico", "anon");
filterChainDefinitionMap.put("/error", "anon");
filterChainDefinitionMap.put("/assets/**", "anon");
filterChainDefinitionMap.put("/plugin/**", "anon");
filterChainDefinitionMap.put("/vendors/**", "anon");
filterChainDefinitionMap.put("/getKaptcha", "anon");
// 加载数据库中配置的资源权限列表
List<Resources> resourcesList = resourcesService.listUrlAndPermission();
if (CollectionUtils.isEmpty(resourcesList)) {
throw new ZhydException("未加载到resources内容,请确认是否执行了init_data.sql");
}
for (Resources resources : resourcesList) {
if (!StringUtils.isEmpty(resources.getUrl()) && !StringUtils.isEmpty(resources.getPermission())) {
String permission = "perms[" + resources.getPermission() + "]";
filterChainDefinitionMap.put(resources.getUrl(), permission);
}
}
// 本博客中并不存在什么特别关键的操作,所以直接使用user认证。如果有朋友是参考本博客的shiro开发其他安全功能(比如支付等)时,建议针对这类操作使用authc权限 by yadong.zhang
filterChainDefinitionMap.put("/**", "user");
return filterChainDefinitionMap;
}
use of com.zyd.blog.framework.exception.ZhydException in project OneBlog by zhangyd-c.
the class BizTagsServiceImpl method updateSelective.
@Override
@Transactional(rollbackFor = Exception.class)
@RedisCache(flush = true)
public boolean updateSelective(Tags entity) {
Assert.notNull(entity, "Tags不可为空!");
Tags old = this.getByName(entity.getName());
if (old != null && !old.getId().equals(entity.getId())) {
throw new ZhydException("标签修改失败,标签已存在![" + entity.getName() + "]");
}
entity.setUpdateTime(new Date());
return bizTagsMapper.updateByPrimaryKeySelective(entity.getBizTags()) > 0;
}
use of com.zyd.blog.framework.exception.ZhydException in project OneBlog by zhangyd-c.
the class BizTypeServiceImpl method removeByPrimaryKey.
@Override
@Transactional(rollbackFor = Exception.class)
public boolean removeByPrimaryKey(Long primaryKey) {
BizArticle article = new BizArticle();
article.setTypeId(primaryKey);
List<BizArticle> articles = bizArticleMapper.select(article);
if (!CollectionUtils.isEmpty(articles)) {
throw new ZhydException("当前分类下存在文章信息,禁止删除!");
}
return bizTypeMapper.deleteByPrimaryKey(primaryKey) > 0;
}
use of com.zyd.blog.framework.exception.ZhydException in project OneBlog by zhangyd-c.
the class ExceptionHandleController method handle.
@ExceptionHandler(value = Exception.class)
@ResponseBody
public ResponseVO handle(Throwable e) {
if (e instanceof ZhydException || e instanceof GlobalFileException) {
return ResultUtil.error(e.getMessage());
}
if (e instanceof UndeclaredThrowableException) {
e = ((UndeclaredThrowableException) e).getUndeclaredThrowable();
}
ResponseStatus responseStatus = ResponseStatus.getResponseStatus(e.getMessage());
if (responseStatus != null) {
log.error(responseStatus.getMessage());
return ResultUtil.error(responseStatus.getCode(), responseStatus.getMessage());
}
// 打印异常栈
e.printStackTrace();
return ResultUtil.error(CommonConst.DEFAULT_ERROR_CODE, ResponseStatus.ERROR.getMessage());
}
use of com.zyd.blog.framework.exception.ZhydException in project OneBlog by zhangyd-c.
the class SysUserServiceImpl method updatePwd.
/**
* 修改密码
*
* @param userPwd
* @return
*/
@Override
public boolean updatePwd(UserPwd userPwd) throws Exception {
if (!userPwd.getNewPassword().equals(userPwd.getNewPasswordRepeat())) {
throw new ZhydException("新密码不一致!");
}
User user = this.getByPrimaryKey(userPwd.getId());
if (null == user) {
throw new ZhydException("用户编号错误!请不要手动操作用户ID!");
}
if (!user.getPassword().equals(PasswordUtil.encrypt(userPwd.getPassword(), user.getUsername()))) {
throw new ZhydException("原密码不正确!");
}
user.setPassword(userPwd.getNewPassword());
return this.updateSelective(user);
}
Aggregations