fix deleted report

This commit is contained in:
gowthaman.b
2024-01-16 16:19:27 +05:30
parent 81afbdab49
commit 2b60e9cc29
5 changed files with 37 additions and 67 deletions

View File

@@ -5,7 +5,6 @@ import com.restapi.config.*
import com.restapi.config.AppConfig.Companion.appConfig
import com.restapi.config.Auth.validateAuthToken
import com.restapi.controllers.Entities
import com.restapi.domain.AnonSession
import com.restapi.domain.DataNotFoundException
import com.restapi.domain.Session
import com.restapi.domain.Session.currentTenant
@@ -13,12 +12,13 @@ import com.restapi.domain.Session.currentUser
import com.restapi.domain.Session.objectMapper
import com.restapi.domain.Session.setAuthorizedUser
import com.restapi.domain.Session.signPayload
import com.restapi.domain.TenantModel
import io.ebean.DataIntegrityException
import io.ebean.DuplicateKeyException
import io.javalin.Javalin
import io.javalin.apibuilder.ApiBuilder.*
import io.javalin.http.*
import io.javalin.http.ContentType
import io.javalin.http.Context
import io.javalin.http.UnauthorizedResponse
import io.javalin.http.util.NaiveRateLimit
import io.javalin.http.util.RateLimitUtil
import io.javalin.json.JavalinJackson
@@ -63,43 +63,7 @@ fun main(args: Array<String>) {
}
.routes {
path("/auth") {
get("/session") {
//a simple session to keep track of anon users
val at = it.getAuthHeader()
val tenant = Session.database.find(TenantModel::class.java)
.where()
.eq("domain",it.host())
.findOne() ?: throw UnauthorizedResponse()
if(at == null){
//new session
val s = AnonSession().apply {
sessionId = UUID.randomUUID().toString()
firstSeenAt = LocalDateTime.now()
lastSeenAt = LocalDateTime.now()
tenantId = tenant.name
headerMap = it.headerMap()
}
Session.database.save(s)
it.json(s)
} else {
val s = Session.database.find(AnonSession::class.java)
.where()
.eq("sessionId", at)
.findOne() ?: throw UnauthorizedResponse()
Session.database.save(
s.apply {
lastSeenAt = LocalDateTime.now()
headerMap = it.headerMap()
}
)
it.json(s)
}
}
get("/endpoint", Auth::endPoint)
get("/init", Auth::init)
get("/code", Auth::code)
@@ -167,7 +131,7 @@ fun main(args: Array<String>) {
.exception(DuplicateKeyException::class.java, Exceptions.dupKeyExceptionHandler)
.exception(DataIntegrityException::class.java, Exceptions.dataIntegrityException)
.exception(DataNotFoundException::class.java, Exceptions.dataNotFoundException)
.exception(IllegalArgumentException::class.java,Exceptions.illegalArgumentException)
.exception(IllegalArgumentException::class.java, Exceptions.illegalArgumentException)
.exception(JsonMappingException::class.java, Exceptions.jsonMappingException)
.exception(InvalidJwtException::class.java, Exceptions.invalidJwtException)
.start(appConfig.portNumber())

View File

@@ -2,7 +2,6 @@ package com.restapi.config
import com.fasterxml.jackson.module.kotlin.readValue
import com.restapi.config.AppConfig.Companion.appConfig
import com.restapi.domain.AnonSession
import com.restapi.domain.Session
import com.restapi.domain.Session.objectMapper
import io.javalin.http.BadRequestResponse
@@ -64,7 +63,6 @@ object Auth {
.setAllowedClockSkewInSeconds(30)
.setRequireSubject()
.setExpectedIssuer(getAuthEndpoint().issuer)
.setExpectedAudience("account")
.setVerificationKeyResolver(HttpsJwksVerificationKeyResolver(HttpsJwks(getAuthEndpoint().jwksUri)))
.build()
@@ -75,23 +73,6 @@ object Auth {
fun validateAuthToken(authToken: String, skipValidate: Boolean = false): AuthUser {
//check if this is anon session
val anonSession = Session.database.find(AnonSession::class.java)
.where()
.eq("sessionId", authToken)
.findOne()
if (anonSession != null) {
return AuthUser(
userName = authToken,
tenant = anonSession.tenantId,
roles = emptyList(),
token = authToken,
expiry = LocalDateTime.now().plusDays(1)
)
}
// Validate the JWT and process it to the Claims
val jwtClaims = if (skipValidate) jwtConsumerSkipValidate.process(authToken) else jwtConsumer.process(authToken)
val userId = jwtClaims.jwtClaims.claimsMap["preferred_username"] as String

View File

@@ -30,6 +30,7 @@ import java.security.spec.PKCS8EncodedKeySpec
import java.security.spec.X509EncodedKeySpec
import java.time.LocalDateTime
import java.util.*
import kotlin.collections.HashMap
import kotlin.jvm.optionals.getOrDefault
@@ -137,7 +138,27 @@ object Session {
}
fun a(){
val a = HashMap<String,String>()
a.put("a", "b");
a.put("a", "b");
a.put("a", "b");
a.put("a", "b");
val b = HashMap<String,String>().apply {
put("a", "b");
put("a", "b");
put("a", "b");
put("a", "b");
}
val c: String? = ""
val x = c?.get(1)
c?.apply {
//will work only when c is not null
}
}
private val sc = DatabaseConfig().apply {
loadFromProperties(Properties().apply {
setProperty("datasource.db.username", appConfig.dbUser())