Skip to content

Commit 18bf55f

Browse files
committed
[refactor/#350] Spring Boot 3 마이그레이션 시 발생한 Deprecation 경고 해결
1 parent 070bc04 commit 18bf55f

3 files changed

Lines changed: 35 additions & 27 deletions

File tree

build.gradle

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ subprojects {
6464
}
6565
}
6666

67+
testing {
68+
suites {
69+
test {
70+
useJUnitJupiter()
71+
}
72+
}
73+
}
74+
6775
dependencies {
6876
annotationProcessor(
6977
'org.projectlombok:lombok',
@@ -103,10 +111,6 @@ subprojects {
103111
)
104112
}
105113

106-
test {
107-
useJUnitPlatform()
108-
}
109-
110114
}
111115

112116
project(':module-jpa') {
@@ -175,7 +179,7 @@ project(':resource-server') {
175179
delete file('src/main/generated')
176180
}
177181

178-
task cleanGeneratedDir(type: Delete) {
182+
tasks.register('cleanGeneratedDir', Delete) {
179183
delete file('src/main/generated')
180184
}
181185
}

module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/cookie/CookieUtils.java

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package com.inhabas.api.auth.domain.oauth2.cookie;
22

3+
import java.io.ByteArrayInputStream;
4+
import java.io.ByteArrayOutputStream;
5+
import java.io.IOException;
6+
import java.io.ObjectInputStream;
7+
import java.io.ObjectOutputStream;
38
import java.time.Duration;
49
import java.util.Base64;
5-
import java.util.Objects;
610
import java.util.Optional;
711

812
import jakarta.servlet.http.Cookie;
@@ -11,9 +15,6 @@
1115

1216
import org.springframework.http.ResponseCookie;
1317
import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest;
14-
import org.springframework.util.SerializationUtils;
15-
16-
import io.micrometer.core.instrument.util.StringUtils;
1718

1819
public interface CookieUtils {
1920

@@ -130,8 +131,14 @@ static void setCookie(
130131
* @return 브라우저 쿠키에 담기 위해 OAuth2AuthorizationRequest 를 string 으로 변환.
131132
*/
132133
static String serialize(OAuth2AuthorizationRequest request) {
133-
134-
return Base64.getUrlEncoder().encodeToString(SerializationUtils.serialize(request));
134+
try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
135+
ObjectOutputStream oos = new ObjectOutputStream(bos)) {
136+
oos.writeObject(request);
137+
oos.flush();
138+
return Base64.getUrlEncoder().encodeToString(bos.toByteArray());
139+
} catch (IOException e) {
140+
throw new IllegalStateException("Failed to serialize OAuth2AuthorizationRequest", e);
141+
}
135142
}
136143

137144
/**
@@ -141,18 +148,19 @@ static String serialize(OAuth2AuthorizationRequest request) {
141148
*/
142149
static <T> T deserialize(Cookie cookie, Class<T> clz) {
143150

144-
if (isDeleted(cookie)) return null;
145-
else {
146-
try {
147-
return clz.cast(
148-
SerializationUtils.deserialize(Base64.getUrlDecoder().decode(cookie.getValue())));
149-
} catch (RuntimeException ex) { // Base64 decoding error or deserialization error
150-
return null;
151+
if (cookie == null || isBlank(cookie.getValue())) return null;
152+
try {
153+
byte[] data = Base64.getUrlDecoder().decode(cookie.getValue());
154+
try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(data))) {
155+
Object obj = ois.readObject();
156+
return clz.cast(obj);
151157
}
158+
} catch (IOException | ClassNotFoundException | IllegalArgumentException ex) {
159+
return null;
152160
}
153161
}
154162

155-
private static boolean isDeleted(Cookie cookie) {
156-
return StringUtils.isBlank(cookie.getValue()) || Objects.isNull(cookie.getValue());
163+
private static boolean isBlank(String s) {
164+
return s == null || s.trim().isEmpty();
157165
}
158166
}

module-auth/src/main/java/com/inhabas/api/auth/domain/oauth2/member/security/DefaultRoleHierarchy.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ public class DefaultRoleHierarchy implements Hierarchical {
2929
@Override
3030
public RoleHierarchy getHierarchy() {
3131

32-
RoleHierarchyImpl roleHierarchy = new RoleHierarchyImpl();
33-
3432
Map<String, List<String>> roleHierarchyMap =
3533
new HashMap<>() {
3634
{
@@ -62,14 +60,12 @@ public RoleHierarchy getHierarchy() {
6260
put(SECRETARY, Arrays.asList(BASIC, DEACTIVATED, NOT_APPROVED, ANONYMOUS));
6361
put(BASIC, Arrays.asList(DEACTIVATED, NOT_APPROVED, ANONYMOUS));
6462
put(DEACTIVATED, Arrays.asList(NOT_APPROVED, ANONYMOUS));
65-
put(NOT_APPROVED, Arrays.asList(ANONYMOUS));
66-
put(SIGNING_UP, Arrays.asList(ANONYMOUS));
63+
put(NOT_APPROVED, Collections.singletonList(ANONYMOUS));
64+
put(SIGNING_UP, Collections.singletonList(ANONYMOUS));
6765
}
6866
};
6967

7068
String roles = RoleHierarchyUtils.roleHierarchyFromMap(roleHierarchyMap);
71-
roleHierarchy.setHierarchy(roles);
72-
73-
return roleHierarchy;
69+
return RoleHierarchyImpl.fromHierarchy(roles);
7470
}
7571
}

0 commit comments

Comments
 (0)