Skip to content

Commit

Permalink
Remove redundant files and format codes (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
haiphucnguyen authored Jan 4, 2025
1 parent 530ab1a commit dad9e96
Show file tree
Hide file tree
Showing 52 changed files with 210 additions and 520 deletions.
44 changes: 29 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ allprojects {
}

subprojects {

afterEvaluate { project ->
if (project.plugins.hasPlugin('java') || project.plugins.hasPlugin('java-library')) {
project.apply(plugin: 'flowinquiry.code-conventions')
project.java {
sourceCompatibility = 21
targetCompatibility = 21
Expand All @@ -28,25 +30,37 @@ allprojects {
if (project.plugins.hasPlugin('java-library')) {
project.apply(plugin: 'maven-publish')

project.publishing {
publications {
// Check if the publication already exists
if (!project.publishing.publications.names.contains("${project.name}MavenJava")) {
create("${project.name}MavenJava", MavenPublication) {
from project.components.java
// Check if sourcesJar task already exists before creating it
if (!project.tasks.names.contains('sourcesJar')) {
project.tasks.register('sourcesJar', Jar) {
archiveClassifier.set('sources') // Classify the JAR as 'sources'
from project.sourceSets.main.allSource // Include all source files
}
}

project.afterEvaluate {
publishing {
publications {
if (!project.publishing.publications.names.contains("${project.name}MavenJava")) {
create("${project.name}MavenJava", MavenPublication) {
from project.components.java

// Reference the sourcesJar task
artifact(tasks.named('sourcesJar'))
}
}
}
}
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/flowinquiry/flowinquiry-server")
credentials {
username = project.findProperty("gpr.user") ?: System.getenv("GITHUB_ACTOR")
password = project.findProperty("gpr.token") ?: System.getenv("GITHUB_TOKEN")
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/flowinquiry/flowinquiry-server")
credentials {
username = project.findProperty("gpr.user") ?: System.getenv("GITHUB_ACTOR")
password = project.findProperty("gpr.token") ?: System.getenv("GITHUB_TOKEN")
}
}
mavenLocal()
}
mavenLocal()
}
}
}
Expand Down
1 change: 0 additions & 1 deletion commons/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ dependencies {
api("org.hibernate.orm:hibernate-core")
api("org.hibernate.validator:hibernate-validator")

api("org.springframework.boot:spring-boot-starter-actuator")
api("org.springframework.boot:spring-boot-starter-aop")
api("org.springframework.boot:spring-boot-starter-data-jpa")
api("org.springframework.boot:spring-boot-loader-tools")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static org.springframework.security.config.Customizer.withDefaults;

import io.flowinquiry.modules.usermanagement.AuthoritiesConstants;
import io.flowinquiry.web.filter.SpaWebFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
Expand All @@ -15,7 +14,6 @@
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.oauth2.server.resource.web.access.BearerTokenAccessDeniedHandler;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
import org.springframework.security.web.servlet.util.matcher.MvcRequestMatcher;
import org.springframework.web.servlet.handler.HandlerMappingIntrospector;

Expand All @@ -33,62 +31,23 @@ public SecurityFilterChain filterChain(HttpSecurity http, MvcRequestMatcher.Buil
throws Exception {
http.cors(withDefaults())
.csrf(AbstractHttpConfigurer::disable)
.addFilterAfter(new SpaWebFilter(), BasicAuthenticationFilter.class)
.authorizeHttpRequests(
authz ->
// prettier-ignore
authz.requestMatchers(
mvc.pattern("/index.html"),
mvc.pattern("/*.js"),
mvc.pattern("/*.txt"),
mvc.pattern("/*.json"),
mvc.pattern("/*.map"),
mvc.pattern("/*.css"))
.permitAll()
.requestMatchers(
mvc.pattern("/*.ico"),
mvc.pattern("/*.png"),
mvc.pattern("/*.svg"),
mvc.pattern("/*.webapp"))
.permitAll()
.requestMatchers(mvc.pattern("/app/**"))
.permitAll()
.requestMatchers(mvc.pattern("/i18n/**"))
.permitAll()
.requestMatchers(mvc.pattern("/content/**"))
.permitAll()
.requestMatchers(mvc.pattern(HttpMethod.POST, "/api/login"))
.permitAll()
.requestMatchers(
mvc.pattern(HttpMethod.POST, "/api/authenticate"))
.permitAll()
.requestMatchers(
mvc.pattern(HttpMethod.GET, "/api/authenticate"))
.permitAll()
.requestMatchers(mvc.pattern("/api/register"))
.permitAll()
.requestMatchers(mvc.pattern("/api/files/**"))
.permitAll()
.requestMatchers(mvc.pattern("/api/activate"))
.permitAll()
.requestMatchers(
mvc.pattern("/api/account/reset-password/init"))
.permitAll()
.requestMatchers(
mvc.pattern(HttpMethod.POST, "/api/login"),
mvc.pattern(HttpMethod.POST, "/api/authenticate"),
mvc.pattern(HttpMethod.GET, "/api/authenticate"),
mvc.pattern("/api/register"),
mvc.pattern("/api/files/**"),
mvc.pattern("/api/activate"),
mvc.pattern("/api/account/reset-password/init"),
mvc.pattern("/api/account/reset-password/finish"))
.permitAll()
.requestMatchers(mvc.pattern("/api/admin/**"))
.hasAuthority(AuthoritiesConstants.ADMIN)
.requestMatchers(mvc.pattern("/api/**"))
.authenticated()
.requestMatchers(mvc.pattern("/management/health"))
.permitAll()
.requestMatchers(mvc.pattern("/management/health/**"))
.permitAll()
.requestMatchers(mvc.pattern("/management/info"))
.permitAll()
.requestMatchers(mvc.pattern("/management/prometheus"))
.permitAll()
.requestMatchers(mvc.pattern("/management/**"))
.hasAuthority(
AuthoritiesConstants.ADMIN)) // Enforces ROLE_ADMIN
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package io.flowinquiry.config;

import static io.flowinquiry.security.SecurityUtils.JWT_ALGORITHM;

import com.nimbusds.jose.jwk.source.ImmutableSecret;
import com.nimbusds.jose.util.Base64;
import io.flowinquiry.security.management.SecurityMetersService;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -13,11 +16,6 @@
import org.springframework.security.oauth2.jwt.NimbusJwtDecoder;
import org.springframework.security.oauth2.jwt.NimbusJwtEncoder;

import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;

import static io.flowinquiry.security.SecurityUtils.JWT_ALGORITHM;

@Configuration
public class SecurityJwtConfiguration {

Expand All @@ -27,27 +25,8 @@ public class SecurityJwtConfiguration {
private String jwtKey;

@Bean
public JwtDecoder jwtDecoder(SecurityMetersService metersService) {
NimbusJwtDecoder jwtDecoder =
NimbusJwtDecoder.withSecretKey(getSecretKey()).macAlgorithm(JWT_ALGORITHM).build();
return token -> {
try {
return jwtDecoder.decode(token);
} catch (Exception e) {
if (e.getMessage().contains("Invalid signature")) {
metersService.trackTokenInvalidSignature();
} else if (e.getMessage().contains("Jwt expired at")) {
metersService.trackTokenExpired();
} else if (e.getMessage().contains("Invalid JWT serialization")
|| e.getMessage().contains("Malformed token")
|| e.getMessage().contains("Invalid unsecured/JWS/JWE")) {
metersService.trackTokenMalformed();
} else {
LOG.error("Unknown JWT error {}", e.getMessage());
}
throw e;
}
};
public JwtDecoder jwtDecoder() {
return NimbusJwtDecoder.withSecretKey(getSecretKey()).macAlgorithm(JWT_ALGORITHM).build();
}

@Bean
Expand Down
1 change: 0 additions & 1 deletion commons/src/main/java/io/flowinquiry/db/DbConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

public interface DbConstants {


String DEFAULT_TENANT = "flowinquiry";

String TENANT_CHANGESET = "config/liquibase/tenant/master.xml";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@

import ch.qos.logback.classic.pattern.ClassicConverter;
import ch.qos.logback.classic.spi.ILoggingEvent;

import java.util.regex.Pattern;

public class MaskingMessageConverter extends ClassicConverter {
public class MaskingMessageConverter extends ClassicConverter {

// Define regex patterns for sensitive data
private static final Pattern EMAIL_PATTERN = Pattern.compile("[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,6}");
private static final Pattern CREDIT_CARD_PATTERN = Pattern.compile("\\b\\d{4}-?\\d{4}-?\\d{4}-?\\d{4}\\b");
private static final Pattern IP_ADDRESS_PATTERN = Pattern.compile("\\b(?:\\d{1,3}\\.){3}\\d{1,3}\\b");
private static final Pattern PHONE_NUMBER_PATTERN = Pattern.compile("\\+?(\\d{1,4})?[-\\s.]?\\(?\\d{1,4}\\)?[-\\s.]?\\d{1,4}[-\\s.]?\\d{1,9}");
private static final Pattern EMAIL_PATTERN =
Pattern.compile("[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,6}");
private static final Pattern CREDIT_CARD_PATTERN =
Pattern.compile("\\b\\d{4}-?\\d{4}-?\\d{4}-?\\d{4}\\b");
private static final Pattern IP_ADDRESS_PATTERN =
Pattern.compile("\\b(?:\\d{1,3}\\.){3}\\d{1,3}\\b");
private static final Pattern PHONE_NUMBER_PATTERN =
Pattern.compile(
"\\+?(\\d{1,4})?[-\\s.]?\\(?\\d{1,4}\\)?[-\\s.]?\\d{1,4}[-\\s.]?\\d{1,9}");

@Override
public String convert(ILoggingEvent event) {
Expand All @@ -28,11 +32,13 @@ private String maskSensitiveData(String message) {
String maskedMessage = IP_ADDRESS_PATTERN.matcher(message).replaceAll("[ANONYMIZED_IP]");

// Mask email addresses
maskedMessage = EMAIL_PATTERN.matcher(maskedMessage).replaceAll("[ANONYMIZED_EMAIL]");
maskedMessage = EMAIL_PATTERN.matcher(maskedMessage).replaceAll("[ANONYMIZED_EMAIL]");
// Mask credit card numbers
maskedMessage = CREDIT_CARD_PATTERN.matcher(maskedMessage).replaceAll("[ANONYMIZED_CREDIT_CARD]");
maskedMessage =
CREDIT_CARD_PATTERN.matcher(maskedMessage).replaceAll("[ANONYMIZED_CREDIT_CARD]");
// Mask phone numbers
maskedMessage = PHONE_NUMBER_PATTERN.matcher(maskedMessage).replaceAll("[ANONYMIZED_PHONE]");
maskedMessage =
PHONE_NUMBER_PATTERN.matcher(maskedMessage).replaceAll("[ANONYMIZED_PHONE]");

return maskedMessage;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package io.flowinquiry.modules.audit;

import j2html.tags.DomContent;

import java.util.List;

import static j2html.TagCreator.each;
import static j2html.TagCreator.table;
import static j2html.TagCreator.tbody;
Expand All @@ -12,6 +8,9 @@
import static j2html.TagCreator.thead;
import static j2html.TagCreator.tr;

import j2html.tags.DomContent;
import java.util.List;

public class ActivityLogUtils {

public static String generateHtmlLog(List<AuditUtils.FieldChange> changes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public class ActivityLogController {

@GetMapping
public ResponseEntity<Page<ActivityLogDTO>> getActivityLogs(
@RequestParam("entityType") EntityType entityType, @RequestParam("entityId") Long entityId, Pageable pageable) {
@RequestParam("entityType") EntityType entityType,
@RequestParam("entityId") Long entityId,
Pageable pageable) {
Page<ActivityLogDTO> activityLogs =
activityLogService.getActivityLogs(entityType, entityId, pageable);
return ResponseEntity.ok(activityLogs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.flowinquiry.modules.collab.domain.EntityType;
import io.flowinquiry.modules.collab.service.CommentService;
import io.flowinquiry.modules.collab.service.dto.CommentDTO;
import java.util.List;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -14,8 +15,6 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/comments")
public class CommentController {
Expand All @@ -40,7 +39,8 @@ public ResponseEntity<Comment> getCommentById(@PathVariable("id") Long id) {

@GetMapping
public ResponseEntity<List<CommentDTO>> getCommentsForEntity(
@RequestParam("entityType") EntityType entityType, @RequestParam("entityId") Long entityId) {
@RequestParam("entityType") EntityType entityType,
@RequestParam("entityId") Long entityId) {
List<CommentDTO> comments = commentService.getCommentsForEntity(entityType, entityId);
return ResponseEntity.ok(comments);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.flowinquiry.modules.fss.service;

import io.flowinquiry.exceptions.ResourceNotFoundException;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
Expand All @@ -11,8 +12,6 @@
import java.nio.file.Files;
import java.nio.file.Paths;
import javax.imageio.ImageIO;

import io.flowinquiry.exceptions.ResourceNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -28,6 +27,11 @@ public class LocalFileStorageService implements StorageService {
public LocalFileStorageService(
@Value("${application.file.rootDirectory:storage}") String rootDirectory) {
this.rootDirectory = rootDirectory;
File storageDir = new File(rootDirectory);
if (!storageDir.exists()) {
storageDir.mkdirs();
LOG.info("Created storage folder : {}", storageDir.getAbsolutePath());
}
}

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

import io.flowinquiry.modules.fss.service.StorageService;
import jakarta.servlet.http.HttpServletRequest;
import java.io.ByteArrayOutputStream;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
Expand All @@ -11,8 +12,6 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.ByteArrayOutputStream;

@RestController
@RequestMapping("/api/files")
public class FileDownloadController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import java.util.Set;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.Set;

@Entity
@Table(name = "fw_organization")
@Getter
Expand Down
Loading

0 comments on commit dad9e96

Please sign in to comment.