Authentication design
Basic authentication table
- The service table
The users table- Character sheet
- The menu list
- The function table
- Resource table
Lemon Extra table
- Child role table
Authentication association table
User-role, many-to-many, superordinate code control.- Roles – menus, many-to-many, database associated tables.
- Role – function, many-to-many, database associated tables.
- Menu – features, many-to-many, database associated tables.
- Features – Resources, many-to-many, database associated tables.
- Service – For all other tables, the service ids are stored in the other table service_id.
Lemon Extra table
- Merchant – Subrole table
- User-subrole table
- Subroles – Menu list
- Sub-roles – Functions
The diagram shows an EXAMPLE of RBAC.
landing
Each login user will use JWT to generate a token, no cache design. See the com. Zuhao. Uhaozutool. Service. UserService. Login.
authentication
Each menu has a fixed URL prefix, and the function has a fixed method: URL.
You can determine whether the current user has access permission according to the accessed URL.
Get the current login person, according to the user query whether have access to this URL.
Example: com. Zuhao. Uhaozutool. Base. The authorize. UserAuthorize
annotations
- @auth can be used on classes and methods. This annotation determines which Authorize logic is used.
- @Authorize implement handle method, coding specific authentication logic.
- @ignore class whose user is annotated by @auth. Some methods do not require authentication.
Basic function points
Build table statements
DROP TABLE IF EXISTS `t_base_auth_service`;
CREATE TABLE `t_base_auth_service`
(
`id` BIGINT(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
`name` VARCHAR(64) NOT NULL DEFAULT ' ' COMMENT 'account',
`description` VARCHAR(1024) NOT NULL DEFAULT ' ' COMMENT 'description',
`if_available` TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'Enabled state, 1 enabled, 2 disabled',
`created_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Creation time',
`last_modified_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Last modified time'.PRIMARY KEY (`id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
ROW_FORMAT = COMPACT COMMENT ='Service list';
DROP TABLE IF EXISTS `t_base_auth_role`;
CREATE TABLE `t_base_auth_role`
(
`id` BIGINT(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
`service_id` BIGINT(11) NOT NULL DEFAULT 0 COMMENT 'service id',
`name` VARCHAR(64) NOT NULL DEFAULT ' ' COMMENT 'Role Name',
`sign` VARCHAR(64) NOT NULL DEFAULT ' ' COMMENT 'Character Logo',
`description` VARCHAR(1024) NOT NULL DEFAULT ' ' COMMENT 'description',
`if_available` TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'Enabled state, 1 enabled, 2 disabled',
`sort` TINYINT(4) NOT NULL DEFAULT 0 COMMENT 'order',
`created_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Creation time',
`last_modified_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Last modified time'.PRIMARY KEY (`id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
ROW_FORMAT = COMPACT COMMENT ='Role table';
DROP TABLE IF EXISTS `t_base_auth_role_menu`;
CREATE TABLE `t_base_auth_role_menu`
(
`id` BIGINT(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
`role_id` BIGINT(11) NOT NULL DEFAULT 0 COMMENT 'character id',
`menu_id` BIGINT(11) NOT NULL DEFAULT 0 COMMENT 'menu ids',
`created_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Creation time',
`last_modified_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Last modified time'.PRIMARY KEY (`id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
ROW_FORMAT = COMPACT COMMENT ='Roles - Menu List';
DROP TABLE IF EXISTS `t_base_auth_menu`;
CREATE TABLE `t_base_auth_menu`
(
`id` BIGINT(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
`service_id` BIGINT(11) NOT NULL DEFAULT 0 COMMENT 'service id',
`parent_id` BIGINT(11) NOT NULL DEFAULT 0 COMMENT 'parent id',
`name` VARCHAR(64) NOT NULL DEFAULT ' ' COMMENT 'Menu name',
`sign` VARCHAR(64) NOT NULL DEFAULT ' ' COMMENT 'Character Logo',
`url_prefix` VARCHAR(64) NOT NULL DEFAULT ' ' COMMENT 'Link prefix',
`level` TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'hierarchy',
`if_has_child` TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'Is there a next level?',
`description` VARCHAR(1024) NOT NULL DEFAULT ' ' COMMENT 'description',
`if_available` TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'Enabled state, 1 enabled, 2 disabled',
`sort` TINYINT(4) NOT NULL DEFAULT 0 COMMENT 'order',
`created_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Creation time',
`last_modified_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Last modified time'.PRIMARY KEY (`id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
ROW_FORMAT = COMPACT COMMENT ='Menu list';
DROP TABLE IF EXISTS `t_base_auth_role_function`;
CREATE TABLE `t_base_auth_role_function`
(
`id` BIGINT(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
`role_id` BIGINT(11) NOT NULL DEFAULT 0 COMMENT 'parent id',
`function_id` BIGINT(11) NOT NULL DEFAULT 0 COMMENT 'parent id',
`created_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Creation time',
`last_modified_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Last modified time'.PRIMARY KEY (`id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
ROW_FORMAT = COMPACT COMMENT ='Roles - Menu';
DROP TABLE IF EXISTS `t_base_auth_function`;
CREATE TABLE `t_base_auth_function`
(
`id` BIGINT(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
`service_id` BIGINT(11) NOT NULL DEFAULT 0 COMMENT 'service id',
`menu_id` BIGINT(11) NOT NULL DEFAULT 0 COMMENT 'parent id',
`sign` VARCHAR(64) NOT NULL DEFAULT ' ' COMMENT 'Method flag',
`name` VARCHAR(64) NOT NULL DEFAULT ' ' COMMENT 'Function name',
`description` VARCHAR(1024) NOT NULL DEFAULT ' ' COMMENT 'description',
`if_available` TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'Enabled state, 1 enabled, 2 disabled',
`created_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Creation time',
`last_modified_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Last modified time'.PRIMARY KEY (`id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
ROW_FORMAT = COMPACT COMMENT ='Menu';
DROP TABLE IF EXISTS `t_base_auth_function_resource`;
CREATE TABLE `t_base_auth_function_resource`
(
`id` BIGINT(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
`function_id` BIGINT(11) NOT NULL DEFAULT 0 COMMENT 'function id',
`resource_id` BIGINT(11) NOT NULL DEFAULT 0 COMMENT 'resource id',
`created_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Creation time',
`last_modified_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Last modified time'.PRIMARY KEY (`id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
ROW_FORMAT = COMPACT COMMENT ='Features - Resource Table';
DROP TABLE IF EXISTS `t_base_auth_resource`;
CREATE TABLE `t_base_auth_resource`
(
`id` BIGINT(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
`service_id` BIGINT(11) NOT NULL DEFAULT 0 COMMENT 'service id',
`url` VARCHAR(64) NOT NULL DEFAULT ' ' COMMENT 'Backend path,method: URL format',
`description` VARCHAR(1024) NOT NULL DEFAULT ' ' COMMENT 'description',
`if_available` TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'Enabled state, 1 enabled, 2 disabled',
`created_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Creation time',
`last_modified_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Last modified time'.PRIMARY KEY (`id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
ROW_FORMAT = COMPACT COMMENT ='Resource table'; Lemon Extra tableCopy the code