Skip to content

Commit 62d030f

Browse files
authored
[ALS-7687] Create PSAMA cache unit test (#232)
* 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.
1 parent 0c1a417 commit 62d030f

34 files changed

+930
-1417
lines changed

pic-sure-auth-services/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ RUN mvn clean install -DskipTests
1515
FROM amazoncorretto:21.0.1-alpine3.18
1616

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

2020
# Copy the AWS certificate
2121
COPY pic-sure-auth-services/aws_certs/certificate.der /certificate.der

pic-sure-auth-services/bdc.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ENV DATASOURCE_USERNAME=${DATASOURCE_USERNAME}
2020
ENV STACK_SPECIFIC_APPLICATION_ID=${application_id_for_base_query}
2121

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

2525
# Copy additional bdc configuration files. Root of the project
2626
COPY config/psama/bdc/psama-db-config.properties /config/psama-db-config.properties

pic-sure-auth-services/dev.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ FROM amazoncorretto:21.0.1-alpine3.18
1313

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

1818
EXPOSE 8090
1919

pic-sure-auth-services/pom.xml

Lines changed: 93 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,45 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
44
<modelVersion>4.0.0</modelVersion>
55
<parent>
6-
<artifactId>pic-sure-auth-microapp</artifactId>
7-
<groupId>edu.harvard.hms.dbmi.avillach.picsure.auth.microapp</groupId>
8-
<version>2.0-SNAPSHOT</version>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>3.3.5</version>
9+
<relativePath/> <!-- lookup parent from repository -->
910
</parent>
1011
<groupId>edu.harvard.hms.dbmi.avillach</groupId>
1112
<artifactId>pic-sure-auth-services</artifactId>
13+
<version>2.0-SNAPSHOT</version>
14+
<name>pic-sure-auth-services</name>
1215
<packaging>jar</packaging>
13-
16+
<url/>
17+
<licenses>
18+
<license/>
19+
</licenses>
20+
<developers>
21+
<developer/>
22+
</developers>
23+
<scm>
24+
<connection/>
25+
<developerConnection/>
26+
<tag/>
27+
<url/>
28+
</scm>
1429
<properties>
15-
<xml.bind.version>2.3.0</xml.bind.version>
30+
<java.version>21</java.version>
1631
</properties>
1732
<dependencies>
1833
<dependency>
19-
<groupId>org.apache.httpcomponents.client5</groupId>
20-
<artifactId>httpclient5</artifactId>
21-
<version>5.2.1</version>
22-
<exclusions>
23-
<exclusion>
24-
<groupId>org.slf4j</groupId>
25-
<artifactId>slf4j-api</artifactId>
26-
</exclusion>
27-
</exclusions>
28-
</dependency>
29-
30-
<!-- https://mvnrepository.com/artifact/org.springframework/spring-web -->
31-
<!-- Web version has been explicitly set to fix security finding in spring-boot-starter-web -->
32-
<dependency>
33-
<groupId>org.springframework</groupId>
34-
<artifactId>spring-web</artifactId>
35-
<version>6.1.5</version>
34+
<groupId>org.springframework.boot</groupId>
35+
<artifactId>spring-boot-starter</artifactId>
3636
</dependency>
37-
3837
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
3938
<dependency>
4039
<groupId>org.springframework.boot</groupId>
4140
<artifactId>spring-boot-starter-web</artifactId>
4241
<version>3.2.3</version>
4342
</dependency>
44-
45-
<!-- Spring autoconfiguration -->
46-
<dependency>
47-
<groupId>org.springframework.boot</groupId>
48-
<artifactId>spring-boot-autoconfigure</artifactId>
49-
<version>3.2.3</version>
50-
</dependency>
51-
<dependency>
52-
<groupId>org.springframework.boot</groupId>
53-
<artifactId>spring-boot-starter-security</artifactId>
54-
<version>3.2.4</version>
55-
</dependency>
56-
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-mail -->
57-
<dependency>
58-
<groupId>org.springframework.boot</groupId>
59-
<artifactId>spring-boot-starter-mail</artifactId>
60-
<version>3.2.4</version>
61-
</dependency>
6243
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa -->
6344
<dependency>
6445
<groupId>org.springframework.boot</groupId>
@@ -82,62 +63,15 @@
8263
<artifactId>spring-context</artifactId>
8364
<version>6.1.10</version>
8465
</dependency>
85-
<!-- https://mvnrepository.com/artifact/net.bytebuddy/byte-buddy -->
86-
<dependency>
87-
<groupId>net.bytebuddy</groupId>
88-
<artifactId>byte-buddy</artifactId>
89-
<version>1.14.13</version>
90-
</dependency>
91-
<!-- https://mvnrepository.com/artifact/com.mysql/mysql-connector-j -->
92-
<dependency>
93-
<groupId>com.mysql</groupId>
94-
<artifactId>mysql-connector-j</artifactId>
95-
<version>8.2.0</version>
96-
</dependency>
97-
<dependency>
98-
<groupId>com.amazonaws.secretsmanager</groupId>
99-
<artifactId>aws-secretsmanager-jdbc</artifactId>
100-
<version>2.0.0</version>
101-
</dependency>
102-
<!-- https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt-api -->
103-
<dependency>
104-
<groupId>io.jsonwebtoken</groupId>
105-
<artifactId>jjwt-api</artifactId>
106-
<version>0.12.5</version>
107-
</dependency>
108-
<dependency>
109-
<groupId>io.jsonwebtoken</groupId>
110-
<artifactId>jjwt-impl</artifactId>
111-
<version>0.12.5</version>
112-
<scope>runtime</scope>
113-
</dependency>
114-
<dependency>
115-
<groupId>io.jsonwebtoken</groupId>
116-
<artifactId>jjwt-jackson</artifactId>
117-
<version>0.12.5</version>
118-
<scope>runtime</scope>
119-
</dependency>
120-
<dependency>
121-
<groupId>com.auth0</groupId>
122-
<artifactId>auth0</artifactId>
123-
<version>2.10.1</version>
124-
</dependency>
125-
<dependency>
126-
<groupId>junit</groupId>
127-
<artifactId>junit</artifactId>
128-
<version>4.13.1</version>
129-
<scope>test</scope>
130-
</dependency>
13166
<dependency>
132-
<groupId>com.jayway.jsonpath</groupId>
133-
<artifactId>json-path</artifactId>
134-
<version>2.9.0</version>
67+
<groupId>org.springframework.boot</groupId>
68+
<artifactId>spring-boot-starter-test</artifactId>
69+
<version>3.3.4</version>
13570
</dependency>
13671
<dependency>
137-
<groupId>org.mockito</groupId>
138-
<artifactId>mockito-core</artifactId>
139-
<version>2.23.4</version>
140-
<scope>test</scope>
72+
<groupId>org.springframework.boot</groupId>
73+
<artifactId>spring-boot-starter-security</artifactId>
74+
<version>3.2.4</version>
14175
</dependency>
14276
<dependency>
14377
<groupId>com.github.spullara.mustache.java</groupId>
@@ -156,7 +90,6 @@
15690
<artifactId>jakarta.mail-api</artifactId>
15791
<version>2.1.3</version>
15892
</dependency>
159-
16093
<!-- https://mvnrepository.com/artifact/io.swagger.core.v3/swagger-jaxrs2 -->
16194
<dependency>
16295
<groupId>io.swagger.core.v3</groupId>
@@ -210,67 +143,76 @@
210143
<artifactId>jackson-annotations</artifactId>
211144
<version>2.17.0</version>
212145
</dependency>
146+
<!-- https://mvnrepository.com/artifact/net.bytebuddy/byte-buddy -->
147+
<dependency>
148+
<groupId>net.bytebuddy</groupId>
149+
<artifactId>byte-buddy</artifactId>
150+
<version>1.14.13</version>
151+
</dependency>
152+
<!-- https://mvnrepository.com/artifact/com.mysql/mysql-connector-j -->
153+
<dependency>
154+
<groupId>com.mysql</groupId>
155+
<artifactId>mysql-connector-j</artifactId>
156+
<version>8.2.0</version>
157+
</dependency>
158+
<dependency>
159+
<groupId>com.amazonaws.secretsmanager</groupId>
160+
<artifactId>aws-secretsmanager-jdbc</artifactId>
161+
<version>2.0.0</version>
162+
</dependency>
163+
<dependency>
164+
<groupId>com.jayway.jsonpath</groupId>
165+
<artifactId>json-path</artifactId>
166+
<version>2.9.0</version>
167+
</dependency>
168+
<!-- https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt-api -->
169+
<dependency>
170+
<groupId>io.jsonwebtoken</groupId>
171+
<artifactId>jjwt-api</artifactId>
172+
<version>0.12.5</version>
173+
</dependency>
174+
<dependency>
175+
<groupId>io.jsonwebtoken</groupId>
176+
<artifactId>jjwt-impl</artifactId>
177+
<version>0.12.5</version>
178+
<scope>runtime</scope>
179+
</dependency>
180+
<dependency>
181+
<groupId>io.jsonwebtoken</groupId>
182+
<artifactId>jjwt-jackson</artifactId>
183+
<version>0.12.5</version>
184+
<scope>runtime</scope>
185+
</dependency>
186+
<dependency>
187+
<groupId>com.auth0</groupId>
188+
<artifactId>auth0</artifactId>
189+
<version>2.10.1</version>
190+
</dependency>
191+
<dependency>
192+
<groupId>org.apache.httpcomponents.client5</groupId>
193+
<artifactId>httpclient5</artifactId>
194+
<version>5.2.1</version>
195+
<exclusions>
196+
<exclusion>
197+
<groupId>org.slf4j</groupId>
198+
<artifactId>slf4j-api</artifactId>
199+
</exclusion>
200+
</exclusions>
201+
</dependency>
202+
<dependency>
203+
<groupId>junit</groupId>
204+
<artifactId>junit</artifactId>
205+
<version>4.13.1</version>
206+
<scope>test</scope>
207+
</dependency>
213208
</dependencies>
214-
<profiles>
215-
<profile>
216-
<id>dev</id>
217-
<dependencies>
218-
<dependency>
219-
<groupId>org.springframework.boot</groupId>
220-
<artifactId>spring-boot-devtools</artifactId>
221-
<optional>true</optional>
222-
</dependency>
223-
</dependencies>
224-
</profile>
225-
</profiles>
209+
226210
<build>
227-
<finalName>${project.artifactId}</finalName>
228211
<plugins>
229-
<plugin>
230-
<groupId>org.apache.maven.plugins</groupId>
231-
<artifactId>maven-compiler-plugin</artifactId>
232-
<version>3.11.0</version>
233-
<configuration>
234-
<source>21</source>
235-
<target>21</target>
236-
</configuration>
237-
</plugin>
238212
<plugin>
239213
<groupId>org.springframework.boot</groupId>
240214
<artifactId>spring-boot-maven-plugin</artifactId>
241-
<version>3.2.4</version>
242-
<configuration>
243-
<mainClass>edu.harvard.hms.dbmi.avillach.auth.Application</mainClass>
244-
<layout>JAR</layout>
245-
</configuration>
246-
<executions>
247-
<execution>
248-
<goals>
249-
<goal>repackage</goal>
250-
</goals>
251-
</execution>
252-
</executions>
253-
</plugin>
254-
<!-- This plugin is used to reserve a network port for use during the build process. -->
255-
<plugin>
256-
<groupId>org.codehaus.mojo</groupId>
257-
<artifactId>build-helper-maven-plugin</artifactId>
258-
<version>1.5</version>
259-
<executions>
260-
<execution>
261-
<id>reserve-network-port</id>
262-
<goals>
263-
<goal>reserve-network-port</goal>
264-
</goals>
265-
<phase>process-test-resources</phase>
266-
<configuration>
267-
<portNames>
268-
<portName>test.server.port</portName>
269-
</portNames>
270-
</configuration>
271-
</execution>
272-
</executions>
273215
</plugin>
274216
</plugins>
275217
</build>
276-
</project>
218+
</project>

pic-sure-auth-services/src/main/java/edu/harvard/hms/dbmi/avillach/auth/config/SecurityConfig.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package edu.harvard.hms.dbmi.avillach.auth.config;
22

33
import edu.harvard.hms.dbmi.avillach.auth.filter.JWTFilter;
4-
import edu.harvard.hms.dbmi.avillach.auth.service.impl.AccessRuleService;
54
import edu.harvard.hms.dbmi.avillach.auth.service.impl.CacheEvictionService;
6-
import edu.harvard.hms.dbmi.avillach.auth.service.impl.SessionService;
75
import edu.harvard.hms.dbmi.avillach.auth.service.impl.UserService;
86
import edu.harvard.hms.dbmi.avillach.auth.utils.JWTUtil;
97
import org.springframework.beans.factory.annotation.Autowired;

pic-sure-auth-services/src/main/java/edu/harvard/hms/dbmi/avillach/auth/service/impl/BasicMailService.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@ public class BasicMailService implements MailService {
4343

4444

4545
@Autowired
46-
public BasicMailService(JavaMailSender mailSender, @Value("${application.template.path}") String templatePath, @Value("${application.system.name}") String systemName,
47-
@Value("${application.access.grant.email.subject") String accessGrantEmailSubject, @Value("${application.admin.users}") String adminUsers) {
46+
public BasicMailService(JavaMailSender mailSender,
47+
@Value("${application.template.path}") String templatePath,
48+
@Value("${application.system.name}") String systemName,
49+
@Value("${application.access.grant.email.subject") String accessGrantEmailSubject,
50+
@Value("${application.admin.users}") String adminUsers) {
4851
this.mailSender = mailSender;
4952
this.templatePath = templatePath;
5053
this.systemName = systemName;

pic-sure-auth-services/src/main/java/edu/harvard/hms/dbmi/avillach/auth/service/impl/PrivilegeService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.springframework.beans.factory.annotation.Autowired;
1313
import org.springframework.beans.factory.annotation.Value;
1414
import org.springframework.context.event.ApplicationContextEvent;
15-
import org.springframework.context.event.ContextRefreshedEvent;
1615
import org.springframework.context.event.EventListener;
1716
import org.springframework.security.core.context.SecurityContext;
1817
import org.springframework.security.core.context.SecurityContextHolder;
@@ -46,7 +45,9 @@ public class PrivilegeService {
4645
private static final String topmedAccessionField = "\\\\_Topmed Study Accession with Subject ID\\\\";
4746

4847
@Autowired
49-
protected PrivilegeService(PrivilegeRepository privilegeRepository, ApplicationService applicationService, AccessRuleService accessRuleService,
48+
protected PrivilegeService(PrivilegeRepository privilegeRepository,
49+
ApplicationService applicationService,
50+
AccessRuleService accessRuleService,
5051
@Value("${fence.variant.annotation.columns}") String variantAnnotationColumns,
5152
@Value("${fence.harmonized.consent.group.concept.path}") String fenceHarmonizedConsentGroupConceptPath,
5253
@Value("${fence.parent.consent.group.concept.path}") String fenceParentConceptPath,

0 commit comments

Comments
 (0)