Class SecurityContext

java.lang.Object
com.elitesland.ystdms.sys.security.SecurityContext

public class SecurityContext extends Object
Security 上下文工具类 提供从 JWT Token 中获取用户信息的能力,以及通过 Feign 获取扩展信息
  • Constructor Details

    • SecurityContext

      public SecurityContext()
  • Method Details

    • setSecurityContextService

      public static void setSecurityContextService(SecurityContextService service)
      设置 SecurityContextService 实例 通过配置类手动调用
    • setJwt

      public static void setJwt(org.springframework.security.oauth2.jwt.Jwt jwt)
    • getJwt

      public static org.springframework.security.oauth2.jwt.Jwt getJwt()
    • clear

      public static void clear()
    • getSubject

      public static String getSubject()
    • getUserId

      public static String getUserId()
      获取用户ID(从JWT的subject中获取)
    • getUsername

      public static String getUsername()
      获取用户名
    • getDept

      public static String getDept()
      获取部门
    • getRoles

      public static List<String> getRoles()
      获取角色列表
    • getTokenType

      public static String getTokenType()
      获取Token类型
    • isAuthenticated

      public static boolean isAuthenticated()
      判断当前是否已认证(有有效的JWT)
    • getClaim

      public static <T> T getClaim(String claimName)
    • getCurrentEmployee

      public static SysEmployeeDTO getCurrentEmployee()
      获取当前登录用户的员工信息
      Returns:
      员工信息,如果未登录或查询失败则返回 null
    • getEmployee

      public static SysEmployeeDTO getEmployee(String username)
      获取指定用户的员工信息
      Parameters:
      username - 用户名
      Returns:
      员工信息,如果查询失败则返回 null
    • getEmployeeByUserId

      public static SysEmployeeDTO getEmployeeByUserId(UUID userId)
      根据 userId 获取员工信息
    • getCurrentOrg

      public static SysOrgRespRpcDTO getCurrentOrg()
      获取当前用户所属的组织信息
      Returns:
      组织信息,如果未登录或查询失败则返回 null
    • getOrg

      public static SysOrgRespRpcDTO getOrg(UUID orgId)
      获取指定ID的组织信息
      Parameters:
      orgId - 组织ID
      Returns:
      组织信息,如果查询失败则返回 null
    • getCurrentOu

      public static List<SysOuDTO> getCurrentOu()
      获取当前用户所属的公司信息
      Returns:
      公司信息列表,如果未登录或查询失败则返回 null
    • getAllOu

      public static List<SysOuDTO> getAllOu()
      获取所有公司信息
      Returns:
      公司信息列表,如果查询失败则返回 null