类 SaStrategy

java.lang.Object
cn.dev33.satoken.strategy.SaStrategy

public final class SaStrategy extends Object
Sa-Token 策略对象

此类统一定义框架内的一些关键性逻辑算法,方便开发者进行按需重写,例:

        // SaStrategy全局单例,所有方法都用以下形式重写 
        SaStrategy.me.setCreateToken((loginId, loginType) -》 {
                // 自定义Token生成的算法 
                return "xxxx";
        });
 
作者:
kong
  • 字段详细资料

    • me

      public static final SaStrategy me
      获取 SaStrategy 对象的单例引用
    • createToken

      public BiFunction<Object,String,String> createToken
      创建 Token 的策略

      参数 [账号id, 账号类型]

    • createSession

      public Function<String,SaSession> createSession
      创建 Session 的策略

      参数 [SessionId]

    • hasElement

      public BiFunction<List<String>,String,Boolean> hasElement
      判断:集合中是否包含指定元素(模糊匹配)

      参数 [集合, 元素]

    • checkMethodAnnotation

      public Consumer<Method> checkMethodAnnotation
      对一个 [Method] 对象进行注解校验 (注解鉴权内部实现)

      参数 [Method句柄]

    • checkElementAnnotation

      public Consumer<AnnotatedElement> checkElementAnnotation
      对一个 [元素] 对象进行注解校验 (注解鉴权内部实现)

      参数 [element元素]

    • getAnnotation

      public BiFunction<AnnotatedElement,Class<? extends Annotation>,Annotation> getAnnotation
      从元素上获取注解

      参数 [element元素,要获取的注解类型]

    • isAnnotationPresent

      public BiFunction<Method,Class<? extends Annotation>,Boolean> isAnnotationPresent
      判断一个 Method 或其所属 Class 是否包含指定注解

      参数 [Method, 注解]

  • 方法详细资料

    • setCreateToken

      public SaStrategy setCreateToken(BiFunction<Object,String,String> createToken)
      重写创建 Token 的策略

      参数 [账号id, 账号类型]

      参数:
      createToken - /
      返回:
      对象自身
    • setCreateSession

      public SaStrategy setCreateSession(Function<String,SaSession> createSession)
      重写创建 Session 的策略

      参数 [SessionId]

      参数:
      createSession - /
      返回:
      对象自身
    • setHasElement

      public SaStrategy setHasElement(BiFunction<List<String>,String,Boolean> hasElement)
      判断:集合中是否包含指定元素(模糊匹配)

      参数 [集合, 元素]

      参数:
      hasElement - /
      返回:
      对象自身
    • setCheckMethodAnnotation

      public SaStrategy setCheckMethodAnnotation(Consumer<Method> checkMethodAnnotation)
      对一个 [Method] 对象进行注解校验 (注解鉴权内部实现)

      参数 [Method句柄]

      参数:
      checkMethodAnnotation - /
      返回:
      对象自身
    • setCheckElementAnnotation

      public SaStrategy setCheckElementAnnotation(Consumer<AnnotatedElement> checkElementAnnotation)
      对一个 [元素] 对象进行注解校验 (注解鉴权内部实现)

      参数 [element元素]

      参数:
      checkElementAnnotation - /
      返回:
      对象自身
    • setGetAnnotation

      public SaStrategy setGetAnnotation(BiFunction<AnnotatedElement,Class<? extends Annotation>,Annotation> getAnnotation)
      从元素上获取注解

      参数 [element元素,要获取的注解类型]

      参数:
      getAnnotation - /
      返回:
      对象自身
    • setIsAnnotationPresent

      public SaStrategy setIsAnnotationPresent(BiFunction<Method,Class<? extends Annotation>,Boolean> isAnnotationPresent)
      判断一个 Method 或其所属 Class 是否包含指定注解

      参数 [Method, 注解]

      参数:
      isAnnotationPresent - /
      返回:
      对象自身