Skip to content

Commit

Permalink
FIX:: security cors update
Browse files Browse the repository at this point in the history
  • Loading branch information
minwoo1999 committed Jun 26, 2024
1 parent ea607e7 commit 4bf88ae
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.example.rework.config.redis.util;

import com.example.rework.mail.MailPurpose;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.time.Duration;
import java.util.List;

@RequiredArgsConstructor
@Service
public class EmailRedisUtil {
private final StringRedisTemplate stringRedisTemplate;

// key를 통해 value 리턴
public List<String> getData(String key) {
ListOperations<String, String> valueOperations = stringRedisTemplate.opsForList();
long size = valueOperations.size(key); // Get the size of the list
return valueOperations.range(key, 0, size - 1); // Get all elements of the list
}
public boolean existData(String key) {
return stringRedisTemplate.hasKey(key);
}


// 유효 시간 동안(key, value)저장
// public void setDataExpire(String key, Integer value, long duration) {
// ValueOperations<String, String> valueOperations = stringRedisTemplate.opsForValue();
// Duration expireDuration = Duration.ofSeconds(duration);
// valueOperations.set(key, value.toString(), expireDuration);
// }
public void setListData(String key, String value, MailPurpose mailPurpose, long duration) {
ListOperations<String, String> listOperations = stringRedisTemplate.opsForList();
String data = value + "|" + mailPurpose;
Duration expireDuration = Duration.ofSeconds(duration);

listOperations.leftPush(key, data);
stringRedisTemplate.expire(key, expireDuration);
}

public void deleteData(String key) {
stringRedisTemplate.delete(key);
}

public void setUpdatePasswordData(String email, long duration) {
ListOperations<String, String> listOperations = stringRedisTemplate.opsForList();
String data = email;
Duration expireDuration = Duration.ofSeconds(duration);

listOperations.leftPush(email, data);
stringRedisTemplate.expire(email, expireDuration);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public class ErrorResponse {
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowCredentials(true);
configuration.setAllowedOrigins(Arrays.asList("http://localhost:5173","https://rework-eight.vercel.app"));
configuration.setAllowedOrigins(Arrays.asList("http://localhost:5173","https://rework-eight.vercel.app", "https://rework.im","https://www.rework.im"));
configuration.setAllowedMethods(Arrays.asList("GET", "POST","PUT","DELETE","PATCH"));
configuration.addAllowedHeader("*");
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.rework.member.application;

public enum VerificationStatus {
UNPROVIDED,
EXPIRED,
MATCHED,
UNMATCHED
}
34 changes: 34 additions & 0 deletions src/main/resources/logback-local.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>

<springProperty name="DISCORD_WEBHOOK_URL" source="logging.discord.webhook-url"/>
<appender name="DISCORD" class="com.github.napstr.logback.DiscordAppender">
<webhookUri>${discord_webhook_url3}</webhookUri>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%d{HH:mm:ss} [%thread] [%-5level] %logger{36} - %msg%n```%ex{full}```</pattern>
</layout>
<username>WanF-logback</username>
<avatarUrl>https://cdn-icons-png.flaticon.com/512/1383/1383395.png</avatarUrl>
<tts>false</tts>
</appender>

<appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<Pattern>${CONSOLE_LOG_PATTERN}</Pattern>
<charset>utf8</charset>
</encoder>
</appender>

<appender name="ASYNC_DISCORD" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="DISCORD" />
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>ERROR</level>
</filter>
</appender>

<root level="INFO">
<appender-ref ref="ASYNC_DISCORD"/>
<appender-ref ref="Console"/>
</root>
</configuration>

0 comments on commit 4bf88ae

Please sign in to comment.