Skip to content

Commit

Permalink
🎨 시크릿키 환경변수로 등록
Browse files Browse the repository at this point in the history
  • Loading branch information
seungheon123 committed Jul 3, 2024
1 parent cd7ace8 commit a05949f
Show file tree
Hide file tree
Showing 24 changed files with 54 additions and 28 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ build/
!**/src/main/**/build/
!**/**/build/
!**/src/test/**/build/
*/Api/build
*/Common/build
*/Search/build
**/build/

### STS ###
.apt_generated
Expand Down
2 changes: 2 additions & 0 deletions Api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation project(':Common')
implementation project(':Domain')
implementation 'org.springframework.boot:spring-boot-starter-security'
testImplementation 'org.springframework.security:spring-security-test'
runtimeOnly 'com.mysql:mysql-connector-j'
testImplementation platform('org.junit:junit-bom:5.9.1')
testImplementation 'org.junit.jupiter:junit-jupiter'
Expand Down
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion Api/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ spring:
hibernate:
format_sql: true
use_sql_comments: true
# show_sql: true
# show_sql: true
9 changes: 6 additions & 3 deletions Auth/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id 'java'
id 'java-library'
}

group = 'org.momo'
Expand All @@ -13,13 +14,15 @@ bootJar { enabled = false }
jar { enabled = true }

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-security'
api project(':Common')
implementation project(':Domain')
//implementation 'org.springframework.boot:spring-boot-starter-security'
testImplementation platform('org.junit:junit-bom:5.9.1')
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'org.springframework.security:spring-security-test'
//testImplementation 'org.springframework.security:spring-security-test'

}

test {
useJUnitPlatform()
}
}
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions Auth/src/main/java/org/momo/security/filter/JwtFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
Authentication authentication = new UsernamePasswordAuthenticationToken(principalDetails, null, principalDetails.getAuthorities());
SecurityContextHolder.getContext().setAuthentication(authentication);
}catch (JwtExpiredHandler e){
response.setContentType("application/json");
BaseResponseDto<Object> baseResponseDto = BaseResponseDto.onFailure(
ErrorStatus.JWT_ACCESS_TOKEN_EXPIRED.getCode(),
ErrorStatus.JWT_ACCESS_TOKEN_EXPIRED.getMessage(),
Expand All @@ -53,6 +54,7 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
objectMapper.writeValue(response.getOutputStream(),baseResponseDto);
return;
}catch (JwtInvalidHandler e){
response.setContentType("application/json");
BaseResponseDto<Object> baseResponseDto = BaseResponseDto.onFailure(
ErrorStatus.JWT_TOKEN_INVALID.getCode(),
ErrorStatus.JWT_TOKEN_INVALID.getMessage(),
Expand Down
13 changes: 9 additions & 4 deletions Common/build.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
plugins {
id 'java'
id 'java-library'
}

group = 'org.momo'
version = '0.0.1-SNAPSHOT'
bootJar { enabled = false }
jar { enabled = true }

repositories {
mavenCentral()
}

dependencies {
// Swagger
api group: 'io.jsonwebtoken', name: 'jjwt-api', version: '0.12.3'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'
api 'org.springframework.boot:spring-boot-starter-security'
testImplementation 'org.springframework.security:spring-security-test'
runtimeOnly group: 'io.jsonwebtoken', name: 'jjwt-impl', version: '0.12.3'
runtimeOnly group: 'io.jsonwebtoken', name: 'jjwt-jackson', version: '0.12.3'
testImplementation platform('org.junit:junit-bom:5.9.1')
testImplementation 'org.junit.jupiter:junit-jupiter'
}

test {
useJUnitPlatform()
}
}
Binary file not shown.
Binary file not shown.
2 changes: 0 additions & 2 deletions Common/build/tmp/jar/MANIFEST.MF

This file was deleted.

11 changes: 11 additions & 0 deletions Common/src/main/java/org/momo/MomoCommonApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.momo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class MomoCommonApplication {
public static void main(String[] args) {
SpringApplication.run(MomoCommonApplication.class,args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public enum ErrorStatus implements BaseErrorCode {

// 멤버 관련 에러
MEMBER_NOT_FOUND(HttpStatus.NOT_FOUND, 401, "사용자가 없습니다."),
PASSWORD_NOT_MATCH(HttpStatus.UNAUTHORIZED, 401, "비밀번호가 일치하지 않습니다."),
USER_NOT_EXISTS(HttpStatus.NOT_FOUND, 404, "존재하지 않는 사용자입니다."),
NICKNAME_EXISTS(HttpStatus.CONFLICT, 409, "이미 존재하는 닉네임입니다."),

Expand Down
4 changes: 3 additions & 1 deletion Common/src/main/java/org/momo/util/JwtUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@
import org.momo.exception.handler.JwtExpiredHandler;
import org.momo.exception.handler.JwtInvalidHandler;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.crypto.SecretKey;
import java.util.Date;

@Component
public class JwtUtil implements InitializingBean {
@Value("${JWT_SECRET}")
private String secret;
private static SecretKey secretKey;
private static final Long expireMs = 1000L * 60; //30분
@Override
public void afterPropertiesSet() throws Exception {
String secret = "aaaaaaaaaaabbbbbbbbbccccccddddeeeeeeeefffffffggggggghhhhhhhhiiiijjjjjjjjkllllllllllllllllllllllll";
byte[] keyBytes = Decoders.BASE64.decode(secret);
secretKey = Keys.hmacShaKeyFor(keyBytes);
}
Expand Down
7 changes: 4 additions & 3 deletions Domain/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'java'
id 'java-library'
}

group = 'org.momo'
Expand All @@ -11,11 +11,12 @@ repositories {

dependencies {
implementation project(':Common')
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
api 'org.springframework.boot:spring-boot-starter-data-jpa'
testImplementation platform('org.junit:junit-bom:5.9.1')
testImplementation 'org.junit.jupiter:junit-jupiter'
runtimeOnly 'com.mysql:mysql-connector-j'
}

test {
useJUnitPlatform()
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 0 additions & 2 deletions Domain/build/tmp/jar/MANIFEST.MF

This file was deleted.

12 changes: 10 additions & 2 deletions Domain/src/main/java/org/momo/MomoDomainApplication.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
package org.momo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@SpringBootApplication
@EnableJpaAuditing
public class MomoDomainApplication {
public static void main(String[] args) {
System.out.println("Hello world!");
SpringApplication.run(MomoDomainApplication.class, args);
}
}
}


4 changes: 2 additions & 2 deletions Domain/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/momo_dev?serverTimezone=UTC&characterEncoding=UTF-8
username: root
password: 12345678
username: ${DB_USERNAME}
password: ${DB_PASS}
jpa:
hibernate:
ddl-auto: update
Expand Down
7 changes: 2 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,11 @@ subprojects {
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
//implementation 'org.springframework.boot:spring-boot-starter-batch'
//implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
//runtimeOnly 'com.mysql:mysql-connector-j'
annotationProcessor 'org.projectlombok:lombok'
//testImplementation 'org.springframework.boot:spring-boot-starter-test'
//testImplementation 'org.springframework.batch:spring-batch-test'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.batch:spring-batch-test'
}

tasks.named('test') {
Expand Down

0 comments on commit a05949f

Please sign in to comment.