All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.zj.dreamly.security.jwt.util.SpringElCheckUtil Maven / Gradle / Ivy

There is a newer version: 1.0.0-beta.6
Show newest version
package com.github.zj.dreamly.security.jwt.util;

import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;

/**
 * @author 苍海之南
 */
@UtilityClass
@Slf4j
public class SpringElCheckUtil {
    private static ExpressionParser PARSER = new SpelExpressionParser();

    /**
     * 校验expression是否能通过rootObject的检测
     *
     * @param context    上下文
     * @param expression 表达式
     * @return 是否通过
     */
    public static boolean check(EvaluationContext context, String expression) {
        Boolean result = PARSER.parseExpression(expression).getValue(context, Boolean.class);
        log.info("expression = {}, eval result = {}", expression, result);
        return result != null ? result : false;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy