Commit 863081af authored by Ghitha Dinan's avatar Ghitha Dinan

json format fixing

parent 0ab37363
package id.co.sangkuriang.inovasi.daerah.master.config package id.co.sangkuriang.inovasi.daerah.master.config
import id.co.sangkuriang.inovasi.daerah.master.constant.TOKEN_FILTER_PATTERNS import id.co.sangkuriang.inovasi.daerah.master.constant.USER_ADMIN_ALLOWED_PATH
import id.co.sangkuriang.inovasi.daerah.master.interceptor.TokenInterceptor import id.co.sangkuriang.inovasi.daerah.master.interceptor.TokenInterceptor
import org.springframework.boot.web.servlet.FilterRegistrationBean import org.springframework.boot.web.servlet.FilterRegistrationBean
import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Bean
...@@ -24,7 +24,7 @@ class SpringWebConfig : WebMvcConfigurer { ...@@ -24,7 +24,7 @@ class SpringWebConfig : WebMvcConfigurer {
fun tokenFilter(): FilterRegistrationBean<TokenInterceptor>? { fun tokenFilter(): FilterRegistrationBean<TokenInterceptor>? {
val registrationBean: FilterRegistrationBean<TokenInterceptor> = val registrationBean: FilterRegistrationBean<TokenInterceptor> =
FilterRegistrationBean<TokenInterceptor>() FilterRegistrationBean<TokenInterceptor>()
TOKEN_FILTER_PATTERNS.forEach { USER_ADMIN_ALLOWED_PATH.forEach {
registrationBean.addUrlPatterns("/$it/*") registrationBean.addUrlPatterns("/$it/*")
} }
registrationBean.filter = TokenInterceptor() registrationBean.filter = TokenInterceptor()
......
...@@ -3,11 +3,20 @@ package id.co.sangkuriang.inovasi.daerah.master.constant ...@@ -3,11 +3,20 @@ package id.co.sangkuriang.inovasi.daerah.master.constant
const val SECRET = "INOVASI-DAERAH" const val SECRET = "INOVASI-DAERAH"
const val TOKEN_PREFIX = "Bearer " const val TOKEN_PREFIX = "Bearer "
const val HEADER_STRING = "Authorization" const val HEADER_STRING = "Authorization"
val TOKEN_FILTER_PATTERNS = const val AUTH_URL = "https://auth.inovasi-daerah.spbe.sangkuriang.co.id/auth"
val USER_ALLOWED_PATH = emptyList<String>()
val USER_ADMIN_ALLOWED_PATH =
listOf( listOf(
"tag", "/tag/*",
"application-category", "/application-category/*",
"province", "/province/*",
"regency", "/regency/*",
"tag" "/tag/*"
) )
val AUDIENCE_FILTER_PATH = mapOf(
"user" to USER_ALLOWED_PATH,
"user-admin" to USER_ADMIN_ALLOWED_PATH
)
...@@ -9,6 +9,7 @@ import com.fasterxml.jackson.databind.ObjectMapper ...@@ -9,6 +9,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
import id.co.sangkuriang.inovasi.daerah.master.constant.HEADER_STRING import id.co.sangkuriang.inovasi.daerah.master.constant.HEADER_STRING
import id.co.sangkuriang.inovasi.daerah.master.constant.SECRET import id.co.sangkuriang.inovasi.daerah.master.constant.SECRET
import id.co.sangkuriang.inovasi.daerah.master.constant.TOKEN_PREFIX import id.co.sangkuriang.inovasi.daerah.master.constant.TOKEN_PREFIX
import id.co.sangkuriang.inovasi.daerah.master.constant.VALIDATOR_MSG_NOT_FOUND
import id.co.sangkuriang.inovasi.daerah.master.model.response.ReturnData import id.co.sangkuriang.inovasi.daerah.master.model.response.ReturnData
import id.co.sangkuriang.inovasi.daerah.master.utility.getPathUrl import id.co.sangkuriang.inovasi.daerah.master.utility.getPathUrl
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken import org.springframework.security.authentication.UsernamePasswordAuthenticationToken
...@@ -44,6 +45,9 @@ class TokenInterceptor : Filter { ...@@ -44,6 +45,9 @@ class TokenInterceptor : Filter {
try { try {
authentication = getAuthentication(req) authentication = getAuthentication(req)
if (authentication == null) {
responseException(res, "User $VALIDATOR_MSG_NOT_FOUND")
}
} catch (e: JWTDecodeException) { } catch (e: JWTDecodeException) {
successAuth = false successAuth = false
responseException(res, e.message.toString()) responseException(res, e.message.toString())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment