Skip to content

Commit a2e8922

Browse files
refactor/#181 Auth 인증 인가 모듈 분리 (#187)
* feat: auth 모듈 생성 * feat: 모듈 세팅 및 스웨거 설정 * feat: auth 패키지 이동 * feat: auth 테스트 및 Github Actions 추가 * feat: 테스트 범위 조정 * fix: 스웨거 description 오타 수정 * fix: 테스트 코드 수정 * fix: unused import 삭제 --------- Co-authored-by: 이한음 <leehaneum160924@kyonggi.ac.kr>
1 parent ad225de commit a2e8922

File tree

32 files changed

+560
-231
lines changed

32 files changed

+560
-231
lines changed

.github/workflows/dev-build-deploy.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ jobs:
5555
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/aics-auth:${{ github.sha }} -f aics-auth/Dockerfile .
5656
docker tag ${{ secrets.DOCKERHUB_USERNAME }}/aics-auth:${{ github.sha }} ${{ secrets.DOCKERHUB_USERNAME }}/aics-auth:latest
5757
58+
- name: Docker image build for aics-auth
59+
run: |
60+
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/aics-auth:${{ github.sha }} -f aics-auth/Dockerfile .
61+
docker tag ${{ secrets.DOCKERHUB_USERNAME }}/aics-auth:${{ github.sha }} ${{ secrets.DOCKERHUB_USERNAME }}/aics-auth:latest
62+
5863
# Docker Hub 이미지 푸시
5964
- name: docker Hub push for aics-admin
6065
run: |
@@ -71,6 +76,11 @@ jobs:
7176
docker push ${{ secrets.DOCKERHUB_USERNAME }}/aics-auth:${{ github.sha }}
7277
docker push ${{ secrets.DOCKERHUB_USERNAME }}/aics-auth:latest
7378
79+
- name: docker Hub push for aics-auth
80+
run: |
81+
docker push ${{ secrets.DOCKERHUB_USERNAME }}/aics-auth:${{ github.sha }}
82+
docker push ${{ secrets.DOCKERHUB_USERNAME }}/aics-auth:latest
83+
7484
deploy-to-dev:
7585
runs-on: ubuntu-latest
7686
needs: build-docker-image
@@ -93,7 +103,7 @@ jobs:
93103
echo "${{ secrets.SERVER_PASSWORD }}" | sudo -S docker-compose -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }} pull aics-api
94104
echo "${{ secrets.SERVER_PASSWORD }}" | sudo -S docker-compose -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }} pull aics-admin
95105
echo "${{ secrets.SERVER_PASSWORD }}" | sudo -S docker-compose -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }} pull aics-auth
96-
106+
97107
echo "${{ secrets.SERVER_PASSWORD }}" | sudo -S docker-compose -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }} up -d aics-api
98108
echo "${{ secrets.SERVER_PASSWORD }}" | sudo -S docker-compose -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }} up -d aics-admin
99109
echo "${{ secrets.SERVER_PASSWORD }}" | sudo -S docker-compose -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }} up -d aics-auth

.github/workflows/pull-request-test-coverage.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ jobs:
4242
${{ github.workspace }}/aics-domain/build/jacoco/test/jacocoTestReport.xml
4343
${{ github.workspace }}/aics-api/build/jacoco/test/jacocoTestReport.xml
4444
${{ github.workspace }}/aics-admin/build/jacoco/test/jacocoTestReport.xml
45+
${{ github.workspace }}/aics-auth/build/jacoco/test/jacocoTestReport.xml
4546
token: ${{ secrets.GITHUB_TOKEN }}
4647
min-coverage-overall: 80
4748
min-coverage-changed-files: 70

aics-admin/src/main/java/kgu/developers/admin/config/SwaggerConfig.java

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
11
package kgu.developers.admin.config;
22

