Search in sources :

Example 1 with BussinessLog

use of com.zyd.blog.business.annotation.BussinessLog in project OneBlog by zhangyd-c.

the class PassportController method submitLogin.

/**
 * 登录
 *
 * @param username
 * @param password
 * @return
 */
@BussinessLog("[{1}]登录系统")
@PostMapping("/signin")
@ResponseBody
public ResponseVO submitLogin(String username, String password, boolean rememberMe, String kaptcha) {
    if (config.isEnableKaptcha()) {
        if (StringUtils.isEmpty(kaptcha) || !kaptcha.equals(SessionUtil.getKaptcha())) {
            return ResultUtil.error("验证码错误!");
        }
        SessionUtil.removeKaptcha();
    }
    UsernamePasswordToken token = new UsernamePasswordToken(username, password, rememberMe);
    // 获取当前的Subject
    Subject currentUser = SecurityUtils.getSubject();
    try {
        // 在调用了login方法后,SecurityManager会收到AuthenticationToken,并将其发送给已配置的Realm执行必须的认证检查
        // 每个Realm都能在必要时对提交的AuthenticationTokens作出反应
        // 所以这一步在调用login(token)方法时,它会走到xxRealm.doGetAuthenticationInfo()方法中,具体验证方式详见此方法
        currentUser.login(token);
        SavedRequest savedRequest = WebUtils.getSavedRequest(RequestHolder.getRequest());
        String historyUrl = null;
        if (null != savedRequest) {
            if (!savedRequest.getMethod().equals("POST")) {
                historyUrl = savedRequest.getRequestUrl();
            }
        }
        return ResultUtil.success(null, historyUrl);
    } catch (Exception e) {
        log.error("登录失败,用户名[{}]:{}", username, e.getMessage());
        token.clear();
        return ResultUtil.error(e.getMessage());
    }
}
Also used : Subject(org.apache.shiro.subject.Subject) UsernamePasswordToken(org.apache.shiro.authc.UsernamePasswordToken) SavedRequest(org.apache.shiro.web.util.SavedRequest) PostMapping(org.springframework.web.bind.annotation.PostMapping) BussinessLog(com.zyd.blog.business.annotation.BussinessLog) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with BussinessLog

use of com.zyd.blog.business.annotation.BussinessLog in project OneBlog by zhangyd-c.

the class RestApiController method uploadFile.

@BussinessLog("wangEditor编辑器中上传文件")
@RequiresPermissions("article:publish")
@PostMapping("/uploadFile")
public ResponseVO uploadFile(@RequestParam("file") MultipartFile file) {
    FileUploader uploader = new GlobalFileUploader();
    VirtualFile virtualFile = uploader.upload(file, FileUploadType.SIMPLE.getPath(), true);
    return ResultUtil.success("图片上传成功", virtualFile.getFullFilePath());
}
Also used : VirtualFile(com.zyd.blog.file.entity.VirtualFile) GlobalFileUploader(com.zyd.blog.plugin.file.GlobalFileUploader) FileUploader(com.zyd.blog.file.FileUploader) GlobalFileUploader(com.zyd.blog.plugin.file.GlobalFileUploader) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) PostMapping(org.springframework.web.bind.annotation.PostMapping) BussinessLog(com.zyd.blog.business.annotation.BussinessLog)

Example 3 with BussinessLog

use of com.zyd.blog.business.annotation.BussinessLog in project OneBlog by zhangyd-c.

the class BussinessLogAspect method handle.

private void handle(ProceedingJoinPoint point) throws Exception {
    Method currentMethod = AspectUtil.INSTANCE.getMethod(point);
    // 获取操作名称
    BussinessLog annotation = currentMethod.getAnnotation(BussinessLog.class);
    boolean save = annotation.save();
    PlatformEnum platform = annotation.platform();
    String bussinessName = AspectUtil.INSTANCE.parseParams(point.getArgs(), annotation.value());
    String ua = RequestUtil.getUa();
    log.info("{} | {} - {} {} - {}", bussinessName, RequestUtil.getIp(), RequestUtil.getMethod(), RequestUtil.getRequestUrl(), ua);
    if (!save) {
        return;
    }
    logService.asyncSaveSystemLog(platform, bussinessName);
}
Also used : Method(java.lang.reflect.Method) BussinessLog(com.zyd.blog.business.annotation.BussinessLog) PlatformEnum(com.zyd.blog.business.enums.PlatformEnum)

