diff --git a/build.gradle.kts b/build.gradle.kts index e86dc77..b7cb0f1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,16 +1,18 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { - id("org.springframework.boot") version "2.3.1.RELEASE" - id("io.spring.dependency-management") version "1.0.9.RELEASE" - id("org.asciidoctor.convert") version "1.5.8" - kotlin("jvm") version "1.6.0" - kotlin("plugin.spring") version "1.6.0" + id("org.springframework.boot") version "3.1.1" + id("io.spring.dependency-management") version "1.1.0" + kotlin("jvm") version "1.8.22" + kotlin("plugin.spring") version "1.8.22" } group = "com.xmppjingle" version = "0.0.2-SNAPSHOT" -java.sourceCompatibility = JavaVersion.VERSION_1_8 + +java { + sourceCompatibility = JavaVersion.VERSION_17 +} repositories { mavenLocal() @@ -18,13 +20,15 @@ repositories { gradlePluginPortal() } -extra["snippetsDir"] = file("build/generated-snippets") - dependencies { + implementation("org.springframework.boot:spring-boot-starter") implementation("org.springframework.boot:spring-boot-starter-data-redis") implementation("org.springframework.boot:spring-boot-starter-web") implementation("org.springframework.boot:spring-boot-starter-security") implementation("org.springframework.security:spring-security-data") + implementation("org.springframework.security:spring-security-config") + implementation("org.springframework.security:spring-security-web") + implementation("org.springframework.security:spring-security-core") implementation("org.springframework:spring-aop") implementation("org.aspectj:aspectjrt") implementation("com.fasterxml.jackson.module:jackson-module-kotlin") @@ -33,9 +37,11 @@ dependencies { implementation("org.apache.commons:commons-lang3:3.12.0") implementation("org.apache.spark:spark-core_2.12:3.3.1") + implementation("redis.clients:jedis:3.6.3") + implementation("com.redislabs:spark-redis_2.12:3.1.0") - implementation("io.lettuce:lettuce-core:6.2.2.RELEASE") + implementation("io.lettuce:lettuce-core:6.2.7.RELEASE") implementation("com.google.code.gson:gson:2.10") implementation("com.squareup.okhttp3:okhttp:3.14.6") @@ -63,13 +69,15 @@ configurations { } } -tasks.withType { - useJUnitPlatform() -} tasks.withType { kotlinOptions { - freeCompilerArgs = listOf("-Xjsr305=strict") - jvmTarget = "1.8" + freeCompilerArgs += "-Xjsr305=strict" + jvmTarget = "17" } } + +tasks.withType { + useJUnitPlatform() +} + diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 943f0cb..c1962a7 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f398c33..37aef8d 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 65dcd68..aeb74cb 100755 --- a/gradlew +++ b/gradlew @@ -85,9 +85,6 @@ done APP_BASE_NAME=${0##*/} APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' - # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -144,7 +141,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac @@ -152,7 +149,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then '' | soft) :;; #( *) # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -197,6 +194,10 @@ if "$cygwin" || "$msys" ; then done fi + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + # Collect all arguments for the java command; # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of # shell script including quotes and variable substitutions, so put them in diff --git a/src/main/kotlin/com/xmppjingle/bjomeliga/api/EventsController.kt b/src/main/kotlin/com/xmppjingle/bjomeliga/api/EventsController.kt index 8a3e55c..b53e205 100644 --- a/src/main/kotlin/com/xmppjingle/bjomeliga/api/EventsController.kt +++ b/src/main/kotlin/com/xmppjingle/bjomeliga/api/EventsController.kt @@ -6,7 +6,10 @@ import org.slf4j.Logger import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.http.ResponseEntity -import org.springframework.web.bind.annotation.* +import org.springframework.web.bind.annotation.CrossOrigin +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RestController @RestController @CrossOrigin(origins = ["*"]) diff --git a/src/main/kotlin/com/xmppjingle/bjomeliga/api/RateLimitController.kt b/src/main/kotlin/com/xmppjingle/bjomeliga/api/RateLimitController.kt index bdfa5fd..ac8fb98 100644 --- a/src/main/kotlin/com/xmppjingle/bjomeliga/api/RateLimitController.kt +++ b/src/main/kotlin/com/xmppjingle/bjomeliga/api/RateLimitController.kt @@ -6,7 +6,6 @@ import org.springframework.http.HttpStatus import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.* - @RestController @RequestMapping("/admin/{customerId}/rate-limit") class RateLimitAdminController { @@ -19,7 +18,7 @@ class RateLimitAdminController { return ResponseEntity.ok(rateLimits) } - @PostMapping("/limits/{customerId}/{endpoint}/{limit}") + @PostMapping("/limits/{endpoint}/{limit}") fun addRateLimit( @PathVariable customerId: String?, @PathVariable endpoint: String?, diff --git a/src/main/kotlin/com/xmppjingle/bjomeliga/config/ApiKeyAuthFilter.kt b/src/main/kotlin/com/xmppjingle/bjomeliga/config/ApiKeyAuthFilter.kt index be25cdb..0977da4 100644 --- a/src/main/kotlin/com/xmppjingle/bjomeliga/config/ApiKeyAuthFilter.kt +++ b/src/main/kotlin/com/xmppjingle/bjomeliga/config/ApiKeyAuthFilter.kt @@ -4,18 +4,15 @@ import io.lettuce.core.RedisClient import io.lettuce.core.api.StatefulRedisConnection import io.lettuce.core.api.sync.RedisCommands import io.lettuce.core.dynamic.RedisCommandFactory -import org.springframework.beans.factory.annotation.Autowired +import jakarta.annotation.PostConstruct +import jakarta.servlet.http.HttpServletRequest +import jakarta.servlet.http.HttpServletResponse import org.springframework.beans.factory.annotation.Value -import org.springframework.data.redis.core.RedisTemplate import org.springframework.security.authentication.AuthenticationManager import org.springframework.security.authentication.BadCredentialsException import org.springframework.security.authentication.UsernamePasswordAuthenticationToken import org.springframework.security.core.Authentication import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter -import org.springframework.stereotype.Component -import javax.annotation.PostConstruct -import javax.servlet.http.HttpServletRequest -import javax.servlet.http.HttpServletResponse class ApiKeyAuthFilter(authenticationManager: AuthenticationManager) : UsernamePasswordAuthenticationFilter() { diff --git a/src/main/kotlin/com/xmppjingle/bjomeliga/config/SecurityConfig.kt b/src/main/kotlin/com/xmppjingle/bjomeliga/config/SecurityConfig.kt index b072868..912845a 100644 --- a/src/main/kotlin/com/xmppjingle/bjomeliga/config/SecurityConfig.kt +++ b/src/main/kotlin/com/xmppjingle/bjomeliga/config/SecurityConfig.kt @@ -1,72 +1,13 @@ package com.xmppjingle.bjomeliga.config -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration -import org.springframework.http.HttpMethod -import org.springframework.security.authentication.AuthenticationManager -import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity -import org.springframework.security.config.annotation.web.builders.HttpSecurity -import org.springframework.security.config.annotation.web.builders.WebSecurity import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter -import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter import org.springframework.stereotype.Component -import springfox.documentation.builders.PathSelectors -import springfox.documentation.builders.RequestHandlerSelectors -import springfox.documentation.spi.DocumentationType -import springfox.documentation.spring.web.plugins.Docket + @Configuration @EnableWebSecurity -@EnableGlobalMethodSecurity(prePostEnabled = true) @Component -internal class SecurityConfig : WebSecurityConfigurerAdapter() { - - private lateinit var apiKeyAuthFilter: ApiKeyAuthFilter - - @Throws(Exception::class) - override fun configure(web: WebSecurity) { - web.ignoring().antMatchers(HttpMethod.OPTIONS).antMatchers(*AUTH_WHITELIST) - } - - private val AUTH_WHITELIST = arrayOf( - "/v2/**", - "/configuration/**", - "/swagger-resources/**", - "/configuration/security", - "/swagger-ui.html", - "/swagger-ui/**", - "/webjars/**", - "/drawer/**", - "/events/**", - "/config/**", - "/experiment/**" - ) - - @Throws(java.lang.Exception::class) - override fun configure(http: HttpSecurity) { - apiKeyAuthFilter = ApiKeyAuthFilter(authenticationManager()) - http.addFilterBefore(apiKeyAuthFilter, UsernamePasswordAuthenticationFilter::class.java) - .authorizeRequests() - // Whitelisted endpoints that do not require authentication - .antMatchers(*AUTH_WHITELIST).permitAll() - // Endpoints that require authentication - .antMatchers("/**/*").authenticated() - .antMatchers("/**/*").denyAll() - } - - @Bean - fun api(): Docket? { - return Docket(DocumentationType.SWAGGER_2) - .select() - .apis(RequestHandlerSelectors.any()) - .paths(PathSelectors.any()) - .build() - } +class SecurityConfig { - @Bean - override fun authenticationManagerBean(): AuthenticationManager { - return super.authenticationManagerBean() - } -} +} \ No newline at end of file diff --git a/src/main/kotlin/com/xmppjingle/bjomeliga/service/CallMeService.kt b/src/main/kotlin/com/xmppjingle/bjomeliga/service/CallMeService.kt index c639e9c..f2841f5 100644 --- a/src/main/kotlin/com/xmppjingle/bjomeliga/service/CallMeService.kt +++ b/src/main/kotlin/com/xmppjingle/bjomeliga/service/CallMeService.kt @@ -1,5 +1,6 @@ package com.xmppjingle.bjomeliga.service +import jakarta.annotation.PostConstruct import okhttp3.MediaType import okhttp3.OkHttpClient import okhttp3.Request @@ -11,7 +12,6 @@ import org.springframework.data.redis.core.RedisTemplate import org.springframework.stereotype.Service import java.time.Instant import java.util.* -import javax.annotation.PostConstruct @Service class CallMeService { diff --git a/src/main/kotlin/com/xmppjingle/bjomeliga/service/DrawerService.kt b/src/main/kotlin/com/xmppjingle/bjomeliga/service/DrawerService.kt index ac936d9..b8888c7 100644 --- a/src/main/kotlin/com/xmppjingle/bjomeliga/service/DrawerService.kt +++ b/src/main/kotlin/com/xmppjingle/bjomeliga/service/DrawerService.kt @@ -1,6 +1,5 @@ package com.xmppjingle.bjomeliga.service -import okhttp3.OkHttpClient import org.slf4j.Logger import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired diff --git a/src/main/kotlin/com/xmppjingle/bjomeliga/service/EventsService.kt b/src/main/kotlin/com/xmppjingle/bjomeliga/service/EventsService.kt index 5f954f1..0c7f9a8 100644 --- a/src/main/kotlin/com/xmppjingle/bjomeliga/service/EventsService.kt +++ b/src/main/kotlin/com/xmppjingle/bjomeliga/service/EventsService.kt @@ -6,13 +6,13 @@ import io.lettuce.core.dynamic.Commands import io.lettuce.core.dynamic.RedisCommandFactory import io.lettuce.core.dynamic.annotation.Command import io.lettuce.core.dynamic.annotation.Param +import jakarta.annotation.PostConstruct import org.slf4j.Logger import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.annotation.Value import org.springframework.data.redis.core.RedisTemplate import org.springframework.stereotype.Service -import javax.annotation.PostConstruct @Service class EventsService { diff --git a/src/main/kotlin/com/xmppjingle/bjomeliga/service/ExperimentService.kt b/src/main/kotlin/com/xmppjingle/bjomeliga/service/ExperimentService.kt index 771fc4a..2377302 100644 --- a/src/main/kotlin/com/xmppjingle/bjomeliga/service/ExperimentService.kt +++ b/src/main/kotlin/com/xmppjingle/bjomeliga/service/ExperimentService.kt @@ -9,6 +9,7 @@ import io.lettuce.core.dynamic.Commands import io.lettuce.core.dynamic.RedisCommandFactory import io.lettuce.core.dynamic.annotation.Command import io.lettuce.core.dynamic.annotation.Param +import jakarta.annotation.PostConstruct import org.apache.commons.math3.distribution.EnumeratedDistribution import org.apache.commons.math3.util.Pair import org.slf4j.Logger @@ -16,7 +17,6 @@ import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.annotation.Value import org.springframework.stereotype.Service -import javax.annotation.PostConstruct @Service class ExperimentService { diff --git a/src/main/kotlin/com/xmppjingle/bjomeliga/service/RecommendationService.kt b/src/main/kotlin/com/xmppjingle/bjomeliga/service/RecommendationService.kt index f492fe1..2ada590 100644 --- a/src/main/kotlin/com/xmppjingle/bjomeliga/service/RecommendationService.kt +++ b/src/main/kotlin/com/xmppjingle/bjomeliga/service/RecommendationService.kt @@ -1,8 +1,8 @@ package com.xmppjingle.bjomeliga.service import com.redislabs.redisgraph.impl.api.RedisGraph +import jakarta.annotation.PostConstruct import org.springframework.stereotype.Service -import javax.annotation.PostConstruct @Service class RecommendationService { diff --git a/src/main/kotlin/com/xmppjingle/bjomeliga/service/RemoteConfigService.kt b/src/main/kotlin/com/xmppjingle/bjomeliga/service/RemoteConfigService.kt index 629ee20..5b3c080 100644 --- a/src/main/kotlin/com/xmppjingle/bjomeliga/service/RemoteConfigService.kt +++ b/src/main/kotlin/com/xmppjingle/bjomeliga/service/RemoteConfigService.kt @@ -4,11 +4,11 @@ import io.lettuce.core.RedisClient import io.lettuce.core.api.StatefulRedisConnection import io.lettuce.core.api.sync.RedisCommands import io.lettuce.core.dynamic.RedisCommandFactory +import jakarta.annotation.PostConstruct import org.slf4j.Logger import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Value import org.springframework.stereotype.Service -import javax.annotation.PostConstruct @Service class RemoteConfigService { diff --git a/src/main/kotlin/com/xmppjingle/bjomeliga/service/SummariesService.kt b/src/main/kotlin/com/xmppjingle/bjomeliga/service/SummariesService.kt index ebc4da7..7583425 100644 --- a/src/main/kotlin/com/xmppjingle/bjomeliga/service/SummariesService.kt +++ b/src/main/kotlin/com/xmppjingle/bjomeliga/service/SummariesService.kt @@ -1,7 +1,6 @@ package com.xmppjingle.bjomeliga.service import com.fasterxml.jackson.annotation.JsonInclude -import okhttp3.OkHttpClient import org.slf4j.Logger import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired diff --git a/src/main/kotlin/com/xmppjingle/bjomeliga/service/ratelimit/RateLimitService.kt b/src/main/kotlin/com/xmppjingle/bjomeliga/service/ratelimit/RateLimitService.kt index 910b024..4960fca 100644 --- a/src/main/kotlin/com/xmppjingle/bjomeliga/service/ratelimit/RateLimitService.kt +++ b/src/main/kotlin/com/xmppjingle/bjomeliga/service/ratelimit/RateLimitService.kt @@ -4,6 +4,7 @@ import io.lettuce.core.RedisClient import io.lettuce.core.api.StatefulRedisConnection import io.lettuce.core.api.sync.RedisCommands import io.lettuce.core.dynamic.RedisCommandFactory +import jakarta.annotation.PostConstruct import org.slf4j.Logger import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired @@ -13,7 +14,6 @@ import org.springframework.core.io.ResourceLoader import org.springframework.stereotype.Service import java.io.IOException import java.util.* -import javax.annotation.PostConstruct @Service diff --git a/src/main/kotlin/com/xmppjingle/bjomeliga/service/ratelimit/RateLimiterAspect.kt b/src/main/kotlin/com/xmppjingle/bjomeliga/service/ratelimit/RateLimiterAspect.kt index b9a386e..6ce5e56 100644 --- a/src/main/kotlin/com/xmppjingle/bjomeliga/service/ratelimit/RateLimiterAspect.kt +++ b/src/main/kotlin/com/xmppjingle/bjomeliga/service/ratelimit/RateLimiterAspect.kt @@ -5,12 +5,12 @@ import io.lettuce.core.RedisClient import io.lettuce.core.api.StatefulRedisConnection import io.lettuce.core.api.sync.RedisCommands import io.lettuce.core.dynamic.RedisCommandFactory +import jakarta.annotation.PostConstruct import org.aspectj.lang.ProceedingJoinPoint import org.aspectj.lang.annotation.Around import org.aspectj.lang.annotation.Aspect import org.aspectj.lang.reflect.MethodSignature import org.springframework.beans.factory.annotation.Value -import javax.annotation.PostConstruct @Aspect class RateLimiterAspect(private val rateLimitService: RateLimitService) { diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 8b13789..5b0183f 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1 +1 @@ - +redis.url:redis://localhost:6333 \ No newline at end of file diff --git a/src/test/kotlin/com/xmppjingle/bjomeliga/BjomeligaApplicationTests.kt b/src/test/kotlin/com/xmppjingle/bjomeliga/BjomeligaApplicationTests.kt index a4a82c5..36aa53f 100644 --- a/src/test/kotlin/com/xmppjingle/bjomeliga/BjomeligaApplicationTests.kt +++ b/src/test/kotlin/com/xmppjingle/bjomeliga/BjomeligaApplicationTests.kt @@ -3,7 +3,6 @@ package com.xmppjingle.bjomeliga import com.xmppjingle.bjomeliga.service.* import org.apache.commons.math3.distribution.EnumeratedDistribution import org.apache.commons.math3.util.Pair -import org.junit.jupiter.api.Test import org.springframework.boot.test.context.SpringBootTest import java.util.* import java.util.concurrent.atomic.AtomicInteger diff --git a/src/test/kotlin/com/xmppjingle/bjomeliga/RecommendationServiceTests.kt b/src/test/kotlin/com/xmppjingle/bjomeliga/RecommendationServiceTests.kt index 1e5dca7..871e630 100644 --- a/src/test/kotlin/com/xmppjingle/bjomeliga/RecommendationServiceTests.kt +++ b/src/test/kotlin/com/xmppjingle/bjomeliga/RecommendationServiceTests.kt @@ -6,9 +6,9 @@ import io.lettuce.core.api.StatefulRedisConnection import io.lettuce.core.api.sync.RedisCommands import net.ishiis.redis.unit.RedisServer import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test -import org.junit.jupiter.api.Assertions.* class RecommendationServiceTest { private lateinit var redisServer: RedisServer