Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to spring boot 2 #79

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 27 additions & 69 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.codenergic.theskeleton</groupId>
<artifactId>theskeleton-server</artifactId>
<version>0.14.0-SNAPSHOT</version>
<version>0.20.0-SNAPSHOT</version>
<name>TheSkeleton Server</name>
<description>
TheSkeleton is the full-stack project template used to help developer building modern web application quickly.
Expand All @@ -24,25 +24,20 @@

<properties>
<bootstrap.version>4.1.0</bootstrap.version>
<commons-lang3.version>3.7</commons-lang3.version>
<commons-lang3.version>3.11</commons-lang3.version>
<fauxflake-core.version>1.1.0</fauxflake-core.version>
<guava.version>21.0</guava.version>
<hibernate.version>5.4.3.Final</hibernate.version>
<immutables.version>2.6.3</immutables.version>
<jacoco.version>0.8.1</jacoco.version>
<libphonenumber.version>8.4.2</libphonenumber.version>
<mapstruct.version>1.3.0.Beta1</mapstruct.version>
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
<maven-git-commit-id-plugin.version>2.2.4</maven-git-commit-id-plugin.version>
<maven-resources-plugin.version>3.1.0</maven-resources-plugin.version>
<minio.version>3.0.6</minio.version>
<mockito.version>2.18.3</mockito.version>
<spring-boot.version>1.5.21.RELEASE</spring-boot.version>
<greenmail.version>1.6.2</greenmail.version>
<guava.version>30.1-jre</guava.version>
<immutables.version>2.8.8</immutables.version>
<jacoco.version>0.8.6</jacoco.version>
<mapstruct.version>1.4.1.Final</mapstruct.version>
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
<maven-git-commit-id-plugin.version>4.0.3</maven-git-commit-id-plugin.version>
<maven-resources-plugin.version>3.2.0</maven-resources-plugin.version>
<minio.version>8.0.3</minio.version>
<spring-boot.version>2.4.2</spring-boot.version>
<spring-boot-email.version>0.6.3</spring-boot-email.version>
<spring-restdocs.version>1.2.4.RELEASE</spring-restdocs.version>
<spring-social-google.version>1.1.3</spring-social-google.version>
<spring-social-security.version>1.1.6.RELEASE</spring-social-security.version>
<docker-maven-plugin.version>1.3.6</docker-maven-plugin.version>
<spring-restdocs.version>2.0.5.RELEASE</spring-restdocs.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
Expand All @@ -54,18 +49,6 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>

<!-- Web MVC, Servlet Container, and Security -->
<dependency>
Expand Down Expand Up @@ -99,50 +82,29 @@
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-jwt</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<groupId>org.springframework.security.oauth.boot</groupId>
<artifactId>spring-security-oauth2-autoconfigure</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session</artifactId>
<artifactId>spring-session-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>

