Skip to content

Commit

Permalink
[ALS-7687] Create PSAMA cache unit test (#232)
Browse files Browse the repository at this point in the history
* Remove duplicate and unused test classes

* Switch project parent to Spring Boot and update dependencies.

Updated the project parent to `spring-boot-starter-parent` with version `3.3.5`. Consolidated and streamlined dependencies to align with Spring Boot configurations, ensuring compatibility and removing redundant entries.

* Refactor tests to use JUnit 5 and Spring Boot Test

Migrated test classes from JUnit 4 to JUnit 5, replacing @before with @beforeeach, @test(expected) with assertThrows, and @RunWith with @SpringBootTest/@ContextConfiguration annotations. Updated Mockito annotations to @MockBean where appropriate and used dependency injection with @Autowired to initialize services.

* Add unit tests for caching mechanisms in auth services

Introduced `CacheTest` to validate caching behavior in `AccessRuleService` and `UserService`. These tests ensure the correct usage of caches like `mergedRulesCache`, `preProcessedAccessRules`, and `mergedTemplateCache`, and verify proper eviction mechanisms.

* Update Dockerfiles for dynamic JAR filename handling

Changed the Dockerfile COPY commands to use a wildcard for JAR filenames, ensuring compatibility with differing build outputs. Additionally, added the packaging type as 'jar' in the pom.xml to standardize project packaging.

* Add AWS Secrets Manager dependency to pom.xml

Included the `aws-secretsmanager-jdbc` dependency in the pom.xml to support secure secrets management with AWS Secrets Manager. This change aims to enhance security by integrating Secrets Manager into the authentication services.
  • Loading branch information
Gcolon021 authored Oct 30, 2024
1 parent 0c1a417 commit 62d030f
Show file tree
Hide file tree
Showing 34 changed files with 930 additions and 1,417 deletions.
2 changes: 1 addition & 1 deletion pic-sure-auth-services/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ RUN mvn clean install -DskipTests
FROM amazoncorretto:21.0.1-alpine3.18

# Copy jar and access token from maven build
COPY --from=build /app/pic-sure-auth-services/target/pic-sure-auth-services.jar /pic-sure-auth-service.jar
COPY --from=build /app/pic-sure-auth-services/target/pic-sure-auth-services-*.jar /pic-sure-auth-service.jar

# Copy the AWS certificate
COPY pic-sure-auth-services/aws_certs/certificate.der /certificate.der
Expand Down
2 changes: 1 addition & 1 deletion pic-sure-auth-services/bdc.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ENV DATASOURCE_USERNAME=${DATASOURCE_USERNAME}
ENV STACK_SPECIFIC_APPLICATION_ID=${application_id_for_base_query}

# Copy jar and access token from maven build
COPY --from=build /app/pic-sure-auth-services/target/pic-sure-auth-services.jar /pic-sure-auth-service.jar
COPY --from=build /app/pic-sure-auth-services/target/pic-sure-auth-services-*.jar /pic-sure-auth-service.jar

# Copy additional bdc configuration files. Root of the project
COPY config/psama/bdc/psama-db-config.properties /config/psama-db-config.properties
Expand Down
2 changes: 1 addition & 1 deletion pic-sure-auth-services/dev.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ FROM amazoncorretto:21.0.1-alpine3.18

# Copy jar and access token from maven build
#COPY target/pic-sure-auth-services.jar /pic-sure-auth-service.jar
COPY --from=build /app/pic-sure-auth-services/target/pic-sure-auth-services.jar /pic-sure-auth-service.jar
COPY --from=build /app/pic-sure-auth-services/target/pic-sure-auth-services-*.jar /pic-sure-auth-service.jar

EXPOSE 8090

Expand Down
244 changes: 93 additions & 151 deletions pic-sure-auth-services/pom.xml
Original file line number Diff line number Diff line change
@@ -1,64 +1,45 @@
<?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/maven-v4_0_0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>pic-sure-auth-microapp</artifactId>
<groupId>edu.harvard.hms.dbmi.avillach.picsure.auth.microapp</groupId>
<version>2.0-SNAPSHOT</version>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>edu.harvard.hms.dbmi.avillach</groupId>
<artifactId>pic-sure-auth-services</artifactId>
<version>2.0-SNAPSHOT</version>
<name>pic-sure-auth-services</name>
<packaging>jar</packaging>

<url/>
<licenses>
<license/>
</licenses>
<developers>
<developer/>
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
</scm>
<properties>
<xml.bind.version>2.3.0</xml.bind.version>
<java.version>21</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>5.2.1</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- https://mvnrepository.com/artifact/org.springframework/spring-web -->
<!-- Web version has been explicitly set to fix security finding in spring-boot-starter-web -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>6.1.5</version>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>

<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>3.2.3</version>
</dependency>

<!-- Spring autoconfiguration -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>3.2.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>3.2.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-mail -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
<version>3.2.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa -->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -82,62 +63,15 @@
<artifactId>spring-context</artifactId>
<version>6.1.10</version>
</dependency>
<!-- https://mvnrepository.com/artifact/net.bytebuddy/byte-buddy -->
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.14.13</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.mysql/mysql-connector-j -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>8.2.0</version>
</dependency>
<dependency>
<groupId>com.amazonaws.secretsmanager</groupId>
<artifactId>aws-secretsmanager-jdbc</artifactId>
<version>2.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt-api -->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
<version>0.12.5</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<version>0.12.5</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-jackson</artifactId>
<version>0.12.5</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>auth0</artifactId>
<version>2.10.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.9.0</version>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>3.3.4</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.23.4</version>
<scope>test</scope>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>3.2.4</version>
</dependency>
<dependency>
<groupId>com.github.spullara.mustache.java</groupId>
Expand All @@ -156,7 +90,6 @@
<artifactId>jakarta.mail-api</artifactId>
<version>2.1.3</version>
</dependency>

<!-- https://mvnrepository.com/artifact/io.swagger.core.v3/swagger-jaxrs2 -->
<dependency>
<groupId>io.swagger.core.v3</groupId>
Expand Down Expand Up @@ -210,67 +143,76 @@
<artifactId>jackson-annotations</artifactId>
<version>2.17.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/net.bytebuddy/byte-buddy -->
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.14.13</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.mysql/mysql-connector-j -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>8.2.0</version>
</dependency>
<dependency>
<groupId>com.amazonaws.secretsmanager</groupId>
<artifactId>aws-secretsmanager-jdbc</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.9.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt-api -->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
<version>0.12.5</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<version>0.12.5</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-jackson</artifactId>
<version>0.12.5</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>auth0</artifactId>
<version>2.10.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>5.2.1</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>dev</id>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
</profile>
</profiles>

<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>21</source>
<target>21</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>3.2.4</version>
<configuration>
<mainClass>edu.harvard.hms.dbmi.avillach.auth.Application</mainClass>
<layout>JAR</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- This plugin is used to reserve a network port for use during the build process. -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>reserve-network-port</id>
<goals>
<goal>reserve-network-port</goal>
</goals>
<phase>process-test-resources</phase>
<configuration>
<portNames>
<portName>test.server.port</portName>
</portNames>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
</project>
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package edu.harvard.hms.dbmi.avillach.auth.config;

import edu.harvard.hms.dbmi.avillach.auth.filter.JWTFilter;
import edu.harvard.hms.dbmi.avillach.auth.service.impl.AccessRuleService;
import edu.harvard.hms.dbmi.avillach.auth.service.impl.CacheEvictionService;
import edu.harvard.hms.dbmi.avillach.auth.service.impl.SessionService;
import edu.harvard.hms.dbmi.avillach.auth.service.impl.UserService;
import edu.harvard.hms.dbmi.avillach.auth.utils.JWTUtil;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ public class BasicMailService implements MailService {


@Autowired
public BasicMailService(JavaMailSender mailSender, @Value("${application.template.path}") String templatePath, @Value("${application.system.name}") String systemName,
@Value("${application.access.grant.email.subject") String accessGrantEmailSubject, @Value("${application.admin.users}") String adminUsers) {
public BasicMailService(JavaMailSender mailSender,
@Value("${application.template.path}") String templatePath,
@Value("${application.system.name}") String systemName,
@Value("${application.access.grant.email.subject") String accessGrantEmailSubject,
@Value("${application.admin.users}") String adminUsers) {
this.mailSender = mailSender;
this.templatePath = templatePath;
this.systemName = systemName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.event.ApplicationContextEvent;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
Expand Down Expand Up @@ -46,7 +45,9 @@ public class PrivilegeService {
private static final String topmedAccessionField = "\\\\_Topmed Study Accession with Subject ID\\\\";

@Autowired
protected PrivilegeService(PrivilegeRepository privilegeRepository, ApplicationService applicationService, AccessRuleService accessRuleService,
protected PrivilegeService(PrivilegeRepository privilegeRepository,
ApplicationService applicationService,
AccessRuleService accessRuleService,
@Value("${fence.variant.annotation.columns}") String variantAnnotationColumns,
@Value("${fence.harmonized.consent.group.concept.path}") String fenceHarmonizedConsentGroupConceptPath,
@Value("${fence.parent.consent.group.concept.path}") String fenceParentConceptPath,
Expand Down
Loading

0 comments on commit 62d030f

Please # to comment.