Search in sources :

Example 1 with ZhydException

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;
}
Also used : ZhydException(com.zyd.blog.framework.exception.ZhydException) Resources(com.zyd.blog.business.entity.Resources) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with ZhydException

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;
}
Also used : ZhydException(com.zyd.blog.framework.exception.ZhydException) BizArticleTags(com.zyd.blog.persistence.beans.BizArticleTags) BizTags(com.zyd.blog.persistence.beans.BizTags) Tags(com.zyd.blog.business.entity.Tags) Date(java.util.Date) RedisCache(com.zyd.blog.business.annotation.RedisCache) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with ZhydException

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;
}
Also used : ZhydException(com.zyd.blog.framework.exception.ZhydException) BizArticle(com.zyd.blog.persistence.beans.BizArticle) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with ZhydException

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());
}
Also used : ZhydException(com.zyd.blog.framework.exception.ZhydException) ResponseStatus(com.zyd.blog.business.enums.ResponseStatus) GlobalFileException(com.zyd.blog.file.exception.GlobalFileException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 5 with ZhydException

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);
}
Also used : ZhydException(com.zyd.blog.framework.exception.ZhydException) SysUser(com.zyd.blog.persistence.beans.SysUser) User(com.zyd.blog.business.entity.User)

Aggregations

ZhydException (com.zyd.blog.framework.exception.ZhydException)11 Transactional (org.springframework.transaction.annotation.Transactional)4 RedisCache (com.zyd.blog.business.annotation.RedisCache)3 User (com.zyd.blog.business.entity.User)2 GlobalFileException (com.zyd.blog.file.exception.GlobalFileException)2 BizArticleTags (com.zyd.blog.persistence.beans.BizArticleTags)2 Date (java.util.Date)2 JapUser (com.fujieid.jap.core.JapUser)1 JapConfig (com.fujieid.jap.core.config.JapConfig)1 JapResponse (com.fujieid.jap.core.result.JapResponse)1 SocialStrategy (com.fujieid.jap.social.SocialStrategy)1 BussinessLog (com.zyd.blog.business.annotation.BussinessLog)1 Article (com.zyd.blog.business.entity.Article)1 Resources (com.zyd.blog.business.entity.Resources)1 SocialConfig (com.zyd.blog.business.entity.SocialConfig)1 Tags (com.zyd.blog.business.entity.Tags)1 ResponseStatus (com.zyd.blog.business.enums.ResponseStatus)1 SysConfigService (com.zyd.blog.business.service.SysConfigService)1 AliyunOssApiClient (com.zyd.blog.file.AliyunOssApiClient)1 ApiClient (com.zyd.blog.file.ApiClient)1