Search in sources :

Example 1 with EmojiFilter

use of com.chao.cloud.common.extra.emoji.annotation.EmojiFilter in project chao-cloud by chaojunzi.

the class EmojiFilterProxy method around.

// 环绕拦截
@Around(value = "@annotation(org.springframework.web.bind.annotation.RequestMapping)")
public Object around(ProceedingJoinPoint pdj) throws Throwable {
    Method method = this.getMethod(pdj);
    // 获取method 中的注解
    EmojiFilter emojiFilter = method.getAnnotation(EmojiFilter.class);
    // 获取参数
    List<Object> args = Stream.of(pdj.getArgs()).filter(o -> !isInclude(o)).collect(Collectors.toList());
    // 开始过滤
    if ((emojiFilter == null || emojiFilter.value()) && !CollUtil.isEmpty(args)) {
        // 参数json化
        String jsonStr = JSONUtil.toJsonStr(args);
        // 提取emoji
        List<String> list = EmojiUtil.extractEmojis(jsonStr);
        if (!CollUtil.isEmpty(list)) {
            String emoji = list.stream().collect(Collectors.joining());
            // 抛出异常
            throw new BusinessException(StrUtil.format("[非法字符:emoji:->{}]", emoji));
        }
    }
    return pdj.proceed();
}
Also used : EmojiFilter(com.chao.cloud.common.extra.emoji.annotation.EmojiFilter) EmojiUtil(cn.hutool.extra.emoji.EmojiUtil) Collectors(java.util.stream.Collectors) Around(org.aspectj.lang.annotation.Around) EmojiFilter(com.chao.cloud.common.extra.emoji.annotation.EmojiFilter) JSONUtil(cn.hutool.json.JSONUtil) List(java.util.List) CollUtil(cn.hutool.core.collection.CollUtil) StrUtil(cn.hutool.core.util.StrUtil) Stream(java.util.stream.Stream) BaseProxy(com.chao.cloud.common.base.BaseProxy) Aspect(org.aspectj.lang.annotation.Aspect) BusinessException(com.chao.cloud.common.exception.BusinessException) Method(java.lang.reflect.Method) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) BusinessException(com.chao.cloud.common.exception.BusinessException) Method(java.lang.reflect.Method) Around(org.aspectj.lang.annotation.Around)

Aggregations

CollUtil (cn.hutool.core.collection.CollUtil)1 StrUtil (cn.hutool.core.util.StrUtil)1 EmojiUtil (cn.hutool.extra.emoji.EmojiUtil)1 JSONUtil (cn.hutool.json.JSONUtil)1 BaseProxy (com.chao.cloud.common.base.BaseProxy)1 BusinessException (com.chao.cloud.common.exception.BusinessException)1 EmojiFilter (com.chao.cloud.common.extra.emoji.annotation.EmojiFilter)1 Method (java.lang.reflect.Method)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)1 Around (org.aspectj.lang.annotation.Around)1 Aspect (org.aspectj.lang.annotation.Aspect)1