File tree 1 file changed +5
-6
lines changed
src/main/kotlin/org/gitanimals/identity/controller/interceptor
1 file changed +5
-6
lines changed Original file line number Diff line number Diff line change @@ -14,8 +14,7 @@ class InternalApiInterceptor(
14
14
response : HttpServletResponse ,
15
15
handler : Any ,
16
16
): Boolean {
17
- val ip = extractIp(request)
18
- return whiteIps.contains(ip)
17
+ return whiteIps.contains(extractIp(request))
19
18
}
20
19
21
20
private fun extractIp (request : HttpServletRequest ): String {
@@ -25,22 +24,22 @@ class InternalApiInterceptor(
25
24
" X-Real-IP" , " X-RealIP" , " REMOTE_ADDR"
26
25
)
27
26
28
- var ip: String = request.getHeader(" X-Forwarded-For" )
27
+ var ip: String? = request.getHeader(" X-Forwarded-For" )
29
28
30
29
for (header in headers) {
31
- if (ip.isEmpty () || " unknown" .equals(ip, ignoreCase = true )) {
30
+ if (ip.isNullOrEmpty () || " unknown" .equals(ip, ignoreCase = true )) {
32
31
ip = request.getHeader(header)
33
32
}
34
33
}
35
34
36
- if (ip.isEmpty () || " unknown" .equals(ip, ignoreCase = true )) {
35
+ if (ip.isNullOrEmpty () || " unknown" .equals(ip, ignoreCase = true )) {
37
36
ip = request.remoteAddr
38
37
}
39
38
40
39
if (ip == " 0:0:0:0:0:0:0:1" ) {
41
40
ip = " 127.0.0.1"
42
41
}
43
42
44
- return ip
43
+ return ip ? : throw IllegalStateException ( " Cannot extract ip " )
45
44
}
46
45
}
You can’t perform that action at this time.
0 commit comments