3-
import static java.lang.String.format;
4-
import static org.springframework.security.config.Elements.JWT;
5-
6-
import java.util.Arrays;
7-
import java.util.HashMap;
8-
import java.util.List;
9-
import java.util.Map;
10-
import java.util.stream.Collectors;
11-
12-
13-
import org.springframework.beans.factory.annotation.Value;
14-
import org.springframework.context.annotation.Bean;
15-
import org.springframework.context.annotation.Configuration;
16-
import org.springframework.core.env.Environment;
17-
183
import io.swagger.v3.oas.models.Components;
194
import io.swagger.v3.oas.models.OpenAPI;
205
import io.swagger.v3.oas.models.info.Info;
@@ -23,6 +8,19 @@
238
import io.swagger.v3.oas.models.servers.Server;
249
import jakarta.annotation.PostConstruct;
2510
import lombok.RequiredArgsConstructor;
11+
import org.springframework.beans.factory.annotation.Value;
12+
import org.springframework.context.annotation.Bean;
13+
import org.springframework.context.annotation.Configuration;
14+
import org.springframework.core.env.Environment;
15+
16+
import java.util.Arrays;
17+
import java.util.HashMap;
18+
import java.util.List;
19+
import java.util.Map;
20+
import java.util.stream.Collectors;
21+
22+
import static java.lang.String.format;
23+
import static org.springframework.security.config.Elements.JWT;
2624

