You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@paimon.apache.org by lz...@apache.org on 2023/07/31 06:28:05 UTC
[incubator-paimon-webui] branch main updated: feat: role & menu service (#8)
This is an automated email from the ASF dual-hosted git repository.
lzljs3620320 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-paimon-webui.git
The following commit(s) were added to refs/heads/main by this push:
new 0b483e8 feat: role & menu service (#8)
0b483e8 is described below
commit 0b483e859152f97ff93aa7ede3a90e6de28f291c
Author: G-XD <38...@users.noreply.github.com>
AuthorDate: Mon Jul 31 14:27:59 2023 +0800
feat: role & menu service (#8)
---
docker-compose.yml | 46 --
paimon-web-common/pom.xml | 5 +
paimon-web-server/pom.xml | 11 +
.../server/configrue/GlobalExceptionHandler.java | 81 ++++
.../web/server/configrue/MybatisPlusConfig.java | 3 +-
.../configrue/MybatisPlusMetaObjectHandler.java | 42 ++
.../web/server/configrue/SaTokenConfigure.java | 37 ++
.../paimon/web/server/constant/Constants.java | 50 +++
.../{UserController.java => LoginController.java} | 50 ++-
.../web/server/controller/SysMenuController.java | 127 ++++++
.../web/server/controller/SysRoleController.java | 160 +++++++
.../web/server/controller/UserController.java | 8 +-
.../UserMapper.java => data/enums/MenuType.java} | 26 +-
.../paimon/web/server/data/model/BaseModel.java | 20 +
.../data/model/{UserTenant.java => RoleMenu.java} | 19 +-
.../server/data/model/{User.java => SysMenu.java} | 61 ++-
.../server/data/model/{User.java => SysRole.java} | 52 +--
.../paimon/web/server/data/model/Tenant.java | 3 -
.../apache/paimon/web/server/data/model/User.java | 13 +-
.../data/model/{UserTenant.java => UserRole.java} | 16 +-
.../paimon/web/server/data/model/UserTenant.java | 3 -
.../paimon/web/server/data/result/PageR.java | 50 +++
.../apache/paimon/web/server/data}/result/R.java | 23 +-
.../web/server/data/result}/enums/Status.java | 28 +-
.../exception/BaseException.java} | 38 +-
.../exception/role/RoleInUsedException.java} | 17 +-
.../exception/user/UserNotExistsException.java} | 17 +-
.../user/UserPasswordNotMatchException.java} | 25 +-
.../paimon/web/server/data/tree/TreeSelect.java | 75 ++++
.../apache/paimon/web/server/data/vo/MetaVo.java | 96 +++++
.../RoleMenuTreeselectVo.java} | 32 +-
.../apache/paimon/web/server/data/vo/RouterVo.java | 135 ++++++
.../paimon/web/server/mapper/RoleMenuMapper.java | 70 ++++
.../paimon/web/server/mapper/SysMenuMapper.java | 120 ++++++
.../paimon/web/server/mapper/SysRoleMapper.java | 74 ++++
.../paimon/web/server/mapper/UserMapper.java | 44 +-
.../paimon/web/server/mapper/UserRoleMapper.java | 80 ++++
.../web/server/service/PermissionService.java | 86 ++++
.../paimon/web/server/service/SysMenuService.java | 156 +++++++
.../paimon/web/server/service/SysRoleService.java | 169 ++++++++
.../paimon/web/server/service/UserService.java | 31 +-
.../server/service/impl/SysMenuServiceImpl.java | 465 +++++++++++++++++++++
.../server/service/impl/SysRoleServiceImpl.java | 310 ++++++++++++++
.../web/server/service/impl/UserServiceImpl.java | 55 ++-
.../paimon/web/server/util/MessageUtils.java | 62 +++
.../paimon/web/server/util/ObjectMapperUtils.java | 304 ++++++++++++++
.../apache/paimon/web/server/util/PageSupport.java | 101 +++++
.../paimon/web/server/util/ServletUtils.java | 100 +++++
.../apache/paimon/web/server/util/SpringUtils.java | 94 +++++
.../UserMapper.java => util/StringUtils.java} | 15 +-
.../src/main/resources/application-dev.yml | 2 +-
.../src/main/resources/application.yml | 13 +
paimon-web-server/src/main/resources/db/ddl-h2.sql | 54 +++
paimon-web-server/src/main/resources/db/dml-h2.sql | 39 +-
.../main/resources/db/migration/V1__add_user.sql | 20 -
.../main/resources/db/migration/V2__add_tenant.sql | 13 -
.../resources/db/migration/V3__add_user_tenant.sql | 13 -
.../src/main/resources/i18n/messages.properties | 32 ++
.../main/resources/i18n/messages_en_US.properties | 32 ++
.../main/resources/i18n/messages_zh_CN.properties | 32 ++
.../src/main/resources/mapper/RoleMenuMapper.xml | 61 +++
.../src/main/resources/mapper/SysMenuMapper.xml | 147 +++++++
.../src/main/resources/mapper/SysRoleMapper.xml | 92 ++++
.../src/main/resources/mapper/UserMapper.xml | 118 ++++++
.../src/main/resources/mapper/UserRoleMapper.xml | 63 +++
.../web/server/controller/PermissionTest.java | 116 +++++
.../server/controller/SysMenuControllerTest.java | 182 ++++++++
.../server/controller/SysRoleControllerTest.java | 232 ++++++++++
pom.xml | 15 +
69 files changed, 4691 insertions(+), 290 deletions(-)
diff --git a/docker-compose.yml b/docker-compose.yml
deleted file mode 100644
index 88ac8b3..0000000
--- a/docker-compose.yml
+++ /dev/null
@@ -1,46 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-version: '3.9'
-services:
- mysql:
- image: mysql:5.7
- restart: always
- container_name: paimon-mysql
- command:
- --lower_case_table_names=1
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_general_ci
- --explicit_defaults_for_timestamp=true
- ports:
- - '3306:3306'
- volumes:
- - mysql:/var/lib/mysql
- environment:
- - MYSQL_HOST=0.0.0.0
- - MYSQL_ROOT_PASSWORD=paimon@123
- - MYSQL_DATABASE=paimon
- networks:
- dev:
- ipv4_address: 172.21.0.17
-
-volumes:
- mysql:
-
-networks:
- dev:
- ipam:
- config:
- - subnet: 172.21.0.0/24
\ No newline at end of file
diff --git a/paimon-web-common/pom.xml b/paimon-web-common/pom.xml
index a06db8d..2f2815e 100644
--- a/paimon-web-common/pom.xml
+++ b/paimon-web-common/pom.xml
@@ -47,6 +47,11 @@ under the License.
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
diff --git a/paimon-web-server/pom.xml b/paimon-web-server/pom.xml
index ea8aeb2..78d43f4 100644
--- a/paimon-web-server/pom.xml
+++ b/paimon-web-server/pom.xml
@@ -114,11 +114,22 @@ under the License.
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-aop</artifactId>
+ </dependency>
+
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>
+ <dependency>
+ <groupId>cn.dev33</groupId>
+ <artifactId>sa-token-spring-boot-starter</artifactId>
+ <version>${sa-token.version}</version>
+ </dependency>
+
<!-- h2 -->
<dependency>
<groupId>com.h2database</groupId>
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/configrue/GlobalExceptionHandler.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/configrue/GlobalExceptionHandler.java
new file mode 100644
index 0000000..f8de4da
--- /dev/null
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/configrue/GlobalExceptionHandler.java
@@ -0,0 +1,81 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.paimon.web.server.configrue;
+
+import org.apache.paimon.web.server.data.result.R;
+import org.apache.paimon.web.server.data.result.enums.Status;
+import org.apache.paimon.web.server.data.result.exception.BaseException;
+
+import cn.dev33.satoken.exception.NotLoginException;
+import cn.dev33.satoken.exception.NotPermissionException;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.dao.DataAccessException;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.HttpRequestMethodNotSupportedException;
+import org.springframework.web.bind.annotation.ControllerAdvice;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.ResponseStatus;
+
+/** GlobalExceptionHandler. */
+@Slf4j
+@ControllerAdvice
+@ResponseBody
+public class GlobalExceptionHandler {
+
+ @ExceptionHandler
+ public R<Void> bizException(BaseException e) {
+ if (e.getStatus() == null) {
+ return R.failed(Status.INTERNAL_SERVER_ERROR_ARGS);
+ }
+ return R.failed(e.getStatus());
+ }
+
+ @ResponseStatus(HttpStatus.UNAUTHORIZED)
+ @ExceptionHandler
+ public R<Void> notLoginException(NotLoginException e) {
+ return R.failed(Status.UNAUTHORIZED);
+ }
+
+ @ResponseStatus(HttpStatus.FORBIDDEN)
+ @ExceptionHandler
+ public R<Void> notPermissionException(NotPermissionException e) {
+ return R.failed(Status.FORBIDDEN);
+ }
+
+ @ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
+ @ExceptionHandler
+ public R<Void> notLoginException(HttpRequestMethodNotSupportedException e) {
+ return R.failed(Status.METHOD_NOT_ALLOWED);
+ }
+
+ @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
+ @ExceptionHandler()
+ public R<Void> notLoginException(DataAccessException e) {
+ log.error("SQLException", e);
+ return R.failed(Status.UNKNOWN_ERROR, "sql error");
+ }
+
+ @ExceptionHandler
+ public R<Void> unknownException(Exception e) {
+ log.error("UnknownException", e);
+ return R.failed(Status.UNKNOWN_ERROR, e.getMessage());
+ }
+}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/configrue/MybatisPlusConfig.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/configrue/MybatisPlusConfig.java
index 0a73b48..98f34ab 100644
--- a/paimon-web-server/src/main/java/org/apache/paimon/web/server/configrue/MybatisPlusConfig.java
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/configrue/MybatisPlusConfig.java
@@ -20,7 +20,6 @@ package org.apache.paimon.web.server.configrue;
import org.apache.paimon.web.server.context.TenantContextHolder;
-import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
@@ -63,7 +62,7 @@ public class MybatisPlusConfig {
}
}));
- interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
+ interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
return interceptor;
}
}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/configrue/MybatisPlusMetaObjectHandler.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/configrue/MybatisPlusMetaObjectHandler.java
new file mode 100644
index 0000000..c99b10a
--- /dev/null
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/configrue/MybatisPlusMetaObjectHandler.java
@@ -0,0 +1,42 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.paimon.web.server.configrue;
+
+import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.ibatis.reflection.MetaObject;
+import org.springframework.stereotype.Component;
+
+import java.time.LocalDateTime;
+
+/** Auto fill createTime and updateTime filed config. */
+@Slf4j
+@Component
+public class MybatisPlusMetaObjectHandler implements MetaObjectHandler {
+ @Override
+ public void insertFill(MetaObject metaObject) {
+ this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, LocalDateTime.now());
+ }
+
+ @Override
+ public void updateFill(MetaObject metaObject) {
+ this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());
+ }
+}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/configrue/SaTokenConfigure.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/configrue/SaTokenConfigure.java
new file mode 100644
index 0000000..11bf305
--- /dev/null
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/configrue/SaTokenConfigure.java
@@ -0,0 +1,37 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.paimon.web.server.configrue;
+
+import cn.dev33.satoken.interceptor.SaInterceptor;
+import cn.dev33.satoken.stp.StpUtil;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+/** Sa-Token path config. */
+@Configuration
+public class SaTokenConfigure implements WebMvcConfigurer {
+ @Override
+ public void addInterceptors(InterceptorRegistry registry) {
+ registry.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin()))
+ .addPathPatterns("/**")
+ .excludePathPatterns("/api/login");
+ }
+}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/constant/Constants.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/constant/Constants.java
new file mode 100644
index 0000000..bae0705
--- /dev/null
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/constant/Constants.java
@@ -0,0 +1,50 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.paimon.web.server.constant;
+
+/** Constants. */
+public class Constants {
+ /** admin id. */
+ public static final int ADMIN_ID = 1;
+ /** all permission. */
+ public static final String ALL_PERMISSION = "*:*:*";
+ /** http url prefix. */
+ public static final String HTTP = "http://";
+
+ /** https url prefix. */
+ public static final String HTTPS = "https://";
+ /** WWW. */
+ public static final String WWW = "www";
+
+ /** Layout component flag. */
+ public static final String LAYOUT = "Layout";
+
+ /** ParentView component flag. */
+ public static final String PARENT_VIEW = "ParentView";
+
+ /** InnerLink component flag. */
+ public static final String INNER_LINK = "InnerLink";
+
+ /** Is frame: Yes. */
+ public static final int YES_FRAME = 0;
+
+ /** Is frame: No. */
+ public static final int NO_FRAME = 1;
+}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/controller/UserController.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/controller/LoginController.java
similarity index 59%
copy from paimon-web-server/src/main/java/org/apache/paimon/web/server/controller/UserController.java
copy to paimon-web-server/src/main/java/org/apache/paimon/web/server/controller/LoginController.java
index 737c3e8..3db7dd2 100644
--- a/paimon-web-server/src/main/java/org/apache/paimon/web/server/controller/UserController.java
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/controller/LoginController.java
@@ -18,40 +18,52 @@
package org.apache.paimon.web.server.controller;
-import org.apache.paimon.web.common.result.R;
-import org.apache.paimon.web.server.data.model.User;
+import org.apache.paimon.web.server.data.result.R;
import org.apache.paimon.web.server.service.UserService;
+import cn.dev33.satoken.stp.SaTokenInfo;
+import cn.dev33.satoken.stp.StpUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
-import static org.apache.paimon.web.common.enums.Status.USER_NOT_EXIST;
-
-/** User api controller. */
+/** Login api controller. */
@Slf4j
@RestController
-@RequestMapping("/api/user")
-public class UserController {
+@RequestMapping("/api")
+public class LoginController {
@Autowired private UserService userService;
/**
- * get user by id.
+ * login by username and password.
+ *
+ * @param username username
+ * @param password password
+ * @return token string
+ */
+ @PostMapping("/login")
+ public R<String> login(String username, String password) {
+ return R.succeed(userService.login(username, password));
+ }
+
+ /**
+ * get token info.
*
- * @param id user-id
- * @return {@link R} with {@link User}
+ * @return token info
*/
- @GetMapping("/get/{id}")
- public R<User> getUserById(@PathVariable("id") Long id) {
- User user = userService.getById(id);
- if (user == null) {
- return R.failed(USER_NOT_EXIST);
- }
- user.setPassword(null);
- return R.succeed(user);
+ @GetMapping("/tokenInfo")
+ public R<SaTokenInfo> tokenInfo() {
+ return R.succeed(StpUtil.getTokenInfo());
+ }
+
+ /** logout. */
+ @PostMapping("/logout")
+ public R<Void> logout() {
+ StpUtil.logout();
+ return R.succeed();
}
}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/controller/SysMenuController.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/controller/SysMenuController.java
new file mode 100644
index 0000000..d613594
--- /dev/null
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/controller/SysMenuController.java
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.paimon.web.server.controller;
+
+import org.apache.paimon.web.server.constant.Constants;
+import org.apache.paimon.web.server.data.model.SysMenu;
+import org.apache.paimon.web.server.data.result.R;
+import org.apache.paimon.web.server.data.result.enums.Status;
+import org.apache.paimon.web.server.data.tree.TreeSelect;
+import org.apache.paimon.web.server.data.vo.RoleMenuTreeselectVo;
+import org.apache.paimon.web.server.data.vo.RouterVo;
+import org.apache.paimon.web.server.service.SysMenuService;
+import org.apache.paimon.web.server.util.StringUtils;
+
+import cn.dev33.satoken.annotation.SaCheckPermission;
+import cn.dev33.satoken.stp.StpUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+/** menu controller. */
+@RestController
+@RequestMapping("/api/menu")
+public class SysMenuController {
+ @Autowired private SysMenuService menuService;
+
+ /** Get menu list. */
+ @SaCheckPermission("system:menu:list")
+ @GetMapping("/list")
+ public R<List<SysMenu>> list(SysMenu menu) {
+ List<SysMenu> menus = menuService.selectMenuList(menu);
+ return R.succeed(menus);
+ }
+
+ /** Get menu info by menuId. */
+ @SaCheckPermission("system:menu:query")
+ @GetMapping(value = "/{menuId}")
+ public R<SysMenu> getInfo(@PathVariable Integer menuId) {
+ return R.succeed(menuService.selectMenuById(menuId));
+ }
+
+ /** Get menu drop-down tree list. */
+ @GetMapping("/treeselect")
+ public R<List<TreeSelect>> treeselect(SysMenu menu) {
+ List<SysMenu> menus = menuService.selectMenuList(menu);
+ return R.succeed(menuService.buildMenuTreeSelect(menus));
+ }
+
+ /** Load the corresponding character menu list tree. */
+ @GetMapping(value = "/roleMenuTreeselect/{roleId}")
+ public R<RoleMenuTreeselectVo> roleMenuTreeselect(@PathVariable("roleId") Integer roleId) {
+ List<SysMenu> menus = menuService.selectMenuList();
+
+ List<TreeSelect> treeMenus = menuService.buildMenuTreeSelect(menus);
+ List<Integer> checkedKeys = menuService.selectMenuListByRoleId(roleId);
+ return R.succeed(new RoleMenuTreeselectVo(checkedKeys, treeMenus));
+ }
+
+ /** add new menu. */
+ @SaCheckPermission("system:menu:add")
+ @PostMapping
+ public R<Void> add(@Validated @RequestBody SysMenu menu) {
+ if (!menuService.checkMenuNameUnique(menu)) {
+ return R.failed(Status.MENU_NAME_IS_EXIST, menu.getMenuName());
+ } else if (Constants.YES_FRAME == menu.getIsFrame()
+ && !StringUtils.isHttp(menu.getPath())) {
+ return R.failed(Status.MENU_PATH_INVALID, menu.getPath());
+ }
+ return menuService.insertMenu(menu) ? R.succeed() : R.failed();
+ }
+
+ /** update menu. */
+ @SaCheckPermission("system:menu:edit")
+ @PutMapping
+ public R<Void> edit(@Validated @RequestBody SysMenu menu) {
+ if (!menuService.checkMenuNameUnique(menu)) {
+ return R.failed(Status.MENU_NAME_IS_EXIST, menu.getMenuName());
+ } else if (Constants.YES_FRAME == menu.getIsFrame()
+ && !StringUtils.isHttp(menu.getPath())) {
+ return R.failed(Status.MENU_PATH_INVALID, menu.getPath());
+ }
+ return menuService.updateMenu(menu) ? R.succeed() : R.failed();
+ }
+
+ /** delete menu. */
+ @SaCheckPermission("system:menu:remove")
+ @DeleteMapping("/{menuId}")
+ public R<Void> remove(@PathVariable("menuId") Integer menuId) {
+ if (menuService.hasChildByMenuId(menuId) || menuService.checkMenuExistRole(menuId)) {
+ return R.failed(Status.MENU_IN_USED);
+ }
+ return menuService.deleteMenuById(menuId) ? R.succeed() : R.failed();
+ }
+
+ /** Get router list. */
+ @GetMapping("/getRouters")
+ public R<List<RouterVo>> getRouters() {
+ int userId = StpUtil.getLoginIdAsInt();
+ List<SysMenu> menus = menuService.selectMenuTreeByUserId(userId);
+ return R.succeed(menuService.buildMenus(menus));
+ }
+}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/controller/SysRoleController.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/controller/SysRoleController.java
new file mode 100644
index 0000000..b4f1f64
--- /dev/null
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/controller/SysRoleController.java
@@ -0,0 +1,160 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.paimon.web.server.controller;
+
+import org.apache.paimon.web.server.data.model.SysRole;
+import org.apache.paimon.web.server.data.model.User;
+import org.apache.paimon.web.server.data.model.UserRole;
+import org.apache.paimon.web.server.data.result.PageR;
+import org.apache.paimon.web.server.data.result.R;
+import org.apache.paimon.web.server.data.result.enums.Status;
+import org.apache.paimon.web.server.service.SysRoleService;
+import org.apache.paimon.web.server.service.UserService;
+import org.apache.paimon.web.server.util.PageSupport;
+
+import cn.dev33.satoken.annotation.SaCheckPermission;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+/** role controller. */
+@RestController
+@RequestMapping("/api/role")
+public class SysRoleController {
+ @Autowired private SysRoleService roleService;
+
+ @Autowired private UserService userService;
+
+ @SaCheckPermission("system:role:list")
+ @GetMapping("/list")
+ public PageR<SysRole> list(SysRole role) {
+ IPage<SysRole> page = PageSupport.startPage();
+ List<SysRole> list = roleService.selectRoleList(page, role);
+ return PageR.<SysRole>builder().success(true).total(page.getTotal()).data(list).build();
+ }
+
+ /** Obtain detailed information based on role number. */
+ @SaCheckPermission("system:role:query")
+ @GetMapping(value = "/{roleId}")
+ public R<SysRole> getInfo(@PathVariable Integer roleId) {
+ return R.succeed(roleService.selectRoleById(roleId));
+ }
+
+ /** Add new role. */
+ @SaCheckPermission("system:role:add")
+ @PostMapping
+ public R<Void> add(@Validated @RequestBody SysRole role) {
+ if (!roleService.checkRoleNameUnique(role)) {
+ return R.failed(Status.ROLE_NAME_IS_EXIST, role.getRoleName());
+ } else if (!roleService.checkRoleKeyUnique(role)) {
+ return R.failed(Status.ROLE_KEY_IS_EXIST, role.getRoleKey());
+ }
+
+ return roleService.insertRole(role) > 0 ? R.succeed() : R.failed();
+ }
+
+ /** Update role info. */
+ @SaCheckPermission("system:role:edit")
+ @PutMapping
+ public R<Void> edit(@Validated @RequestBody SysRole role) {
+ roleService.checkRoleAllowed(role);
+ if (!roleService.checkRoleNameUnique(role)) {
+ return R.failed(Status.ROLE_NAME_IS_EXIST, role.getRoleName());
+ } else if (!roleService.checkRoleKeyUnique(role)) {
+ return R.failed(Status.ROLE_KEY_IS_EXIST, role.getRoleKey());
+ }
+
+ if (roleService.updateRole(role) > 0) {
+ // TODO update user permissions cache
+ return R.succeed();
+ }
+ return R.failed();
+ }
+
+ /** Update role status. */
+ @SaCheckPermission("system:role:edit")
+ @PutMapping("/changeStatus")
+ public R<Void> changeStatus(@RequestBody SysRole role) {
+ roleService.checkRoleAllowed(role);
+ return roleService.updateRoleStatus(role) ? R.succeed() : R.failed();
+ }
+
+ /** Delete role. */
+ @SaCheckPermission("system:role:remove")
+ @DeleteMapping("/{roleIds}")
+ public R<Void> remove(@PathVariable Integer[] roleIds) {
+ return roleService.deleteRoleByIds(roleIds) > 0 ? R.succeed() : R.failed();
+ }
+
+ /** Obtain a list of role selection boxes. */
+ @SaCheckPermission("system:role:query")
+ @GetMapping("/all")
+ public R<List<SysRole>> all() {
+ return R.succeed(roleService.list());
+ }
+
+ /** Query the list of assigned user roles. */
+ @SaCheckPermission("system:role:list")
+ @GetMapping("/authUser/allocatedList")
+ public PageR<User> allocatedList(User user) {
+ IPage<SysRole> page = PageSupport.startPage();
+ List<User> list = userService.selectAllocatedList(user);
+ return PageR.<User>builder().success(true).total(page.getTotal()).data(list).build();
+ }
+
+ /** Query the list of unassigned user roles. */
+ @SaCheckPermission("system:role:list")
+ @GetMapping("/authUser/unallocatedList")
+ public PageR<User> unallocatedList(User user) {
+ IPage<SysRole> page = PageSupport.startPage();
+ List<User> list = userService.selectUnallocatedList(user);
+ return PageR.<User>builder().success(true).total(page.getTotal()).data(list).build();
+ }
+
+ /** Unauthorize User. */
+ @SaCheckPermission("system:role:edit")
+ @PutMapping("/authUser/cancel")
+ public R<Void> cancelAuthUser(@RequestBody UserRole userRole) {
+ return roleService.deleteAuthUser(userRole) > 0 ? R.succeed() : R.failed();
+ }
+
+ /** Batch Unauthorize User. */
+ @SaCheckPermission("system:role:edit")
+ @PutMapping("/authUser/cancelAll")
+ public R<Void> cancelAuthUserAll(Integer roleId, Integer[] userIds) {
+ return roleService.deleteAuthUsers(roleId, userIds) > 0 ? R.succeed() : R.failed();
+ }
+
+ /** Batch Set User Authorization. */
+ @SaCheckPermission("system:role:edit")
+ @PutMapping("/authUser/selectAll")
+ public R<Void> selectAuthUserAll(Integer roleId, Integer[] userIds) {
+ return roleService.insertAuthUsers(roleId, userIds) > 0 ? R.succeed() : R.failed();
+ }
+}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/controller/UserController.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/controller/UserController.java
index 737c3e8..94e74c9 100644
--- a/paimon-web-server/src/main/java/org/apache/paimon/web/server/controller/UserController.java
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/controller/UserController.java
@@ -18,10 +18,11 @@
package org.apache.paimon.web.server.controller;
-import org.apache.paimon.web.common.result.R;
import org.apache.paimon.web.server.data.model.User;
+import org.apache.paimon.web.server.data.result.R;
import org.apache.paimon.web.server.service.UserService;
+import cn.dev33.satoken.annotation.SaCheckPermission;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
@@ -29,7 +30,7 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
-import static org.apache.paimon.web.common.enums.Status.USER_NOT_EXIST;
+import static org.apache.paimon.web.server.data.result.enums.Status.USER_NOT_EXIST;
/** User api controller. */
@Slf4j
@@ -45,7 +46,8 @@ public class UserController {
* @param id user-id
* @return {@link R} with {@link User}
*/
- @GetMapping("/get/{id}")
+ @SaCheckPermission("system:user:query")
+ @GetMapping("/{id}")
public R<User> getUserById(@PathVariable("id") Long id) {
User user = userService.getById(id);
if (user == null) {
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/mapper/UserMapper.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/enums/MenuType.java
similarity index 69%
copy from paimon-web-server/src/main/java/org/apache/paimon/web/server/mapper/UserMapper.java
copy to paimon-web-server/src/main/java/org/apache/paimon/web/server/data/enums/MenuType.java
index d70479c..75fdd00 100644
--- a/paimon-web-server/src/main/java/org/apache/paimon/web/server/mapper/UserMapper.java
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/enums/MenuType.java
@@ -16,13 +16,25 @@
* limitations under the License.
*/
-package org.apache.paimon.web.server.mapper;
+package org.apache.paimon.web.server.data.enums;
-import org.apache.paimon.web.server.data.model.User;
+/** menu type enum. */
+public enum MenuType {
+ /** directory. */
+ DIR("M"),
+ /** menu. */
+ MENU("C"),
+ /** button. */
+ BUTTON("F"),
+ ;
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import org.apache.ibatis.annotations.Mapper;
+ private final String type;
-/** User table mapper. */
-@Mapper
-public interface UserMapper extends BaseMapper<User> {}
+ MenuType(String type) {
+ this.type = type;
+ }
+
+ public String getType() {
+ return this.type;
+ }
+}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/BaseModel.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/BaseModel.java
index 7d7525c..1647519 100644
--- a/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/BaseModel.java
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/BaseModel.java
@@ -19,16 +19,25 @@
package org.apache.paimon.web.server.data.model;
import com.baomidou.mybatisplus.annotation.FieldFill;
+import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;
+import java.util.HashMap;
+import java.util.Map;
/** base model of table. */
@Data
public abstract class BaseModel implements Serializable {
+ /** id. */
+ @TableId(type = IdType.AUTO)
+ private Integer id;
+
/** create time. */
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
@@ -36,4 +45,15 @@ public abstract class BaseModel implements Serializable {
/** update time. */
@TableField(fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
+
+ @TableField(exist = false)
+ @JsonInclude(JsonInclude.Include.NON_EMPTY)
+ private Map<String, Object> params;
+
+ public Map<String, Object> getParams() {
+ if (params == null) {
+ params = new HashMap<>(8);
+ }
+ return params;
+ }
}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/UserTenant.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/RoleMenu.java
similarity index 78%
copy from paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/UserTenant.java
copy to paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/RoleMenu.java
index c4f4873..8fd475f 100644
--- a/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/UserTenant.java
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/RoleMenu.java
@@ -18,23 +18,18 @@
package org.apache.paimon.web.server.data.model;
-import com.baomidou.mybatisplus.annotation.TableLogic;
import lombok.Data;
import lombok.EqualsAndHashCode;
-/** user_tenant table model. */
+/** role_menu table. */
@Data
@EqualsAndHashCode(callSuper = true)
-public class UserTenant extends BaseModel {
+public class RoleMenu extends BaseModel {
+ /** role id. */
+ private Integer roleId;
- private static final long serialVersionUID = 1L;
-
- /** ID. */
- private Integer id;
+ /** menu id. */
+ private Integer menuId;
- /** user id. */
- private Integer userId;
-
- /** tenant id. */
- @TableLogic private Integer tenantId;
+ private static final long serialVersionUID = 1L;
}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/User.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/SysMenu.java
similarity index 53%
copy from paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/User.java
copy to paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/SysMenu.java
index cc3efdc..846b68b 100644
--- a/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/User.java
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/SysMenu.java
@@ -18,44 +18,63 @@
package org.apache.paimon.web.server.data.model;
-import com.baomidou.mybatisplus.annotation.TableLogic;
import lombok.Data;
import lombok.EqualsAndHashCode;
-/** user table model. */
+import java.util.ArrayList;
+import java.util.List;
+
+/** sys_menu table. */
@Data
@EqualsAndHashCode(callSuper = true)
-public class User extends BaseModel {
+public class SysMenu extends BaseModel {
+ /** menu name. */
+ private String menuName;
- private static final long serialVersionUID = 1L;
+ /** parent id. */
+ private Integer parentId;
- /** ID. */
- private Integer id;
+ /** sort. */
+ private Integer sort;
- /** username. */
- private String username;
+ /** route path. */
+ private String path;
- /** password. */
- private String password;
+ /** route params. */
+ private String query;
- /** nickname. */
- private String nickname;
+ /** is cache(0:cache 1:no_cache). */
+ private Integer isCache;
- /** login type (0:LOCAL,1:LDAP). */
- private Integer userType;
+ /** menu type(M:directory C:menu F:button). */
+ private String type;
- /** mobile phone. */
- private String mobile;
+ /** is visible(0:display 1:hide). */
+ private String visible;
- /** email. */
- private String email;
+ /** component path. */
+ private String component;
+
+ /** is frame. */
+ private Integer isFrame;
/** is enable. */
private Boolean enabled;
/** is delete. */
- @TableLogic private Boolean isDelete;
+ private Boolean isDelete;
+
+ /** menu perms. */
+ private String perms;
- /** avatar url. */
- private String url;
+ /** menu icon. */
+ private String icon;
+
+ /** remark. */
+ private String remark;
+
+ /** children menu. */
+ private List<SysMenu> children = new ArrayList<SysMenu>();
+
+ private static final long serialVersionUID = 1L;
}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/User.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/SysRole.java
similarity index 65%
copy from paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/User.java
copy to paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/SysRole.java
index cc3efdc..288d9e5 100644
--- a/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/User.java
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/SysRole.java
@@ -18,37 +18,25 @@
package org.apache.paimon.web.server.data.model;
+import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import lombok.Data;
import lombok.EqualsAndHashCode;
-/** user table model. */
+import java.util.Set;
+
+/** sys_role. */
@Data
@EqualsAndHashCode(callSuper = true)
-public class User extends BaseModel {
-
- private static final long serialVersionUID = 1L;
-
- /** ID. */
- private Integer id;
-
- /** username. */
- private String username;
-
- /** password. */
- private String password;
-
- /** nickname. */
- private String nickname;
+public class SysRole extends BaseModel {
+ /** role name. */
+ private String roleName;
- /** login type (0:LOCAL,1:LDAP). */
- private Integer userType;
+ /** role key. */
+ private String roleKey;
- /** mobile phone. */
- private String mobile;
-
- /** email. */
- private String email;
+ /** sort. */
+ private Integer sort;
/** is enable. */
private Boolean enabled;
@@ -56,6 +44,20 @@ public class User extends BaseModel {
/** is delete. */
@TableLogic private Boolean isDelete;
- /** avatar url. */
- private String url;
+ /** remark. */
+ private String remark;
+
+ /** Does the user have this role identity. Default false. */
+ @TableField(exist = false)
+ private boolean flag = false;
+
+ /** menu ids. */
+ @TableField(exist = false)
+ private Integer[] menuIds;
+
+ /** Role menu permissions. */
+ @TableField(exist = false)
+ private Set<String> permissions;
+
+ private static final long serialVersionUID = 1L;
}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/Tenant.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/Tenant.java
index 0467960..9a2d306 100644
--- a/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/Tenant.java
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/Tenant.java
@@ -29,9 +29,6 @@ public class Tenant extends BaseModel {
private static final long serialVersionUID = 1L;
- /** ID. */
- private Integer id;
-
/** tenant name. */
private String name;
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/User.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/User.java
index cc3efdc..cb8c2aa 100644
--- a/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/User.java
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/User.java
@@ -18,6 +18,8 @@
package org.apache.paimon.web.server.data.model;
+import org.apache.paimon.web.server.constant.Constants;
+
import com.baomidou.mybatisplus.annotation.TableLogic;
import lombok.Data;
import lombok.EqualsAndHashCode;
@@ -29,9 +31,6 @@ public class User extends BaseModel {
private static final long serialVersionUID = 1L;
- /** ID. */
- private Integer id;
-
/** username. */
private String username;
@@ -58,4 +57,12 @@ public class User extends BaseModel {
/** avatar url. */
private String url;
+
+ public boolean isAdmin() {
+ return isAdmin(this.getId());
+ }
+
+ public static boolean isAdmin(Integer userId) {
+ return userId != null && Constants.ADMIN_ID == userId;
+ }
}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/UserTenant.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/UserRole.java
similarity index 81%
copy from paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/UserTenant.java
copy to paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/UserRole.java
index c4f4873..e302abe 100644
--- a/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/UserTenant.java
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/UserRole.java
@@ -18,23 +18,19 @@
package org.apache.paimon.web.server.data.model;
-import com.baomidou.mybatisplus.annotation.TableLogic;
import lombok.Data;
import lombok.EqualsAndHashCode;
-/** user_tenant table model. */
+/** user_role. */
@Data
@EqualsAndHashCode(callSuper = true)
-public class UserTenant extends BaseModel {
-
- private static final long serialVersionUID = 1L;
-
- /** ID. */
- private Integer id;
+public class UserRole extends BaseModel {
/** user id. */
private Integer userId;
- /** tenant id. */
- @TableLogic private Integer tenantId;
+ /** role id. */
+ private Integer roleId;
+
+ private static final long serialVersionUID = 1L;
}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/UserTenant.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/UserTenant.java
index c4f4873..b85e8e3 100644
--- a/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/UserTenant.java
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/UserTenant.java
@@ -29,9 +29,6 @@ public class UserTenant extends BaseModel {
private static final long serialVersionUID = 1L;
- /** ID. */
- private Integer id;
-
/** user id. */
private Integer userId;
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/result/PageR.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/result/PageR.java
new file mode 100644
index 0000000..3aaf501
--- /dev/null
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/result/PageR.java
@@ -0,0 +1,50 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.paimon.web.server.data.result;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Builder;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+/** Paging Results. */
+@Data
+@Builder
+public class PageR<T> implements Serializable {
+
+ private static final long serialVersionUID = -5143774412936881374L;
+ /** total. */
+ private final long total;
+ /** is success. */
+ private final boolean success;
+ /** result data. */
+ private final List<T> data;
+
+ public PageR(
+ @JsonProperty("total") long total,
+ @JsonProperty("success") boolean success,
+ @JsonProperty("data") List<T> data) {
+ this.total = total;
+ this.success = success;
+ this.data = data;
+ }
+}
diff --git a/paimon-web-common/src/main/java/org/apache/paimon/web/common/result/R.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/result/R.java
similarity index 64%
rename from paimon-web-common/src/main/java/org/apache/paimon/web/common/result/R.java
rename to paimon-web-server/src/main/java/org/apache/paimon/web/server/data/result/R.java
index c6ec251..7601281 100644
--- a/paimon-web-common/src/main/java/org/apache/paimon/web/common/result/R.java
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/result/R.java
@@ -16,10 +16,12 @@
* limitations under the License.
*/
-package org.apache.paimon.web.common.result;
+package org.apache.paimon.web.server.data.result;
-import org.apache.paimon.web.common.enums.Status;
+import org.apache.paimon.web.server.data.result.enums.Status;
+import org.apache.paimon.web.server.util.MessageUtils;
+import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
/** result. */
@@ -32,7 +34,10 @@ public class R<T> {
/** result data. */
private final T data;
- public R(int code, String msg, T data) {
+ public R(
+ @JsonProperty("code") int code,
+ @JsonProperty("msg") String msg,
+ @JsonProperty("data") T data) {
this.code = code;
this.msg = msg;
this.data = data;
@@ -47,11 +52,11 @@ public class R<T> {
}
public static <T> R<T> succeed() {
- return of(null, Status.SUCCESS.getCode(), Status.SUCCESS.getMsg());
+ return of(null, Status.SUCCESS.getCode(), MessageUtils.getMsg(Status.SUCCESS.getMsg()));
}
public static <T> R<T> succeed(T data) {
- return of(data, Status.SUCCESS.getCode(), Status.SUCCESS.getMsg());
+ return of(data, Status.SUCCESS.getCode(), MessageUtils.getMsg(Status.SUCCESS.getMsg()));
}
public static <T> R<T> failed() {
@@ -59,10 +64,14 @@ public class R<T> {
}
public static <T> R<T> failed(Status status) {
- return of(null, status.getCode(), status.getMsg());
+ return of(null, status.getCode(), MessageUtils.getMsg(status.getMsg()));
+ }
+
+ public static <T> R<T> failed(Status status, Object... args) {
+ return of(null, status.getCode(), MessageUtils.getMsg(status.getMsg(), args));
}
public static <T> R<T> failed(T data) {
- return of(data, Status.FAILED.getCode(), Status.FAILED.getMsg());
+ return of(data, Status.FAILED.getCode(), MessageUtils.getMsg(Status.FAILED.getMsg()));
}
}
diff --git a/paimon-web-common/src/main/java/org/apache/paimon/web/common/enums/Status.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/result/enums/Status.java
similarity index 57%
rename from paimon-web-common/src/main/java/org/apache/paimon/web/common/enums/Status.java
rename to paimon-web-server/src/main/java/org/apache/paimon/web/server/data/result/enums/Status.java
index 5de3d77..e20edca 100644
--- a/paimon-web-common/src/main/java/org/apache/paimon/web/common/enums/Status.java
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/result/enums/Status.java
@@ -16,21 +16,39 @@
* limitations under the License.
*/
-package org.apache.paimon.web.common.enums;
+package org.apache.paimon.web.server.data.result.enums;
/**
* Status enum.
*
* <p><b>NOTE:</b> This enumeration is used to define status codes and internationalization messages
* for response data. <br>
- * This is mainly responsible for the internationalization information returned by the interface.
+ * This is mainly responsible for the internationalization information returned by the interface
*/
public enum Status {
/** response data msg. */
- SUCCESS(200, "Successfully"),
- FAILED(400, "Failed"),
+ SUCCESS(200, "successfully"),
+ FAILED(400, "failed"),
+ UNAUTHORIZED(401, "unauthorized"),
+ FORBIDDEN(403, "forbidden"),
+ METHOD_NOT_ALLOWED(405, "method.not.allowed"),
- USER_NOT_EXIST(10001, "User Not Exist"),
+ // TODO
+ UNKNOWN_ERROR(500, "unknown.error"),
+ INTERNAL_SERVER_ERROR_ARGS(501, "internal.server.error"),
+ REQUEST_PARAMS_NOT_VALID_ERROR(7002, "invalid.request.parameter"),
+ REQUEST_PARAMS_ERROR(7003, "request.parameter.error"),
+
+ USER_NOT_EXIST(10001, "user.not.exist"),
+ USER_PASSWORD_ERROR(10002, "user.password.error"),
+ /** ------------role-----------------. */
+ ROLE_IN_USED(10101, "role.in.used"),
+ ROLE_NAME_IS_EXIST(10102, "role.name.exist"),
+ ROLE_KEY_IS_EXIST(10103, "role.key.exist"),
+ /** ------------menu-----------------. */
+ MENU_IN_USED(10201, "menu.in.used"),
+ MENU_NAME_IS_EXIST(10202, "menu.name.exist"),
+ MENU_PATH_INVALID(10203, "menu.path.invalid"),
;
private final int code;
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/Tenant.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/result/exception/BaseException.java
similarity index 56%
copy from paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/Tenant.java
copy to paimon-web-server/src/main/java/org/apache/paimon/web/server/data/result/exception/BaseException.java
index 0467960..7be2100 100644
--- a/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/Tenant.java
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/result/exception/BaseException.java
@@ -16,28 +16,32 @@
* limitations under the License.
*/
-package org.apache.paimon.web.server.data.model;
+package org.apache.paimon.web.server.data.result.exception;
-import com.baomidou.mybatisplus.annotation.TableLogic;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
+import org.apache.paimon.web.server.data.result.enums.Status;
-/** tenant use to isolate data. */
-@Data
-@EqualsAndHashCode(callSuper = true)
-public class Tenant extends BaseModel {
+/** base exception. */
+public abstract class BaseException extends RuntimeException {
+ /** status. */
+ private final Status status;
- private static final long serialVersionUID = 1L;
+ /** msg args. */
+ private final Object[] args;
- /** ID. */
- private Integer id;
+ public BaseException(Status status, Object[] args) {
+ this.status = status;
+ this.args = args;
+ }
- /** tenant name. */
- private String name;
+ public BaseException(Status status) {
+ this(status, null);
+ }
- /** tenant description. */
- private String description;
+ public Status getStatus() {
+ return status;
+ }
- /** is delete. */
- @TableLogic private Boolean isDelete;
+ public Object[] getArgs() {
+ return args;
+ }
}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/mapper/UserMapper.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/result/exception/role/RoleInUsedException.java
similarity index 67%
copy from paimon-web-server/src/main/java/org/apache/paimon/web/server/mapper/UserMapper.java
copy to paimon-web-server/src/main/java/org/apache/paimon/web/server/data/result/exception/role/RoleInUsedException.java
index d70479c..d9630ea 100644
--- a/paimon-web-server/src/main/java/org/apache/paimon/web/server/mapper/UserMapper.java
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/result/exception/role/RoleInUsedException.java
@@ -16,13 +16,14 @@
* limitations under the License.
*/
-package org.apache.paimon.web.server.mapper;
+package org.apache.paimon.web.server.data.result.exception.role;
-import org.apache.paimon.web.server.data.model.User;
+import org.apache.paimon.web.server.data.result.enums.Status;
+import org.apache.paimon.web.server.data.result.exception.BaseException;
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import org.apache.ibatis.annotations.Mapper;
-
-/** User table mapper. */
-@Mapper
-public interface UserMapper extends BaseMapper<User> {}
+/** Exception to role in used. */
+public class RoleInUsedException extends BaseException {
+ public RoleInUsedException(Object... args) {
+ super(Status.ROLE_IN_USED, args);
+ }
+}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/mapper/UserMapper.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/result/exception/user/UserNotExistsException.java
similarity index 67%
copy from paimon-web-server/src/main/java/org/apache/paimon/web/server/mapper/UserMapper.java
copy to paimon-web-server/src/main/java/org/apache/paimon/web/server/data/result/exception/user/UserNotExistsException.java
index d70479c..1872c55 100644
--- a/paimon-web-server/src/main/java/org/apache/paimon/web/server/mapper/UserMapper.java
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/result/exception/user/UserNotExistsException.java
@@ -16,13 +16,14 @@
* limitations under the License.
*/
-package org.apache.paimon.web.server.mapper;
+package org.apache.paimon.web.server.data.result.exception.user;
-import org.apache.paimon.web.server.data.model.User;
+import org.apache.paimon.web.server.data.result.enums.Status;
+import org.apache.paimon.web.server.data.result.exception.BaseException;
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import org.apache.ibatis.annotations.Mapper;
-
-/** User table mapper. */
-@Mapper
-public interface UserMapper extends BaseMapper<User> {}
+/** Exception to user not exists. */
+public class UserNotExistsException extends BaseException {
+ public UserNotExistsException() {
+ super(Status.USER_NOT_EXIST);
+ }
+}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/UserTenant.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/result/exception/user/UserPasswordNotMatchException.java
similarity index 66%
copy from paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/UserTenant.java
copy to paimon-web-server/src/main/java/org/apache/paimon/web/server/data/result/exception/user/UserPasswordNotMatchException.java
index c4f4873..8d4e6b4 100644
--- a/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/UserTenant.java
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/result/exception/user/UserPasswordNotMatchException.java
@@ -16,25 +16,16 @@
* limitations under the License.
*/
-package org.apache.paimon.web.server.data.model;
+package org.apache.paimon.web.server.data.result.exception.user;
-import com.baomidou.mybatisplus.annotation.TableLogic;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-/** user_tenant table model. */
-@Data
-@EqualsAndHashCode(callSuper = true)
-public class UserTenant extends BaseModel {
+import org.apache.paimon.web.server.data.result.enums.Status;
+import org.apache.paimon.web.server.data.result.exception.BaseException;
+/** Exception to user password not match. */
+public class UserPasswordNotMatchException extends BaseException {
private static final long serialVersionUID = 1L;
- /** ID. */
- private Integer id;
-
- /** user id. */
- private Integer userId;
-
- /** tenant id. */
- @TableLogic private Integer tenantId;
+ public UserPasswordNotMatchException() {
+ super(Status.USER_PASSWORD_ERROR);
+ }
}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/tree/TreeSelect.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/tree/TreeSelect.java
new file mode 100644
index 0000000..ca1a8f7
--- /dev/null
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/tree/TreeSelect.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.paimon.web.server.data.tree;
+
+import org.apache.paimon.web.server.data.model.SysMenu;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/** Treeselect model. */
+public class TreeSelect implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ /** node ID. */
+ private Integer id;
+
+ /** node name. */
+ private String label;
+
+ /** children node. */
+ @JsonInclude(JsonInclude.Include.NON_EMPTY)
+ private List<TreeSelect> children;
+
+ public TreeSelect() {}
+
+ public TreeSelect(SysMenu menu) {
+ this.id = menu.getId();
+ this.label = menu.getMenuName();
+ this.children =
+ menu.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public void setLabel(String label) {
+ this.label = label;
+ }
+
+ public List<TreeSelect> getChildren() {
+ return children;
+ }
+
+ public void setChildren(List<TreeSelect> children) {
+ this.children = children;
+ }
+}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/vo/MetaVo.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/vo/MetaVo.java
new file mode 100644
index 0000000..19bf2a5
--- /dev/null
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/vo/MetaVo.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.paimon.web.server.data.vo;
+
+import org.apache.paimon.web.server.util.StringUtils;
+
+/** Route display information. */
+public class MetaVo {
+ /** Set the name of the route displayed in the sidebar and Bread crumbs. */
+ private String title;
+
+ /** Set the icon for this route. */
+ private String icon;
+
+ /** cache or no. */
+ private boolean noCache;
+
+ /** link path. */
+ private String link;
+
+ public MetaVo() {}
+
+ public MetaVo(String title, String icon) {
+ this.title = title;
+ this.icon = icon;
+ }
+
+ public MetaVo(String title, String icon, boolean noCache) {
+ this.title = title;
+ this.icon = icon;
+ this.noCache = noCache;
+ }
+
+ public MetaVo(String title, String icon, String link) {
+ this.title = title;
+ this.icon = icon;
+ this.link = link;
+ }
+
+ public MetaVo(String title, String icon, boolean noCache, String link) {
+ this.title = title;
+ this.icon = icon;
+ this.noCache = noCache;
+ if (StringUtils.isHttp(link)) {
+ this.link = link;
+ }
+ }
+
+ public boolean isNoCache() {
+ return noCache;
+ }
+
+ public void setNoCache(boolean noCache) {
+ this.noCache = noCache;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public String getIcon() {
+ return icon;
+ }
+
+ public void setIcon(String icon) {
+ this.icon = icon;
+ }
+
+ public String getLink() {
+ return link;
+ }
+
+ public void setLink(String link) {
+ this.link = link;
+ }
+}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/UserTenant.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/vo/RoleMenuTreeselectVo.java
similarity index 57%
copy from paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/UserTenant.java
copy to paimon-web-server/src/main/java/org/apache/paimon/web/server/data/vo/RoleMenuTreeselectVo.java
index c4f4873..11418be 100644
--- a/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/UserTenant.java
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/vo/RoleMenuTreeselectVo.java
@@ -16,25 +16,25 @@
* limitations under the License.
*/
-package org.apache.paimon.web.server.data.model;
+package org.apache.paimon.web.server.data.vo;
-import com.baomidou.mybatisplus.annotation.TableLogic;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
+import org.apache.paimon.web.server.data.tree.TreeSelect;
-/** user_tenant table model. */
-@Data
-@EqualsAndHashCode(callSuper = true)
-public class UserTenant extends BaseModel {
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Getter;
- private static final long serialVersionUID = 1L;
+import java.util.List;
- /** ID. */
- private Integer id;
+/** Role Menu List Tree Vo. */
+@Getter
+public class RoleMenuTreeselectVo {
+ private final List<Integer> checkedKeys;
+ private final List<TreeSelect> menus;
- /** user id. */
- private Integer userId;
-
- /** tenant id. */
- @TableLogic private Integer tenantId;
+ public RoleMenuTreeselectVo(
+ @JsonProperty("checkedKeys") List<Integer> checkedKeys,
+ @JsonProperty("menus") List<TreeSelect> menus) {
+ this.checkedKeys = checkedKeys;
+ this.menus = menus;
+ }
}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/vo/RouterVo.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/vo/RouterVo.java
new file mode 100644
index 0000000..d485691
--- /dev/null
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/vo/RouterVo.java
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.paimon.web.server.data.vo;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+
+import java.util.List;
+
+/** route config info. */
+@JsonInclude(JsonInclude.Include.NON_EMPTY)
+public class RouterVo {
+ /** route name. */
+ private String name;
+
+ /** route path. */
+ private String path;
+
+ /**
+ * Do you want to hide the route? When true is set, the route will no longer appear in the
+ * sidebar.
+ */
+ private boolean hidden;
+
+ /**
+ * Redirect address. When setting noRedirect, the route cannot be clicked in Breadcrumb
+ * navigation.
+ */
+ private String redirect;
+
+ /** component path. */
+ private String component;
+
+ /** route query params:eg. {"id": 1, "name": "xx"}. */
+ private String query;
+
+ /**
+ * When there are more than one routes declared by children under a route, it will
+ * automatically. become nested mode - such as component pages
+ */
+ private Boolean alwaysShow;
+
+ /** other meta info. */
+ private MetaVo meta;
+
+ /** children route. */
+ private List<RouterVo> children;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ public boolean getHidden() {
+ return hidden;
+ }
+
+ public void setHidden(boolean hidden) {
+ this.hidden = hidden;
+ }
+
+ public String getRedirect() {
+ return redirect;
+ }
+
+ public void setRedirect(String redirect) {
+ this.redirect = redirect;
+ }
+
+ public String getComponent() {
+ return component;
+ }
+
+ public void setComponent(String component) {
+ this.component = component;
+ }
+
+ public String getQuery() {
+ return query;
+ }
+
+ public void setQuery(String query) {
+ this.query = query;
+ }
+
+ public Boolean getAlwaysShow() {
+ return alwaysShow;
+ }
+
+ public void setAlwaysShow(Boolean alwaysShow) {
+ this.alwaysShow = alwaysShow;
+ }
+
+ public MetaVo getMeta() {
+ return meta;
+ }
+
+ public void setMeta(MetaVo meta) {
+ this.meta = meta;
+ }
+
+ public List<RouterVo> getChildren() {
+ return children;
+ }
+
+ public void setChildren(List<RouterVo> children) {
+ this.children = children;
+ }
+}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/mapper/RoleMenuMapper.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/mapper/RoleMenuMapper.java
new file mode 100644
index 0000000..6b6a133
--- /dev/null
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/mapper/RoleMenuMapper.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.paimon.web.server.mapper;
+
+import org.apache.paimon.web.server.data.model.RoleMenu;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+
+import java.util.List;
+
+/** role-menu mapper. */
+@Mapper
+public interface RoleMenuMapper extends BaseMapper<RoleMenu> {
+ /**
+ * Query menu usage quantity.
+ *
+ * @param menuId menu ID
+ * @return result
+ */
+ int checkMenuExistRole(Integer menuId);
+
+ /**
+ * Delete roles and menu associations through role ID.
+ *
+ * @param roleId role ID
+ * @return result
+ */
+ int deleteRoleMenuByRoleId(Integer roleId);
+
+ /**
+ * Batch delete role menu association information.
+ *
+ * @param roleIds roleIds
+ * @return result
+ */
+ int deleteRoleMenu(Integer[] roleIds);
+
+ /**
+ * Batch Add Role Menu Information.
+ *
+ * @param roleMenuList role-menu List
+ * @return result
+ */
+ int batchRoleMenu(List<RoleMenu> roleMenuList);
+
+ /**
+ * Query the menu permissions that users have.
+ *
+ * @param userId user ID
+ * @return result
+ */
+ List<RoleMenu> queryRoleMenuByUser(Integer userId);
+}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/mapper/SysMenuMapper.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/mapper/SysMenuMapper.java
new file mode 100644
index 0000000..62fc9e9
--- /dev/null
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/mapper/SysMenuMapper.java
@@ -0,0 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.paimon.web.server.mapper;
+
+import org.apache.paimon.web.server.data.model.SysMenu;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/** Menu mapper. */
+@Mapper
+public interface SysMenuMapper extends BaseMapper<SysMenu> {
+ /**
+ * Query system menu list.
+ *
+ * @param menu query params
+ * @return result
+ */
+ List<SysMenu> selectMenuList(@Param("menu") SysMenu menu);
+
+ /**
+ * Query all menu perms.
+ *
+ * @return permission List
+ */
+ List<String> selectMenuPerms();
+
+ /**
+ * Query system menu list by user.
+ *
+ * @param menu query params
+ * @return menu list
+ */
+ List<SysMenu> selectMenuListByUserId(
+ @Param("menu") SysMenu menu, @Param("userId") Integer userId);
+
+ /**
+ * Query permissions based on role ID.
+ *
+ * @param roleId role ID
+ * @return permission List
+ */
+ List<String> selectMenuPermsByRoleId(Integer roleId);
+
+ /**
+ * Query permissions by user ID.
+ *
+ * @param userId user ID
+ * @return permission List
+ */
+ List<String> selectMenuPermsByUserId(Integer userId);
+
+ /**
+ * Query all menu list.
+ *
+ * @return menu list
+ */
+ List<SysMenu> selectMenuTreeAll();
+
+ /**
+ * Query menu list by user ID.
+ *
+ * @param userId user ID
+ * @return menu list
+ */
+ List<SysMenu> selectMenuTreeByUserId(Integer userId);
+
+ /**
+ * Query menu tree information based on role ID.
+ *
+ * @param roleId role ID
+ * @return selected menu list
+ */
+ List<Integer> selectMenuListByRoleId(Integer roleId);
+
+ /**
+ * Query information by menu ID.
+ *
+ * @param menuId menu ID
+ * @return menu info
+ */
+ SysMenu selectMenuById(Integer menuId);
+
+ /**
+ * Is there a menu sub node present.
+ *
+ * @param menuId menu ID
+ * @return result
+ */
+ int hasChildByMenuId(Integer menuId);
+
+ /**
+ * Verify if the menu name is unique.
+ *
+ * @param menuName menu name
+ * @param parentId parent ID
+ * @return result
+ */
+ SysMenu checkMenuNameUnique(
+ @Param("menuName") String menuName, @Param("parentId") Integer parentId);
+}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/mapper/SysRoleMapper.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/mapper/SysRoleMapper.java
new file mode 100644
index 0000000..87bf304
--- /dev/null
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/mapper/SysRoleMapper.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.paimon.web.server.mapper;
+
+import org.apache.paimon.web.server.data.model.SysRole;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/** Role Mapper. */
+@Mapper
+public interface SysRoleMapper extends BaseMapper<SysRole> {
+
+ List<SysRole> selectRoleList(IPage<SysRole> page, @Param("role") SysRole role);
+
+ /**
+ * Query roles by user ID.
+ *
+ * @param userId user ID
+ * @return role list
+ */
+ List<SysRole> selectRolePermissionByUserId(Integer userId);
+
+ /**
+ * Query all roles.
+ *
+ * @return role list
+ */
+ List<SysRole> selectRoleAll();
+
+ /**
+ * Obtain a list of role selection boxes by user ID.
+ *
+ * @param userId user ID
+ * @return result
+ */
+ List<Integer> selectRoleListByUserId(Integer userId);
+
+ /**
+ * Query role info by role ID.
+ *
+ * @param roleId role ID
+ * @return role info
+ */
+ SysRole selectRoleById(Integer roleId);
+
+ /**
+ * Query role info by user.
+ *
+ * @param userName user name
+ * @return role list
+ */
+ List<SysRole> selectRolesByUserName(String userName);
+}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/mapper/UserMapper.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/mapper/UserMapper.java
index d70479c..6de395d 100644
--- a/paimon-web-server/src/main/java/org/apache/paimon/web/server/mapper/UserMapper.java
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/mapper/UserMapper.java
@@ -23,6 +23,48 @@ import org.apache.paimon.web.server.data.model.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
+import java.util.List;
+
/** User table mapper. */
@Mapper
-public interface UserMapper extends BaseMapper<User> {}
+public interface UserMapper extends BaseMapper<User> {
+ /**
+ * Query user list.
+ *
+ * @param user query params
+ * @return user list
+ */
+ List<User> selectUserList(User user);
+
+ /**
+ * Query user list by role ID.
+ *
+ * @param user query params
+ * @return user list
+ */
+ List<User> selectAllocatedList(User user);
+
+ /**
+ * Query the list of unassigned user roles.
+ *
+ * @param user query params
+ * @return user list
+ */
+ List<User> selectUnallocatedList(User user);
+
+ /**
+ * Query user info by username.
+ *
+ * @param username username
+ * @return user info
+ */
+ User selectUserByUserName(String username);
+
+ /**
+ * Query user info by user ID.
+ *
+ * @param userId user ID
+ * @return user info
+ */
+ User selectUserById(Integer userId);
+}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/mapper/UserRoleMapper.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/mapper/UserRoleMapper.java
new file mode 100644
index 0000000..af4b4fc
--- /dev/null
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/mapper/UserRoleMapper.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.paimon.web.server.mapper;
+
+import org.apache.paimon.web.server.data.model.UserRole;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/** User Role Mapper. */
+@Mapper
+public interface UserRoleMapper extends BaseMapper<UserRole> {
+ /**
+ * Delete user and role associations by user ID.
+ *
+ * @param userId user ID
+ * @return result
+ */
+ int deleteUserRoleByUserId(Integer userId);
+
+ /**
+ * Batch delete user and role associations by user IDs.
+ *
+ * @param ids user IDs
+ * @return result
+ */
+ int deleteUserRole(Integer[] ids);
+
+ /**
+ * Query the number of roles used by role ID.
+ *
+ * @param roleId role ID
+ * @return result
+ */
+ int countUserRoleByRoleId(Integer roleId);
+
+ /**
+ * Batch Add User Role Information.
+ *
+ * @param userRoleList user-role list
+ * @return result
+ */
+ int batchUserRole(List<UserRole> userRoleList);
+
+ /**
+ * Delete user-role association information.
+ *
+ * @param userRole user-role association
+ * @return result
+ */
+ int deleteUserRoleInfo(UserRole userRole);
+
+ /**
+ * Batch Unauthorization of User Roles.
+ *
+ * @param roleId role ID
+ * @param userIds user IDs
+ * @return result
+ */
+ int deleteUserRoleInfos(@Param("roleId") Integer roleId, @Param("userIds") Integer[] userIds);
+}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/service/PermissionService.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/service/PermissionService.java
new file mode 100644
index 0000000..6a746a7
--- /dev/null
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/service/PermissionService.java
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.paimon.web.server.service;
+
+import org.apache.paimon.web.server.constant.Constants;
+
+import cn.dev33.satoken.stp.StpInterface;
+import com.google.common.base.Preconditions;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/** Permission service by sa-token. TODO add cache */
+@Component
+public class PermissionService implements StpInterface {
+ @Autowired private SysRoleService roleService;
+
+ @Autowired private SysMenuService menuService;
+
+ /**
+ * Get permission list by user ID.
+ *
+ * @param userId user id
+ * @param loginType login type
+ * @return permission list
+ */
+ @Override
+ public List<String> getPermissionList(Object userId, String loginType) {
+ Preconditions.checkArgument(userId != null);
+ int userIdNum = Integer.parseInt(userId.toString());
+ Set<String> perms = new HashSet<String>();
+ // 管理员拥有所有权限
+ if (userIdNum == Constants.ADMIN_ID) {
+ perms.add(Constants.ALL_PERMISSION);
+ } else {
+ List<Integer> roles = roleService.selectRoleListByUserId(userIdNum);
+ if (!CollectionUtils.isEmpty(roles)) {
+ for (int roleId : roles) {
+ Set<String> rolePerms = menuService.selectMenuPermsByRoleId(roleId);
+ perms.addAll(rolePerms);
+ }
+ } else {
+ perms.addAll(menuService.selectMenuPermsByUserId(userIdNum));
+ }
+ }
+ return new ArrayList<>(perms);
+ }
+
+ /**
+ * Get role list by user ID.
+ *
+ * @param userId user ID
+ * @param loginType login type
+ * @return role list
+ */
+ @Override
+ public List<String> getRoleList(Object userId, String loginType) {
+ Preconditions.checkArgument(userId != null);
+ Set<String> roles =
+ new HashSet<String>(
+ roleService.selectRolePermissionByUserId(
+ Integer.valueOf(userId.toString())));
+ return new ArrayList<>(roles);
+ }
+}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/service/SysMenuService.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/service/SysMenuService.java
new file mode 100644
index 0000000..c75590b
--- /dev/null
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/service/SysMenuService.java
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.paimon.web.server.service;
+
+import org.apache.paimon.web.server.data.model.SysMenu;
+import org.apache.paimon.web.server.data.tree.TreeSelect;
+import org.apache.paimon.web.server.data.vo.RouterVo;
+
+import java.util.List;
+import java.util.Set;
+
+/** Menu service. */
+public interface SysMenuService {
+ /**
+ * Query menu list by user.
+ *
+ * @return menu list
+ */
+ List<SysMenu> selectMenuList();
+
+ /**
+ * Query menu list.
+ *
+ * @param menu query params
+ * @return menu list
+ */
+ List<SysMenu> selectMenuList(SysMenu menu);
+
+ /**
+ * Query permissions by user ID.
+ *
+ * @param userId user ID
+ * @return permission List
+ */
+ Set<String> selectMenuPermsByUserId(Integer userId);
+
+ /**
+ * Query permissions by role ID.
+ *
+ * @param roleId role ID
+ * @return permission List
+ */
+ Set<String> selectMenuPermsByRoleId(Integer roleId);
+
+ /**
+ * Query menu list by user ID.
+ *
+ * @param userId user ID
+ * @return menu list
+ */
+ List<SysMenu> selectMenuTreeByUserId(Integer userId);
+
+ /**
+ * Query menu tree information by role ID.
+ *
+ * @param roleId role ID
+ * @return selected menu list
+ */
+ List<Integer> selectMenuListByRoleId(Integer roleId);
+
+ /**
+ * Build router by menu.
+ *
+ * @param menus menu list
+ * @return router list
+ */
+ List<RouterVo> buildMenus(List<SysMenu> menus);
+
+ /**
+ * Builder menu tree.
+ *
+ * @param menus menu list
+ * @return menu tree
+ */
+ List<SysMenu> buildMenuTree(List<SysMenu> menus);
+
+ /**
+ * Builder tree select by menu.
+ *
+ * @param menus menu list
+ * @return menu tree select
+ */
+ List<TreeSelect> buildMenuTreeSelect(List<SysMenu> menus);
+
+ /**
+ * Query menu info by menu ID.
+ *
+ * @param menuId menu ID
+ * @return menu info
+ */
+ SysMenu selectMenuById(Integer menuId);
+
+ /**
+ * Is there a menu sub node present.
+ *
+ * @param menuId menu ID
+ * @return result
+ */
+ boolean hasChildByMenuId(Integer menuId);
+
+ /**
+ * Query menu usage quantity.
+ *
+ * @param menuId menu ID
+ * @return result
+ */
+ boolean checkMenuExistRole(Integer menuId);
+
+ /**
+ * Add menu.
+ *
+ * @param menu menu info
+ * @return result
+ */
+ boolean insertMenu(SysMenu menu);
+
+ /**
+ * Update menu.
+ *
+ * @param menu menu info
+ * @return result
+ */
+ boolean updateMenu(SysMenu menu);
+
+ /**
+ * Delete menu.
+ *
+ * @param menuId menu ID
+ * @return result
+ */
+ boolean deleteMenuById(Integer menuId);
+
+ /**
+ * Verify if the menu name is unique.
+ *
+ * @param menu menu info
+ * @return result
+ */
+ boolean checkMenuNameUnique(SysMenu menu);
+}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/service/SysRoleService.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/service/SysRoleService.java
new file mode 100644
index 0000000..d7701c0
--- /dev/null
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/service/SysRoleService.java
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.paimon.web.server.service;
+
+import org.apache.paimon.web.server.data.model.SysRole;
+import org.apache.paimon.web.server.data.model.UserRole;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+import java.util.List;
+import java.util.Set;
+
+/** Role service. */
+public interface SysRoleService extends IService<SysRole> {
+ /**
+ * Paging and querying role data based on conditions.
+ *
+ * @param page page params
+ * @param role query params
+ * @return role list
+ */
+ public List<SysRole> selectRoleList(IPage<SysRole> page, SysRole role);
+
+ /**
+ * Query role list based on user ID.
+ *
+ * @param userId user ID
+ * @return role list
+ */
+ public List<SysRole> selectRolesByUserId(Integer userId);
+
+ /**
+ * Query role permissions based on user ID.
+ *
+ * @param userId user ID
+ * @return permissions
+ */
+ public Set<String> selectRolePermissionByUserId(Integer userId);
+
+ /**
+ * Query user role list by user ID.
+ *
+ * @param userId user ID
+ * @return role list
+ */
+ List<Integer> selectRoleListByUserId(Integer userId);
+
+ /**
+ * Query role info by role ID.
+ *
+ * @param roleId role ID
+ * @return role info
+ */
+ SysRole selectRoleById(Integer roleId);
+
+ /**
+ * Verify if the role name is unique.
+ *
+ * @param role role info
+ * @return result
+ */
+ boolean checkRoleNameUnique(SysRole role);
+
+ /**
+ * Verify whether role permissions are unique.
+ *
+ * @param role role info
+ * @return result
+ */
+ boolean checkRoleKeyUnique(SysRole role);
+
+ /**
+ * Verify whether the role allows operations.
+ *
+ * @param role role info
+ */
+ boolean checkRoleAllowed(SysRole role);
+
+ /**
+ * Save role information.
+ *
+ * @param role role info
+ * @return result
+ */
+ int insertRole(SysRole role);
+
+ /**
+ * Update role information.
+ *
+ * @param role role info
+ * @return result
+ */
+ int updateRole(SysRole role);
+
+ /**
+ * Delete role through role ID.
+ *
+ * @param roleId role ID
+ * @return result
+ */
+ int deleteRoleById(Integer roleId);
+
+ /**
+ * Batch delete role information.
+ *
+ * @param roleIds role IDs
+ * @return result
+ */
+ int deleteRoleByIds(Integer[] roleIds);
+
+ /**
+ * Unauthorize user role.
+ *
+ * @param userRole user-role
+ * @return result
+ */
+ int deleteAuthUser(UserRole userRole);
+
+ /**
+ * Batch unauthorization of user roles.
+ *
+ * @param roleId role ID
+ * @param userIds user IDs that needs to be unlicensed
+ * @return 结果
+ */
+ int deleteAuthUsers(Integer roleId, Integer[] userIds);
+
+ /**
+ * Batch selection of authorized user roles.
+ *
+ * @param roleId role ID
+ * @param userIds user IDs that needs to be deleted
+ * @return result
+ */
+ int insertAuthUsers(Integer roleId, Integer[] userIds);
+
+ /**
+ * Query the number of role usage through role ID.
+ *
+ * @param roleId role ID
+ * @return result
+ */
+ int countUserRoleByRoleId(Integer roleId);
+
+ /**
+ * Update Role Status.
+ *
+ * @param role role info
+ * @return result
+ */
+ boolean updateRoleStatus(SysRole role);
+}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/service/UserService.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/service/UserService.java
index d519367..e0bd750 100644
--- a/paimon-web-server/src/main/java/org/apache/paimon/web/server/service/UserService.java
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/service/UserService.java
@@ -19,8 +19,37 @@
package org.apache.paimon.web.server.service;
import org.apache.paimon.web.server.data.model.User;
+import org.apache.paimon.web.server.data.result.exception.BaseException;
import com.baomidou.mybatisplus.extension.service.IService;
+import java.util.List;
+
/** User Service. */
-public interface UserService extends IService<User> {}
+public interface UserService extends IService<User> {
+
+ /**
+ * login by username and password.
+ *
+ * @param username username
+ * @param password pwd
+ * @return {@link String}
+ */
+ String login(String username, String password) throws BaseException;
+
+ /**
+ * Query the list of assigned user roles.
+ *
+ * @param user query params
+ * @return user list
+ */
+ List<User> selectAllocatedList(User user);
+
+ /**
+ * Query the list of unassigned user roles.
+ *
+ * @param user query params
+ * @return user list
+ */
+ List<User> selectUnallocatedList(User user);
+}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/service/impl/SysMenuServiceImpl.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/service/impl/SysMenuServiceImpl.java
new file mode 100644
index 0000000..26e4523
--- /dev/null
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/service/impl/SysMenuServiceImpl.java
@@ -0,0 +1,465 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.paimon.web.server.service.impl;
+
+import org.apache.paimon.web.server.constant.Constants;
+import org.apache.paimon.web.server.data.enums.MenuType;
+import org.apache.paimon.web.server.data.model.SysMenu;
+import org.apache.paimon.web.server.data.model.User;
+import org.apache.paimon.web.server.data.tree.TreeSelect;
+import org.apache.paimon.web.server.data.vo.MetaVo;
+import org.apache.paimon.web.server.data.vo.RouterVo;
+import org.apache.paimon.web.server.mapper.RoleMenuMapper;
+import org.apache.paimon.web.server.mapper.SysMenuMapper;
+import org.apache.paimon.web.server.mapper.SysRoleMapper;
+import org.apache.paimon.web.server.service.SysMenuService;
+import org.apache.paimon.web.server.util.StringUtils;
+
+import cn.dev33.satoken.stp.StpUtil;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/** Menu service. */
+@Service
+public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu>
+ implements SysMenuService {
+ public static final String PREMISSION_STRING = "perms[\"{0}\"]";
+
+ @Autowired private SysMenuMapper menuMapper;
+
+ @Autowired private SysRoleMapper roleMapper;
+
+ @Autowired private RoleMenuMapper roleMenuMapper;
+
+ /**
+ * Query menu list by user.
+ *
+ * @return menu list
+ */
+ @Override
+ public List<SysMenu> selectMenuList() {
+ return selectMenuList(new SysMenu());
+ }
+
+ /**
+ * Query menu list.
+ *
+ * @param menu query params
+ * @return menu list
+ */
+ @Override
+ public List<SysMenu> selectMenuList(SysMenu menu) {
+ List<SysMenu> menuList;
+ int userId = StpUtil.getLoginIdAsInt();
+ if (User.isAdmin(userId)) {
+ menuList = menuMapper.selectMenuList(menu);
+ } else {
+ menuList = menuMapper.selectMenuListByUserId(menu, userId);
+ }
+ return menuList;
+ }
+
+ /**
+ * Query permissions by user ID.
+ *
+ * @param userId user ID
+ * @return permission List
+ */
+ @Override
+ public Set<String> selectMenuPermsByUserId(Integer userId) {
+ List<String> perms = menuMapper.selectMenuPermsByUserId(userId);
+ Set<String> permsSet = new HashSet<>();
+ for (String perm : perms) {
+ if (StringUtils.isNotEmpty(perm)) {
+ permsSet.addAll(Arrays.asList(perm.trim().split(",")));
+ }
+ }
+ return permsSet;
+ }
+
+ /**
+ * Query permissions by role ID.
+ *
+ * @param roleId role ID
+ * @return permission List
+ */
+ @Override
+ public Set<String> selectMenuPermsByRoleId(Integer roleId) {
+ List<String> perms = menuMapper.selectMenuPermsByRoleId(roleId);
+ Set<String> permsSet = new HashSet<>();
+ for (String perm : perms) {
+ if (StringUtils.isNotEmpty(perm)) {
+ permsSet.addAll(Arrays.asList(perm.trim().split(",")));
+ }
+ }
+ return permsSet;
+ }
+
+ /**
+ * Query menu list by user ID.
+ *
+ * @param userId user ID
+ * @return menu list
+ */
+ @Override
+ public List<SysMenu> selectMenuTreeByUserId(Integer userId) {
+ List<SysMenu> menus = null;
+ if (userId != null && userId == 1) {
+ menus = menuMapper.selectMenuTreeAll();
+ } else {
+ menus = menuMapper.selectMenuTreeByUserId(userId);
+ }
+ return getChildPerms(menus, 0);
+ }
+
+ /**
+ * Query menu tree information by role ID.
+ *
+ * @param roleId role ID
+ * @return selected menu list
+ */
+ @Override
+ public List<Integer> selectMenuListByRoleId(Integer roleId) {
+ return menuMapper.selectMenuListByRoleId(roleId);
+ }
+
+ /**
+ * Build router by menu.
+ *
+ * @param menus menu list
+ * @return router list
+ */
+ @Override
+ public List<RouterVo> buildMenus(List<SysMenu> menus) {
+ List<RouterVo> routers = new LinkedList<RouterVo>();
+ for (SysMenu menu : menus) {
+ RouterVo router = new RouterVo();
+ router.setHidden("1".equals(menu.getVisible()));
+ router.setName(getRouteName(menu));
+ router.setPath(getRouterPath(menu));
+ router.setComponent(getComponent(menu));
+ router.setQuery(menu.getQuery());
+ router.setMeta(
+ new MetaVo(
+ menu.getMenuName(),
+ menu.getIcon(),
+ menu.getIsCache() == 1,
+ menu.getPath()));
+ List<SysMenu> cMenus = menu.getChildren();
+ if (!CollectionUtils.isEmpty(cMenus) && MenuType.DIR.getType().equals(menu.getType())) {
+ router.setAlwaysShow(true);
+ router.setRedirect("noRedirect");
+ router.setChildren(buildMenus(cMenus));
+ } else if (isMenuFrame(menu)) {
+ router.setMeta(null);
+ List<RouterVo> childrenList = new ArrayList<RouterVo>();
+ RouterVo children = new RouterVo();
+ children.setPath(menu.getPath());
+ children.setComponent(menu.getComponent());
+ children.setName(StringUtils.capitalize(menu.getPath()));
+ children.setMeta(
+ new MetaVo(
+ menu.getMenuName(),
+ menu.getIcon(),
+ menu.getIsCache() == 1,
+ menu.getPath()));
+ children.setQuery(menu.getQuery());
+ childrenList.add(children);
+ router.setChildren(childrenList);
+ } else if (menu.getParentId() == 0 && isInnerLink(menu)) {
+ router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon()));
+ router.setPath("/");
+ List<RouterVo> childrenList = new ArrayList<RouterVo>();
+ RouterVo children = new RouterVo();
+ String routerPath = innerLinkReplaceEach(menu.getPath());
+ children.setPath(routerPath);
+ children.setComponent(Constants.INNER_LINK);
+ children.setName(StringUtils.capitalize(routerPath));
+ children.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), menu.getPath()));
+ childrenList.add(children);
+ router.setChildren(childrenList);
+ }
+ routers.add(router);
+ }
+ return routers;
+ }
+
+ /**
+ * Builder menu tree.
+ *
+ * @param menus menu list
+ * @return menu tree
+ */
+ @Override
+ public List<SysMenu> buildMenuTree(List<SysMenu> menus) {
+ List<SysMenu> returnList = new ArrayList<SysMenu>();
+ List<Integer> tempList = menus.stream().map(SysMenu::getId).collect(Collectors.toList());
+ for (Iterator<SysMenu> iterator = menus.iterator(); iterator.hasNext(); ) {
+ SysMenu menu = (SysMenu) iterator.next();
+ if (!tempList.contains(menu.getParentId())) {
+ recursionFn(menus, menu);
+ returnList.add(menu);
+ }
+ }
+ if (returnList.isEmpty()) {
+ returnList = menus;
+ }
+ return returnList;
+ }
+
+ /**
+ * Builder tree select by menu.
+ *
+ * @param menus menu list
+ * @return menu tree select
+ */
+ @Override
+ public List<TreeSelect> buildMenuTreeSelect(List<SysMenu> menus) {
+ List<SysMenu> menuTrees = buildMenuTree(menus);
+ return menuTrees.stream().map(TreeSelect::new).collect(Collectors.toList());
+ }
+
+ /**
+ * Query menu info by menu ID.
+ *
+ * @param menuId menu ID
+ * @return menu info
+ */
+ @Override
+ public SysMenu selectMenuById(Integer menuId) {
+ return menuMapper.selectMenuById(menuId);
+ }
+
+ /**
+ * Is there a menu sub node present.
+ *
+ * @param menuId menu ID
+ * @return result
+ */
+ @Override
+ public boolean hasChildByMenuId(Integer menuId) {
+ int result = menuMapper.hasChildByMenuId(menuId);
+ return result > 0;
+ }
+
+ /**
+ * Query menu usage quantity.
+ *
+ * @param menuId menu ID
+ * @return result
+ */
+ @Override
+ public boolean checkMenuExistRole(Integer menuId) {
+ int result = roleMenuMapper.checkMenuExistRole(menuId);
+ return result > 0;
+ }
+
+ /**
+ * Add menu.
+ *
+ * @param menu menu info
+ * @return result
+ */
+ @Override
+ public boolean insertMenu(SysMenu menu) {
+ return this.save(menu);
+ }
+
+ /**
+ * Update menu.
+ *
+ * @param menu menu info
+ * @return result
+ */
+ @Override
+ public boolean updateMenu(SysMenu menu) {
+ return this.updateById(menu);
+ }
+
+ /**
+ * Delete menu.
+ *
+ * @param menuId menu ID
+ * @return result
+ */
+ @Override
+ public boolean deleteMenuById(Integer menuId) {
+ return this.removeById(menuId);
+ }
+
+ /**
+ * Verify if the menu name is unique.
+ *
+ * @param menu menu info
+ * @return result
+ */
+ @Override
+ public boolean checkMenuNameUnique(SysMenu menu) {
+ Integer menuId = menu.getId() == null ? -1 : menu.getId();
+ SysMenu info = menuMapper.checkMenuNameUnique(menu.getMenuName(), menu.getParentId());
+ return info != null && !menuId.equals(info.getId());
+ }
+
+ /**
+ * Get router name.
+ *
+ * @param menu menu info
+ * @return router name
+ */
+ public String getRouteName(SysMenu menu) {
+ String routerName = StringUtils.capitalize(menu.getPath());
+ if (isMenuFrame(menu)) {
+ routerName = StringUtils.EMPTY;
+ }
+ return routerName;
+ }
+
+ /**
+ * Get router path.
+ *
+ * @param menu menu info
+ * @return router path
+ */
+ public String getRouterPath(SysMenu menu) {
+ String routerPath = menu.getPath();
+ if (menu.getParentId() != 0 && isInnerLink(menu)) {
+ routerPath = innerLinkReplaceEach(routerPath);
+ }
+ if (0 == menu.getParentId()
+ && MenuType.DIR.getType().equals(menu.getType())
+ && Constants.NO_FRAME == menu.getIsFrame()) {
+ routerPath = "/" + menu.getPath();
+ } else if (isMenuFrame(menu)) {
+ routerPath = "/";
+ }
+ return routerPath;
+ }
+
+ /**
+ * Get component information.
+ *
+ * @param menu menu info
+ * @return component info
+ */
+ public String getComponent(SysMenu menu) {
+ String component = Constants.LAYOUT;
+ if (StringUtils.isNotEmpty(menu.getComponent()) && !isMenuFrame(menu)) {
+ component = menu.getComponent();
+ } else if (StringUtils.isEmpty(menu.getComponent())
+ && menu.getParentId() != 0
+ && isInnerLink(menu)) {
+ component = Constants.INNER_LINK;
+ } else if (StringUtils.isEmpty(menu.getComponent()) && isParentView(menu)) {
+ component = Constants.PARENT_VIEW;
+ }
+ return component;
+ }
+
+ /**
+ * Is it a menu internal jump.
+ *
+ * @param menu menu info
+ * @return result
+ */
+ public boolean isMenuFrame(SysMenu menu) {
+ return menu.getParentId() == 0
+ && MenuType.MENU.getType().equals(menu.getType())
+ && menu.getIsFrame().equals(Constants.NO_FRAME);
+ }
+
+ /**
+ * Is it an internal chain component.
+ *
+ * @param menu menu info
+ * @return result
+ */
+ public boolean isInnerLink(SysMenu menu) {
+ return menu.getIsFrame().equals(Constants.NO_FRAME) && StringUtils.isHttp(menu.getPath());
+ }
+
+ /**
+ * Is parent_view component.
+ *
+ * @param menu menu info
+ * @return result
+ */
+ public boolean isParentView(SysMenu menu) {
+ return menu.getParentId() != 0 && MenuType.DIR.getType().equals(menu.getType());
+ }
+
+ /**
+ * Get all child nodes by the parent node ID.
+ *
+ * @param list menu list
+ * @param parentId parent ID
+ * @return menu list
+ */
+ public List<SysMenu> getChildPerms(List<SysMenu> list, int parentId) {
+ List<SysMenu> returnList = new ArrayList<SysMenu>();
+ for (SysMenu t : list) {
+ if (t.getParentId() == parentId) {
+ recursionFn(list, t);
+ returnList.add(t);
+ }
+ }
+ return returnList;
+ }
+
+ private void recursionFn(List<SysMenu> list, SysMenu t) {
+ List<SysMenu> childList = getChildList(list, t);
+ t.setChildren(childList);
+ for (SysMenu tChild : childList) {
+ if (hasChild(list, tChild)) {
+ recursionFn(list, tChild);
+ }
+ }
+ }
+
+ private List<SysMenu> getChildList(List<SysMenu> list, SysMenu t) {
+ List<SysMenu> tlist = new ArrayList<SysMenu>();
+ for (SysMenu n : list) {
+ if (n.getParentId().equals(t.getId())) {
+ tlist.add(n);
+ }
+ }
+ return tlist;
+ }
+
+ private boolean hasChild(List<SysMenu> list, SysMenu t) {
+ return getChildList(list, t).size() > 0;
+ }
+
+ public String innerLinkReplaceEach(String path) {
+ return StringUtils.replaceEach(
+ path,
+ new String[] {Constants.HTTP, Constants.HTTPS, Constants.WWW, "."},
+ new String[] {"", "", "", "/"});
+ }
+}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/service/impl/SysRoleServiceImpl.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/service/impl/SysRoleServiceImpl.java
new file mode 100644
index 0000000..829dc29
--- /dev/null
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/service/impl/SysRoleServiceImpl.java
@@ -0,0 +1,310 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.paimon.web.server.service.impl;
+
+import org.apache.paimon.web.server.data.model.RoleMenu;
+import org.apache.paimon.web.server.data.model.SysRole;
+import org.apache.paimon.web.server.data.model.UserRole;
+import org.apache.paimon.web.server.data.result.exception.role.RoleInUsedException;
+import org.apache.paimon.web.server.mapper.RoleMenuMapper;
+import org.apache.paimon.web.server.mapper.SysRoleMapper;
+import org.apache.paimon.web.server.mapper.UserRoleMapper;
+import org.apache.paimon.web.server.service.SysRoleService;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.google.common.base.Preconditions;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/** Role Service. */
+@Service
+public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole>
+ implements SysRoleService {
+
+ @Autowired private SysRoleMapper roleMapper;
+
+ @Autowired private RoleMenuMapper roleMenuMapper;
+
+ @Autowired private UserRoleMapper userRoleMapper;
+
+ /**
+ * Query role list.
+ *
+ * @param role query params
+ * @return role list
+ */
+ @Override
+ public List<SysRole> selectRoleList(IPage<SysRole> page, SysRole role) {
+ return roleMapper.selectRoleList(page, role);
+ }
+
+ /**
+ * Query role list by user ID.
+ *
+ * @param userId user ID
+ * @return role list
+ */
+ @Override
+ public List<SysRole> selectRolesByUserId(Integer userId) {
+ List<SysRole> userRoles = roleMapper.selectRolePermissionByUserId(userId);
+ List<SysRole> roles = this.list();
+ for (SysRole role : roles) {
+ for (SysRole userRole : userRoles) {
+ if (role.getId().intValue() == userRole.getId().intValue()) {
+ role.setFlag(true);
+ break;
+ }
+ }
+ }
+ return roles;
+ }
+
+ /**
+ * Query role permission by user ID.
+ *
+ * @param userId user ID
+ * @return permission list
+ */
+ @Override
+ public Set<String> selectRolePermissionByUserId(Integer userId) {
+ List<SysRole> perms = roleMapper.selectRolePermissionByUserId(userId);
+ Set<String> permsSet = new HashSet<>();
+ for (SysRole perm : perms) {
+ if (perm != null) {
+ permsSet.addAll(Arrays.asList(perm.getRoleKey().trim().split(",")));
+ }
+ }
+ return permsSet;
+ }
+
+ /**
+ * Query role list by user ID.
+ *
+ * @param userId user ID
+ * @return role IDs
+ */
+ @Override
+ public List<Integer> selectRoleListByUserId(Integer userId) {
+ return roleMapper.selectRoleListByUserId(userId);
+ }
+
+ /**
+ * Query role info by role ID.
+ *
+ * @param roleId role ID
+ * @return role info
+ */
+ @Override
+ public SysRole selectRoleById(Integer roleId) {
+ return this.getById(roleId);
+ }
+
+ /**
+ * Verify if the role name is unique.
+ *
+ * @param role role info
+ * @return result
+ */
+ @Override
+ public boolean checkRoleNameUnique(SysRole role) {
+ int roleId = role.getId() == null ? -1 : role.getId();
+ SysRole info = this.lambdaQuery().eq(SysRole::getRoleName, role.getRoleName()).one();
+ return info == null || info.getId() == roleId;
+ }
+
+ /**
+ * Verify whether role permissions are unique.
+ *
+ * @param role role info
+ * @return result
+ */
+ @Override
+ public boolean checkRoleKeyUnique(SysRole role) {
+ int roleId = role.getId() == null ? -1 : role.getId();
+ SysRole info = this.lambdaQuery().eq(SysRole::getRoleKey, role.getRoleKey()).one();
+ return info == null || info.getId() == roleId;
+ }
+
+ /**
+ * Verify whether the role allows operations.
+ *
+ * @param role role info
+ */
+ @Override
+ public boolean checkRoleAllowed(SysRole role) {
+ return role.getId() != null && role.getId() == 1;
+ }
+
+ /**
+ * Add role.
+ *
+ * @param role role info
+ * @return result
+ */
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public int insertRole(SysRole role) {
+ this.save(role);
+ return insertRoleMenu(role);
+ }
+
+ /**
+ * Update role.
+ *
+ * @param role role info
+ * @return result
+ */
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public int updateRole(SysRole role) {
+ this.updateById(role);
+ roleMenuMapper.deleteRoleMenuByRoleId(role.getId());
+ return insertRoleMenu(role);
+ }
+
+ /**
+ * Add role-menu association information.
+ *
+ * @param role role info
+ */
+ public int insertRoleMenu(SysRole role) {
+ int rows = 1;
+ if (role.getMenuIds() != null && role.getMenuIds().length > 0) {
+ List<RoleMenu> list = new ArrayList<RoleMenu>();
+ for (Integer menuId : role.getMenuIds()) {
+ RoleMenu rm = new RoleMenu();
+ rm.setRoleId(role.getId());
+ rm.setMenuId(menuId);
+ list.add(rm);
+ }
+ if (list.size() > 0) {
+ rows = roleMenuMapper.batchRoleMenu(list);
+ }
+ }
+ return rows;
+ }
+
+ /**
+ * Delete role.
+ *
+ * @param roleId role ID
+ * @return result
+ */
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public int deleteRoleById(Integer roleId) {
+ roleMenuMapper.deleteRoleMenuByRoleId(roleId);
+ return roleMapper.deleteById(roleId);
+ }
+
+ /**
+ * Batch delete role.
+ *
+ * @param roleIds role IDs
+ * @return result
+ */
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public int deleteRoleByIds(Integer[] roleIds) {
+ for (Integer roleId : roleIds) {
+ SysRole sysRole = new SysRole();
+ sysRole.setId(roleId);
+ checkRoleAllowed(sysRole);
+ SysRole role = selectRoleById(roleId);
+ if (countUserRoleByRoleId(roleId) > 0) {
+ throw new RoleInUsedException(role.getRoleName());
+ }
+ }
+ roleMenuMapper.deleteRoleMenu(roleIds);
+ return roleMapper.deleteBatchIds(Arrays.asList(roleIds));
+ }
+
+ /**
+ * Unauthorize user role.
+ *
+ * @param userRole user-role association
+ * @return result
+ */
+ @Override
+ public int deleteAuthUser(UserRole userRole) {
+ return userRoleMapper.deleteById(userRole);
+ }
+
+ /**
+ * Batch unauthorize user role.
+ *
+ * @param roleId role ID
+ * @param userIds user IDs
+ * @return result
+ */
+ @Override
+ public int deleteAuthUsers(Integer roleId, Integer[] userIds) {
+ return userRoleMapper.deleteUserRoleInfos(roleId, userIds);
+ }
+
+ /**
+ * Batch add role-menu association information.
+ *
+ * @param roleId role ID
+ * @param userIds user IDs
+ * @return result
+ */
+ @Override
+ public int insertAuthUsers(Integer roleId, Integer[] userIds) {
+ List<UserRole> list = new ArrayList<UserRole>();
+ for (Integer userId : userIds) {
+ UserRole ur = new UserRole();
+ ur.setUserId(userId);
+ ur.setRoleId(roleId);
+ list.add(ur);
+ }
+ return userRoleMapper.batchUserRole(list);
+ }
+
+ /**
+ * Query the number of roles used by role ID.
+ *
+ * @param roleId role ID
+ * @return result
+ */
+ @Override
+ public int countUserRoleByRoleId(Integer roleId) {
+ return userRoleMapper
+ .selectCount(new QueryWrapper<UserRole>().eq("role_id", roleId))
+ .intValue();
+ }
+
+ @Override
+ public boolean updateRoleStatus(SysRole role) {
+ Preconditions.checkArgument(role != null && role.getId() != null);
+ return this.lambdaUpdate()
+ .set(SysRole::getEnabled, role.getEnabled())
+ .eq(SysRole::getId, role.getId())
+ .update();
+ }
+}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/service/impl/UserServiceImpl.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/service/impl/UserServiceImpl.java
index d923254..35e45e5 100644
--- a/paimon-web-server/src/main/java/org/apache/paimon/web/server/service/impl/UserServiceImpl.java
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/service/impl/UserServiceImpl.java
@@ -19,12 +19,65 @@
package org.apache.paimon.web.server.service.impl;
import org.apache.paimon.web.server.data.model.User;
+import org.apache.paimon.web.server.data.result.exception.BaseException;
+import org.apache.paimon.web.server.data.result.exception.user.UserNotExistsException;
+import org.apache.paimon.web.server.data.result.exception.user.UserPasswordNotMatchException;
import org.apache.paimon.web.server.mapper.UserMapper;
import org.apache.paimon.web.server.service.UserService;
+import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import java.util.List;
+
/** UserServiceImpl. */
@Service
-public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {}
+public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
+
+ @Autowired private UserMapper userMapper;
+
+ /**
+ * login by username and password.
+ *
+ * @param username username
+ * @param password pwd
+ * @return {@link String}
+ */
+ @Override
+ public String login(String username, String password) throws BaseException {
+ User user = this.lambdaQuery().eq(User::getUsername, username).one();
+ if (user == null) {
+ throw new UserNotExistsException();
+ }
+ if (!user.getPassword().equals(password)) {
+ throw new UserPasswordNotMatchException();
+ }
+ StpUtil.login(user.getId());
+
+ return StpUtil.getTokenValue();
+ }
+
+ /**
+ * Query the list of assigned user roles.
+ *
+ * @param user query params
+ * @return user list
+ */
+ @Override
+ public List<User> selectAllocatedList(User user) {
+ return userMapper.selectAllocatedList(user);
+ }
+
+ /**
+ * Query the list of unassigned user roles.
+ *
+ * @param user query params
+ * @return user list
+ */
+ @Override
+ public List<User> selectUnallocatedList(User user) {
+ return userMapper.selectUnallocatedList(user);
+ }
+}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/util/MessageUtils.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/util/MessageUtils.java
new file mode 100644
index 0000000..22ac794
--- /dev/null
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/util/MessageUtils.java
@@ -0,0 +1,62 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.paimon.web.server.util;
+
+import org.springframework.context.MessageSource;
+import org.springframework.context.i18n.LocaleContextHolder;
+
+import java.util.Arrays;
+import java.util.Objects;
+
+/** i18n util. */
+public class MessageUtils {
+
+ private static final MessageSource MESSAGE_SOURCE = SpringUtils.getBean(MessageSource.class);
+
+ public MessageUtils() {}
+
+ /**
+ * According to messageKey and parameters, get the message and delegate to spring messageSource.
+ *
+ * @param code msg key
+ * @return {@link String} internationalization information
+ */
+ public static String getMsg(Object code) {
+ return MESSAGE_SOURCE.getMessage(
+ code.toString(), null, code.toString(), LocaleContextHolder.getLocale());
+ }
+
+ /**
+ * According to messageKey and parameters, get the message and delegate to spring messageSource.
+ *
+ * @param code msg key
+ * @param messageArgs msg parameters
+ * @return {@link String} internationalization information
+ */
+ public static String getMsg(Object code, Object... messageArgs) {
+ Object[] objs =
+ Arrays.stream(messageArgs)
+ .filter(Objects::nonNull)
+ .map(MessageUtils::getMsg)
+ .toArray();
+ return MESSAGE_SOURCE.getMessage(
+ code.toString(), objs, code.toString(), LocaleContextHolder.getLocale());
+ }
+}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/util/ObjectMapperUtils.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/util/ObjectMapperUtils.java
new file mode 100644
index 0000000..1a615d4
--- /dev/null
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/util/ObjectMapperUtils.java
@@ -0,0 +1,304 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.paimon.web.server.util;
+
+import com.fasterxml.jackson.core.JsonFactoryBuilder;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.JavaType;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
+import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
+import org.apache.commons.lang3.StringUtils;
+
+import javax.annotation.Nullable;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.UncheckedIOException;
+import java.util.Collection;
+import java.util.Map;
+
+import static com.fasterxml.jackson.core.JsonFactory.Feature.INTERN_FIELD_NAMES;
+import static com.fasterxml.jackson.core.JsonParser.Feature.ALLOW_COMMENTS;
+import static com.fasterxml.jackson.core.json.JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS;
+import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES;
+import static com.fasterxml.jackson.databind.type.TypeFactory.defaultInstance;
+
+/** jackson common object mapper. */
+public class ObjectMapperUtils {
+ private static final String EMPTY_JSON = "{}";
+ private static final String EMPTY_ARRAY_JSON = "[]";
+ private static final ObjectMapper MAPPER;
+
+ static {
+ MAPPER =
+ new ObjectMapper(
+ new JsonFactoryBuilder()
+ .configure(INTERN_FIELD_NAMES, false)
+ .configure(ALLOW_UNESCAPED_CONTROL_CHARS, true)
+ .build());
+ MAPPER.disable(FAIL_ON_UNKNOWN_PROPERTIES);
+ MAPPER.enable(ALLOW_COMMENTS);
+ MAPPER.registerModule(new ParameterNamesModule());
+ MAPPER.registerModule(new JavaTimeModule());
+ MAPPER.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
+ }
+
+ public static String toJSON(@Nullable Object obj) {
+ if (obj == null) {
+ return null;
+ }
+ try {
+ return MAPPER.writeValueAsString(obj);
+ } catch (JsonProcessingException e) {
+ throw new UncheckedIOException(e);
+ }
+ }
+
+ /**
+ * Please do not use formatted JSON when outputting logs.
+ *
+ * <p>For better readability
+ */
+ public static String toPrettyJson(@Nullable Object obj) {
+ if (obj == null) {
+ return null;
+ }
+ try {
+ return MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(obj);
+ } catch (JsonProcessingException e) {
+ throw new UncheckedIOException(e);
+ }
+ }
+
+ public static void toJSON(@Nullable Object obj, OutputStream writer) {
+ if (obj == null) {
+ return;
+ }
+ try {
+ MAPPER.writeValue(writer, obj);
+ } catch (IOException e) {
+ throw wrapException(e);
+ }
+ }
+
+ public static <T> T fromJSON(@Nullable byte[] bytes, Class<T> valueType) {
+ if (bytes == null) {
+ return null;
+ }
+ try {
+ return MAPPER.readValue(bytes, valueType);
+ } catch (IOException e) {
+ throw wrapException(e);
+ }
+ }
+
+ private static RuntimeException wrapException(IOException e) {
+ return new UncheckedIOException(e);
+ }
+
+ public static <T> T fromJSON(@Nullable String json, Class<T> valueType) {
+ if (json == null) {
+ return null;
+ }
+ try {
+ return MAPPER.readValue(json, valueType);
+ } catch (IOException e) {
+ throw wrapException(e);
+ }
+ }
+
+ public static <T> T fromJSON(@Nullable String json, TypeReference<T> type) {
+ if (json == null) {
+ return null;
+ }
+ try {
+ return MAPPER.readValue(json, type);
+ } catch (IOException e) {
+ throw wrapException(e);
+ }
+ }
+
+ public static <T> T fromJSON(Object value, Class<T> valueType) {
+ if (value == null) {
+ return null;
+ } else if (value instanceof String) {
+ return fromJSON((String) value, valueType);
+ } else if (value instanceof byte[]) {
+ return fromJSON((byte[]) value, valueType);
+ } else {
+ return null;
+ }
+ }
+
+ public static <T> T value(Object rawValue, Class<T> type) {
+ return MAPPER.convertValue(rawValue, type);
+ }
+
+ public static <T> T update(T rawValue, String newProperty) {
+ try {
+ return MAPPER.readerForUpdating(rawValue).readValue(newProperty);
+ } catch (IOException e) {
+ throw wrapException(e);
+ }
+ }
+
+ public static <T> T value(Object rawValue, TypeReference<T> type) {
+ return MAPPER.convertValue(rawValue, type);
+ }
+
+ public static <T> T value(Object rawValue, JavaType type) {
+ return MAPPER.convertValue(rawValue, type);
+ }
+
+ public static <T> T unwrapJsonP(String raw, Class<T> type) {
+ return fromJSON(unwrapJsonP(raw), type);
+ }
+
+ private static String unwrapJsonP(String raw) {
+ raw = StringUtils.trim(raw);
+ raw = StringUtils.removeEnd(raw, ";");
+ raw = raw.substring(raw.indexOf('(') + 1);
+ raw = raw.substring(0, raw.lastIndexOf(')'));
+ raw = StringUtils.trim(raw);
+ return raw;
+ }
+
+ public static <E, T extends Collection<E>> T fromJSON(
+ String json, Class<? extends Collection> collectionType, Class<E> valueType) {
+ if (StringUtils.isEmpty(json)) {
+ json = EMPTY_ARRAY_JSON;
+ }
+ try {
+ return MAPPER.readValue(
+ json, defaultInstance().constructCollectionType(collectionType, valueType));
+ } catch (IOException e) {
+ throw wrapException(e);
+ }
+ }
+
+ /** use {@link #fromJson(String)} instead. */
+ public static <K, V, T extends Map<K, V>> T fromJSON(
+ String json, Class<? extends Map> mapType, Class<K> keyType, Class<V> valueType) {
+ if (StringUtils.isEmpty(json)) {
+ json = EMPTY_JSON;
+ }
+ try {
+ return MAPPER.readValue(
+ json, defaultInstance().constructMapType(mapType, keyType, valueType));
+ } catch (IOException e) {
+ throw wrapException(e);
+ }
+ }
+
+ public static <T> T fromJSON(InputStream inputStream, Class<T> type) {
+ try {
+ return MAPPER.readValue(inputStream, type);
+ } catch (IOException e) {
+ throw wrapException(e);
+ }
+ }
+
+ public static <E, T extends Collection<E>> T fromJSON(
+ byte[] bytes, Class<? extends Collection> collectionType, Class<E> valueType) {
+ try {
+ return MAPPER.readValue(
+ bytes, defaultInstance().constructCollectionType(collectionType, valueType));
+ } catch (IOException e) {
+ throw wrapException(e);
+ }
+ }
+
+ public static <E, T extends Collection<E>> T fromJSON(
+ InputStream inputStream,
+ Class<? extends Collection> collectionType,
+ Class<E> valueType) {
+ try {
+ return MAPPER.readValue(
+ inputStream,
+ defaultInstance().constructCollectionType(collectionType, valueType));
+ } catch (IOException e) {
+ throw wrapException(e);
+ }
+ }
+
+ public static Map<String, Object> fromJson(InputStream is) {
+ return fromJSON(is, Map.class, String.class, Object.class);
+ }
+
+ public static Map<String, Object> fromJson(String string) {
+ return fromJSON(string, Map.class, String.class, Object.class);
+ }
+
+ public static Map<String, Object> fromJson(byte[] bytes) {
+ return fromJSON(bytes, Map.class, String.class, Object.class);
+ }
+
+ /** use {@link #fromJson(byte[])} instead. */
+ public static <K, V, T extends Map<K, V>> T fromJSON(
+ byte[] bytes, Class<? extends Map> mapType, Class<K> keyType, Class<V> valueType) {
+ try {
+ return MAPPER.readValue(
+ bytes, defaultInstance().constructMapType(mapType, keyType, valueType));
+ } catch (IOException e) {
+ throw wrapException(e);
+ }
+ }
+
+ /** use {@link #fromJson(InputStream)} instead. */
+ public static <K, V, T extends Map<K, V>> T fromJSON(
+ InputStream inputStream,
+ Class<? extends Map> mapType,
+ Class<K> keyType,
+ Class<V> valueType) {
+ try {
+ return MAPPER.readValue(
+ inputStream, defaultInstance().constructMapType(mapType, keyType, valueType));
+ } catch (IOException e) {
+ throw wrapException(e);
+ }
+ }
+
+ public static boolean isJSON(String jsonStr) {
+ if (StringUtils.isBlank(jsonStr)) {
+ return false;
+ }
+ try (JsonParser parser = new ObjectMapper().getFactory().createParser(jsonStr)) {
+ while (parser.nextToken() != null) {
+ // do nothing.
+ }
+ return true;
+ } catch (IOException ioe) {
+ return false;
+ }
+ }
+
+ public static boolean isBadJSON(String jsonStr) {
+ return !isJSON(jsonStr);
+ }
+
+ public static ObjectMapper mapper() {
+ return MAPPER;
+ }
+}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/util/PageSupport.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/util/PageSupport.java
new file mode 100644
index 0000000..8e33805
--- /dev/null
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/util/PageSupport.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.paimon.web.server.util;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.metadata.OrderItem;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+
+/** Page support. */
+public class PageSupport {
+
+ private static final char SEPARATOR = '_';
+ /** pageNum. */
+ public static final String PAGE_NUM = "pageNum";
+
+ /** pageSize. */
+ public static final String PAGE_SIZE = "pageSize";
+
+ /** order column. */
+ public static final String ORDER_BY_COLUMN = "orderByColumn";
+
+ /** desc or asc. */
+ public static final String IS_ASC = "isAsc";
+
+ /** page params reasonable. */
+ public static final String REASONABLE = "reasonable";
+
+ public static <T> IPage<T> startPage() {
+ Integer pageNum = ServletUtils.getParameterToInt(PAGE_NUM, 1);
+ Integer pageSize = ServletUtils.getParameterToInt(PAGE_SIZE, 10);
+ Page<T> page = new Page<>(pageNum, pageSize);
+ String orderBy = getOrderBy();
+ if (StringUtils.isNotEmpty(orderBy)) {
+ OrderItem orderItem = new OrderItem(orderBy, isAsc());
+ page.addOrder(orderItem);
+ }
+ return page;
+ }
+
+ public static String getOrderBy() {
+ String orderByColumn = ServletUtils.getParameter(ORDER_BY_COLUMN);
+ if (StringUtils.isEmpty(orderByColumn)) {
+ return "";
+ }
+ return toUnderScoreCase(orderByColumn);
+ }
+
+ public static boolean isAsc() {
+ String isAsc = ServletUtils.getParameter(IS_ASC);
+ return isAsc.equals("asc") || isAsc.equals("ascending");
+ }
+
+ public static String toUnderScoreCase(String str) {
+ if (StringUtils.isBlank(str)) {
+ return null;
+ }
+ StringBuilder sb = new StringBuilder();
+ boolean preCharIsUpperCase = true;
+ boolean curreCharIsUpperCase = true;
+ boolean nexteCharIsUpperCase = true;
+ for (int i = 0; i < str.length(); i++) {
+ char c = str.charAt(i);
+ if (i > 0) {
+ preCharIsUpperCase = Character.isUpperCase(str.charAt(i - 1));
+ } else {
+ preCharIsUpperCase = false;
+ }
+
+ curreCharIsUpperCase = Character.isUpperCase(c);
+
+ if (i < (str.length() - 1)) {
+ nexteCharIsUpperCase = Character.isUpperCase(str.charAt(i + 1));
+ }
+
+ if (preCharIsUpperCase && curreCharIsUpperCase && !nexteCharIsUpperCase) {
+ sb.append(SEPARATOR);
+ } else if ((i != 0 && !preCharIsUpperCase) && curreCharIsUpperCase) {
+ sb.append(SEPARATOR);
+ }
+ sb.append(Character.toLowerCase(c));
+ }
+
+ return sb.toString();
+ }
+}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/util/ServletUtils.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/util/ServletUtils.java
new file mode 100644
index 0000000..e1e0fed
--- /dev/null
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/util/ServletUtils.java
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.paimon.web.server.util;
+
+import org.apache.commons.lang3.BooleanUtils;
+import org.springframework.web.context.request.RequestAttributes;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+
+import javax.servlet.ServletRequest;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/** Servlet utils. */
+public class ServletUtils {
+
+ public static String getParameter(String name) {
+ return getRequest().getParameter(name);
+ }
+
+ public static String getParameter(String name, String defaultValue) {
+ String parameter = getRequest().getParameter(name);
+ return StringUtils.isBlank(parameter) ? defaultValue : parameter;
+ }
+
+ public static Integer getParameterToInt(String name) {
+ return Integer.parseInt(getRequest().getParameter(name));
+ }
+
+ public static Integer getParameterToInt(String name, Integer defaultValue) {
+ try {
+ return Integer.parseInt(getRequest().getParameter(name));
+ } catch (Exception e) {
+ return defaultValue;
+ }
+ }
+
+ public static Boolean getParameterToBool(String name) {
+ return BooleanUtils.toBoolean(getRequest().getParameter(name));
+ }
+
+ public static Boolean getParameterToBool(String name, Boolean defaultValue) {
+ try {
+ return BooleanUtils.toBoolean(getRequest().getParameter(name));
+ } catch (Exception e) {
+ return defaultValue;
+ }
+ }
+
+ public static Map<String, String[]> getParams(ServletRequest request) {
+ final Map<String, String[]> map = request.getParameterMap();
+ return Collections.unmodifiableMap(map);
+ }
+
+ public static Map<String, String> getParamMap(ServletRequest request) {
+ Map<String, String> params = new HashMap<>();
+ for (Map.Entry<String, String[]> entry : getParams(request).entrySet()) {
+ params.put(entry.getKey(), StringUtils.join(entry.getValue(), ","));
+ }
+ return params;
+ }
+
+ public static HttpServletRequest getRequest() {
+ return getRequestAttributes().getRequest();
+ }
+
+ public static HttpServletResponse getResponse() {
+ return getRequestAttributes().getResponse();
+ }
+
+ public static HttpSession getSession() {
+ return getRequest().getSession();
+ }
+
+ public static ServletRequestAttributes getRequestAttributes() {
+ RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
+ return (ServletRequestAttributes) attributes;
+ }
+}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/util/SpringUtils.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/util/SpringUtils.java
new file mode 100644
index 0000000..5f4c6db
--- /dev/null
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/util/SpringUtils.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.paimon.web.server.util;
+
+import org.springframework.aop.framework.AopContext;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.stereotype.Component;
+
+/** spring utils. */
+@Component
+public final class SpringUtils implements BeanFactoryPostProcessor, ApplicationContextAware {
+ /** Spring beanFactory. */
+ private static ConfigurableListableBeanFactory beanFactory;
+
+ private static ApplicationContext applicationContext;
+
+ @Override
+ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
+ throws BeansException {
+ SpringUtils.beanFactory = beanFactory;
+ }
+
+ @Override
+ public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
+ SpringUtils.applicationContext = applicationContext;
+ }
+
+ /**
+ * Get bean by bean name.
+ *
+ * @param name bean name
+ * @return An instance of a bean registered with the given name
+ */
+ @SuppressWarnings("unchecked")
+ public static <T> T getBean(String name) throws BeansException {
+ return (T) beanFactory.getBean(name);
+ }
+
+ /**
+ * Get bean by bean class type.
+ *
+ * @param clz bean class
+ * @return An instance of a bean registered with the given class
+ */
+ public static <T> T getBean(Class<T> clz) throws BeansException {
+ return (T) beanFactory.getBean(clz);
+ }
+
+ /** Get AOP proxy object. */
+ @SuppressWarnings("unchecked")
+ public static <T> T getAopProxy(T invoker) {
+ return (T) AopContext.currentProxy();
+ }
+
+ /**
+ * Get the current environment configuration, no configuration returned null.
+ *
+ * @return current envs
+ */
+ public static String[] getActiveProfiles() {
+ return applicationContext.getEnvironment().getActiveProfiles();
+ }
+
+ /**
+ * Get the current environment configuration. When there are multiple environment
+ * configurations, only the first one is obtained.
+ *
+ * @return current env
+ */
+ public static String getActiveProfile() {
+ final String[] activeProfiles = getActiveProfiles();
+ return activeProfiles.length > 0 ? activeProfiles[0] : null;
+ }
+}
diff --git a/paimon-web-server/src/main/java/org/apache/paimon/web/server/mapper/UserMapper.java b/paimon-web-server/src/main/java/org/apache/paimon/web/server/util/StringUtils.java
similarity index 70%
copy from paimon-web-server/src/main/java/org/apache/paimon/web/server/mapper/UserMapper.java
copy to paimon-web-server/src/main/java/org/apache/paimon/web/server/util/StringUtils.java
index d70479c..61cf6f1 100644
--- a/paimon-web-server/src/main/java/org/apache/paimon/web/server/mapper/UserMapper.java
+++ b/paimon-web-server/src/main/java/org/apache/paimon/web/server/util/StringUtils.java
@@ -16,13 +16,14 @@
* limitations under the License.
*/
-package org.apache.paimon.web.server.mapper;
+package org.apache.paimon.web.server.util;
-import org.apache.paimon.web.server.data.model.User;
+import org.apache.paimon.web.server.constant.Constants;
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import org.apache.ibatis.annotations.Mapper;
+/** common string utils. */
+public class StringUtils extends org.apache.commons.lang3.StringUtils {
-/** User table mapper. */
-@Mapper
-public interface UserMapper extends BaseMapper<User> {}
+ public static boolean isHttp(String link) {
+ return StringUtils.startsWithAny(link, Constants.HTTP, Constants.HTTPS);
+ }
+}
diff --git a/paimon-web-server/src/main/resources/application-dev.yml b/paimon-web-server/src/main/resources/application-dev.yml
index 4006d8a..252158b 100644
--- a/paimon-web-server/src/main/resources/application-dev.yml
+++ b/paimon-web-server/src/main/resources/application-dev.yml
@@ -16,7 +16,7 @@
spring:
datasource:
driver-class-name: org.h2.Driver
- url: jdbc:h2:mem:paimon;MODE=MySQL;DB_CLOSE_DELAY=-1;DATABASE_TO_LOWER=true;INIT=runscript from 'classpath:db/ddl-h2.sql'
+ url: jdbc:h2:mem:paimon;MODE=MySQL;DB_CLOSE_DELAY=-1;DATABASE_TO_LOWER=true;;NON_KEYWORDS=USER;INIT=runscript from 'classpath:db/ddl-h2.sql'
username: root
password: root
sql:
diff --git a/paimon-web-server/src/main/resources/application.yml b/paimon-web-server/src/main/resources/application.yml
index 4342834..4e702ad 100644
--- a/paimon-web-server/src/main/resources/application.yml
+++ b/paimon-web-server/src/main/resources/application.yml
@@ -23,6 +23,9 @@ spring:
name: PaimonManager
profiles:
active: dev
+ messages:
+ basename: i18n/messages
+ encoding: UTF-8
# mvc config
mvc:
@@ -40,6 +43,7 @@ spring:
date-format: yyyy-MM-dd HH:mm:ss # Date format, the default is yyyy-MM-dd HH:mm:ss
mybatis-plus:
+ mapperLocations: classpath*:mapper/*Mapper.xml
global-config:
banner: false
db-config:
@@ -47,3 +51,12 @@ mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.nologging.NoLoggingImpl
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
+
+sa-token:
+ token-name: ${spring.application.name}
+ timeout: 2592000
+ active-timeout: -1
+ is-concurrent: true
+ is-share: true
+ token-style: uuid
+ is-log: false
\ No newline at end of file
diff --git a/paimon-web-server/src/main/resources/db/ddl-h2.sql b/paimon-web-server/src/main/resources/db/ddl-h2.sql
index 5dc28cd..4f406e1 100644
--- a/paimon-web-server/src/main/resources/db/ddl-h2.sql
+++ b/paimon-web-server/src/main/resources/db/ddl-h2.sql
@@ -48,3 +48,57 @@ CREATE TABLE if not exists `user_tenant`
`update_time` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'update time'
) ENGINE = InnoDB;
+CREATE TABLE if not exists `sys_role`
+(
+ `id` int(11) not null auto_increment primary key comment 'id',
+ `role_name` varchar(30) not null comment 'role name',
+ `role_key` varchar(100) not null comment 'role key',
+ `sort` int(4) not null comment 'sort',
+ `enabled` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'is enable',
+ `is_delete` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'is delete',
+ `remark` varchar(500) default null comment 'remark',
+ `create_time` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'create time',
+ `update_time` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'update time'
+) engine = innodb;
+
+CREATE TABLE if not exists `sys_menu`
+(
+ `id` int(11) not null auto_increment primary key comment 'id',
+ `menu_name` varchar(50) not null comment 'menu name',
+ `parent_id` int(11) default 0 comment 'parent id',
+ `sort` int(4) default 0 comment 'sort',
+ `path` varchar(200) default '' comment 'route path',
+ `query` varchar(255) default null comment 'route params',
+ `is_cache` int(1) default 0 comment 'is cache(0:cache 1:no_cache)',
+ `type` char(1) default '' comment 'menu type(M:directory C:menu F:button)',
+ `visible` char(1) default 0 comment 'is visible(0:display 1:hide)',
+ `component` varchar(255) default null comment 'component path',
+ `is_frame` int(1) default 0 comment 'is frame',
+ `enabled` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'is enable',
+ `is_delete` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'is delete',
+ `perms` varchar(100) default null comment 'menu perms',
+ `icon` varchar(100) default '#' comment 'menu icon',
+ `remark` varchar(500) default '' comment 'remark',
+ `create_time` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'create time',
+ `update_time` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'update time'
+) engine = innodb;
+
+CREATE TABLE if not exists `user_role`
+(
+ `id` int(11) not null auto_increment primary key comment 'id',
+ `user_id` int(11) not null comment 'user id',
+ `role_id` int(11) not null comment 'role id',
+ `create_time` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'create time',
+ `update_time` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'update time',
+ unique key `idx_user_role` (`user_id`, `role_id`)
+) engine = innodb;
+
+CREATE TABLE if not exists `role_menu`
+(
+ `id` int(11) not null auto_increment primary key comment 'id',
+ `role_id` int(11) not null comment 'role id',
+ `menu_id` int(11) not null comment 'menu id',
+ `create_time` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'create time',
+ `update_time` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'update time',
+ unique key `idx_role_menu` (`role_id`, `menu_id`)
+) engine = innodb;
\ No newline at end of file
diff --git a/paimon-web-server/src/main/resources/db/dml-h2.sql b/paimon-web-server/src/main/resources/db/dml-h2.sql
index a8cb3e3..a8b0c54 100644
--- a/paimon-web-server/src/main/resources/db/dml-h2.sql
+++ b/paimon-web-server/src/main/resources/db/dml-h2.sql
@@ -17,9 +17,46 @@ INSERT INTO `user` ( id, username, password, nickname, mobile
, email, enabled, is_delete)
VALUES ( 1, 'admin', '21232f297a57a5a743894a0e4a801fc3', 'Admin', 0
, 'admin@paimon.com', 1, 0);
+INSERT INTO `user` (id, username, password, nickname, mobile, email, enabled, is_delete)
+VALUES (2, 'common', '21232f297a57a5a743894a0e4a801fc3', 'common', 0, 'common@paimon.com', 1, 0);
INSERT INTO `tenant` (id, name, description)
VALUES (1, 'DefaultTenant', 'DefaultTenant');
INSERT INTO `user_tenant` (`id`, `user_id`, `tenant_id`)
-VALUES (1, 1, 1);
\ No newline at end of file
+VALUES (1, 1, 1);
+
+insert into sys_role (id, role_name, role_key, sort)
+values (1, 'admin', 'admin', 1),
+ (2, 'common', 'common', 2);
+
+insert into sys_menu (id, menu_name, parent_id, sort, path, component, is_frame, type, perms, icon, remark)
+values (1, 'all', 0, 1, 'system', null, 1, 'M', 'system', 'admin', 'system root path'),
+ (100, 'user manager', 1, 1, 'user', 'user/index', 1, 'C', 'system:user:list', 'user', 'user manager'),
+ (1000, 'user query', 100, 1, '', '', 1, 'F', 'system:user:query', '#', ''),
+ (1001, 'user add', 100, 2, '', '', 1, 'F', 'system:user:add', '#', ''),
+ (1002, 'user edit', 100, 3, '', '', 1, 'F', 'system:user:edit', '#', ''),
+ (1003, 'user del', 100, 4, '', '', 1, 'F', 'system:user:remove', '#', ''),
+ (1004, 'user reset', 100, 5, '', '', 1, 'F', 'system:user:resetPwd', '#', ''),
+ (200, 'role manager', 1, 1, 'role', 'role/index', 1, 'C', 'system:role:list', 'role', 'role manager'),
+ (2000, 'role query', 200, 1, '', '', 1, 'F', 'system:role:query', '#', ''),
+ (2001, 'role add', 200, 2, '', '', 1, 'F', 'system:role:add', '#', ''),
+ (2002, 'role edit', 200, 3, '', '', 1, 'F', 'system:role:edit', '#', ''),
+ (2003, 'role del', 200, 4, '', '', 1, 'F', 'system:role:remove', '#', ''),
+ (300, 'menu manager', 1, 1, 'menu', 'menu/index', 1, 'C', 'system:menu:list', 'menu', 'menu manager'),
+ (3000, 'menu query', 300, 1, '', '', 1, 'F', 'system:menu:query', '#', ''),
+ (3001, 'menu add', 300, 2, '', '', 1, 'F', 'system:menu:add', '#', ''),
+ (3002, 'menu edit', 300, 3, '', '', 1, 'F', 'system:menu:edit', '#', ''),
+ (3003, 'menu del', 300, 4, '', '', 1, 'F', 'system:menu:remove', '#', '');
+
+insert into user_role (id, user_id, role_id)
+values (1, 1, 1), (2, 2, 2);
+
+insert into role_menu (role_id, menu_id)
+values (1, 1),
+ (1, 100),
+ (1, 1000),
+ (1, 1001),
+ (1, 1002),
+ (1, 1003),
+ (1, 1004);
\ No newline at end of file
diff --git a/paimon-web-server/src/main/resources/db/migration/V1__add_user.sql b/paimon-web-server/src/main/resources/db/migration/V1__add_user.sql
deleted file mode 100644
index eb572a4..0000000
--- a/paimon-web-server/src/main/resources/db/migration/V1__add_user.sql
+++ /dev/null
@@ -1,20 +0,0 @@
-DROP TABLE IF EXISTS `user`;
-CREATE TABLE `user`
-(
- `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'ID',
- `username` varchar(50) NOT NULL COMMENT 'username',
- `password` varchar(50) NULL DEFAULT NULL COMMENT 'password',
- `nickname` varchar(50) NULL DEFAULT NULL COMMENT 'nickname',
- `user_type` int DEFAULT 0 NOT NULL COMMENT 'login type (0:LOCAL,1:LDAP)',
- `url` varchar(100) NULL DEFAULT NULL COMMENT 'avatar url',
- `mobile` varchar(20) NULL DEFAULT NULL COMMENT 'mobile phone',
- `email` varchar(100) NULL DEFAULT NULL COMMENT 'email',
- `enabled` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'is enable',
- `is_delete` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'is delete',
- `create_time` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'create time',
- `update_time` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'update time',
- unique key `idx_username` (`username`)
-) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;
-
-INSERT INTO `user` (id, username, password, nickname, mobile, email, enabled, is_delete)
-VALUES (1, 'admin', '21232f297a57a5a743894a0e4a801fc3', 'Admin', 0, 'admin@paimon.com', 1, 0);
\ No newline at end of file
diff --git a/paimon-web-server/src/main/resources/db/migration/V2__add_tenant.sql b/paimon-web-server/src/main/resources/db/migration/V2__add_tenant.sql
deleted file mode 100644
index 675ea74..0000000
--- a/paimon-web-server/src/main/resources/db/migration/V2__add_tenant.sql
+++ /dev/null
@@ -1,13 +0,0 @@
-DROP TABLE IF EXISTS `tenant`;
-
-CREATE TABLE `tenant`
-(
- `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'ID',
- `name` varchar(64) NULL DEFAULT NULL COMMENT 'tenant name',
- `description` varchar(255) NULL DEFAULT NULL COMMENT 'tenant description',
- `is_delete` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'is delete',
- `create_time` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'create time',
- `update_time` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'update time'
-) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;
-
-INSERT INTO `tenant` (id, name, description) VALUES (1, 'DefaultTenant', 'DefaultTenant');
\ No newline at end of file
diff --git a/paimon-web-server/src/main/resources/db/migration/V3__add_user_tenant.sql b/paimon-web-server/src/main/resources/db/migration/V3__add_user_tenant.sql
deleted file mode 100644
index 2e24873..0000000
--- a/paimon-web-server/src/main/resources/db/migration/V3__add_user_tenant.sql
+++ /dev/null
@@ -1,13 +0,0 @@
-DROP TABLE IF EXISTS `user_tenant`;
-
-CREATE TABLE `user_tenant`
-(
- `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'ID',
- `user_id` int(11) NOT NULL COMMENT 'user id',
- `tenant_id` int(11) NOT NULL COMMENT 'tenant id',
- `create_time` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'create time',
- `update_time` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'update time'
-) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;
-
-INSERT INTO `user_tenant` (`id`, `user_id`, `tenant_id`)
-VALUES (1, 1, 1);
\ No newline at end of file
diff --git a/paimon-web-server/src/main/resources/i18n/messages.properties b/paimon-web-server/src/main/resources/i18n/messages.properties
new file mode 100644
index 0000000..ed08361
--- /dev/null
+++ b/paimon-web-server/src/main/resources/i18n/messages.properties
@@ -0,0 +1,32 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+successfully=Successfully
+failed=Failed
+unauthorized=User Not Login
+forbidden=User Not Have Permission
+unknown.error=Unknown Error:{0}
+method.not.allowed=Method Not Allowed
+invalid.request.parameter=Request Parameter {0} Is Not Valid
+request.parameter.error=Request Parameter Error
+internal.server.error=Internal Server Error:{0}
+user.not.exist=User Not Exist
+role.in.used=This role {0} is in used
+role.name.exist=This role name {0} is exist
+role.key.exist=This role key {0} is exist
+menu.in.used=This menu is in used
+menu.name.exist=This menu name is exist:{0}
+menu.path.invalid=This menu path is invalid:{0}
diff --git a/paimon-web-server/src/main/resources/i18n/messages_en_US.properties b/paimon-web-server/src/main/resources/i18n/messages_en_US.properties
new file mode 100644
index 0000000..ed08361
--- /dev/null
+++ b/paimon-web-server/src/main/resources/i18n/messages_en_US.properties
@@ -0,0 +1,32 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+successfully=Successfully
+failed=Failed
+unauthorized=User Not Login
+forbidden=User Not Have Permission
+unknown.error=Unknown Error:{0}
+method.not.allowed=Method Not Allowed
+invalid.request.parameter=Request Parameter {0} Is Not Valid
+request.parameter.error=Request Parameter Error
+internal.server.error=Internal Server Error:{0}
+user.not.exist=User Not Exist
+role.in.used=This role {0} is in used
+role.name.exist=This role name {0} is exist
+role.key.exist=This role key {0} is exist
+menu.in.used=This menu is in used
+menu.name.exist=This menu name is exist:{0}
+menu.path.invalid=This menu path is invalid:{0}
diff --git a/paimon-web-server/src/main/resources/i18n/messages_zh_CN.properties b/paimon-web-server/src/main/resources/i18n/messages_zh_CN.properties
new file mode 100644
index 0000000..84e3484
--- /dev/null
+++ b/paimon-web-server/src/main/resources/i18n/messages_zh_CN.properties
@@ -0,0 +1,32 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+successfully=请求成功
+failed=请求失败
+unauthorized=用户未登陆
+forbidden=用户无权限
+unknown.error=未知错误:{0}
+method.not.allowed=请求方法不支持
+invalid.request.parameter=请求参数 {0} 无效
+request.parameter.error=请求参数错误
+internal.server.error=服务器内部错误:{0}
+user.not.exist=用户不存在
+role.in.used=此角色{0}正在使用中
+role.name.exist=此角色名称{0}已使用
+role.key.exist=此角色关键字{0}已使用
+menu.in.used=此菜单正在使用中
+menu.name.exist=此菜单名称已存在:{0}
+menu.path.invalid=此菜单路径无效:{0}
diff --git a/paimon-web-server/src/main/resources/mapper/RoleMenuMapper.xml b/paimon-web-server/src/main/resources/mapper/RoleMenuMapper.xml
new file mode 100644
index 0000000..d6d3e69
--- /dev/null
+++ b/paimon-web-server/src/main/resources/mapper/RoleMenuMapper.xml
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<!DOCTYPE mapper
+PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.apache.paimon.web.server.mapper.RoleMenuMapper">
+
+ <resultMap type="org.apache.paimon.web.server.data.model.RoleMenu" id="SysRoleMenuResult">
+ <result property="id" column="id" />
+ <result property="roleId" column="role_id" />
+ <result property="menuId" column="menu_id" />
+ </resultMap>
+
+ <select id="checkMenuExistRole" resultType="Integer">
+ select count(1) from role_menu where menu_id = #{menuId} limit 1
+ </select>
+
+ <select id="queryRoleMenuByUser" resultMap="SysRoleMenuResult">
+ select *
+ from role_menu
+ where role_id in (select role_id
+ from user_role
+ where user_id = #{userId})
+ </select>
+
+ <delete id="deleteRoleMenuByRoleId" parameterType="Integer">
+ delete from role_menu where role_id=#{roleId}
+ </delete>
+
+ <delete id="deleteRoleMenu" parameterType="Integer">
+ delete from role_menu where role_id in
+ <foreach collection="array" item="roleId" open="(" separator="," close=")">
+ #{roleId}
+ </foreach>
+ </delete>
+
+ <insert id="batchRoleMenu">
+ insert into role_menu(role_id, menu_id) values
+ <foreach item="item" index="index" collection="list" separator=",">
+ (#{item.roleId},#{item.menuId})
+ </foreach>
+ </insert>
+
+</mapper>
\ No newline at end of file
diff --git a/paimon-web-server/src/main/resources/mapper/SysMenuMapper.xml b/paimon-web-server/src/main/resources/mapper/SysMenuMapper.xml
new file mode 100644
index 0000000..77eae20
--- /dev/null
+++ b/paimon-web-server/src/main/resources/mapper/SysMenuMapper.xml
@@ -0,0 +1,147 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<!DOCTYPE mapper
+ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+ "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.apache.paimon.web.server.mapper.SysMenuMapper">
+
+ <resultMap type="org.apache.paimon.web.server.data.model.SysMenu" id="SysMenuResult">
+ <id property="id" column="id" />
+ <result property="menuName" column="menu_name" />
+ <result property="parentId" column="parent_id" />
+ <result property="sort" column="sort" />
+ <result property="path" column="path" />
+ <result property="component" column="component" />
+ <result property="query" column="query" />
+ <result property="isFrame" column="is_frame" />
+ <result property="isCache" column="is_cache" />
+ <result property="type" column="type" />
+ <result property="visible" column="visible" />
+ <result property="enabled" column="enabled" />
+ <result property="perms" column="perms" />
+ <result property="icon" column="icon" />
+ <result property="createTime" column="create_time" />
+ <result property="updateTime" column="update_time" />
+ <result property="remark" column="remark" />
+ </resultMap>
+
+ <sql id="selectMenuVo">
+ select id, menu_name, parent_id, sort, path, component, `query`, is_frame, is_cache, type, visible, enabled, ifnull(perms,'') as perms, icon, create_time
+ from sys_menu
+ </sql>
+
+ <select id="selectMenuList" parameterType="org.apache.paimon.web.server.data.model.SysMenu" resultMap="SysMenuResult">
+ <include refid="selectMenuVo"/>
+ <where>
+ <if test="menu.menuName != null and menu.menuName != ''">
+ AND menu_name like concat('%', #{menu.menuName}, '%')
+ </if>
+ <if test="menu.visible != null and menu.visible != ''">
+ AND visible = #{menu.visible}
+ </if>
+ <if test="menu.enabled != null and menu.enabled != ''">
+ AND enabled = #{menu.enabled}
+ </if>
+ </where>
+ order by parent_id, sort
+ </select>
+
+ <select id="selectMenuTreeAll" resultMap="SysMenuResult">
+ select distinct m.id, m.parent_id, m.menu_name, m.path, m.component, m.`query`, m.visible, m.enabled, ifnull(m.perms,'') as perms, m.is_frame, m.is_cache, m.type, m.icon, m.sort, m.create_time
+ from sys_menu m where m.type in ('M', 'C') and m.enabled = 1
+ order by m.parent_id, m.sort
+ </select>
+
+ <select id="selectMenuListByUserId" resultMap="SysMenuResult">
+ select distinct m.id, m.parent_id, m.menu_name, m.path, m.component, m.`query`, m.visible, m.enabled, ifnull(m.perms,'') as perms, m.is_frame, m.is_cache, m.type, m.icon, m.sort, m.create_time
+ from sys_menu m
+ left join role_menu rm on m.id = rm.menu_id
+ left join user_role urole on rm.role_id = urole.role_id
+ left join sys_role ro on urole.role_id = ro.id
+ where urole.user_id = #{userId}
+ <if test="menu.menuName != null and menu.menuName != ''">
+ AND m.menu_name like concat('%', #{menu.menuName}, '%')
+ </if>
+ <if test="menu.visible != null and menu.visible != ''">
+ AND m.visible = #{visible}
+ </if>
+ <if test="menu.enabled != null and menu.enabled != ''">
+ AND m.enabled = #{enabled}
+ </if>
+ order by m.parent_id, m.sort
+ </select>
+
+ <select id="selectMenuTreeByUserId" parameterType="Integer" resultMap="SysMenuResult">
+ select distinct m.id, m.parent_id, m.menu_name, m.path, m.component, m.`query`, m.visible, m.enabled, ifnull(m.perms,'') as perms, m.is_frame, m.is_cache, m.type, m.icon, m.sort, m.create_time
+ from sys_menu m
+ left join role_menu rm on m.id = rm.menu_id
+ left join user_role urole on rm.role_id = urole.role_id
+ left join sys_role ro on urole.role_id = ro.id
+ left join user u on urole.user_id = u.id
+ where u.id = #{userId} and m.type in ('M', 'C') and m.enabled = 1 AND ro.enabled = 1
+ order by m.parent_id, m.sort
+ </select>
+
+ <select id="selectMenuListByRoleId" resultType="Integer">
+ select m.id
+ from sys_menu m
+ left join role_menu rm on m.id = rm.menu_id
+ where rm.role_id = #{roleId}
+ order by m.parent_id, m.sort
+ </select>
+
+ <select id="selectMenuPerms" resultType="String">
+ select distinct m.perms
+ from sys_menu m
+ left join role_menu rm on m.id = rm.menu_id
+ left join user_role urole on rm.role_id = urole.role_id
+ </select>
+
+ <select id="selectMenuPermsByUserId" parameterType="Integer" resultType="String">
+ select distinct m.perms
+ from sys_menu m
+ left join role_menu rm on m.id = rm.menu_id
+ left join user_role urole on rm.role_id = urole.role_id
+ left join sys_role r on r.id = urole.role_id
+ where m.enabled = 1 and r.enabled = 1 and urole.user_id = #{userId}
+ </select>
+
+ <select id="selectMenuPermsByRoleId" parameterType="Integer" resultType="String">
+ select distinct m.perms
+ from sys_menu m
+ left join role_menu rm on m.id = rm.menu_id
+ where m.enabled = 1 and rm.role_id = #{roleId}
+ </select>
+
+ <select id="selectMenuById" parameterType="Integer" resultMap="SysMenuResult">
+ <include refid="selectMenuVo"/>
+ where id = #{menuId}
+ </select>
+
+ <select id="hasChildByMenuId" resultType="Integer">
+ select count(1) from sys_menu where parent_id = #{menuId} limit 1
+ </select>
+
+ <select id="checkMenuNameUnique" parameterType="org.apache.paimon.web.server.data.model.SysMenu" resultMap="SysMenuResult">
+ <include refid="selectMenuVo"/>
+ where menu_name=#{menuName} and parent_id = #{parentId} limit 1
+ </select>
+
+</mapper>
\ No newline at end of file
diff --git a/paimon-web-server/src/main/resources/mapper/SysRoleMapper.xml b/paimon-web-server/src/main/resources/mapper/SysRoleMapper.xml
new file mode 100644
index 0000000..213ae26
--- /dev/null
+++ b/paimon-web-server/src/main/resources/mapper/SysRoleMapper.xml
@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<!DOCTYPE mapper
+PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.apache.paimon.web.server.mapper.SysRoleMapper">
+
+ <resultMap type="org.apache.paimon.web.server.data.model.SysRole" id="SysRoleResult">
+ <id property="id" column="id" />
+ <result property="roleName" column="role_name" />
+ <result property="roleKey" column="role_key" />
+ <result property="sort" column="sort" />
+ <result property="enabled" column="enabled" />
+ <result property="isDelete" column="is_delete" />
+ <result property="createTime" column="create_time" />
+ <result property="updateTime" column="update_time" />
+ <result property="remark" column="remark" />
+ </resultMap>
+
+ <sql id="selectRoleVo">
+ select distinct r.id, r.role_name, r.role_key, r.sort,
+ r.enabled, r.is_delete, r.create_time, r.remark
+ from sys_role r
+ left join user_role urole on urole.role_id = r.id
+ left join user u on u.id = urole.user_id
+ </sql>
+
+ <select id="selectRoleList" parameterType="org.apache.paimon.web.server.data.model.SysRole" resultMap="SysRoleResult">
+ <include refid="selectRoleVo"/>
+ where r.is_delete = '0'
+ <if test="role.id != null and role.id != 0">
+ AND r.id = #{role.id}
+ </if>
+ <if test="role.roleName != null and role.roleName != ''">
+ AND r.role_name like concat('%', #{role.roleName}, '%')
+ </if>
+ <if test="role.enabled != null and role.enabled != ''">
+ AND r.enabled = #{role.enabled}
+ </if>
+ <if test="role.roleKey != null and role.roleKey != ''">
+ AND r.role_key like concat('%', #{role.roleKey}, '%')
+ </if>
+ <if test="role.params.beginTime != null and role.params.beginTime != ''"><!-- 开始时间检索 -->
+ and date_format(r.create_time,'%y%m%d') >= date_format(#{role.params.beginTime},'%y%m%d')
+ </if>
+ <if test="role.params.endTime != null and role.params.endTime != ''"><!-- 结束时间检索 -->
+ and date_format(r.create_time,'%y%m%d') <= date_format(#{role.params.endTime},'%y%m%d')
+ </if>
+ order by r.sort
+ </select>
+
+ <select id="selectRolePermissionByUserId" parameterType="Integer" resultMap="SysRoleResult">
+ <include refid="selectRoleVo"/>
+ WHERE r.is_delete = '0' and ur.user_id = #{userId}
+ </select>
+
+ <select id="selectRoleAll" resultMap="SysRoleResult">
+ <include refid="selectRoleVo"/>
+ </select>
+
+ <select id="selectRoleListByUserId" parameterType="Integer" resultType="Integer">
+ select r.id from sys_role r left join user_role urole on urole.role_id = r.id left join user u on u.id = urole.user_id where u.id = #{userId}
+ </select>
+
+ <select id="selectRoleById" parameterType="Integer" resultMap="SysRoleResult">
+ <include refid="selectRoleVo"/>
+ where r.id = #{id}
+ </select>
+
+ <select id="selectRolesByUserName" parameterType="String" resultMap="SysRoleResult">
+ <include refid="selectRoleVo"/>
+ WHERE r.is_delete = 0 and u.user_name = #{userName}
+ </select>
+
+</mapper>
\ No newline at end of file
diff --git a/paimon-web-server/src/main/resources/mapper/UserMapper.xml b/paimon-web-server/src/main/resources/mapper/UserMapper.xml
new file mode 100644
index 0000000..fc13d9f
--- /dev/null
+++ b/paimon-web-server/src/main/resources/mapper/UserMapper.xml
@@ -0,0 +1,118 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<!DOCTYPE mapper
+PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.apache.paimon.web.server.mapper.UserMapper">
+
+ <resultMap type="org.apache.paimon.web.server.data.model.User" id="SysUserResult">
+ <id property="id" column="id" />
+ <result property="username" column="user_name" />
+ <result property="nickname" column="nick_name" />
+ <result property="email" column="email" />
+ <result property="mobile" column="mobile" />
+ <result property="url" column="url" />
+ <result property="enabled" column="enabled" />
+ <result property="password" column="password" />
+ <result property="isDelete" column="is_delete" />
+ <result property="createTime" column="create_time" />
+ <result property="updateTime" column="update_time" />
+ <collection property="roles" javaType="java.util.List" resultMap="RoleResult" />
+ </resultMap>
+
+ <resultMap id="RoleResult" type="org.apache.paimon.web.server.data.model.SysRole">
+ <id property="id" column="role_id" />
+ <result property="roleName" column="role_name" />
+ <result property="roleKey" column="role_key" />
+ <result property="sort" column="sort" />
+ <result property="enabled" column="enabled" />
+ </resultMap>
+
+ <sql id="selectUserVo">
+ select u.id, u.username, u.nickname, u.email, u.url, u.mobile, u.password, u.is_delete, u.enabled, u.create_time,
+ r.id, r.role_name, r.role_key, r.sort, r.enabled as role_status
+ from user u
+ left join user_role urole on u.id = urole.user_id
+ left join sys_role r on r.id = urole.role_id
+ </sql>
+
+ <select id="selectUserList" parameterType="org.apache.paimon.web.server.data.model.User" resultMap="SysUserResult">
+ select u.id, u.nickname, u.username, u.email, u.url, u.mobile, u.enabled, u.is_delete, u.create_time from user u
+ where u.is_delete = '0'
+ <if test="id != null and id != 0">
+ AND u.id = #{userId}
+ </if>
+ <if test="username != null and username != ''">
+ AND u.username like concat('%', #{userName}, '%')
+ </if>
+ <if test="enabled != null and enabled != ''">
+ AND u.enabled = #{enabled}
+ </if>
+ <if test="mobile != null and mobile != ''">
+ AND u.mobile like concat('%', #{mobile}, '%')
+ </if>
+ <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
+ AND date_format(u.create_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d')
+ </if>
+ <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
+ AND date_format(u.create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d')
+ </if>
+ </select>
+
+ <select id="selectAllocatedList" parameterType="org.apache.paimon.web.server.data.model.User" resultMap="SysUserResult">
+ select distinct u.id, u.username, u.nickname, u.email, u.mobile, u.enabled, u.create_time
+ from user u
+ left join user_role urole on u.id = urole.user_id
+ left join sys_role r on r.id = urole.role_id
+ where u.is_delete = '0' and r.id = #{roleId}
+ <if test="username != null and username != ''">
+ AND u.username like concat('%', #{username}, '%')
+ </if>
+ <if test="mobile != null and mobile != ''">
+ AND u.mobile like concat('%', #{mobile}, '%')
+ </if>
+ </select>
+
+ <select id="selectUnallocatedList" parameterType="org.apache.paimon.web.server.data.model.User" resultMap="SysUserResult">
+ select distinct u.id u.username, u.nickname, u.email, u.mobile, u.enabled, u.create_time
+ from user u
+ left join user_role urole on u.id = urole.user_id
+ left join sys_role r on r.id = urole.role_id
+ where u.is_delete = '0' and (r.id != #{roleId} or r.id IS NULL)
+ and u.id not in (select u.id from user u inner join user_role urole on u.id = urole.user_id and urole.role_id = #{roleId})
+ <if test="username != null and username != ''">
+ AND u.username like concat('%', #{username}, '%')
+ </if>
+ <if test="mobile != null and mobile != ''">
+ AND u.mobile like concat('%', #{mobile}, '%')
+ </if>
+ </select>
+
+ <select id="selectUserByUserName" parameterType="String" resultMap="SysUserResult">
+ <include refid="selectUserVo"/>
+ where u.username = #{username} and u.is_delete = '0'
+ </select>
+
+ <select id="selectUserById" parameterType="Long" resultMap="SysUserResult">
+ <include refid="selectUserVo"/>
+ where u.id = #{id}
+ </select>
+
+</mapper>
\ No newline at end of file
diff --git a/paimon-web-server/src/main/resources/mapper/UserRoleMapper.xml b/paimon-web-server/src/main/resources/mapper/UserRoleMapper.xml
new file mode 100644
index 0000000..72d67a6
--- /dev/null
+++ b/paimon-web-server/src/main/resources/mapper/UserRoleMapper.xml
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<!DOCTYPE mapper
+PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.apache.paimon.web.server.mapper.UserRoleMapper">
+
+ <resultMap type="org.apache.paimon.web.server.data.model.UserRole" id="SysUserRoleResult">
+ <result property="id" column="id" />
+ <result property="userId" column="user_id" />
+ <result property="roleId" column="role_id" />
+ </resultMap>
+
+ <delete id="deleteUserRoleByUserId" parameterType="Integer">
+ delete from user_role where user_id=#{userId}
+ </delete>
+
+ <select id="countUserRoleByRoleId" resultType="Integer">
+ select count(1) from user_role where role_id=#{roleId}
+ </select>
+
+ <delete id="deleteUserRole" parameterType="Integer">
+ delete from user_role where user_id in
+ <foreach collection="array" item="userId" open="(" separator="," close=")">
+ #{userId}
+ </foreach>
+ </delete>
+
+ <insert id="batchUserRole">
+ insert into user_role(user_id, role_id) values
+ <foreach item="item" index="index" collection="list" separator=",">
+ (#{item.userId},#{item.roleId})
+ </foreach>
+ </insert>
+
+ <delete id="deleteUserRoleInfo" parameterType="org.apache.paimon.web.server.data.model.UserRole">
+ delete from user_role where user_id=#{userId} and role_id=#{roleId}
+ </delete>
+
+ <delete id="deleteUserRoleInfos">
+ delete from user_role where role_id=#{roleId} and user_id in
+ <foreach collection="userIds" item="userId" open="(" separator="," close=")">
+ #{userId}
+ </foreach>
+ </delete>
+</mapper>
\ No newline at end of file
diff --git a/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/PermissionTest.java b/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/PermissionTest.java
new file mode 100644
index 0000000..730693e
--- /dev/null
+++ b/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/PermissionTest.java
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.paimon.web.server.controller;
+
+import org.apache.paimon.web.server.data.model.User;
+import org.apache.paimon.web.server.data.result.R;
+import org.apache.paimon.web.server.data.result.enums.Status;
+import org.apache.paimon.web.server.util.ObjectMapperUtils;
+import org.apache.paimon.web.server.util.StringUtils;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.http.MediaType;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
+import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
+import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/** Test of permission service. */
+@SpringBootTest
+@AutoConfigureMockMvc
+public class PermissionTest {
+ private static final String loginPath = "/api/login";
+ private static final String logoutPath = "/api/logout";
+
+ private static final String getUserPath = "/api/user";
+
+ @Value("${spring.application.name}")
+ private String tokenName;
+
+ @Autowired private MockMvc mockMvc;
+
+ private String token;
+
+ @BeforeEach
+ public void before() throws Exception {
+ String result =
+ mockMvc.perform(
+ MockMvcRequestBuilders.post(loginPath)
+ .queryParam("username", "common")
+ .queryParam("password", "21232f297a57a5a743894a0e4a801fc3")
+ .contentType(MediaType.APPLICATION_JSON_VALUE)
+ .accept(MediaType.APPLICATION_JSON_VALUE))
+ .andExpect(MockMvcResultMatchers.status().isOk())
+ .andDo(MockMvcResultHandlers.print())
+ .andReturn()
+ .getResponse()
+ .getContentAsString();
+ R<?> r = ObjectMapperUtils.fromJSON(result, R.class);
+ assertEquals(200, r.getCode());
+
+ assertTrue(StringUtils.isNotBlank(r.getData().toString()));
+
+ this.token = r.getData().toString();
+ }
+
+ @AfterEach
+ public void after() throws Exception {
+ String result =
+ mockMvc.perform(
+ MockMvcRequestBuilders.post(logoutPath)
+ .header(tokenName, token)
+ .contentType(MediaType.APPLICATION_JSON_VALUE)
+ .accept(MediaType.APPLICATION_JSON_VALUE))
+ .andExpect(MockMvcResultMatchers.status().isOk())
+ .andDo(MockMvcResultHandlers.print())
+ .andReturn()
+ .getResponse()
+ .getContentAsString();
+ R<?> r = ObjectMapperUtils.fromJSON(result, R.class);
+ assertEquals(200, r.getCode());
+ }
+
+ @Test
+ public void testNoPermission() throws Exception {
+ String responseString =
+ mockMvc.perform(
+ MockMvcRequestBuilders.get(getUserPath + "/" + 1)
+ .header(tokenName, token)
+ .contentType(MediaType.APPLICATION_JSON_VALUE)
+ .accept(MediaType.APPLICATION_JSON_VALUE))
+ .andExpect(MockMvcResultMatchers.status().is4xxClientError())
+ .andDo(MockMvcResultHandlers.print())
+ .andReturn()
+ .getResponse()
+ .getContentAsString();
+
+ R<User> r = ObjectMapperUtils.fromJSON(responseString, new TypeReference<R<User>>() {});
+ assertEquals(Status.FORBIDDEN.getCode(), r.getCode());
+ }
+}
diff --git a/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/SysMenuControllerTest.java b/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/SysMenuControllerTest.java
new file mode 100644
index 0000000..ae4505b
--- /dev/null
+++ b/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/SysMenuControllerTest.java
@@ -0,0 +1,182 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.paimon.web.server.controller;
+
+import org.apache.paimon.web.server.data.model.SysMenu;
+import org.apache.paimon.web.server.data.result.R;
+import org.apache.paimon.web.server.data.tree.TreeSelect;
+import org.apache.paimon.web.server.data.vo.RoleMenuTreeselectVo;
+import org.apache.paimon.web.server.util.ObjectMapperUtils;
+import org.apache.paimon.web.server.util.StringUtils;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.http.MediaType;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
+import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
+import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
+
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/** Test for SysMenuController. */
+@SpringBootTest
+@AutoConfigureMockMvc
+public class SysMenuControllerTest {
+
+ private static final String menuPath = "/api/menu";
+ private static final String loginPath = "/api/login";
+ private static final String logoutPath = "/api/logout";
+
+ @Value("${spring.application.name}")
+ private String tokenName;
+
+ @Autowired private MockMvc mockMvc;
+
+ private String token;
+
+ @BeforeEach
+ public void before() throws Exception {
+ String result =
+ mockMvc.perform(
+ MockMvcRequestBuilders.post(loginPath)
+ .queryParam("username", "admin")
+ .queryParam("password", "21232f297a57a5a743894a0e4a801fc3")
+ .contentType(MediaType.APPLICATION_JSON_VALUE)
+ .accept(MediaType.APPLICATION_JSON_VALUE))
+ .andExpect(MockMvcResultMatchers.status().isOk())
+ .andDo(MockMvcResultHandlers.print())
+ .andReturn()
+ .getResponse()
+ .getContentAsString();
+ R<?> r = ObjectMapperUtils.fromJSON(result, R.class);
+ assertEquals(200, r.getCode());
+
+ assertTrue(StringUtils.isNotBlank(r.getData().toString()));
+
+ this.token = r.getData().toString();
+ }
+
+ @AfterEach
+ public void after() throws Exception {
+ String result =
+ mockMvc.perform(
+ MockMvcRequestBuilders.post(logoutPath)
+ .header(tokenName, token)
+ .contentType(MediaType.APPLICATION_JSON_VALUE)
+ .accept(MediaType.APPLICATION_JSON_VALUE))
+ .andExpect(MockMvcResultMatchers.status().isOk())
+ .andDo(MockMvcResultHandlers.print())
+ .andReturn()
+ .getResponse()
+ .getContentAsString();
+ R<?> r = ObjectMapperUtils.fromJSON(result, R.class);
+ assertEquals(200, r.getCode());
+ }
+
+ @Test
+ public void testList() throws Exception {
+ String result =
+ mockMvc.perform(
+ MockMvcRequestBuilders.get(menuPath + "/list")
+ .header(tokenName, token)
+ .contentType(MediaType.APPLICATION_JSON_VALUE)
+ .accept(MediaType.APPLICATION_JSON_VALUE))
+ .andExpect(MockMvcResultMatchers.status().isOk())
+ .andDo(MockMvcResultHandlers.print())
+ .andReturn()
+ .getResponse()
+ .getContentAsString();
+ R<List<SysMenu>> r =
+ ObjectMapperUtils.fromJSON(result, new TypeReference<R<List<SysMenu>>>() {});
+ assertEquals(200, r.getCode());
+ assertNotNull(r.getData());
+ assertTrue(r.getData().size() > 0);
+ }
+
+ @Test
+ public void testGetInfo() throws Exception {
+ String result =
+ mockMvc.perform(
+ MockMvcRequestBuilders.get(menuPath + "/1")
+ .header(tokenName, token)
+ .contentType(MediaType.APPLICATION_JSON_VALUE)
+ .accept(MediaType.APPLICATION_JSON_VALUE))
+ .andExpect(MockMvcResultMatchers.status().isOk())
+ .andDo(MockMvcResultHandlers.print())
+ .andReturn()
+ .getResponse()
+ .getContentAsString();
+ R<SysMenu> r = ObjectMapperUtils.fromJSON(result, new TypeReference<R<SysMenu>>() {});
+ assertEquals(200, r.getCode());
+ assertNotNull(r.getData());
+ assertEquals(1, (int) r.getData().getId());
+ }
+
+ @Test
+ public void testGetTreeselect() throws Exception {
+ String result =
+ mockMvc.perform(
+ MockMvcRequestBuilders.get(menuPath + "/treeselect")
+ .header(tokenName, token)
+ .contentType(MediaType.APPLICATION_JSON_VALUE)
+ .accept(MediaType.APPLICATION_JSON_VALUE))
+ .andExpect(MockMvcResultMatchers.status().isOk())
+ .andDo(MockMvcResultHandlers.print())
+ .andReturn()
+ .getResponse()
+ .getContentAsString();
+ R<List<TreeSelect>> r =
+ ObjectMapperUtils.fromJSON(result, new TypeReference<R<List<TreeSelect>>>() {});
+ assertEquals(200, r.getCode());
+ assertNotNull(r.getData());
+ assertTrue(r.getData().size() > 0);
+ }
+
+ @Test
+ public void testGetRoleMenuTreeselect() throws Exception {
+ String result =
+ mockMvc.perform(
+ MockMvcRequestBuilders.get(menuPath + "/roleMenuTreeselect/1")
+ .header(tokenName, token)
+ .contentType(MediaType.APPLICATION_JSON_VALUE)
+ .accept(MediaType.APPLICATION_JSON_VALUE))
+ .andExpect(MockMvcResultMatchers.status().isOk())
+ .andDo(MockMvcResultHandlers.print())
+ .andReturn()
+ .getResponse()
+ .getContentAsString();
+ R<RoleMenuTreeselectVo> r =
+ ObjectMapperUtils.fromJSON(result, new TypeReference<R<RoleMenuTreeselectVo>>() {});
+ assertEquals(200, r.getCode());
+ assertNotNull(r.getData());
+ assertNotNull(r.getData().getMenus());
+ assertNotNull(r.getData().getCheckedKeys());
+ }
+}
diff --git a/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/SysRoleControllerTest.java b/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/SysRoleControllerTest.java
new file mode 100644
index 0000000..462a585
--- /dev/null
+++ b/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/SysRoleControllerTest.java
@@ -0,0 +1,232 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.paimon.web.server.controller;
+
+import org.apache.paimon.web.server.data.model.SysRole;
+import org.apache.paimon.web.server.data.result.PageR;
+import org.apache.paimon.web.server.data.result.R;
+import org.apache.paimon.web.server.util.ObjectMapperUtils;
+import org.apache.paimon.web.server.util.StringUtils;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.MethodOrderer;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestMethodOrder;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.http.MediaType;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
+import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
+import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/** Test for SysRoleController. */
+@SpringBootTest
+@AutoConfigureMockMvc
+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
+public class SysRoleControllerTest {
+
+ private static final String rolePath = "/api/role";
+ private static final String loginPath = "/api/login";
+ private static final String logoutPath = "/api/logout";
+
+ private static final int roleId = 3;
+ private static final String roleName = "test";
+
+ @Value("${spring.application.name}")
+ private String tokenName;
+
+ @Autowired private MockMvc mockMvc;
+
+ private String token;
+
+ @BeforeEach
+ public void before() throws Exception {
+ String result =
+ mockMvc.perform(
+ MockMvcRequestBuilders.post(loginPath)
+ .queryParam("username", "admin")
+ .queryParam("password", "21232f297a57a5a743894a0e4a801fc3")
+ .contentType(MediaType.APPLICATION_JSON_VALUE)
+ .accept(MediaType.APPLICATION_JSON_VALUE))
+ .andExpect(MockMvcResultMatchers.status().isOk())
+ .andDo(MockMvcResultHandlers.print())
+ .andReturn()
+ .getResponse()
+ .getContentAsString();
+ R<?> r = ObjectMapperUtils.fromJSON(result, R.class);
+ assertEquals(200, r.getCode());
+
+ assertTrue(StringUtils.isNotBlank(r.getData().toString()));
+
+ this.token = r.getData().toString();
+ }
+
+ @AfterEach
+ public void after() throws Exception {
+ String result =
+ mockMvc.perform(
+ MockMvcRequestBuilders.post(logoutPath)
+ .header(tokenName, token)
+ .contentType(MediaType.APPLICATION_JSON_VALUE)
+ .accept(MediaType.APPLICATION_JSON_VALUE))
+ .andExpect(MockMvcResultMatchers.status().isOk())
+ .andDo(MockMvcResultHandlers.print())
+ .andReturn()
+ .getResponse()
+ .getContentAsString();
+ R<?> r = ObjectMapperUtils.fromJSON(result, R.class);
+ assertEquals(200, r.getCode());
+ }
+
+ @Test
+ @Order(1)
+ public void testAddRole() throws Exception {
+ SysRole sysRole = new SysRole();
+ sysRole.setId(roleId);
+ sysRole.setRoleName(roleName);
+ sysRole.setRoleKey(roleName);
+ sysRole.setSort(3);
+ sysRole.setEnabled(true);
+ sysRole.setIsDelete(false);
+ sysRole.setRemark(roleName);
+
+ mockMvc.perform(
+ MockMvcRequestBuilders.post(rolePath)
+ .header(tokenName, token)
+ .content(ObjectMapperUtils.toJSON(sysRole))
+ .contentType(MediaType.APPLICATION_JSON_VALUE)
+ .accept(MediaType.APPLICATION_JSON_VALUE))
+ .andExpect(MockMvcResultMatchers.status().isOk())
+ .andDo(MockMvcResultHandlers.print());
+ }
+
+ @Test
+ @Order(2)
+ public void testQueryRole() throws Exception {
+ String responseString =
+ mockMvc.perform(
+ MockMvcRequestBuilders.get(rolePath + "/" + roleId)
+ .header(tokenName, token)
+ .contentType(MediaType.APPLICATION_JSON_VALUE)
+ .accept(MediaType.APPLICATION_JSON_VALUE))
+ .andExpect(MockMvcResultMatchers.status().isOk())
+ .andDo(MockMvcResultHandlers.print())
+ .andReturn()
+ .getResponse()
+ .getContentAsString();
+
+ R<SysRole> r =
+ ObjectMapperUtils.fromJSON(responseString, new TypeReference<R<SysRole>>() {});
+ assertEquals(200, r.getCode());
+ assertNotNull(r.getData());
+ assertEquals(r.getData().getRoleName(), roleName);
+ }
+
+ @Test
+ @Order(3)
+ public void testEditRole() throws Exception {
+ String newRoleName = roleName + "-edit";
+ SysRole sysRole = new SysRole();
+ sysRole.setId(roleId);
+ sysRole.setRoleName(newRoleName);
+ sysRole.setRoleKey(newRoleName);
+ sysRole.setSort(3);
+ sysRole.setEnabled(true);
+ sysRole.setIsDelete(false);
+ sysRole.setRemark(newRoleName);
+
+ mockMvc.perform(
+ MockMvcRequestBuilders.put(rolePath)
+ .header(tokenName, token)
+ .content(ObjectMapperUtils.toJSON(sysRole))
+ .contentType(MediaType.APPLICATION_JSON_VALUE)
+ .accept(MediaType.APPLICATION_JSON_VALUE))
+ .andExpect(MockMvcResultMatchers.status().isOk());
+
+ String responseString =
+ mockMvc.perform(
+ MockMvcRequestBuilders.get(rolePath + "/" + roleId)
+ .header(tokenName, token)
+ .contentType(MediaType.APPLICATION_JSON_VALUE)
+ .accept(MediaType.APPLICATION_JSON_VALUE))
+ .andExpect(MockMvcResultMatchers.status().isOk())
+ .andDo(MockMvcResultHandlers.print())
+ .andReturn()
+ .getResponse()
+ .getContentAsString();
+
+ R<SysRole> r =
+ ObjectMapperUtils.fromJSON(responseString, new TypeReference<R<SysRole>>() {});
+ assertEquals(200, r.getCode());
+ assertNotNull(r.getData());
+ assertEquals(r.getData().getRoleName(), newRoleName);
+ }
+
+ @Test
+ @Order(5)
+ public void testDeleteRole() throws Exception {
+ String delResponseString =
+ mockMvc.perform(
+ MockMvcRequestBuilders.delete(rolePath + "/" + roleId)
+ .header(tokenName, token)
+ .contentType(MediaType.APPLICATION_JSON_VALUE)
+ .accept(MediaType.APPLICATION_JSON_VALUE))
+ .andExpect(MockMvcResultMatchers.status().isOk())
+ .andDo(MockMvcResultHandlers.print())
+ .andReturn()
+ .getResponse()
+ .getContentAsString();
+
+ R<?> result = ObjectMapperUtils.fromJSON(delResponseString, R.class);
+ assertEquals(200, result.getCode());
+ }
+
+ @Test
+ @Order(4)
+ public void testGetRoleList() throws Exception {
+ String responseString =
+ mockMvc.perform(
+ MockMvcRequestBuilders.get(rolePath + "/list")
+ .header(tokenName, token)
+ .contentType(MediaType.APPLICATION_JSON_VALUE)
+ .accept(MediaType.APPLICATION_JSON_VALUE))
+ .andExpect(MockMvcResultMatchers.status().isOk())
+ .andDo(MockMvcResultHandlers.print())
+ .andReturn()
+ .getResponse()
+ .getContentAsString();
+
+ PageR<?> r = ObjectMapperUtils.fromJSON(responseString, PageR.class);
+ assertNotNull(r);
+ assertTrue(
+ r.getData() != null
+ && ((r.getTotal() > 0 && r.getData().size() > 0)
+ || (r.getTotal() == 0 && r.getData().size() == 0)));
+ }
+}
diff --git a/pom.xml b/pom.xml
index 6fbec7d..1194f24 100644
--- a/pom.xml
+++ b/pom.xml
@@ -110,6 +110,8 @@ under the License.
*/
</spotless.license.header>
<mybatis-plus.version>3.5.3.1</mybatis-plus.version>
+ <sa-token.version>1.35.0.RC</sa-token.version>
+ <common-lang3.version>3.12.0</common-lang3.version>
</properties>
<dependencyManagement>
@@ -189,6 +191,19 @@ under the License.
<version>${mybatis-plus.version}</version>
</dependency>
+ <dependency>
+ <groupId>cn.dev33</groupId>
+ <artifactId>sa-token-spring-boot-starter</artifactId>
+ <version>${sa-token.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>${common-lang3.version}</version>
+ </dependency>
+
+
</dependencies>
</dependencyManagement>