Skip to content

Commit

Permalink
Merge branch 'release/0.0.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnymillergh committed Aug 26, 2021
2 parents a976f19 + 6bfce58 commit 88d052f
Show file tree
Hide file tree
Showing 55 changed files with 1,071 additions and 1,636 deletions.
28 changes: 27 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
# [0.0.4](https://github.com/johnnymillergh/muscle-and-fitness-server/compare/0.0.3...0.0.4) (2021-08-18)
# [0.0.5](https://github.com/johnnymillergh/muscle-and-fitness-server/compare/0.0.4...0.0.5) (2021-08-26)


### Features

* **$auth-center:** download and export role info ([b6640ce](https://github.com/johnnymillergh/muscle-and-fitness-server/commit/b6640cec6d45e826bb536e9293ca6cfaa790bb6c))
* **$auth-center:** import role data from Excel ([3468082](https://github.com/johnnymillergh/muscle-and-fitness-server/commit/3468082f45d9d2dc7c18fb39f90fa7a13f9dbde4))


### Performance Improvements

* **$api-gateway:** parse user's ID from JWT ([a70434f](https://github.com/johnnymillergh/muscle-and-fitness-server/commit/a70434f3ad98932b457be926571202c968b438f0))
* **$Druid:** dynamic connection pool size ([ea37259](https://github.com/johnnymillergh/muscle-and-fitness-server/commit/ea372596670366db47aec8439c1b12487e68ed30))
* **$Druid:** set connection pool size equal to 2*processors ([a654323](https://github.com/johnnymillergh/muscle-and-fitness-server/commit/a654323b432cc1f7858a8bc07b568f2719642e4f))
* **$OSS:** transform IO by NIO ([bce0cf4](https://github.com/johnnymillergh/muscle-and-fitness-server/commit/bce0cf4df5fa607996c8ef16808021f4ce635655))
* **$starter:** refine Excel data abstract class ([9d5de27](https://github.com/johnnymillergh/muscle-and-fitness-server/commit/9d5de27077fba78014c458ebb4fa30b8c422a5b6))
* **$starter:** simplify AbstractExcelImportController.java ([651615c](https://github.com/johnnymillergh/muscle-and-fitness-server/commit/651615c08c0e07aff27bf955ce3956794602b933))


### BREAKING CHANGES

* **$Druid:** set connection pool size equal to 2*processors
* **$Druid:** dynamic connection pool size, set by CPU core count



# [0.0.4](https://github.com/johnnymillergh/muscle-and-fitness-server/compare/0.0.3...0.0.4) (2021-08-18)


### Features
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ Here is the highlights of **Muscle and Fitness Server**:

4. Secured API. [RBAC](https://en.wikipedia.org/wiki/Role-based_access_control) by API gateway and Auth Center. JWT authentication, and RBAC authorization.

5. [MySQL Replication for High Availability](https://severalnines.com/resources/database-management-tutorials/mysql-replication-high-availability-tutorial). Multi data source. [Dynamic SQL read-write isolation](https://baomidou.com/guide/dynamic-datasource.html). MyBatis-Plus is the integrated ORM library.
5. [MySQL Replication for High Availability](https://severalnines.com/resources/database-management-tutorials/mysql-replication-high-availability-tutorial). Multi data source. [Dynamic SQL read-write isolation](https://baomidou.com/guide/dynamic-datasource.html). [MyBatis-Plus](https://github.com/baomidou/mybatis-plus) is the integrated ORM library. [Druid](https://github.com/alibaba/druid) is the database connection pool. Dynamically enhance connection pool size by CPU count (logical processor count). Read more at [How to Find the Optimal Database Connection Pool Size](https://wiki.postgresql.org/wiki/Number_Of_Database_Connections#How_to_Find_the_Optimal_Database_Connection_Pool_Size), [Sizing the Connection Pool](https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-usagenotes-j2ee-concepts-connection-pooling.html#idm46216069663472).

6. Redis 6.x support. [Master-slave replication for high availability](https://redis.io/topics/replication). Redis cluster
6. Redis 6.x support. [Master-slave replication for high availability](https://redis.io/topics/replication). Redis cluster.

7. Docker, Rancher Kubernetes support. Google JIB for building Docker container images.

Expand Down
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.4</version>
<version>0.0.5</version>
</parent>

<!-- Build Settings -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.jmsoftware.maf.reactivespringcloudstarter.helper.SpringBootStartupHelper;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
Expand All @@ -18,16 +19,11 @@
@EnableDiscoveryClient
@SpringBootApplication
public class ApiGatewayApplication {
private static final StopWatch STOP_WATCH = new StopWatch();
private static SpringBootStartupHelper springBootStartupHelper;

public ApiGatewayApplication(SpringBootStartupHelper springBootStartupHelper) {
ApiGatewayApplication.springBootStartupHelper = springBootStartupHelper;
}

public static void main(String[] args) {
STOP_WATCH.start();
SpringApplication.run(ApiGatewayApplication.class, args);
springBootStartupHelper.stop(STOP_WATCH);
val stopWatch = new StopWatch();
stopWatch.start();
val configurableApplicationContext = SpringApplication.run(ApiGatewayApplication.class, args);
val springBootStartupHelper = configurableApplicationContext.getBean(SpringBootStartupHelper.class);
springBootStartupHelper.stop(stopWatch);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public Mono<Void> save(ServerWebExchange exchange, SecurityContext context) {
public Mono<SecurityContext> load(ServerWebExchange exchange) {
val request = exchange.getRequest();
// Ignore allowed URL
for (var ignoredUrl : mafConfiguration.flattenIgnoredUrls()) {
if (antPathMatcher.match(ignoredUrl, request.getURI().getPath())) {
for (var ignoredUrl : this.mafConfiguration.flattenIgnoredUrls()) {
if (this.antPathMatcher.match(ignoredUrl, request.getURI().getPath())) {
return Mono.empty();
}
}
Expand All @@ -56,10 +56,11 @@ public Mono<SecurityContext> load(ServerWebExchange exchange) {
HttpHeaders.AUTHORIZATION, request.getMethod(), request.getURI());
return Mono.error(new SecurityException(HttpStatus.NETWORK_AUTHENTICATION_REQUIRED, "JWT Required"));
}
return authCenterRemoteApi.parse(authorization)
return this.authCenterRemoteApi.parse(authorization)
.map(parseJwtResponse -> {
log.info("parseJwtResponse: {}", parseJwtResponse);
val userPrincipal = UserPrincipal.createByUsername(parseJwtResponse.getUsername());
userPrincipal.setId(parseJwtResponse.getId());
val authentication = new UsernamePasswordAuthenticationToken(userPrincipal, null);
log.warn("About to authenticate… Authentication is created. {}", authentication);
return authentication;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,10 @@ public Mono<AuthorizationDecision> check(Mono<Authentication> authentication, Au
request.getMethod(), request.getURI(), userPrincipal.getUsername());
request
.mutate()
.headers(httpHeaders -> httpHeaders.set(MafHttpHeader.X_USERNAME.getHeader(),
userPrincipal.getUsername()))
.headers(httpHeaders -> {
httpHeaders.set(MafHttpHeader.X_ID.getHeader(), String.valueOf(userPrincipal.getId()));
httpHeaders.set(MafHttpHeader.X_USERNAME.getHeader(), userPrincipal.getUsername());
})
.build();
return new AuthorizationDecision(true);
}
Expand Down
24 changes: 23 additions & 1 deletion auth-center/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.4</version>
<version>0.0.5</version>
</parent>

<!-- Build Settings -->
Expand Down Expand Up @@ -219,5 +219,27 @@
<version>${jjwt.version}</version>
<scope>runtime</scope>
</dependency>

<!-- Apache POI - Java API To Access Microsoft Format Files -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>${poi.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${poi.version}</version>
<scope>provided</scope>
</dependency>

<!-- OSS Dependencies -->
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<version>${minio.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.jmsoftware.maf.springcloudstarter.helper.SpringBootStartupHelper;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
Expand All @@ -13,24 +14,18 @@
* <p>
* Change description here.
*
* @author Johnny Miller (锺俊), email: johnnysviva@outlook.com
* @date 3/12/20 9:57 AM
* @author Johnny Miller (锺俊), email: johnnysviva@outlook.com, date: 3/12/20 9:57 AM
**/
@Slf4j
@EnableFeignClients
@EnableDiscoveryClient
@SpringBootApplication
public class AuthCenterApplication {
private static final StopWatch STOP_WATCH = new StopWatch();
private static SpringBootStartupHelper springBootStartupHelper;

public AuthCenterApplication(SpringBootStartupHelper springBootStartupHelper) {
AuthCenterApplication.springBootStartupHelper = springBootStartupHelper;
}

public static void main(String[] args) {
STOP_WATCH.start();
SpringApplication.run(AuthCenterApplication.class, args);
springBootStartupHelper.stop(STOP_WATCH);
val stopWatch = new StopWatch();
stopWatch.start();
val configurableApplicationContext = SpringApplication.run(AuthCenterApplication.class, args);
val springBootStartupHelper = configurableApplicationContext.getBean(SpringBootStartupHelper.class);
springBootStartupHelper.stop(stopWatch);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

import java.util.Date;
import java.time.LocalDateTime;

import static com.baomidou.mybatisplus.annotation.FieldFill.INSERT;
import static com.baomidou.mybatisplus.annotation.FieldFill.UPDATE;
Expand All @@ -21,109 +21,83 @@
@Data
@TableName(value = Permission.TABLE_NAME)
public class Permission {
public static final String TABLE_NAME = "permission";
public static final String COL_ID = "id";
public static final String COL_URL = "url";
public static final String COL_DESCRIPTION = "description";
public static final String COL_TYPE = "type";
public static final String COL_PERMISSION_EXPRESSION = "permission_expression";
public static final String COL_METHOD = "method";
public static final String COL_SORT = "sort";
public static final String COL_PARENT_ID = "parent_id";
public static final String COL_CREATED_BY = "created_by";
public static final String COL_CREATED_TIME = "created_time";
public static final String COL_MODIFIED_BY = "modified_by";
public static final String COL_MODIFIED_TIME = "modified_time";
public static final String COL_DELETED = "deleted";
/**
* Primary key
*/
@TableId(value = COL_ID, type = IdType.AUTO)
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
*/
@TableField(value = COL_URL)
private String url;

/**
* Permission description
*/
@TableField(value = COL_DESCRIPTION)
private String description;

/**
* Permission type. 1 - page; 2 - button
*/
@TableField(value = COL_TYPE)
private Byte type;

/**
* Permission expression
*/
@TableField(value = COL_PERMISSION_EXPRESSION)
private String permissionExpression;

/**
* HTTP method of API
*/
@TableField(value = COL_METHOD)
private Object method;

/**
* Sort number
*/
@TableField(value = COL_SORT)
private Integer sort;

/**
* Primary key of parent
*/
@TableField(value = COL_PARENT_ID)
private Long parentId;

/**
* Created by
*/
@TableField(value = COL_CREATED_BY, fill = INSERT)
private Long createdBy;

/**
* Created time
*/
@TableField(value = COL_CREATED_TIME, fill = INSERT)
private Date createdTime;

private LocalDateTime createdTime;
/**
* Modified by
*/
@TableField(value = COL_MODIFIED_BY, fill = UPDATE)
private Long modifiedBy;

/**
* Modified time
*/
@TableField(value = COL_MODIFIED_TIME, fill = UPDATE)
private Date modifiedTime;

private LocalDateTime modifiedTime;
/**
* Deleted flag
*/
@TableField(value = COL_DELETED, fill = INSERT)
private Byte deleted;

public static final String TABLE_NAME = "permission";

public static final String COL_ID = "id";

public static final String COL_URL = "url";

public static final String COL_DESCRIPTION = "description";

public static final String COL_TYPE = "type";

public static final String COL_PERMISSION_EXPRESSION = "permission_expression";

public static final String COL_METHOD = "method";

public static final String COL_SORT = "sort";

public static final String COL_PARENT_ID = "parent_id";

public static final String COL_CREATED_BY = "created_by";

public static final String COL_CREATED_TIME = "created_time";

public static final String COL_MODIFIED_BY = "modified_by";

public static final String COL_MODIFIED_TIME = "modified_time";

public static final String COL_DELETED = "deleted";
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,57 @@
package com.jmsoftware.maf.authcenter.role.controller;

import com.jmsoftware.maf.authcenter.role.entity.RoleExcelBean;
import com.jmsoftware.maf.authcenter.role.service.RoleService;
import com.jmsoftware.maf.springcloudstarter.controller.AbstractExcelDataController;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.Instant;
import java.util.List;

/**
* Description: RoleController, change description here.
*
* @author 钟俊(zhongjun), email: zhongjun@toguide.cn, date: 12/17/2020 4:44 PM
**/
@Slf4j
@RestController
@RequiredArgsConstructor
public class RoleController {
@RequestMapping("/roles")
public class RoleController extends AbstractExcelDataController<RoleExcelBean> {
private final RoleService roleService;

@Override
public void onExceptionOccurred() {
log.error("Exception occurred when uploading excel for role.");
this.fileName.set("role-stat" + Instant.now() + ".xlsx");
}

@Override
protected void beforeDatabaseOperation(List<RoleExcelBean> beanList) {
log.info("BeforeDatabaseOperation: {}", beanList);
}

@Override
protected void executeDatabaseOperation(List<RoleExcelBean> beanList) throws Exception {
log.info("ExecuteDatabaseOperation: {}", beanList);
this.roleService.save(beanList);
}

@Override
protected String getTemplateFileName() {
return RoleService.ROLE_TEMPLATE_EXCEL;
}

@Override
protected List<RoleExcelBean> getListForExporting() {
return this.roleService.getListForExporting();
}

@Override
protected void validateBeforeAddToBeanList(List<RoleExcelBean> beanList, RoleExcelBean bean, int index) throws IllegalArgumentException {
this.roleService.validateBeforeAddToBeanList(beanList, bean, index);
}
}
Loading

0 comments on commit 88d052f

Please sign in to comment.