Skip to content

Commit

Permalink
perf($auth-center): DDD modularized microservice
Browse files Browse the repository at this point in the history
feature/domain-driven-design-refactoring-feb-2-2022

Version: 0.0.8-SNAPSHOT
  • Loading branch information
johnnymillergh committed Feb 2, 2022
1 parent a9063f4 commit f883d81
Show file tree
Hide file tree
Showing 80 changed files with 440 additions and 241 deletions.
2 changes: 1 addition & 1 deletion api-gateway/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>com.jmsoftware.maf</groupId>
<artifactId>muscle-and-fitness-server</artifactId>
<version>0.0.7</version>
<version>0.0.8-SNAPSHOT</version>
</parent>

<!-- Build Settings -->
Expand Down
23 changes: 23 additions & 0 deletions auth-center/auth-center-biz/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<!-- Sub-module Basics -->
<artifactId>auth-center-biz</artifactId>
<name>Muscle and Fitness Server :: Auth Center - Biz</name>
<description>Authentication and Authorization Center (AAC) for incoming requests from clients.</description>
<parent>
<groupId>com.jmsoftware.maf</groupId>
<artifactId>auth-center</artifactId>
<version>0.0.8-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<dependencies>
<dependency>
<groupId>com.jmsoftware.maf</groupId>
<artifactId>auth-center-domain</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.jmsoftware.maf.authcenter.permission.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.jmsoftware.maf.authcenter.permission.entity.GetServicesInfoResponse;
import com.jmsoftware.maf.authcenter.permission.entity.persistence.Permission;
import com.jmsoftware.maf.authcenter.permission.response.GetServicesInfoResponse;
import com.jmsoftware.maf.authcenter.permission.persistence.Permission;
import com.jmsoftware.maf.common.domain.authcenter.permission.GetPermissionListByRoleIdListPayload;
import com.jmsoftware.maf.common.domain.authcenter.permission.GetPermissionListByRoleIdListResponse;
import com.jmsoftware.maf.common.domain.authcenter.permission.PermissionType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jmsoftware.maf.authcenter.permission.configuration.PermissionConfiguration;
import com.jmsoftware.maf.authcenter.permission.entity.GetServicesInfoResponse;
import com.jmsoftware.maf.authcenter.permission.entity.persistence.Permission;
import com.jmsoftware.maf.authcenter.permission.response.GetServicesInfoResponse;
import com.jmsoftware.maf.authcenter.permission.persistence.Permission;
import com.jmsoftware.maf.authcenter.permission.mapper.PermissionMapper;
import com.jmsoftware.maf.authcenter.permission.service.PermissionService;
import com.jmsoftware.maf.authcenter.role.service.RoleService;
Expand Down Expand Up @@ -39,7 +39,9 @@
@Slf4j
@Service
@RequiredArgsConstructor
public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permission> implements PermissionService {
public class PermissionServiceImpl
extends ServiceImpl<PermissionMapper, Permission>
implements PermissionService {
private final RoleService roleService;
private final DiscoveryClient discoveryClient;
private final RestTemplate restTemplate;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package com.jmsoftware.maf.authcenter.role;
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.jmsoftware.maf.authcenter.role.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.jmsoftware.maf.authcenter.role.entity.RoleExcelBean;
import com.jmsoftware.maf.authcenter.role.entity.persistence.Role;
import com.jmsoftware.maf.authcenter.role.RoleExcelBean;
import com.jmsoftware.maf.authcenter.role.persistence.Role;
import com.jmsoftware.maf.common.domain.authcenter.role.GetRoleListByUserIdResponse;
import com.jmsoftware.maf.common.domain.authcenter.role.GetRoleListByUserIdSingleResponse;
import lombok.NonNull;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jmsoftware.maf.authcenter.role.entity.RoleExcelBean;
import com.jmsoftware.maf.authcenter.role.entity.constant.RoleRedisKey;
import com.jmsoftware.maf.authcenter.role.entity.persistence.Role;
import com.jmsoftware.maf.authcenter.role.RoleExcelBean;
import com.jmsoftware.maf.authcenter.role.constant.RoleRedisKey;
import com.jmsoftware.maf.authcenter.role.persistence.Role;
import com.jmsoftware.maf.authcenter.role.mapper.RoleMapper;
import com.jmsoftware.maf.authcenter.role.service.RoleService;
import com.jmsoftware.maf.common.domain.authcenter.role.GetRoleListByUserIdResponse;
Expand Down Expand Up @@ -46,7 +46,9 @@
@Slf4j
@Service
@RequiredArgsConstructor
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {
public class RoleServiceImpl
extends ServiceImpl<RoleMapper, Role>
implements RoleService {
private final MafProjectProperties mafProjectProperties;
private final MafConfigurationProperties mafConfigurationProperties;
private final RedisTemplate<String, String> redisTemplate;
Expand All @@ -55,8 +57,8 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
@Override
@SneakyThrows({JsonProcessingException.class})
public GetRoleListByUserIdResponse getRoleList(@NotNull Long userId) {
val key = String.format(this.mafProjectProperties.getProjectParentArtifactId()
+ RoleRedisKey.GET_ROLE_LIST_BY_USER_ID.getKeyInfixFormat(), userId);
val key = String.format(String.format("%s%s", this.mafProjectProperties.getProjectParentArtifactId(),
RoleRedisKey.GET_ROLE_LIST_BY_USER_ID.getKeyInfixFormat()), userId);
val hasKey = this.redisTemplate.hasKey(key);
if (BooleanUtil.isTrue(hasKey)) {
return this.objectMapper.readValue(this.redisTemplate.opsForValue().get(key),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package com.jmsoftware.maf.authcenter.security;
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.jmsoftware.maf.authcenter.security.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.jmsoftware.maf.authcenter.security.service.JwtService;
import com.jmsoftware.maf.common.domain.authcenter.security.ParseJwtResponse;
import com.jmsoftware.maf.common.domain.authcenter.security.UserPrincipal;
Expand Down Expand Up @@ -64,6 +64,7 @@ public String createJwt(Authentication authentication, Boolean rememberMe) {
}

@Override
@SuppressWarnings("scwjava-time_ReplacenewDatewithjava.time")
public String createJwt(Boolean rememberMe, Long id, String subject, List<String> roles,
Collection<? extends GrantedAuthority> authorities) {
val now = new Date();
Expand Down Expand Up @@ -120,7 +121,7 @@ public Claims parseJwt(String jwt) throws SecurityException {
// If it's noe equal, that indicates current user has signed out or logged in before.
// Both situations reveal the JWT has expired.
val jwtInRedis = (String) this.redisTemplate.opsForValue().get(redisKeyOfJwt);
if (!StrUtil.equals(jwt, jwtInRedis)) {
if (!CharSequenceUtil.equals(jwt, jwtInRedis)) {
throw new SecurityException(HttpStatus.UNAUTHORIZED, "JWT is expired (Not equaled)");
}
return claims;
Expand Down Expand Up @@ -151,7 +152,8 @@ public String getUsernameFromRequest(HttpServletRequest request) throws Security
@Override
public String getJwtFromRequest(HttpServletRequest request) {
val bearerToken = request.getHeader(HttpHeaders.AUTHORIZATION);
if (StrUtil.isNotBlank(bearerToken) && bearerToken.startsWith(JwtConfigurationProperties.TOKEN_PREFIX)) {
if (CharSequenceUtil.isNotBlank(bearerToken)
&& bearerToken.startsWith(JwtConfigurationProperties.TOKEN_PREFIX)) {
return bearerToken.substring(JwtConfigurationProperties.TOKEN_PREFIX.length());
}
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package com.jmsoftware.maf.authcenter.user;
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.jmsoftware.maf.authcenter.user.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.jmsoftware.maf.authcenter.user.entity.persistence.User;
import com.jmsoftware.maf.authcenter.user.entity.persistence.UserRole;
import com.jmsoftware.maf.authcenter.user.persistence.User;
import com.jmsoftware.maf.authcenter.user.persistence.UserRole;
import lombok.NonNull;
import org.springframework.validation.annotation.Validated;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.jmsoftware.maf.authcenter.user.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.jmsoftware.maf.authcenter.user.entity.GetUserPageListPayload;
import com.jmsoftware.maf.authcenter.user.entity.GetUserStatusPayload;
import com.jmsoftware.maf.authcenter.user.entity.persistence.User;
import com.jmsoftware.maf.authcenter.user.payload.GetUserPageListPayload;
import com.jmsoftware.maf.authcenter.user.payload.GetUserStatusPayload;
import com.jmsoftware.maf.authcenter.user.persistence.User;
import com.jmsoftware.maf.common.bean.PageResponseBodyBean;
import com.jmsoftware.maf.common.domain.authcenter.user.*;
import com.jmsoftware.maf.common.exception.SecurityException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jmsoftware.maf.authcenter.role.entity.persistence.Role;
import com.jmsoftware.maf.authcenter.role.persistence.Role;
import com.jmsoftware.maf.authcenter.role.service.RoleService;
import com.jmsoftware.maf.authcenter.user.entity.persistence.User;
import com.jmsoftware.maf.authcenter.user.entity.persistence.UserRole;
import com.jmsoftware.maf.authcenter.user.mapper.UserRoleMapper;
import com.jmsoftware.maf.authcenter.user.persistence.User;
import com.jmsoftware.maf.authcenter.user.persistence.UserRole;
import com.jmsoftware.maf.authcenter.user.service.UserRoleService;
import com.jmsoftware.maf.common.exception.BizException;
import lombok.NonNull;
Expand All @@ -27,7 +27,9 @@
@Slf4j
@Service
@RequiredArgsConstructor
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements UserRoleService {
public class UserRoleServiceImpl
extends ServiceImpl<UserRoleMapper, UserRole>
implements UserRoleService {
private final RoleService roleService;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jmsoftware.maf.authcenter.security.service.JwtService;
import com.jmsoftware.maf.authcenter.user.entity.GetUserPageListPayload;
import com.jmsoftware.maf.authcenter.user.entity.GetUserStatusPayload;
import com.jmsoftware.maf.authcenter.user.entity.constant.UserRedisKey;
import com.jmsoftware.maf.authcenter.user.entity.persistence.User;
import com.jmsoftware.maf.authcenter.user.constant.UserRedisKey;
import com.jmsoftware.maf.authcenter.user.mapper.UserMapper;
import com.jmsoftware.maf.authcenter.user.payload.GetUserPageListPayload;
import com.jmsoftware.maf.authcenter.user.payload.GetUserStatusPayload;
import com.jmsoftware.maf.authcenter.user.persistence.User;
import com.jmsoftware.maf.authcenter.user.service.UserRoleService;
import com.jmsoftware.maf.authcenter.user.service.UserService;
import com.jmsoftware.maf.common.bean.PageResponseBodyBean;
Expand Down Expand Up @@ -55,7 +55,9 @@
@Service
@RequiredArgsConstructor
@CacheConfig(cacheNames = "user-service-cache")
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
public class UserServiceImpl
extends ServiceImpl<UserMapper, User>
implements UserService {
private final BCryptPasswordEncoder bCryptPasswordEncoder;
private final JwtService jwtService;
private final MessageSource messageSource;
Expand Down Expand Up @@ -140,7 +142,7 @@ public PageResponseBodyBean<User> getUserPageList(@Valid @NotNull GetUserPageLis
log.info("{}", payload);
val page = new Page<User>(payload.getCurrentPage(), payload.getPageSize());
val queryWrapper = Wrappers.lambdaQuery(User.class);
if (StrUtil.isNotBlank(payload.getUsername())) {
if (CharSequenceUtil.isNotBlank(payload.getUsername())) {
queryWrapper.like(User::getUsername, payload.getUsername());
}
page.setOrders(ListUtil.of(OrderItem.desc(payload.getOrderBy())));
Expand Down
Loading

0 comments on commit f883d81

Please sign in to comment.