diff --git a/api-portal/src/main/java/com/jmsoftware/apiportal/remoteapi/AuthCenterRemoteApi.java b/api-portal/src/main/java/com/jmsoftware/apiportal/remoteapi/AuthCenterRemoteApi.java index 45924a88..3624105a 100644 --- a/api-portal/src/main/java/com/jmsoftware/apiportal/remoteapi/AuthCenterRemoteApi.java +++ b/api-portal/src/main/java/com/jmsoftware/apiportal/remoteapi/AuthCenterRemoteApi.java @@ -4,6 +4,8 @@ import com.jmsoftware.common.bean.ResponseBodyBean; import com.jmsoftware.common.domain.authcenter.permission.GetPermissionListByRoleIdListPayload; import com.jmsoftware.common.domain.authcenter.permission.GetPermissionListByRoleIdListResponse; +import com.jmsoftware.common.domain.authcenter.permission.GetPermissionListByUserIdPayload; +import com.jmsoftware.common.domain.authcenter.permission.GetPermissionListByUserIdResponse; import com.jmsoftware.common.domain.authcenter.role.GetRoleListByUserIdPayload; import com.jmsoftware.common.domain.authcenter.role.GetRoleListByUserIdResponse; import com.jmsoftware.common.domain.authcenter.user.GetUserByLoginTokenPayload; @@ -65,4 +67,14 @@ public interface AuthCenterRemoteApi { @ValidateArgument @PostMapping("/permission-remote-api/get-permission-list-by-role-id-list") ResponseBodyBean getPermissionListByRoleIdList(@Valid @RequestBody GetPermissionListByRoleIdListPayload payload); + + /** + * Get permission list by user id response body bean. + * + * @param payload the payload + * @return the response body bean + */ + @ValidateArgument + @PostMapping("/permission-remote-api/get-permission-list-by-user-id") + ResponseBodyBean getPermissionListByUserId(@Valid @RequestBody GetPermissionListByUserIdPayload payload); } diff --git a/api-portal/src/main/java/com/jmsoftware/apiportal/universal/domain/ApiStatus.java b/api-portal/src/main/java/com/jmsoftware/apiportal/universal/domain/ApiStatus.java deleted file mode 100644 index 8c9e88b0..00000000 --- a/api-portal/src/main/java/com/jmsoftware/apiportal/universal/domain/ApiStatus.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.jmsoftware.apiportal.universal.domain; - -import lombok.Getter; - -/** - * Description: ApiStatus, change description here. - * - * @author Johnny Miller (鍾俊), email: johnnysviva@outlook.com - * @date 2019-04-07 23:32 - **/ -@Getter -public enum ApiStatus { - /** - * Idled API (not stored in db). - */ - IDLED(0), - /** - * API in used (stored in db). - */ - IN_USE(1); - - private final Integer status; - - ApiStatus(Integer status) { - this.status = status; - } - - /** - * Get ApiStatus by status. - * - * @param status status code - * @return ApiStatus enum - */ - public static ApiStatus getByStatus(Integer status) { - ApiStatus[] apiStatuses = ApiStatus.values(); - for (ApiStatus apiStatus : apiStatuses) { - if (apiStatus.status.equals(status)) { - return apiStatus; - } - } - return null; - } -} diff --git a/api-portal/src/main/java/com/jmsoftware/apiportal/universal/domain/GetApiListPLO.java b/api-portal/src/main/java/com/jmsoftware/apiportal/universal/domain/GetApiListPLO.java deleted file mode 100644 index cbb7d800..00000000 --- a/api-portal/src/main/java/com/jmsoftware/apiportal/universal/domain/GetApiListPLO.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.jmsoftware.apiportal.universal.domain; - -import com.jmsoftware.common.bean.PaginationBase; -import lombok.Data; -import lombok.EqualsAndHashCode; - -/** - *

GetApiListPLO

- *

Change description here

- * - * @author Johnny Miller (鍾俊), email: johnnysviva@outlook.com - * @date 2019-05-11 13:48 - **/ -@Data -@EqualsAndHashCode(callSuper = true) -public class GetApiListPLO extends PaginationBase { -} diff --git a/api-portal/src/main/java/com/jmsoftware/apiportal/universal/domain/GetUserInfoRO.java b/api-portal/src/main/java/com/jmsoftware/apiportal/universal/domain/GetUserInfoRO.java deleted file mode 100644 index 1ecd37cd..00000000 --- a/api-portal/src/main/java/com/jmsoftware/apiportal/universal/domain/GetUserInfoRO.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.jmsoftware.apiportal.universal.domain; - -import lombok.Data; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -/** - *

GetUserInfoRO

- *

Change description here

- * - * @author Johnny Miller (鍾俊), email: johnnysviva@outlook.com - * @date 2019-06-30 11:01 - **/ -@Data -public class GetUserInfoRO { - private Long id; - private String username; - private String email; - private String cellphone; - private String fullName; - private Date birthday; - private String gender; - private Integer status; - private List usersRoles = new ArrayList<>(); - - @Data - public static class UsersRole { - private Long roleId; - private String roleName; - private String roleDescription; - } -} diff --git a/api-portal/src/main/java/com/jmsoftware/apiportal/universal/domain/PermissionPO.java b/api-portal/src/main/java/com/jmsoftware/apiportal/universal/domain/PermissionPO.java deleted file mode 100644 index 84f835ef..00000000 --- a/api-portal/src/main/java/com/jmsoftware/apiportal/universal/domain/PermissionPO.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.jmsoftware.apiportal.universal.domain; - -import lombok.Data; - -import java.util.Date; - -/** - *

PermissionPO

- *

Persistence class for table `t_permission`

- * - * @author Johnny Miller (鍾俊), email: johnnysviva@outlook.com - * @date 2019-03-23 19:48 - **/ -@Data -public class PermissionPO { - /** - * Primary key - */ - private Long id; - /** - * URL. If type of record is page (1), URL stands for route; if type of record is button (2), URL stands for API - */ - private String url; - /** - * PermissionPO description - */ - private String description; - /** - * PermissionPO type. Page-1, Button-2 - */ - private Integer type; - /** - * PermissionPO expression. - */ - private String permissionExpression; - /** - * HTTP method of API. - */ - private String method; - /** - * Sort. - */ - private Integer sort; - /** - * Primary key of parent. - */ - private Long parentId; - /** - * Deleted flag - */ - private Byte deleted; - /** - * Created time - */ - private Date createdTime; - /** - * Modified time - */ - private Date modifiedTime; -} diff --git a/api-portal/src/main/java/com/jmsoftware/apiportal/universal/domain/RolePO.java b/api-portal/src/main/java/com/jmsoftware/apiportal/universal/domain/RolePO.java deleted file mode 100644 index afe61506..00000000 --- a/api-portal/src/main/java/com/jmsoftware/apiportal/universal/domain/RolePO.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.jmsoftware.apiportal.universal.domain; - -import lombok.Data; - -import java.util.Date; - -/** - *

RolePO

- *

Persistence class for table `t_role`

- * - * @author Johnny Miller (鍾俊), email: johnnysviva@outlook.com - * @date 2019-03-23 19:50 - **/ -@Data -public class RolePO { - /** - * Primary key - */ - private Long id; - /** - * Role name - */ - private String name; - /** - * Role description - */ - private String description; - /** - * Create time - */ - private Date createdTime; - /** - * Modify time - */ - private Date modifiedTime; -} diff --git a/api-portal/src/main/java/com/jmsoftware/apiportal/universal/domain/RolePermissionPO.java b/api-portal/src/main/java/com/jmsoftware/apiportal/universal/domain/RolePermissionPO.java deleted file mode 100644 index 0faf19b7..00000000 --- a/api-portal/src/main/java/com/jmsoftware/apiportal/universal/domain/RolePermissionPO.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.jmsoftware.apiportal.universal.domain; - -import lombok.Data; - -/** - *

RolePermissionPO

- *

Role-permission relation. Persistence class for table `t_role_permission`

- * - * @author Johnny Miller (鍾俊), email: johnnysviva@outlook.com - * @date 2019-03-23 19:50 - **/ -@Data -public class RolePermissionPO { - /** - * Role's ID. - */ - private Long roleId; - /** - * Permission's ID. - */ - private Long permissionId; -} diff --git a/api-portal/src/main/java/com/jmsoftware/apiportal/universal/mapper/PermissionMapper.java b/api-portal/src/main/java/com/jmsoftware/apiportal/universal/mapper/PermissionMapper.java deleted file mode 100644 index f1e58da2..00000000 --- a/api-portal/src/main/java/com/jmsoftware/apiportal/universal/mapper/PermissionMapper.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.jmsoftware.apiportal.universal.mapper; - -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.jmsoftware.apiportal.universal.domain.PermissionPO; -import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Param; -import org.springframework.stereotype.Component; - -import java.util.List; - -/** - *

PermissionMapper

- *

CRUD operations for table `t_permission`

- * - * @author Johnny Miller (鍾俊), email: johnnysviva@outlook.com - * @date 2019-03-02 17:52 - **/ -@Mapper -@Component -public interface PermissionMapper extends BaseMapper { - /** - * Save a permission - * - * @param po persistence object - * @return permission's ID - */ - Long insertPermission(PermissionPO po); - - /** - * Select permission list by role id - * - * @param ids Role's id list - * @return Permission list - */ - List selectByRoleIdList(List ids); - - /** - * Find permission by URL. - * - * @param url URL - * @return permission - */ - Long countInUseApiByUrl(@Param("url") String url); - - /** - * Find APIs by URL prefix. - * - * @param urlPrefix URL prefix - * @return permissions - */ - List selectApisByUrlPrefix(String urlPrefix); - - /** - * Select API page list - * - * @param page pagination object - * @return API list - */ - IPage selectApiPageList(Page page); -} diff --git a/api-portal/src/main/java/com/jmsoftware/apiportal/universal/mapper/RoleMapper.java b/api-portal/src/main/java/com/jmsoftware/apiportal/universal/mapper/RoleMapper.java deleted file mode 100644 index 1a7843ab..00000000 --- a/api-portal/src/main/java/com/jmsoftware/apiportal/universal/mapper/RoleMapper.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.jmsoftware.apiportal.universal.mapper; - -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.jmsoftware.apiportal.universal.domain.RolePO; -import org.apache.ibatis.annotations.Mapper; -import org.springframework.stereotype.Component; - -import java.util.List; - -/** - *

RoleMapper

- *

CRUD operations for table `t_role`

- * - * @author Johnny Miller (鍾俊), email: johnnysviva@outlook.com - * @date 2019-03-02 17:52 - **/ -@Mapper -@Component -public interface RoleMapper extends BaseMapper { - /** - * Select role by user ID. - * - * @param userId User ID - * @return Roles - */ - List selectByUserId(Long userId); - - /** - * Select page list - * - * @param page page object - * @return role page list - */ - List selectPageList(Page page); - - /** - * Check role name's uniqueness - *

- * If id is null, then check for creating role's name; otherwise, check for created role's name - * - * @param po persistence object - * @return the occurrence of the name of role - */ - Integer checkRoleName(RolePO po); - - /** - * Insert role - * - * @param po persistence object - * @return primary key - */ - Long insertRole(RolePO po); - - /** - * Select role by name - * - * @param name role name - * @return role - */ - RolePO selectRoleByName(String name); - - /** - * Update role by ID - * - * @param po persistence object - * @return affected row - */ - int updateRoleById(RolePO po); - - /** - * Selection role list for selection - * - * @param page pagination object - * @return role page list - */ - IPage selectRoleListForSelection(Page page); -} diff --git a/api-portal/src/main/java/com/jmsoftware/apiportal/universal/mapper/RolePermissionMapper.java b/api-portal/src/main/java/com/jmsoftware/apiportal/universal/mapper/RolePermissionMapper.java deleted file mode 100644 index dcb0710c..00000000 --- a/api-portal/src/main/java/com/jmsoftware/apiportal/universal/mapper/RolePermissionMapper.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.jmsoftware.apiportal.universal.mapper; - -import com.jmsoftware.apiportal.universal.domain.RolePermissionPO; -import org.apache.ibatis.annotations.Mapper; -import org.springframework.stereotype.Component; - -import java.util.List; - -/** - *

RolePermissionMapper

- *

CRUD operations for table `t_role_permission`

- * - * @author Johnny Miller (鍾俊), email: johnnysviva@outlook.com - * @date 2019-03-02 17:55 - **/ -@Mapper -@Component -public interface RolePermissionMapper { - /** - * Delete by role's ID - * - * @param po persistence object - * @return affected row - */ - Integer deleteByRoleId(RolePermissionPO po); - - /** - * Insert a batch of records - * - * @param poList PO list - * @return affected row - */ - Integer insertBatch(List poList); -} diff --git a/api-portal/src/main/java/com/jmsoftware/apiportal/universal/mapper/UserRoleMapper.java b/api-portal/src/main/java/com/jmsoftware/apiportal/universal/mapper/UserRoleMapper.java deleted file mode 100644 index 6a76fd51..00000000 --- a/api-portal/src/main/java/com/jmsoftware/apiportal/universal/mapper/UserRoleMapper.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.jmsoftware.apiportal.universal.mapper; - -/** - *

UserRoleMapper

- *

CRUD operations for table `t_user_role`

- * - * @author Johnny Miller (鍾俊), email: johnnysviva@outlook.com - * @date 2019-03-02 17:33 - **/ -public interface UserRoleMapper { -} diff --git a/api-portal/src/main/java/com/jmsoftware/apiportal/universal/service/PermissionService.java b/api-portal/src/main/java/com/jmsoftware/apiportal/universal/service/PermissionService.java deleted file mode 100644 index c243c0c1..00000000 --- a/api-portal/src/main/java/com/jmsoftware/apiportal/universal/service/PermissionService.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.jmsoftware.apiportal.universal.service; - - -import com.jmsoftware.apiportal.universal.domain.ApiStatus; -import com.jmsoftware.apiportal.universal.domain.GetApiListPLO; -import com.jmsoftware.apiportal.universal.domain.PermissionPO; - -import java.util.List; - -/** - *

PermissionService

- *

Change description here

- * - * @author Johnny Miller (鍾俊), email: johnnysviva@outlook.com - * @date 2019-05-10 20:45 - **/ -public interface PermissionService { - /** - * Save permissionPO - * - * @param po permissionPO - * @return true - successful operation; false - failed operation - */ - boolean savePermission(PermissionPO po); - - /** - * Select permission list by role id - * - * @param ids Role's id list - * @return PermissionPO list - */ - List selectByRoleIdList(List ids); - - /** - * Check if API is in use by URL - * - * @param url URL - * @return api status - * @see ApiStatus - */ - ApiStatus checkApiIsInUse(String url); - - /** - * Find APIs by URL prefix. - * - * @param urlPrefix URL prefix - * @return permissions - */ - List selectApisByUrlPrefix(String urlPrefix); - - /** - * Query API list - * - * @param plo payload object - * @return API list - */ - List queryApiList(GetApiListPLO plo); -} diff --git a/api-portal/src/main/java/com/jmsoftware/apiportal/universal/service/RoleService.java b/api-portal/src/main/java/com/jmsoftware/apiportal/universal/service/RoleService.java deleted file mode 100644 index 6b7b7a0a..00000000 --- a/api-portal/src/main/java/com/jmsoftware/apiportal/universal/service/RoleService.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.jmsoftware.apiportal.universal.service; - -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.jmsoftware.apiportal.universal.domain.RolePO; - -import java.util.List; - -/** - *

RoleService

- *

Change description here

- * - * @author Johnny Miller (鍾俊), email: johnnysviva@outlook.com - * @date 2019-05-18 12:03 - **/ -public interface RoleService { - /** - * Get role list - * - * @param page page object - * @return role list - */ - List getList(Page page); - - /** - * Check the uniqueness of name of role - *

- * If id is null, then check for creating role's name; otherwise, check for created role's name - * - * @param po persistence object - * @return true - available; false - not available - */ - boolean checkRoleName(RolePO po); - - /** - * Insert a role - * - * @param po persistence object - * @return true - insert successfully; false - insert failure - */ - boolean insertRole(RolePO po); - - /** - * Handle the name of role - * - * @param roleName the name of role - * @return processed role name - */ - String handleRoleName(String roleName); - - /** - * Search role by name - * - * @param roleName role name - * @return role - */ - RolePO searchRole(String roleName); - - /** - * Update role - * - * @param po persistence object - * @return true - update successfully; false - update failure - */ - boolean updateRole(RolePO po); - - /** - * Get roles by user ID - * - * @param userId user ID - * @return role list - */ - List getRolesByUserId(Long userId); - - /** - * Get role list for selection - * - * @param page page object - * @return role list - */ - List getListForSelection(Page page); -} diff --git a/api-portal/src/main/java/com/jmsoftware/apiportal/universal/service/impl/CustomUserDetailsServiceImpl.java b/api-portal/src/main/java/com/jmsoftware/apiportal/universal/service/impl/CustomUserDetailsServiceImpl.java index bbc23c8e..6fea9101 100644 --- a/api-portal/src/main/java/com/jmsoftware/apiportal/universal/service/impl/CustomUserDetailsServiceImpl.java +++ b/api-portal/src/main/java/com/jmsoftware/apiportal/universal/service/impl/CustomUserDetailsServiceImpl.java @@ -37,30 +37,31 @@ public class CustomUserDetailsServiceImpl implements UserDetailsService { @Override @SneakyThrows public UserDetails loadUserByUsername(String credentials) throws UsernameNotFoundException { - val payload = new GetUserByLoginTokenPayload(); - payload.setLoginToken(credentials); - val response = authCenterRemoteApi.getUserByLoginToken(payload); - val data = response.getData(); - if (ObjectUtil.isNull(data)) { + val getUserByLoginTokenPayload = new GetUserByLoginTokenPayload(); + getUserByLoginTokenPayload.setLoginToken(credentials); + val getUserByLoginTokenResponseResponseBody = + authCenterRemoteApi.getUserByLoginToken(getUserByLoginTokenPayload); + val getUserByLoginTokenResponse = getUserByLoginTokenResponseResponseBody.getData(); + if (ObjectUtil.isNull(getUserByLoginTokenResponse)) { val errorMessage = String.format("User's account not found, credentials: %s", credentials); log.error(errorMessage); throw new UsernameNotFoundException(errorMessage); } - val payload1 = new GetRoleListByUserIdPayload(); - payload1.setUserId(data.getId()); - val roleListByUserIdResponse = authCenterRemoteApi.getRoleListByUserId(payload1); - val roleList = roleListByUserIdResponse.getData().getRoleList(); + val getRoleListByUserIdPayload = new GetRoleListByUserIdPayload(); + getRoleListByUserIdPayload.setUserId(getUserByLoginTokenResponse.getId()); + val getRoleListByUserIdResponseResponseBody = + authCenterRemoteApi.getRoleListByUserId(getRoleListByUserIdPayload); + val roleList = getRoleListByUserIdResponseResponseBody.getData().getRoleList(); if (CollUtil.isEmpty(roleList)) { throw new SecurityException(HttpStatus.ROLE_NOT_FOUND); } - val payload2 = new GetPermissionListByRoleIdListPayload(); - roleList.forEach(role -> { - payload2.getRoleIdList().add(role.getId()); - }); - val permissionListByRoleIdListResponse = authCenterRemoteApi.getPermissionListByRoleIdList(payload2); + val getPermissionListByRoleIdListPayload = new GetPermissionListByRoleIdListPayload(); + roleList.forEach(role -> getPermissionListByRoleIdListPayload.getRoleIdList().add(role.getId())); + val permissionListByRoleIdListResponseBody = + authCenterRemoteApi.getPermissionListByRoleIdList(getPermissionListByRoleIdListPayload); val roleNameList = roleList.stream().map(GetRoleListByUserIdResponse.Role::getName).collect(Collectors.toList()); - return UserPrincipal.create(data, roleNameList, - permissionListByRoleIdListResponse.getData().getPermissionList()); + return UserPrincipal.create(getUserByLoginTokenResponse, roleNameList, + permissionListByRoleIdListResponseBody.getData().getPermissionList()); } } diff --git a/api-portal/src/main/java/com/jmsoftware/apiportal/universal/service/impl/PermissionServiceImpl.java b/api-portal/src/main/java/com/jmsoftware/apiportal/universal/service/impl/PermissionServiceImpl.java deleted file mode 100644 index 10a3a55c..00000000 --- a/api-portal/src/main/java/com/jmsoftware/apiportal/universal/service/impl/PermissionServiceImpl.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.jmsoftware.apiportal.universal.service.impl; - -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.jmsoftware.apiportal.universal.domain.ApiStatus; -import com.jmsoftware.apiportal.universal.domain.GetApiListPLO; -import com.jmsoftware.apiportal.universal.domain.PermissionPO; -import com.jmsoftware.apiportal.universal.mapper.PermissionMapper; -import com.jmsoftware.apiportal.universal.service.PermissionService; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; - -import java.util.List; - -/** - *

PermissionServiceImpl

- *

Change description here

- * - * @author Johnny Miller (鍾俊), email: johnnysviva@outlook.com - * @date 2019-05-10 20:46 - **/ -@Slf4j -@Service -@RequiredArgsConstructor -public class PermissionServiceImpl implements PermissionService { - private final PermissionMapper permissionMapper; - - @Override - public boolean savePermission(PermissionPO po) { - return permissionMapper.insertPermission(po) > 0; - } - - @Override - public List selectByRoleIdList(List ids) { - return permissionMapper.selectByRoleIdList(ids); - } - - @Override - public ApiStatus checkApiIsInUse(String url) { - return permissionMapper.countInUseApiByUrl(url) == 1 ? ApiStatus.IN_USE : ApiStatus.IDLED; - } - - @Override - public List selectApisByUrlPrefix(String urlPrefix) { - return permissionMapper.selectApisByUrlPrefix(urlPrefix); - } - - @Override - public List queryApiList(GetApiListPLO plo) { - return permissionMapper.selectApiPageList(new Page(plo.getCurrentPage(), plo.getPageSize())).getRecords(); - } -} diff --git a/api-portal/src/main/java/com/jmsoftware/apiportal/universal/service/impl/RbacAuthorityServiceImpl.java b/api-portal/src/main/java/com/jmsoftware/apiportal/universal/service/impl/RbacAuthorityServiceImpl.java index db1f8b3e..879de6eb 100644 --- a/api-portal/src/main/java/com/jmsoftware/apiportal/universal/service/impl/RbacAuthorityServiceImpl.java +++ b/api-portal/src/main/java/com/jmsoftware/apiportal/universal/service/impl/RbacAuthorityServiceImpl.java @@ -7,14 +7,11 @@ import com.google.common.collect.Multimap; import com.jmsoftware.apiportal.remoteapi.AuthCenterRemoteApi; import com.jmsoftware.apiportal.universal.configuration.CustomConfiguration; -import com.jmsoftware.apiportal.universal.domain.PermissionType; -import com.jmsoftware.apiportal.universal.domain.RolePO; import com.jmsoftware.apiportal.universal.domain.UserPrincipal; import com.jmsoftware.apiportal.universal.service.RbacAuthorityService; -import com.jmsoftware.apiportal.universal.service.RoleService; import com.jmsoftware.common.constant.HttpStatus; -import com.jmsoftware.common.domain.authcenter.permission.GetPermissionListByRoleIdListPayload; -import com.jmsoftware.common.domain.authcenter.permission.GetPermissionListByRoleIdListResponse; +import com.jmsoftware.common.domain.authcenter.permission.GetPermissionListByUserIdPayload; +import com.jmsoftware.common.domain.authcenter.permission.PermissionType; import com.jmsoftware.common.exception.SecurityException; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; @@ -24,11 +21,9 @@ import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.web.util.matcher.AntPathRequestMatcher; import org.springframework.stereotype.Service; -import org.springframework.web.servlet.mvc.condition.RequestMethodsRequestCondition; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; import javax.servlet.http.HttpServletRequest; -import java.util.List; import java.util.stream.Collectors; /** @@ -43,8 +38,6 @@ @RequiredArgsConstructor public class RbacAuthorityServiceImpl implements RbacAuthorityService { private final AuthCenterRemoteApi authCenterRemoteApi; - - private final RoleService roleService; private final RequestMappingHandlerMapping mapping; private final CustomConfiguration customConfiguration; private final JwtServiceImpl jwtServiceImpl; @@ -70,30 +63,26 @@ public boolean hasPermission(HttpServletRequest request, Authentication authenti log.error("Invalid user principal. {}", principal); return false; } - UserPrincipal userPrincipal = (UserPrincipal) principal; - Long userId = userPrincipal.getId(); - // TODO: auth-center roleService.getRolesByUserId(userId) - List rolesByUserId = roleService.getRolesByUserId(userId); - val payload = new GetPermissionListByRoleIdListPayload(); - rolesByUserId.forEach(rolePO -> { - payload.getRoleIdList().add(rolePO.getId()); - }); - val permissionListByRoleIdListResponse = authCenterRemoteApi.getPermissionListByRoleIdList(payload); - val permissionList = permissionListByRoleIdListResponse.getData().getPermissionList(); + val userPrincipal = (UserPrincipal) principal; + val userId = userPrincipal.getId(); + val getPermissionListByUserIdPayload = new GetPermissionListByUserIdPayload(); + getPermissionListByUserIdPayload.setUserId(userId); + val getPermissionListByUserIdResponse = + authCenterRemoteApi.getPermissionListByUserId(getPermissionListByUserIdPayload); + val permissionList = getPermissionListByUserIdResponse.getData().getPermissionList(); // Filter button permission for frond-end - List buttonPermissionList = - permissionList.stream() - // Sieve out page permissions - .filter(permission -> ObjectUtil.equal(permission.getType(), - PermissionType.BUTTON.getType())) - // Sieve out permission that has no URL - .filter(permission -> StrUtil.isNotBlank(permission.getUrl())) - // Sieve out permission that has no method - .filter(permission -> StrUtil.isNotBlank(permission.getMethod())) - .collect(Collectors.toList()); - for (GetPermissionListByRoleIdListResponse.Permission btnPerm : buttonPermissionList) { + val buttonPermissionList = permissionList.stream() + // Sieve out page permissions + .filter(permission -> ObjectUtil.equal(permission.getType(), + PermissionType.BUTTON.getType())) + // Sieve out permission that has no URL + .filter(permission -> StrUtil.isNotBlank(permission.getUrl())) + // Sieve out permission that has no method + .filter(permission -> StrUtil.isNotBlank(permission.getMethod())) + .collect(Collectors.toList()); + for (val buttonPermission : buttonPermissionList) { // TODO: check is AntPathRequestMatcher supports RESTFul request - AntPathRequestMatcher antPathMatcher = new AntPathRequestMatcher(btnPerm.getUrl(), btnPerm.getMethod()); + val antPathMatcher = new AntPathRequestMatcher(buttonPermission.getUrl(), buttonPermission.getMethod()); if (antPathMatcher.matches(request)) { log.info("Resource [{}] {} is accessible for user(username: {})", request.getMethod(), request.getRequestURL(), username); @@ -120,7 +109,7 @@ private void checkRequest(HttpServletRequest request) { // 1:new AntPathRequestMatcher(uri,method) 这种方式可以直接判断方法是否匹配, // 因为这里我们把 方法不匹配 自定义抛出,所以,我们使用第2种方式创建 // 2:new AntPathRequestMatcher(uri) 这种方式不校验请求方法,只校验请求路径 - AntPathRequestMatcher antPathMatcher = new AntPathRequestMatcher(uri); + val antPathMatcher = new AntPathRequestMatcher(uri); if (antPathMatcher.matches(request)) { if (!urlMapping.get(uri).contains(currentMethod)) { throw new SecurityException(HttpStatus.METHOD_NOT_ALLOWED); @@ -144,12 +133,10 @@ private Multimap allUrlMapping() { handlerMethods.forEach((key, value) -> { // 获取当前 key 下的获取所有URL val url = key.getPatternsCondition().getPatterns(); - RequestMethodsRequestCondition method = key.getMethodsCondition(); + val method = key.getMethodsCondition(); // 为每个URL添加所有的请求方法 - url.forEach(item -> urlMapping.putAll(item, method.getMethods() - .stream() - .map(Enum::toString) - .collect(Collectors.toList()))); + url.forEach(item -> urlMapping.putAll(item, + method.getMethods().stream().map(Enum::toString).collect(Collectors.toList()))); }); return urlMapping; } diff --git a/api-portal/src/main/java/com/jmsoftware/apiportal/universal/service/impl/RoleServiceImpl.java b/api-portal/src/main/java/com/jmsoftware/apiportal/universal/service/impl/RoleServiceImpl.java deleted file mode 100644 index eade8346..00000000 --- a/api-portal/src/main/java/com/jmsoftware/apiportal/universal/service/impl/RoleServiceImpl.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.jmsoftware.apiportal.universal.service.impl; - -import cn.hutool.core.util.StrUtil; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.jmsoftware.apiportal.universal.domain.RolePO; -import com.jmsoftware.apiportal.universal.mapper.RoleMapper; -import com.jmsoftware.apiportal.universal.service.RoleService; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; - -import java.util.List; - -/** - *

RoleServiceImpl

- *

Change description here

- * - * @author Johnny Miller (鍾俊), email: johnnysviva@outlook.com - * @date 2019-05-18 12:03 - **/ -@Service -@RequiredArgsConstructor -public class RoleServiceImpl implements RoleService { - private final RoleMapper roleMapper; - - @Override - public List getList(Page page) { - return roleMapper.selectPageList(page); - } - - @Override - public boolean checkRoleName(RolePO po) { - return roleMapper.checkRoleName(po) == 0; - } - - @Override - public boolean insertRole(RolePO po) { - return roleMapper.insertRole(po) > 0; - } - - @Override - public String handleRoleName(String roleName) { - String processedRoleName = StrUtil.trim(roleName).toLowerCase(); - return processedRoleName.replaceAll("\\s", "_"); - } - - @Override - public RolePO searchRole(String roleName) { - return roleMapper.selectRoleByName(roleName); - } - - @Override - public boolean updateRole(RolePO po) { - return roleMapper.updateRoleById(po) == 1; - } - - @Override - public List getRolesByUserId(Long userId) { - return roleMapper.selectByUserId(userId); - } - - @Override - public List getListForSelection(Page page) { - return roleMapper.selectRoleListForSelection(page).getRecords(); - } -} diff --git a/api-portal/src/main/resources/mapper/.empty b/api-portal/src/main/resources/mapper/.empty deleted file mode 100644 index e69de29b..00000000 diff --git a/api-portal/src/main/resources/mapper/rbac/PermissionMapper.xml b/api-portal/src/main/resources/mapper/rbac/PermissionMapper.xml deleted file mode 100644 index 423fb908..00000000 --- a/api-portal/src/main/resources/mapper/rbac/PermissionMapper.xml +++ /dev/null @@ -1,71 +0,0 @@ - - - - - INSERT INTO permission(url, - description, - type, - method, - created_time, - modified_time) - VALUES (#{url}, - #{description}, - #{type}, - #{method}, - now(), - now()) - - - - - - - - - - diff --git a/api-portal/src/main/resources/mapper/rbac/RoleMapper.xml b/api-portal/src/main/resources/mapper/rbac/RoleMapper.xml deleted file mode 100644 index 9346a876..00000000 --- a/api-portal/src/main/resources/mapper/rbac/RoleMapper.xml +++ /dev/null @@ -1,80 +0,0 @@ - - - - - id, - `name`, - description, - created_time, - modified_time - - - - - - - - - - - - - - - - - - INSERT INTO role(name, description, created_time, modified_time) - VALUES (#{name}, #{description}, now(), now()) - - - - - - UPDATE role - SET name = #{name}, - description = #{description}, - modified_time = now() - WHERE id = #{id} - - - - diff --git a/api-portal/src/main/resources/mapper/rbac/RolePermissionMapper.xml b/api-portal/src/main/resources/mapper/rbac/RolePermissionMapper.xml deleted file mode 100644 index 82a81bc6..00000000 --- a/api-portal/src/main/resources/mapper/rbac/RolePermissionMapper.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - DELETE - FROM role_permission - WHERE role_id = #{roleId} - - - - INSERT INTO role_permission(role_id, permission_id) - VALUES - - (#{item.roleId}, #{item.permissionId}) - - - diff --git a/auth-center/src/main/java/com/jmsoftware/authcenter/permission/mapper/PermissionMapper.java b/auth-center/src/main/java/com/jmsoftware/authcenter/permission/mapper/PermissionMapper.java index 75f21141..cd335828 100644 --- a/auth-center/src/main/java/com/jmsoftware/authcenter/permission/mapper/PermissionMapper.java +++ b/auth-center/src/main/java/com/jmsoftware/authcenter/permission/mapper/PermissionMapper.java @@ -72,4 +72,12 @@ public interface PermissionMapper { * @return the list */ List selectPermissionListByRoleIdList(List roleIdList); + + /** + * Select permission list by user id list. + * + * @param userId the user id + * @return the list + */ + List selectPermissionListByUserId(Long userId); } diff --git a/auth-center/src/main/java/com/jmsoftware/authcenter/permission/remote/PermissionRemoteApiController.java b/auth-center/src/main/java/com/jmsoftware/authcenter/permission/remote/PermissionRemoteApiController.java index 9d589c6c..28756a05 100644 --- a/auth-center/src/main/java/com/jmsoftware/authcenter/permission/remote/PermissionRemoteApiController.java +++ b/auth-center/src/main/java/com/jmsoftware/authcenter/permission/remote/PermissionRemoteApiController.java @@ -4,7 +4,10 @@ import com.jmsoftware.common.bean.ResponseBodyBean; import com.jmsoftware.common.domain.authcenter.permission.GetPermissionListByRoleIdListPayload; import com.jmsoftware.common.domain.authcenter.permission.GetPermissionListByRoleIdListResponse; +import com.jmsoftware.common.domain.authcenter.permission.GetPermissionListByUserIdPayload; +import com.jmsoftware.common.domain.authcenter.permission.GetPermissionListByUserIdResponse; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -29,7 +32,14 @@ public class PermissionRemoteApiController { private final PermissionService permissionService; @PostMapping("/get-permission-list-by-role-id-list") + @ApiOperation(value = "Get permission list by role id list", notes = "GGet permission list by role id list") public ResponseBodyBean getPermissionListByRoleIdList(@Valid @RequestBody GetPermissionListByRoleIdListPayload payload) { return ResponseBodyBean.ofSuccess(permissionService.getPermissionListByRoleIdList(payload)); } + + @PostMapping("/get-permission-list-by-user-id") + @ApiOperation(value = "Get permission list by user id", notes = "Get permission list by user id") + public ResponseBodyBean getPermissionListByUserId(@Valid @RequestBody GetPermissionListByUserIdPayload payload) { + return ResponseBodyBean.ofSuccess(permissionService.getPermissionListByUserId(payload)); + } } diff --git a/auth-center/src/main/java/com/jmsoftware/authcenter/permission/service/PermissionService.java b/auth-center/src/main/java/com/jmsoftware/authcenter/permission/service/PermissionService.java index 0a189b37..e514fe20 100644 --- a/auth-center/src/main/java/com/jmsoftware/authcenter/permission/service/PermissionService.java +++ b/auth-center/src/main/java/com/jmsoftware/authcenter/permission/service/PermissionService.java @@ -3,6 +3,8 @@ import com.jmsoftware.authcenter.permission.entity.PermissionPersistence; import com.jmsoftware.common.domain.authcenter.permission.GetPermissionListByRoleIdListPayload; import com.jmsoftware.common.domain.authcenter.permission.GetPermissionListByRoleIdListResponse; +import com.jmsoftware.common.domain.authcenter.permission.GetPermissionListByUserIdPayload; +import com.jmsoftware.common.domain.authcenter.permission.GetPermissionListByUserIdResponse; import lombok.NonNull; import java.util.List; @@ -72,4 +74,20 @@ public interface PermissionService { * @return the permission list by role id list */ List getPermissionListByRoleIdList(@NonNull List roleIdList); + + /** + * Gets permission list by user id. + * + * @param payload the payload + * @return the permission list by user id + */ + GetPermissionListByUserIdResponse getPermissionListByUserId(GetPermissionListByUserIdPayload payload); + + /** + * Gets permission list by user id. + * + * @param userId the user id + * @return the permission list by user id + */ + List getPermissionListByUserId(@NonNull Long userId); } diff --git a/auth-center/src/main/java/com/jmsoftware/authcenter/permission/service/impl/PermissionServiceImpl.java b/auth-center/src/main/java/com/jmsoftware/authcenter/permission/service/impl/PermissionServiceImpl.java index 32c6f81c..58428844 100644 --- a/auth-center/src/main/java/com/jmsoftware/authcenter/permission/service/impl/PermissionServiceImpl.java +++ b/auth-center/src/main/java/com/jmsoftware/authcenter/permission/service/impl/PermissionServiceImpl.java @@ -8,6 +8,8 @@ import com.jmsoftware.authcenter.universal.aspect.ValidateArgument; import com.jmsoftware.common.domain.authcenter.permission.GetPermissionListByRoleIdListPayload; import com.jmsoftware.common.domain.authcenter.permission.GetPermissionListByRoleIdListResponse; +import com.jmsoftware.common.domain.authcenter.permission.GetPermissionListByUserIdPayload; +import com.jmsoftware.common.domain.authcenter.permission.GetPermissionListByUserIdResponse; import lombok.NonNull; import lombok.val; import org.springframework.stereotype.Service; @@ -78,4 +80,22 @@ public List getPermissionListByRoleIdList(@NonNull List { + val permission = new GetPermissionListByUserIdResponse.Permission(); + BeanUtil.copyProperties(permissionPersistence, permission); + response.getPermissionList().add(permission); + }); + return response; + } + + @Override + public List getPermissionListByUserId(@NonNull Long userId) { + return permissionMapper.selectPermissionListByUserId(userId); + } } diff --git a/auth-center/src/main/resources/mapper/permission/PermissionMapper.xml b/auth-center/src/main/resources/mapper/permission/PermissionMapper.xml index b078b508..cd950dfa 100644 --- a/auth-center/src/main/resources/mapper/permission/PermissionMapper.xml +++ b/auth-center/src/main/resources/mapper/permission/PermissionMapper.xml @@ -161,4 +161,18 @@ #{item} + + diff --git a/common/src/main/java/com/jmsoftware/common/domain/authcenter/permission/GetPermissionListByUserIdPayload.java b/common/src/main/java/com/jmsoftware/common/domain/authcenter/permission/GetPermissionListByUserIdPayload.java new file mode 100644 index 00000000..4611a83e --- /dev/null +++ b/common/src/main/java/com/jmsoftware/common/domain/authcenter/permission/GetPermissionListByUserIdPayload.java @@ -0,0 +1,22 @@ +package com.jmsoftware.common.domain.authcenter.permission; + +import lombok.Data; + +import javax.validation.constraints.NotNull; + +/** + *

GetPermissionListByUserIdPayload

+ *

+ * Change description here. + * + * @author Johnny Miller (鍾俊), email: johnnysviva@outlook.com + * @date 5/12/20 9:03 AM + **/ +@Data +public class GetPermissionListByUserIdPayload { + /** + * The User id. + */ + @NotNull + private Long userId; +} diff --git a/common/src/main/java/com/jmsoftware/common/domain/authcenter/permission/GetPermissionListByUserIdResponse.java b/common/src/main/java/com/jmsoftware/common/domain/authcenter/permission/GetPermissionListByUserIdResponse.java new file mode 100644 index 00000000..b6b1a508 --- /dev/null +++ b/common/src/main/java/com/jmsoftware/common/domain/authcenter/permission/GetPermissionListByUserIdResponse.java @@ -0,0 +1,42 @@ +package com.jmsoftware.common.domain.authcenter.permission; + +import lombok.Data; + +import java.util.LinkedList; +import java.util.List; + +/** + *

GetPermissionListByUserIdResponse

+ *

+ * Change description here. + * + * @author Johnny Miller (鍾俊), email: johnnysviva@outlook.com + * @date 5/12/20 9:04 AM + **/ +@Data +public class GetPermissionListByUserIdResponse { + /** + * The Permission list. + */ + private final List permissionList = new LinkedList<>(); + + @Data + public static class Permission { + /** + * The Url. + */ + private String url; + /** + * The Type. + */ + private Integer type; + /** + * The Permission expression. + */ + private String permissionExpression; + /** + * The Method. + */ + private String method; + } +} diff --git a/api-portal/src/main/java/com/jmsoftware/apiportal/universal/domain/PermissionType.java b/common/src/main/java/com/jmsoftware/common/domain/authcenter/permission/PermissionType.java similarity index 95% rename from api-portal/src/main/java/com/jmsoftware/apiportal/universal/domain/PermissionType.java rename to common/src/main/java/com/jmsoftware/common/domain/authcenter/permission/PermissionType.java index de61f4f5..188e4cee 100644 --- a/api-portal/src/main/java/com/jmsoftware/apiportal/universal/domain/PermissionType.java +++ b/common/src/main/java/com/jmsoftware/common/domain/authcenter/permission/PermissionType.java @@ -1,4 +1,4 @@ -package com.jmsoftware.apiportal.universal.domain; +package com.jmsoftware.common.domain.authcenter.permission; import lombok.Getter; import lombok.extern.slf4j.Slf4j;