Commit e3d90af5 authored by Ghitha Dinan's avatar Ghitha Dinan

add role user

parent 40e15017
Pipeline #401 canceled with stages
package id.go.kemenag.madrasah.pmrms.auth.constant
import java.io.File
const val ROOT_DIR = "D:\\app-files\\pmrms\\files\\"
val UPLOAD_DIR = "${ROOT_DIR}uploads${File.separator}"
val UPLOAD_USER_DIR = "${UPLOAD_DIR}users"
......@@ -14,5 +14,5 @@ val USER_ADMIN_ALLOWED_PATH =
)
val AUDIENCE_FILTER_PATH = mapOf(
"admin" to USER_ADMIN_ALLOWED_PATH
"user-admin" to USER_ADMIN_ALLOWED_PATH
)
......@@ -5,10 +5,7 @@ import id.go.kemenag.madrasah.pmrms.auth.model.response.ReturnData
import id.go.kemenag.madrasah.pmrms.auth.service.AuthService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.bind.annotation.*
import javax.validation.Valid
@RestController
......@@ -22,4 +19,9 @@ class AuthController {
fun login(@Valid @RequestBody request: LoginRequest): ResponseEntity<ReturnData> {
return service.login(request)
}
@GetMapping(value = ["detail"], produces = ["application/json"])
fun detail(): ResponseEntity<ReturnData> {
return service.detail()
}
}
package id.go.kemenag.madrasah.pmrms.auth.helpers
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.ObjectMapper
import id.go.kemenag.madrasah.pmrms.auth.pojo.Users
import org.springframework.security.core.context.SecurityContextHolder
import java.net.MalformedURLException
import java.net.URL
import javax.servlet.http.HttpServletRequest
fun getUserLogin(): Users? {
return try {
val principal = SecurityContextHolder.getContext().authentication.principal as Any
val objectMapper = ObjectMapper()
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
objectMapper.readValue(principal.toString(), Users::class.java)
} catch (e: Exception) {
null
}
}
@Throws(MalformedURLException::class)
fun getBaseUrl(request: HttpServletRequest): String {
try {
val requestURL = URL(request.requestURL.toString())
val port = if (requestURL.port == -1) "" else ":" + requestURL.port
return requestURL.protocol + "://" + requestURL.host + port + request.contextPath + "/"
} catch (e: Exception) {
throw e
}
}
fun getFullUrl(request: HttpServletRequest): String {
val requestURL = StringBuilder(request.requestURL.toString())
val queryString = request.queryString
return if (queryString == null) {
requestURL.toString()
} else {
requestURL.append('?').append(queryString).toString()
}
}
......@@ -8,6 +8,7 @@ import id.go.kemenag.madrasah.pmrms.auth.constant.EXPIRATION_TIME
import id.go.kemenag.madrasah.pmrms.auth.constant.SECRET
import id.go.kemenag.madrasah.pmrms.auth.constant.TOKEN_PREFIX
import id.go.kemenag.madrasah.pmrms.auth.exception.BadRequestException
import id.go.kemenag.madrasah.pmrms.auth.helpers.getUserLogin
import id.go.kemenag.madrasah.pmrms.auth.helpers.responseSuccess
import id.go.kemenag.madrasah.pmrms.auth.model.request.auth.LoginRequest
import id.go.kemenag.madrasah.pmrms.auth.model.response.ReturnData
......@@ -62,4 +63,12 @@ class AuthService {
return jwtres
}
fun detail(): ResponseEntity<ReturnData> {
return try {
responseSuccess(data = repoUser.findByIdAndActive(getUserLogin()?.id))
} catch (e: Exception) {
throw e
}
}
}
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