Skip to content

Commit 3719133

Browse files
authored
Add jwt enhacer to remove undesire char (#36)
* Added JWT Enhancer * Moke code compatible * Added jwt package in service and move jwt services in that package
1 parent 31e55aa commit 3719133

File tree

5 files changed

+16
-5
lines changed

5 files changed

+16
-5
lines changed

src/main/kotlin/com/hrv/mart/apigatewayadmin/config/jwt/JwtAuthenticationManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.hrv.mart.apigatewayadmin.config.jwt
22

3-
import com.hrv.mart.apigatewayadmin.service.JWTService
3+
import com.hrv.mart.apigatewayadmin.service.jwt.JWTService
44
import org.springframework.security.authentication.ReactiveAuthenticationManager
55
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken
66
import org.springframework.security.core.Authentication

src/main/kotlin/com/hrv/mart/apigatewayadmin/controller/AuthController.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.hrv.mart.apigatewayadmin.controller
22

33
import com.hrv.mart.apigatewayadmin.service.AuthService
4-
import com.hrv.mart.apigatewayadmin.service.JWTService
4+
import com.hrv.mart.apigatewayadmin.service.jwt.JWTService
55
import org.springframework.beans.factory.annotation.Autowired
66
import org.springframework.http.server.reactive.ServerHttpResponse
77
import org.springframework.web.bind.annotation.PostMapping

src/main/kotlin/com/hrv/mart/apigatewayadmin/service/AuthService.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.hrv.mart.apigatewayadmin.service
22

3+
import com.hrv.mart.apigatewayadmin.service.jwt.JWTEnhancer
34
import com.hrv.mart.authlibrary.repository.AuthRepository
45
import org.springframework.beans.factory.annotation.Autowired
56
import org.springframework.http.server.reactive.ServerHttpResponse
@@ -15,7 +16,7 @@ class AuthService (
1516
fun login(appwriteJWT: String, response: ServerHttpResponse) =
1617
authRepository
1718
.createAdminAuth(
18-
jwt = appwriteJWT.replace(specialCharCode.toChar().toString(), ""),
19+
jwt = JWTEnhancer.enhanceJWT(appwriteJWT),
1920
response = response
2021
)
2122
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.hrv.mart.apigatewayadmin.service.jwt
2+
3+
class JWTEnhancer {
4+
5+
companion object {
6+
private const val specialCharCode= 34
7+
fun enhanceJWT(jwt: String) =
8+
jwt.replace(specialCharCode.toChar().toString(), "")
9+
}
10+
}

src/main/kotlin/com/hrv/mart/apigatewayadmin/service/JWTService.kt renamed to src/main/kotlin/com/hrv/mart/apigatewayadmin/service/jwt/JWTService.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.hrv.mart.apigatewayadmin.service
1+
package com.hrv.mart.apigatewayadmin.service.jwt
22

33
import io.jsonwebtoken.Jwts
44
import io.jsonwebtoken.SignatureAlgorithm
@@ -47,6 +47,6 @@ class JWTService (
4747
Jwts.parserBuilder()
4848
.setSigningKey(keyPair.public)
4949
.build()
50-
.parseClaimsJws(jwt)
50+
.parseClaimsJws(JWTEnhancer.enhanceJWT(jwt))
5151

5252
}

0 commit comments

Comments
 (0)