Class AuthUtils


  • public class AuthUtils
    extends java.lang.Object
    • Field Detail

      • ROOT_PATH_PRIVILEGE_PATH

        public static PartialPath ROOT_PATH_PRIVILEGE_PATH
    • Method Detail

      • validatePassword

        public static void validatePassword​(java.lang.String password)
                                     throws AuthException
        Validate password
        Parameters:
        password - user password
        Throws:
        AuthException - contains message why password is invalid
      • validatePassword

        public static boolean validatePassword​(java.lang.String originPassword,
                                               java.lang.String encryptPassword)
        Checking whether origin password is mapping to encrypt password by encryption
        Parameters:
        originPassword - the password before encryption
        encryptPassword - the password after encryption
      • validateUsername

        public static void validateUsername​(java.lang.String username)
                                     throws AuthException
        Validate username
        Parameters:
        username - username
        Throws:
        AuthException - contains message why username is invalid
      • validateRolename

        public static void validateRolename​(java.lang.String rolename)
                                     throws AuthException
        Validate role name
        Parameters:
        rolename - role name
        Throws:
        AuthException - contains message why rolename is invalid
      • validatePrivilege

        public static void validatePrivilege​(int privilegeId)
                                      throws AuthException
        Validate privilege
        Parameters:
        privilegeId - privilege ID
        Throws:
        AuthException - contains message why privilege is invalid
      • validatePath

        public static void validatePath​(PartialPath path)
                                 throws AuthException
        Validate path
        Parameters:
        path - series path
        Throws:
        AuthException - contains message why path is invalid
      • validatePrivilegeOnPath

        public static void validatePrivilegeOnPath​(PartialPath path,
                                                   int privilegeId)
                                            throws AuthException
        Validate privilege on path
        Parameters:
        path - the path of privilege
        privilegeId - privilege Id
        Throws:
        AuthException - contains message why path is invalid
      • encryptPassword

        public static java.lang.String encryptPassword​(java.lang.String password)
        Encrypt password
        Parameters:
        password - password
        Returns:
        encrypted password if success
      • checkPrivilege

        public static boolean checkPrivilege​(PartialPath path,
                                             int privilegeId,
                                             java.util.List<PathPrivilege> privilegeList)
                                      throws AuthException
        Check privilege
        Parameters:
        path - series path
        privilegeId - privilege Id
        privilegeList - privileges in List structure
        Returns:
        True if privilege-check passed
        Throws:
        AuthException - throw if path is invalid or path in privilege is invalid
      • getPrivileges

        public static java.util.Set<java.lang.Integer> getPrivileges​(PartialPath path,
                                                                     java.util.List<PathPrivilege> privilegeList)
                                                              throws AuthException
        Get privileges
        Parameters:
        path - The seriesPath on which the privileges take effect. If seriesPath-free privileges are desired, this should be null
        Returns:
        The privileges granted to the role
        Throws:
        AuthException - throw if path is invalid or path in privilege is invalid
      • hasPrivilege

        public static boolean hasPrivilege​(PartialPath path,
                                           int privilegeId,
                                           java.util.List<PathPrivilege> privilegeList)
        Check if series path has this privilege
        Parameters:
        path - series path
        privilegeId - privilege Id
        privilegeList - privileges in List structure
        Returns:
        True if series path has this privilege
      • addPrivilege

        public static void addPrivilege​(PartialPath path,
                                        int privilegeId,
                                        java.util.List<PathPrivilege> privilegeList)
        Add privilege
        Parameters:
        path - series path
        privilegeId - privilege Id
        privilegeList - privileges in List structure of user or role
      • removePrivilege

        public static void removePrivilege​(PartialPath path,
                                           int privilegeId,
                                           java.util.List<PathPrivilege> privilegeList)
        Remove privilege
        Parameters:
        path - series path
        privilegeId - privilege Id
        privilegeList - privileges in List structure of user or role
      • generateEmptyPermissionInfoResp

        public static org.apache.iotdb.confignode.rpc.thrift.TPermissionInfoResp generateEmptyPermissionInfoResp()
        Generate empty permission response when failed
      • strToPermissions

        public static java.util.Set<java.lang.Integer> strToPermissions​(java.lang.String[] authorizationList)
                                                                 throws AuthException
        Transform permission from name to privilegeId
        Parameters:
        authorizationList - the list of privilege name
        Returns:
        the list of privilege Ids
        Throws:
        AuthException - throws if there are no privilege matched
      • serializePartialPathList

        public static java.nio.ByteBuffer serializePartialPathList​(java.util.List<PartialPath> paths)
      • deserializePartialPathList

        public static java.util.List<PartialPath> deserializePartialPathList​(java.nio.ByteBuffer buffer)