2725
@Configuration
2826
@RequiredArgsConstructor
@@ -39,6 +37,9 @@ public class SwaggerConfig {
3937
@Value("${profiles.admin-api-port}")
4038
private int adminApiPort;
4139

40+
@Value("${profiles.auth-api-port}")
41+
private int authApiPort;
42+
4243
private final Map<String, Map<String, Object>> profileServerConfig = new HashMap<>();
4344

4445
@PostConstruct
@@ -96,19 +97,32 @@ private SecurityScheme securityScheme() {
9697
private String getDescription() {
9798
String activeProfile = getActiveProfile();
9899
return format("""
99-
AI 컴퓨터공학부 커뮤니티 관리자, AICS-HOME ADMIN API 입니다.\n\n
100-
로그인 API를 통해 액세스 토큰을 발급 받고 헤더에 값을 넣어주세요 . \n\n
101-
별다른 절차 없이 API를 사용하실 수 있습니다.\n\n
102-
103-
사용자 API 문서는 다음 링크에서 확인하실 수 있습니다.\n
104-
<ul>
105-
<li>AICS-HOME API : <a href="%s" target="_blank">%s</a></li>
106-
</ul>
107-
""",
108-
getApiSwaggerByProfile(activeProfile), getApiSwaggerByProfile(activeProfile)
100+
AI 컴퓨터공학부 커뮤니티 관리자, AICS-HOME ADMIN API 입니다.
101+
102+
로그인 API를 통해 액세스 토큰을 발급 받고 헤더에 값을 넣어주세요.
103+
104+
별다른 절차 없이 API를 사용하실 수 있습니다.
105+
106+
사용자 API 문서는 다음 링크에서 확인하실 수 있습니다.
107+
<ul>
108+
<li>AICS-HOME API : <a href="%s" target="_blank">%s</a></li>
109+
</ul>
110+
111+
인증 인가 API 문서는 다음 링크에서 확인하실 수 있습니다.
112+
<ul>
113+
<li>AICS-HOME AUTH API : <a href="%s" target="_blank">%s</a></li>
114+
</ul>
115+
""",
116+
getApiSwaggerByProfile(activeProfile), getApiSwaggerByProfile(activeProfile),
117+
getAuthSwaggerByProfile(activeProfile), getAuthSwaggerByProfile(activeProfile)
109118
);
110119
}
111120

121+
private String getAuthSwaggerByProfile(String profile) {
122+
String url = (String) profileServerConfig.get(profile).get("url");
123+
return url + ":" + authApiPort + "/swagger-ui/index.html";
124+
}
125+
112126
private String getApiSwaggerByProfile(String profile) {
113127
String url = (String) profileServerConfig.get(profile).get("url");
114128
return url + ":" + apiPort + "/swagger-ui/index.html";

aics-admin/src/main/resources/application-dev.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ spring:
1111
profiles:
1212
current-ip: ${CURRENT_IP}
1313
api-port: ${API_SERVER_PORT:8080}
14-
admin-api-port: ${ADMIN_API_SERVER_PORT:8081}
14+
admin-api-port: ${ADMIN_API_SERVER_PORT:8081}
15+
auth-api-port: ${AUTH_API_SERVER_PORT:8082}

aics-admin/src/main/resources/application-local.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ spring:
66
profiles:
77
current-ip: ${CURRENT_IP:localhost}
88
api-port: ${API_SERVER_PORT:8080}
9-
admin-api-port: ${ADMIN_API_SERVER_PORT:8081}
9+
admin-api-port: ${ADMIN_API_SERVER_PORT:8081}
10+
auth-api-port: ${AUTH_API_SERVER_PORT:8082}

aics-admin/src/testFixtures/java/lab/application/LabAdminFacadeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void init() {
4242
.loc("8500")
4343
.site("http://labA.kyonggi.ac.kr")
4444
.advisor("박민준")
45-
.file(testFile)
45+
.imgFile(testFile)
4646
.build()
4747
);
4848
}

aics-api/src/main/java/kgu/developers/api/config/SwaggerConfig.java

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
11
package kgu.developers.api.config;
22

3-
import static java.lang.String.format;
4-
import static org.springframework.security.config.Elements.JWT;
5-
6-
import java.util.Arrays;
7-
import java.util.HashMap;
8-
import java.util.List;
9-
import java.util.Map;
10-
import java.util.stream.Collectors;
11-
12-
13-
import org.springframework.beans.factory.annotation.Value;
14-
import org.springframework.context.annotation.Bean;
15-
import org.springframework.context.annotation.Configuration;
16-
import org.springframework.core.env.Environment;
17-
183
import io.swagger.v3.oas.models.Components;
194
import io.swagger.v3.oas.models.OpenAPI;
205
import io.swagger.v3.oas.models.info.Info;
@@ -23,6 +8,19 @@
238
import io.swagger.v3.oas.models.servers.Server;
249
import jakarta.annotation.PostConstruct;
2510
import lombok.RequiredArgsConstructor;
11+
import org.springframework.beans.factory.annotation.Value;
12+
import org.springframework.context.annotation.Bean;
13+
import org.springframework.context.annotation.Configuration;
14+
import org.springframework.core.env.Environment;
15+
16+
import java.util.Arrays;
17+
import java.util.HashMap;
18+
import java.util.List;
19+
import java.util.Map;
20+
import java.util.stream.Collectors;
21+
22+
import static java.lang.String.format;
23+
import static org.springframework.security.config.Elements.JWT;
2624

2725
@Configuration
2826
@RequiredArgsConstructor
@@ -39,6 +37,9 @@ public class SwaggerConfig {
3937
@Value("${profiles.admin-api-port}")
4038
private int adminApiPort;
4139

40+
@Value("${profiles.auth-api-port}")
41+
private int authApiPort;
42+
4243
private final Map<String, Map<String, Object>> profileServerConfig = new HashMap<>();
4344

4445
@PostConstruct
@@ -96,16 +97,26 @@ private SecurityScheme securityScheme() {
9697
private String getDescription() {
9798
String activeProfile = getActiveProfile();
9899
return format("""
99-
AI 컴퓨터공학부 커뮤니티, AICS-HOME API 입니다.\n\n
100-
로그인 API를 통해 액세스 토큰을 발급 받고 헤더에 값을 넣어주세요 . \n\n
101-
별다른 절차 없이 API를 사용하실 수 있습니다.\n\n
102-
103-
관리자 API 문서는 다음 링크에서 확인하실 수 있습니다.\n
104-
<ul>
105-
<li>AICS-HOME ADMIN API : <a href="%s" target="_blank">%s</a></li>
106-
</ul>
107-
""",
108-
getAdminSwaggerByProfile(activeProfile), getAdminSwaggerByProfile(activeProfile)
100+
AI 컴퓨터공학부 커뮤니티 관리자, AICS-HOME ADMIN API 입니다.
101+
102+
로그인 API를 통해 액세스 토큰을 발급 받고 헤더에 값을 넣어주세요.
103+
104+
별다른 절차 없이 API를 사용하실 수 있습니다.
105+
106+
관리자 API 문서는 다음 링크에서 확인하실 수 있습니다.
107+
<ul>
108+
<li>AICS-HOME ADMIN API : <a href="%s" target="_blank">%s</a></li>
109+
</ul>
110+
111+
인증 인가 API 문서는 다음 링크에서 확인하실 수 있습니다.
112+
<ul>
113+
<li>AICS-HOME AUTH API : <a href="%s" target="_blank">%s</a></li>
114+
</ul>
115+
""",
116+
getAdminSwaggerByProfile(activeProfile),
117+
getAdminSwaggerByProfile(activeProfile),
118+
getAuthSwaggerByProfile(activeProfile),
119+
getAuthSwaggerByProfile(activeProfile)
109120
);
110121
}
111122

@@ -114,6 +125,11 @@ private String getAdminSwaggerByProfile(String profile) {
114125
return url + ":" + adminApiPort + "/swagger-ui/index.html";
115126
}
116127

128+
private String getAuthSwaggerByProfile(String profile) {
129+
String url = (String) profileServerConfig.get(profile).get("url");
130+
return url + ":" + authApiPort + "/swagger-ui/index.html";
131+
}
132+
117133
private String getActiveProfile() {
118134
return Arrays.stream(environment.getActiveProfiles())
119135
.findFirst()

aics-api/src/main/resources/application-dev.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ spring:
1111
profiles:
1212
current-ip: ${CURRENT_IP}
1313
api-port: ${API_SERVER_PORT:8080}
14-
admin-api-port: ${ADMIN_API_SERVER_PORT:8081}
14+
admin-api-port: ${ADMIN_API_SERVER_PORT:8081}
15+
auth-api-port: ${AUTH_API_SERVER_PORT:8082}

aics-api/src/main/resources/application-local.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ spring:
66
profiles:
77
current-ip: ${CURRENT_IP:localhost}
88
api-port: ${API_SERVER_PORT:8080}
9-
admin-api-port: ${ADMIN_API_SERVER_PORT:8081}
9+
admin-api-port: ${ADMIN_API_SERVER_PORT:8081}
10+
auth-api-port: ${AUTH_API_SERVER_PORT:8082}

aics-api/src/testFixtures/java/lab/application/LabFacadeTest.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import java.util.List;
66

7+
import kgu.developers.domain.file.domain.FileEntity;
8+
import mock.repository.FakeFileRepository;
79
import org.junit.jupiter.api.BeforeEach;
810
import org.junit.jupiter.api.DisplayName;
911
import org.junit.jupiter.api.Test;
@@ -21,16 +23,20 @@ public class LabFacadeTest {
2123
@BeforeEach
2224
public void init() {
2325
FakeLabRepository fakeLabRepository = new FakeLabRepository();
26+
FakeFileRepository fakeFileRepository = new FakeFileRepository();
2427
labFacade = new LabFacade(
2528
new LabQueryService(fakeLabRepository)
2629
);
2730

31+
FileEntity testFile = fakeFileRepository.save(FileEntity.builder().id(1L).build());
32+
2833
fakeLabRepository.save(
2934
Lab.create(
3035
"인공지능 연구실",
3136
"8502, 8503",
3237
"http://ailab.kyonggi.ac.kr",
33-
"김인철"
38+
"김인철",
39+
testFile
3440
)
3541
);
3642

@@ -39,7 +45,8 @@ public void init() {
3945
"알고리즘 연구실",
4046
"8504",
4147
"http://algeo.kyonggi.ac.kr/",
42-
"배상원"
48+
"배상원",
49+
testFile
4350
)
4451
);
4552
}

0 commit comments

Comments
 (0)