Example 4 with BussinessLog

use of com.zyd.blog.business.annotation.BussinessLog in project OneBlog by zhangyd-c.

the class RenderController method type.

/**
 * 分类列表
 *
 * @param typeId
 * @param model
 * @return
 */
@GetMapping("/type/{typeId}")
@BussinessLog(value = "进入文章分类[{1}]列表页", platform = PlatformEnum.WEB)
public ModelAndView type(@PathVariable("typeId") Long typeId, Model model) {
    ArticleConditionVO vo = new ArticleConditionVO();
    vo.setTypeId(typeId);
    model.addAttribute("url", "type/" + typeId);
    loadIndexPage(vo, model);
    return ResultUtil.view(INDEX_URL);
}
Also used : ArticleConditionVO(com.zyd.blog.business.vo.ArticleConditionVO) GetMapping(org.springframework.web.bind.annotation.GetMapping) BussinessLog(com.zyd.blog.business.annotation.BussinessLog)

Example 5 with BussinessLog

use of com.zyd.blog.business.annotation.BussinessLog in project OneBlog by zhangyd-c.

the class RestApiController method qq.

@PostMapping("/qq/{qq}")
@BussinessLog(value = "获取QQ信息", platform = PlatformEnum.WEB)
public ResponseVO qq(@PathVariable("qq") String qq) {
    if (StringUtils.isEmpty(qq)) {
        return ResultUtil.error("");
    }
    Map<String, String> resultMap = new HashMap<>(4);
    String nickname = "匿名";
    String json = RestClientUtil.get("https://r.qzone.qq.com/fcg-bin/cgi_get_portrait.fcg?uins=" + qq, "GBK");
    if (!StringUtils.isEmpty(json)) {
        try {
            json = json.replaceAll("portraitCallBack|\\\\s*|\\t|\\r|\\n", "");
            json = json.substring(1, json.length() - 1);
            log.info(json);
            JSONObject object = JSONObject.parseObject(json);
            JSONArray array = object.getJSONArray(qq);
            nickname = array.getString(6);
        } catch (Exception e) {
            log.error("通过QQ号获取用户昵称发生异常", e);
        }
    }
    resultMap.put("avatar", "https://q1.qlogo.cn/g?b=qq&nk=" + qq + "&s=40");
    resultMap.put("nickname", nickname);
    resultMap.put("email", qq + "@qq.com");
    resultMap.put("url", "https://user.qzone.qq.com/" + qq);
    return ResultUtil.success(null, resultMap);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) HashMap(java.util.HashMap) JSONArray(com.alibaba.fastjson.JSONArray) ZhydArticleException(com.zyd.blog.framework.exception.ZhydArticleException) ZhydCommentException(com.zyd.blog.framework.exception.ZhydCommentException) ZhydLinkException(com.zyd.blog.framework.exception.ZhydLinkException) BussinessLog(com.zyd.blog.business.annotation.BussinessLog)

Aggregations

BussinessLog (com.zyd.blog.business.annotation.BussinessLog)18 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)9 PostMapping (org.springframework.web.bind.annotation.PostMapping)9 GetMapping (org.springframework.web.bind.annotation.GetMapping)7 ArticleConditionVO (com.zyd.blog.business.vo.ArticleConditionVO)4 User (com.zyd.blog.business.entity.User)3 HashMap (java.util.HashMap)3 JSONObject (com.alibaba.fastjson.JSONObject)2 Article (com.zyd.blog.business.entity.Article)2 Notice (com.zyd.blog.business.entity.Notice)2 FileUploader (com.zyd.blog.file.FileUploader)2 VirtualFile (com.zyd.blog.file.entity.VirtualFile)2 ZhydCommentException (com.zyd.blog.framework.exception.ZhydCommentException)2 GlobalFileUploader (com.zyd.blog.plugin.file.GlobalFileUploader)2 JSONArray (com.alibaba.fastjson.JSONArray)1 Comment (com.zyd.blog.business.entity.Comment)1 Template (com.zyd.blog.business.entity.Template)1 PlatformEnum (com.zyd.blog.business.enums.PlatformEnum)1 ZhydArticleException (com.zyd.blog.framework.exception.ZhydArticleException)1 ZhydException (com.zyd.blog.framework.exception.ZhydException)1