-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from nhnacademy-be5-T3Team/chore/removeDB
feature: #14 SecureKeyManager 동작 구현
- Loading branch information
Showing
15 changed files
with
183 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 0 additions & 55 deletions
55
src/main/java/com/t3t/authenticationapi/account/config/RedisConfig.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/com/t3t/authenticationapi/config/DataSourceConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.t3t.authenticationapi.config; | ||
|
||
import com.t3t.authenticationapi.property.DatabaseProperties; | ||
import org.springframework.boot.jdbc.DataSourceBuilder; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import javax.sql.DataSource; | ||
|
||
@Configuration | ||
public class DataSourceConfig { | ||
@Bean | ||
public DataSource dataSource(DatabaseProperties databaseProperties){ | ||
return DataSourceBuilder.create() | ||
.url(databaseProperties.getDatabaseUrl()) | ||
.driverClassName(databaseProperties.getDriverClassName()) | ||
.username(databaseProperties.getUsername()) | ||
.password(databaseProperties.getPassword()) | ||
.build(); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/t3t/authenticationapi/config/DatabasePropertiesConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.t3t.authenticationapi.config; | ||
|
||
import com.t3t.authenticationapi.keymanager.properties.SecretKeyProperties; | ||
import com.t3t.authenticationapi.keymanager.service.SecretKeyManagerService; | ||
import com.t3t.authenticationapi.property.DatabaseProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.core.env.Environment; | ||
|
||
@Configuration | ||
public class DatabasePropertiesConfig { | ||
@Bean | ||
@Profile({"prod", "dev", "test"}) | ||
public DatabaseProperties dataSourceProperties(SecretKeyManagerService secretKeyManagerService, | ||
SecretKeyProperties secretKeyProperties, | ||
Environment environment) { | ||
|
||
String activeProfile = environment.getActiveProfiles()[0]; | ||
String activeProfileSuffix = activeProfile.equals("prod") ? "" : "_" + activeProfile; | ||
|
||
return DatabaseProperties.builder() | ||
.databaseUrl(String.format("jdbc:mysql://%s:%s/%s%s", | ||
secretKeyManagerService.getSecretValue(secretKeyProperties.getDatabaseIpAddressKeyId()), | ||
secretKeyManagerService.getSecretValue(secretKeyProperties.getDatabasePortKeyId()), | ||
secretKeyManagerService.getSecretValue(secretKeyProperties.getDatabaseNameKeyId()), | ||
activeProfileSuffix)) | ||
.driverClassName("com.mysql.cj.jdbc.Driver") | ||
.username(secretKeyManagerService.getSecretValue(secretKeyProperties.getDatabaseUsernameKeyId())) | ||
.password(secretKeyManagerService.getSecretValue(secretKeyProperties.getDatabasePasswordKeyId())) | ||
.build(); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
src/main/java/com/t3t/authenticationapi/config/RedisConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.t3t.authenticationapi.config; | ||
|
||
import com.t3t.authenticationapi.keymanager.properties.SecretKeyProperties; | ||
import com.t3t.authenticationapi.keymanager.service.SecretKeyManagerService; | ||
import com.t3t.authenticationapi.property.RedisProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
import org.springframework.data.redis.connection.RedisStandaloneConfiguration; | ||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories; | ||
import org.springframework.data.redis.serializer.StringRedisSerializer; | ||
|
||
/** | ||
* redis 연결을 위한 configuration 클래스 | ||
* @author joohyun1996 (이주현) | ||
*/ | ||
@Configuration | ||
@EnableRedisRepositories | ||
public class RedisConfig { | ||
@Bean | ||
public RedisProperties redisProperties(SecretKeyManagerService secretKeyManagerService, | ||
SecretKeyProperties secretKeyProperties, | ||
Environment environment){ | ||
|
||
String activeProfile = environment.getActiveProfiles()[0]; | ||
String activeProfileSuffix = activeProfile.equals("prod") ? "" : "_" + activeProfile; | ||
|
||
return RedisProperties.builder() | ||
.host(secretKeyManagerService.getSecretValue(secretKeyProperties.getRedisIpAddressKeyId())) | ||
.port(Integer.valueOf(secretKeyManagerService.getSecretValue(secretKeyProperties.getRedisPortKeyId()))) | ||
.password(secretKeyManagerService.getSecretValue(secretKeyProperties.getRedisPasswordKeyId())) | ||
.database(20) | ||
.build(); | ||
} | ||
|
||
/** | ||
* RedisServer에 연결을 생성하는데 사용되는 클래스 | ||
* getConnection() 호출될 때 마다 새로운 LettuceConnection 생성 | ||
* Thread-safe 하다 | ||
* 동기, 비동기, 리액티브 api 모두 가능 | ||
* @author joohyun1996 (이주현) | ||
*/ | ||
@Bean | ||
public RedisConnectionFactory redisConnectionFactory(RedisProperties redisProperties){ | ||
RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration(redisProperties.getHost(), redisProperties.getPort()); | ||
configuration.setPassword(redisProperties.getPassword()); | ||
configuration.setDatabase(redisProperties.getDatabase()); | ||
return new LettuceConnectionFactory(configuration); | ||
} | ||
|
||
@Bean | ||
public RedisTemplate<String, String> redisTemplate(RedisProperties redisProperties){ | ||
RedisTemplate<String, String> redisTemplate = new RedisTemplate<>(); | ||
redisTemplate.setKeySerializer(new StringRedisSerializer()); | ||
redisTemplate.setValueSerializer(new StringRedisSerializer()); | ||
redisTemplate.setConnectionFactory(redisConnectionFactory(redisProperties)); | ||
return redisTemplate; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/java/com/t3t/authenticationapi/property/DatabaseProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.t3t.authenticationapi.property; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class DatabaseProperties { | ||
private String databaseUrl; | ||
private String driverClassName; | ||
private String username; | ||
private String password; | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/t3t/authenticationapi/property/RedisProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.t3t.authenticationapi.property; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class RedisProperties { | ||
private String host; | ||
private Integer port; | ||
private Integer database; | ||
private String password; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
eureka: | ||
client: | ||
service-url: | ||
defaultZone: ${eurekaServiceUrlDefaultZone} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 0 additions & 4 deletions
4
src/test/java/com/t3t/authenticationapi/filter/CustomLogoutFilterTest.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.