<!-- Social Media Integration -->
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-security</artifactId>
<version>${spring-social-security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-facebook</artifactId>
</dependency>
<dependency>
<groupId>com.github.spring-social</groupId>
<artifactId>spring-social-google</artifactId>
<version>${spring-social-google.version}</version>
</dependency>

<!-- Api Docs -->
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-core</artifactId>
<version>${spring-restdocs.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-mockmvc</artifactId>
<version>${spring-restdocs.version}</version>
<scope>test</scope>
</dependency>

Expand Down Expand Up @@ -171,18 +133,11 @@
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
<artifactId>hibernate-ehcache</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>${hibernate.version}</version>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
Expand Down Expand Up @@ -218,7 +173,7 @@
<!-- Email -->
<dependency>
<groupId>it.ozimov</groupId>
<artifactId>spring-boot-thymeleaf-email</artifactId>
<artifactId>spring-boot-email-core</artifactId>
<version>${spring-boot-email.version}</version>
<exclusions>
<exclusion>
Expand All @@ -229,20 +184,23 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</exclusion>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.icegreen</groupId>
<artifactId>greenmail</artifactId>
<version>1.5.5</version>
<version>${greenmail.version}</version>
<scope>test</scope>
</dependency>

<!-- Utilities -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
Expand Down Expand Up @@ -284,7 +242,7 @@
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-jdk8</artifactId>
<artifactId>mapstruct</artifactId>
<version>${mapstruct.version}</version>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import java.util.Set;

import javax.annotation.Nullable;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;

import org.codenergic.theskeleton.core.data.RestData;
import org.hibernate.validator.constraints.NotBlank;
import org.hibernate.validator.constraints.NotEmpty;
import org.immutables.value.Value;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.codenergic.theskeleton.core.data;

import java.util.Optional;

import org.codenergic.theskeleton.core.security.User;
import org.springframework.data.domain.AuditorAware;
import org.springframework.security.core.Authentication;
Expand All @@ -8,13 +10,13 @@

public class AuditInformationAuditor implements AuditorAware<AuditInformation> {
@Override
public AuditInformation getCurrentAuditor() {
public Optional<AuditInformation> getCurrentAuditor() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
AuditInformation auditInformation = new AuditInformation();
if (authentication instanceof OAuth2Authentication)
auditInformation.setClientId(((OAuth2Authentication) authentication).getOAuth2Request().getClientId());
if (authentication.getPrincipal() instanceof User)
auditInformation.setUserId(((User) authentication.getPrincipal()).getId());
return auditInformation;
return Optional.of(auditInformation);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.codenergic.theskeleton.core.data;

public class S3BucketProperties {
String name;

public S3BucketProperties setName(String name) {
this.name = name;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,23 @@
*/
package org.codenergic.theskeleton.core.data;

import java.util.ArrayList;
import java.net.MalformedURLException;
import java.net.URI;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import io.minio.BucketExistsArgs;
import io.minio.MakeBucketArgs;
import io.minio.MinioClient;
import io.minio.errors.InvalidEndpointException;
import io.minio.errors.InvalidPortException;
import io.minio.policy.PolicyType;

@Configuration
class S3ClientConfig {
Expand All @@ -45,9 +43,9 @@ public ScheduledFuture<List<String>> createBuckets(MinioClient minioClient, Sche
.peek(bucket -> logger.info("Checking bucket [{}]", bucket.name))
.peek(bucket -> {
try {
if (!minioClient.bucketExists(bucket.name)) {
if (!minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucket.name).build())) {
logger.info("Bucket doesn't exists, creating one");
minioClient.makeBucket(bucket.name);
minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucket.name).build());
logger.info("Bucket created");
} else {
logger.info("Bucket already exists");
Expand All @@ -56,25 +54,16 @@ public ScheduledFuture<List<String>> createBuckets(MinioClient minioClient, Sche
logger.error(e.getMessage(), e);
}
})
.peek(bucket -> bucket.getPolicies().stream()
.filter(Objects::nonNull)
.filter(policy -> Objects.nonNull(policy.policy))
.filter(policy -> StringUtils.isNotBlank(policy.prefix))
.peek(policy -> logger.info("Setting policy [{}] to bucket [{}] with prefix [{}]", policy.policy, bucket.name, policy.prefix))
.forEach(policy -> {
try {
minioClient.setBucketPolicy(bucket.name, policy.prefix, policy.policy);
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}))
.map(bucket -> bucket.name)
.collect(Collectors.toList()), 5, TimeUnit.SECONDS);
}

@Bean
public MinioClient s3Client(S3ClientProperties clientProps) throws InvalidEndpointException, InvalidPortException {
return new MinioClient(clientProps.endpoint, clientProps.accessKey, clientProps.secretKey);
public MinioClient s3Client(S3ClientProperties clientProps) throws MalformedURLException {
return MinioClient.builder()
.endpoint(URI.create(clientProps.endpoint).toURL())
.credentials(clientProps.accessKey, clientProps.secretKey)
.build();
}

@Bean
Expand All @@ -83,55 +72,4 @@ public S3ClientProperties s3ClientProperties() {
return new S3ClientProperties();
}

public static class S3ClientProperties {
private String accessKey;
private List<S3BucketProperties> buckets = new ArrayList<>();
private String endpoint;
private String secretKey;

public List<S3BucketProperties> getBuckets() {
return buckets;
}

public void setAccessKey(String accessKey) {
this.accessKey = accessKey;
}

public void setEndpoint(String endpoint) {
this.endpoint = endpoint;
}

public void setSecretKey(String secretKey) {
this.secretKey = secretKey;
}
}

public static class S3BucketProperties {
private String name;
private List<S3BucketPolicyProperties> policies = new ArrayList<>();

public List<S3BucketPolicyProperties> getPolicies() {
return policies;
}

public S3BucketProperties setName(String name) {
this.name = name;
return this;
}
}

public static class S3BucketPolicyProperties {
private PolicyType policy;
private String prefix = "*";

public S3BucketPolicyProperties setPolicy(PolicyType policy) {
this.policy = policy;
return this;
}

public S3BucketPolicyProperties setPrefix(String prefix) {
this.prefix = prefix;
return this;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.codenergic.theskeleton.core.data;

import java.util.ArrayList;
import java.util.List;

public class S3ClientProperties {
String accessKey;
List<S3BucketProperties> buckets = new ArrayList<>();
String endpoint;
String secretKey;

public List<S3BucketProperties> getBuckets() {
return buckets;
}

public void setAccessKey(String accessKey) {
this.accessKey = accessKey;
}

public void setEndpoint(String endpoint) {
this.endpoint = endpoint;
}

public void setSecretKey(String secretKey) {
this.secretKey = secretKey;
}

public String getEndpoint() {
return endpoint;
}
}
Loading