diff --git a/machine-learning/README.md b/machine-learning/README.md deleted file mode 100644 index 80f2d2c6cd..0000000000 --- a/machine-learning/README.md +++ /dev/null @@ -1,3 +0,0 @@ -### Relevant Articles: - -- [Introduction to Supervised Learning in Kotlin](https://www.baeldung.com/kotlin-supervised-learning) diff --git a/machine-learning/pom.xml b/machine-learning/pom.xml deleted file mode 100644 index 842e488985..0000000000 --- a/machine-learning/pom.xml +++ /dev/null @@ -1,163 +0,0 @@ - - - 4.0.0 - machine-learning - 1.0-SNAPSHOT - machine-learning - jar - - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - - - - - org.jetbrains.kotlin - kotlin-stdlib-jdk8 - ${kotlin.version} - - - org.nd4j - nd4j-native-platform - ${dl4j.version} - - - org.deeplearning4j - deeplearning4j-core - ${dl4j.version} - - - org.jetbrains.kotlin - kotlin-stdlib-jdk8 - ${kotlin.version} - - - org.jetbrains.kotlin - kotlin-test - ${kotlin.version} - test - - - org.jetbrains.kotlin - kotlin-stdlib-jdk8 - ${kotlin.version} - - - - - src/main/kotlin - src/test - - - - - maven-clean-plugin - ${clean.plugin.version} - - - - maven-resources-plugin - ${resources.plugin.version} - - - maven-compiler-plugin - ${compiler.plugin.version} - - - maven-surefire-plugin - ${surefire.plugin.version} - - - maven-jar-plugin - ${jar.plugin.version} - - - maven-install-plugin - ${install.plugin.version} - - - maven-deploy-plugin - ${deploy.plugin.version} - - - - maven-site-plugin - ${site.plugin.version} - - - maven-project-info-reports-plugin - ${report.plugin.version} - - - - - - org.jetbrains.kotlin - kotlin-maven-plugin - ${kotlin.version} - - - compile - compile - - compile - - - - test-compile - test-compile - - test-compile - - - - - 1.8 - - - - org.apache.maven.plugins - maven-compiler-plugin - - - compile - compile - - compile - - - - testCompile - test-compile - - testCompile - - - - - - - - - UTF-8 - 1.7 - 1.7 - 1.3.50 - 0.9.1 - 3.1.0 - 3.0.2 - 3.0.2 - 3.8.0 - 2.22.1 - 2.5.2 - 2.8.2 - 3.7.1 - 3.0.0 - - - diff --git a/machine-learning/src/main/kotlin/com/baeldung/cnn/ConvolutionalNeuralNetwork.kt b/machine-learning/src/main/kotlin/com/baeldung/cnn/ConvolutionalNeuralNetwork.kt deleted file mode 100644 index b77fe273ae..0000000000 --- a/machine-learning/src/main/kotlin/com/baeldung/cnn/ConvolutionalNeuralNetwork.kt +++ /dev/null @@ -1,117 +0,0 @@ -package com.baeldung.cnn - -import org.datavec.api.records.reader.impl.collection.ListStringRecordReader -import org.datavec.api.split.ListStringSplit -import org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator -import org.deeplearning4j.eval.Evaluation -import org.deeplearning4j.nn.conf.NeuralNetConfiguration -import org.deeplearning4j.nn.conf.inputs.InputType -import org.deeplearning4j.nn.conf.layers.* -import org.deeplearning4j.nn.multilayer.MultiLayerNetwork -import org.deeplearning4j.nn.weights.WeightInit -import org.nd4j.linalg.activations.Activation -import org.nd4j.linalg.learning.config.Adam -import org.nd4j.linalg.lossfunctions.LossFunctions - -object ConvolutionalNeuralNetwork { - - @JvmStatic - fun main(args: Array) { - val dataset = ZalandoMNISTDataSet().load() - dataset.shuffle() - val trainDatasetIterator = createDatasetIterator(dataset.subList(0, 50_000)) - val testDatasetIterator = createDatasetIterator(dataset.subList(50_000, 60_000)) - - val cnn = buildCNN() - learning(cnn, trainDatasetIterator) - testing(cnn, testDatasetIterator) - } - - private fun createDatasetIterator(dataset: MutableList>): RecordReaderDataSetIterator { - val listStringRecordReader = ListStringRecordReader() - listStringRecordReader.initialize(ListStringSplit(dataset)) - return RecordReaderDataSetIterator(listStringRecordReader, 128, 28 * 28, 10) - } - - private fun buildCNN(): MultiLayerNetwork { - val multiLayerNetwork = MultiLayerNetwork(NeuralNetConfiguration.Builder() - .seed(123) - .l2(0.0005) - .updater(Adam()) - .weightInit(WeightInit.XAVIER) - .list() - .layer(0, buildInitialConvolutionLayer()) - .layer(1, buildBatchNormalizationLayer()) - .layer(2, buildPoolingLayer()) - .layer(3, buildConvolutionLayer()) - .layer(4, buildBatchNormalizationLayer()) - .layer(5, buildPoolingLayer()) - .layer(6, buildDenseLayer()) - .layer(7, buildBatchNormalizationLayer()) - .layer(8, buildDenseLayer()) - .layer(9, buildOutputLayer()) - .setInputType(InputType.convolutionalFlat(28, 28, 1)) - .backprop(true) - .build()) - multiLayerNetwork.init() - return multiLayerNetwork - } - - private fun buildOutputLayer(): OutputLayer? { - return OutputLayer.Builder(LossFunctions.LossFunction.NEGATIVELOGLIKELIHOOD) - .nOut(10) - .activation(Activation.SOFTMAX) - .build() - } - - private fun buildDenseLayer(): DenseLayer? { - return DenseLayer.Builder().activation(Activation.RELU) - .nOut(500) - .dropOut(0.5) - .build() - } - - private fun buildPoolingLayer(): SubsamplingLayer? { - return SubsamplingLayer.Builder(SubsamplingLayer.PoolingType.MAX) - .kernelSize(2, 2) - .stride(2, 2) - .build() - } - - private fun buildBatchNormalizationLayer() = BatchNormalization.Builder().build() - - private fun buildConvolutionLayer(): ConvolutionLayer? { - return ConvolutionLayer.Builder(5, 5) - .stride(1, 1) // nIn need not specified in later layers - .nOut(50) - .activation(Activation.IDENTITY) - .build() - } - - private fun buildInitialConvolutionLayer(): ConvolutionLayer? { - return ConvolutionLayer.Builder(5, 5) - .nIn(1) - .stride(1, 1) - .nOut(20) - .activation(Activation.IDENTITY) - .build() - } - - private fun learning(cnn: MultiLayerNetwork, trainSet: RecordReaderDataSetIterator) { - for (i in 0 until 10) { - cnn.fit(trainSet) - } - } - - private fun testing(cnn: MultiLayerNetwork, testSet: RecordReaderDataSetIterator) { - val evaluation = Evaluation(10) - while (testSet.hasNext()) { - val next = testSet.next() - val output = cnn.output(next.features) - evaluation.eval(next.labels, output) - } - - println(evaluation.stats()) - println(evaluation.confusionToString()) - } -} \ No newline at end of file diff --git a/machine-learning/src/main/kotlin/com/baeldung/cnn/ZalandoMNISTDataSet.kt b/machine-learning/src/main/kotlin/com/baeldung/cnn/ZalandoMNISTDataSet.kt deleted file mode 100644 index f29c8f2d0b..0000000000 --- a/machine-learning/src/main/kotlin/com/baeldung/cnn/ZalandoMNISTDataSet.kt +++ /dev/null @@ -1,45 +0,0 @@ -package com.baeldung.cnn - -import java.io.File -import java.nio.ByteBuffer -import java.util.* -import java.util.stream.Collectors -import kotlin.streams.asStream - -class ZalandoMNISTDataSet { - private val OFFSET_SIZE = 4 //in bytes - private val NUM_ITEMS_OFFSET = 4 - private val ITEMS_SIZE = 4 - private val ROWS = 28 - private val COLUMNS = 28 - private val IMAGE_OFFSET = 16 - private val IMAGE_SIZE = ROWS * COLUMNS - - fun load(): MutableList> { - val labelsFile = File("machine-learning/src/main/resources/train-labels-idx1-ubyte") - val imagesFile = File("machine-learning/src/main/resources/train-images-idx3-ubyte") - - val labelBytes = labelsFile.readBytes() - val imageBytes = imagesFile.readBytes() - - val byteLabelCount = Arrays.copyOfRange(labelBytes, NUM_ITEMS_OFFSET, NUM_ITEMS_OFFSET + ITEMS_SIZE) - val numberOfLabels = ByteBuffer.wrap(byteLabelCount).int - - val list = mutableListOf>() - - for (i in 0 until numberOfLabels) { - val label = labelBytes[OFFSET_SIZE + ITEMS_SIZE + i] - val startBoundary = i * IMAGE_SIZE + IMAGE_OFFSET - val endBoundary = i * IMAGE_SIZE + IMAGE_OFFSET + IMAGE_SIZE - val imageData = Arrays.copyOfRange(imageBytes, startBoundary, endBoundary) - - val imageDataList = imageData.iterator() - .asSequence() - .asStream().map { b -> b.toString() } - .collect(Collectors.toList()) - imageDataList.add(label.toString()) - list.add(imageDataList) - } - return list - } -} \ No newline at end of file diff --git a/machine-learning/src/main/kotlin/com/baeldung/simplelinearregression/SimpleLinearRegression.kt b/machine-learning/src/main/kotlin/com/baeldung/simplelinearregression/SimpleLinearRegression.kt deleted file mode 100644 index 5ab520924e..0000000000 --- a/machine-learning/src/main/kotlin/com/baeldung/simplelinearregression/SimpleLinearRegression.kt +++ /dev/null @@ -1,31 +0,0 @@ -package com.baeldung.simplelinearregression - -import kotlin.math.pow - -class SimpleLinearRegression(private val xs: List, private val ys: List) { - var slope: Double = 0.0 - var yIntercept: Double = 0.0 - - init { - val covariance = calculateCovariance(xs, ys) - val variance = calculateVariance(xs) - slope = calculateSlope(covariance, variance) - yIntercept = calculateYIntercept(ys, slope, xs) - } - - fun predict(independentVariable: Double) = slope * independentVariable + yIntercept - - fun calculateRSquared(): Double { - val sst = ys.sumByDouble { y -> (y - ys.average()).pow(2) } - val ssr = xs.zip(ys) { x, y -> (y - predict(x.toDouble())).pow(2) }.sum() - return (sst - ssr) / sst - } - - private fun calculateYIntercept(ys: List, slope: Double, xs: List) = ys.average() - slope * xs.average() - - private fun calculateSlope(covariance: Double, variance: Double) = covariance / variance - - private fun calculateCovariance(xs: List, ys: List) = xs.zip(ys) { x, y -> (x - xs.average()) * (y - ys.average()) }.sum() - - private fun calculateVariance(xs: List) = xs.sumByDouble { x -> (x - xs.average()).pow(2) } -} \ No newline at end of file diff --git a/machine-learning/src/main/resources/train-labels-idx1-ubyte b/machine-learning/src/main/resources/train-labels-idx1-ubyte deleted file mode 100644 index 30424ca2ea..0000000000 Binary files a/machine-learning/src/main/resources/train-labels-idx1-ubyte and /dev/null differ diff --git a/machine-learning/src/test/com/baeldung/simplelinearregression/SimpleLinearRegressionUnitTest.kt b/machine-learning/src/test/com/baeldung/simplelinearregression/SimpleLinearRegressionUnitTest.kt deleted file mode 100644 index a741639d50..0000000000 --- a/machine-learning/src/test/com/baeldung/simplelinearregression/SimpleLinearRegressionUnitTest.kt +++ /dev/null @@ -1,40 +0,0 @@ -package com.baeldung.simplelinearregression - -import org.junit.Assert.assertEquals -import org.junit.jupiter.api.Test - -class SimpleLinearRegressionUnitTest { - @Test - fun givenAProperDataSetWhenFedToASimpleLinearRegressionModelThenItPredictsCorrectly() { - val xs = arrayListOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) - val ys = arrayListOf(25, 35, 49, 60, 75, 90, 115, 130, 150, 200) - - val model = SimpleLinearRegression(xs, ys) - - val predictionOne = model.predict(2.5) - assertEquals(38.99, predictionOne, 0.01) - - val predictionTwo = model.predict(7.5) - assertEquals(128.84, predictionTwo, 0.01) - } - - @Test - fun givenAPredictableDataSetWhenCalculatingTheLossFunctionThenTheModelIsConsideredReliable() { - val xs = arrayListOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) - val ys = arrayListOf(25, 35, 49, 60, 75, 90, 115, 130, 150, 200) - - val model = SimpleLinearRegression(xs, ys) - - assertEquals(0.95, model.calculateRSquared(), 0.01) - } - - @Test - fun givenAnUnpredictableDataSetWhenCalculatingTheLossFunctionThenTheModelIsConsideredUnreliable() { - val xs = arrayListOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) - val ys = arrayListOf(200, 0, 200, 0, 0, 0, -115, 1000, 0, 1) - - val model = SimpleLinearRegression(xs, ys) - - assertEquals(0.01, model.calculateRSquared(), 0.01) - } -} \ No newline at end of file diff --git a/pom.xml b/pom.xml index ed2f31c394..15a9170672 100644 --- a/pom.xml +++ b/pom.xml @@ -498,7 +498,6 @@ lombok-custom lucene - machine-learning mapstruct maven-modules @@ -996,7 +995,6 @@ lombok-custom lucene - machine-learning mapstruct maven-modules diff --git a/spring-5-data-reactive/README.md b/spring-5-data-reactive/README.md index 42fcba96f2..0931161700 100644 --- a/spring-5-data-reactive/README.md +++ b/spring-5-data-reactive/README.md @@ -6,7 +6,6 @@ This module contains articles about reactive Spring 5 Data The "REST With Spring" Classes: http://bit.ly/restwithspring ### Relevant Articles -- [Reactive Flow with MongoDB, Kotlin, and Spring WebFlux](https://www.baeldung.com/kotlin-mongodb-spring-webflux) - [Spring Data Reactive Repositories with MongoDB](https://www.baeldung.com/spring-data-mongodb-reactive) - [Spring Data MongoDB Tailable Cursors](https://www.baeldung.com/spring-data-mongodb-tailable-cursors) - [A Quick Look at R2DBC with Spring Data](https://www.baeldung.com/spring-data-r2dbc) diff --git a/spring-5-data-reactive/pom.xml b/spring-5-data-reactive/pom.xml index 396f7f5959..0fb689f16d 100644 --- a/spring-5-data-reactive/pom.xml +++ b/spring-5-data-reactive/pom.xml @@ -31,18 +31,6 @@ org.springframework.boot spring-boot-starter-web - - com.fasterxml.jackson.module - jackson-module-kotlin - - - org.jetbrains.kotlin - kotlin-stdlib-jdk8 - - - org.jetbrains.kotlin - kotlin-reflect - org.projectlombok lombok @@ -52,12 +40,6 @@ reactor-test test - - org.jetbrains.kotlin - kotlin-test - ${kotlin.version} - test - io.reactivex.rxjava2 rxjava @@ -128,53 +110,6 @@ org.springframework.boot spring-boot-maven-plugin - - kotlin-maven-plugin - ${kotlin-maven-plugin.version} - - - compile - - compile - - - - ${project.basedir}/src/main/kotlin - ${project.basedir}/src/main/java - - - - - test-compile - - test-compile - - - - ${project.basedir}/src/test/kotlin - ${project.basedir}/src/test/java - - - - - org.jetbrains.kotlin - - - -Xjsr305=strict - - - spring - - 1.8 - - - - org.jetbrains.kotlin - kotlin-maven-allopen - ${kotlin.version} - - - org.apache.maven.plugins maven-compiler-plugin @@ -215,8 +150,6 @@ - 1.2.40 - 1.2.40 5.2.2.RELEASE 1.0.0.RELEASE 0.8.1.RELEASE diff --git a/spring-5-data-reactive/src/main/kotlin/com/baeldung/Application.kt b/spring-5-data-reactive/src/main/kotlin/com/baeldung/Application.kt deleted file mode 100644 index 5a59d11de0..0000000000 --- a/spring-5-data-reactive/src/main/kotlin/com/baeldung/Application.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.baeldung - -import org.springframework.boot.SpringApplication -import org.springframework.boot.autoconfigure.SpringBootApplication -import org.springframework.boot.autoconfigure.data.mongo.MongoReactiveDataAutoConfiguration - -@SpringBootApplication(exclude = arrayOf(MongoReactiveDataAutoConfiguration::class)) -class Application - -fun main(args: Array) { - SpringApplication.run(Application::class.java, *args) -} diff --git a/spring-5-data-reactive/src/main/kotlin/com/baeldung/Event.kt b/spring-5-data-reactive/src/main/kotlin/com/baeldung/Event.kt deleted file mode 100644 index 17fa9699a8..0000000000 --- a/spring-5-data-reactive/src/main/kotlin/com/baeldung/Event.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.baeldung - -import org.springframework.data.mongodb.core.mapping.Document - -@Document -data class Event(val id: String, val name: String) diff --git a/spring-5-data-reactive/src/main/kotlin/com/baeldung/EventRepository.kt b/spring-5-data-reactive/src/main/kotlin/com/baeldung/EventRepository.kt deleted file mode 100644 index e66af71ea6..0000000000 --- a/spring-5-data-reactive/src/main/kotlin/com/baeldung/EventRepository.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.baeldung - -import org.springframework.data.mongodb.core.mapping.Document -import org.springframework.data.mongodb.repository.ReactiveMongoRepository - -interface EventRepository : ReactiveMongoRepository diff --git a/spring-5-data-reactive/src/main/kotlin/com/baeldung/MongoConfig.kt b/spring-5-data-reactive/src/main/kotlin/com/baeldung/MongoConfig.kt deleted file mode 100644 index 64d51a176a..0000000000 --- a/spring-5-data-reactive/src/main/kotlin/com/baeldung/MongoConfig.kt +++ /dev/null @@ -1,25 +0,0 @@ -package com.baeldung - -import com.mongodb.reactivestreams.client.MongoClient -import com.mongodb.reactivestreams.client.MongoClients -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.data.mongodb.config.AbstractReactiveMongoConfiguration -import org.springframework.data.mongodb.core.ReactiveMongoTemplate -import org.springframework.data.mongodb.repository.config.EnableReactiveMongoRepositories - - -@Configuration -@EnableReactiveMongoRepositories(basePackageClasses = arrayOf(EventRepository::class)) -class MongoConfig : AbstractReactiveMongoConfiguration() { - - override fun reactiveMongoClient(): MongoClient = mongoClient() - - @Bean - fun mongoClient(): MongoClient = MongoClients.create() - - override fun getDatabaseName(): String = "mongoDatabase" - - @Bean - override fun reactiveMongoTemplate(): ReactiveMongoTemplate = ReactiveMongoTemplate(mongoClient(), databaseName) -} diff --git a/spring-5-data-reactive/src/main/kotlin/com/baeldung/SendEmitter.kt b/spring-5-data-reactive/src/main/kotlin/com/baeldung/SendEmitter.kt deleted file mode 100644 index 6fa3118d8f..0000000000 --- a/spring-5-data-reactive/src/main/kotlin/com/baeldung/SendEmitter.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.baeldung - -import org.springframework.http.MediaType -import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.RequestParam -import org.springframework.web.bind.annotation.RestController -import java.util.* - - -@RestController -class SendEmitter(val eventRepository: EventRepository) { - - @GetMapping(value = "/save", produces = arrayOf(MediaType.TEXT_EVENT_STREAM_VALUE)) - fun executeExample(@RequestParam("eventName") eventName: String) = - eventRepository.save(Event(UUID.randomUUID().toString(), eventName)).flux() -} diff --git a/spring-5-data-reactive/src/main/resources/static/index.html b/spring-5-data-reactive/src/main/resources/static/index.html deleted file mode 100644 index a0b8f6f884..0000000000 --- a/spring-5-data-reactive/src/main/resources/static/index.html +++ /dev/null @@ -1,39 +0,0 @@ - - - - -
- - -
- - - -
- - - - diff --git a/spring-5-mvc/README.md b/spring-5-mvc/README.md index aff8bb227c..edb6cec455 100644 --- a/spring-5-mvc/README.md +++ b/spring-5-mvc/README.md @@ -3,7 +3,6 @@ This module contains articles about Spring 5 model-view-controller (MVC) pattern ### Relevant Articles: -- [Spring Boot and Kotlin](https://www.baeldung.com/spring-boot-kotlin) - [Spring MVC Streaming and SSE Request Processing](https://www.baeldung.com/spring-mvc-sse-streams) - [Interface Driven Controllers in Spring](https://www.baeldung.com/spring-interface-driven-controllers) - [Returning Plain HTML From a Spring MVC Controller](https://www.baeldung.com/spring-mvc-return-html) diff --git a/spring-5-mvc/pom.xml b/spring-5-mvc/pom.xml index 0bb69d8057..39fcd22824 100644 --- a/spring-5-mvc/pom.xml +++ b/spring-5-mvc/pom.xml @@ -42,22 +42,6 @@ org.slf4j jcl-over-slf4j
- - - org.jetbrains.kotlin - kotlin-stdlib-jre8 - ${kotlin.version} - - - org.jetbrains.kotlin - kotlin-reflect - ${kotlin.version} - - - com.fasterxml.jackson.module - jackson-module-kotlin - ${jackson.version} - org.springframework.boot @@ -103,77 +87,11 @@ org.springframework.boot spring-boot-maven-plugin - - kotlin-maven-plugin - org.jetbrains.kotlin - ${kotlin.version} - - - spring - - ${java.version} - - - - compile - compile - - compile - - - - test-compile - test-compile - - test-compile - - - - - - org.jetbrains.kotlin - kotlin-maven-allopen - ${kotlin.version} - - - - - org.codehaus.mojo - build-helper-maven-plugin - - - generate-sources - - add-source - - - - ${basedir}/src/main/java - ${basedir}/src/main/kotlin - - - - - test-compile - test-compile - - add-test-source - - - - ${basedir}/src/test/java - ${basedir}/src/test/kotlin - - - - - 2.9.0 - 1.2.71 4.5.8 com.baeldung.Spring5Application 0.18 diff --git a/spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/HelloController.kt b/spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/HelloController.kt deleted file mode 100644 index 69be7dac7e..0000000000 --- a/spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/HelloController.kt +++ /dev/null @@ -1,23 +0,0 @@ -package com.baeldung.springbootkotlin - -import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.RestController - -@RestController -class HelloController(val helloService: HelloService) { - - @GetMapping("/hello") - fun helloKotlin(): String { - return "hello world" - } - - @GetMapping("/hello-service") - fun helloKotlinService(): String { - return helloService.getHello() - } - - @GetMapping("/hello-dto") - fun helloDto(): HelloDto { - return HelloDto("Hello from the dto") - } -} \ No newline at end of file diff --git a/spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/HelloDto.kt b/spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/HelloDto.kt deleted file mode 100644 index f61c101f0f..0000000000 --- a/spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/HelloDto.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.baeldung.springbootkotlin - -data class HelloDto(val greeting: String) diff --git a/spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/HelloService.kt b/spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/HelloService.kt deleted file mode 100644 index 67791a0c2d..0000000000 --- a/spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/HelloService.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.baeldung.springbootkotlin - -import org.springframework.stereotype.Service - -@Service -class HelloService { - - fun getHello(): String { - return "hello service" - } -} \ No newline at end of file diff --git a/spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/KotlinDemoApplication.kt b/spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/KotlinDemoApplication.kt deleted file mode 100644 index 8904d8d805..0000000000 --- a/spring-5-mvc/src/main/kotlin/com/baeldung/springbootkotlin/KotlinDemoApplication.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.baeldung.springbootkotlin - -import org.springframework.boot.SpringApplication -import org.springframework.boot.autoconfigure.SpringBootApplication -import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration - -@SpringBootApplication(scanBasePackages = arrayOf("com.baeldung.springbootkotlin"), exclude = arrayOf(SecurityAutoConfiguration::class)) -class KotlinDemoApplication - -fun main(args: Array) { - SpringApplication.run(KotlinDemoApplication::class.java, *args) -} diff --git a/spring-5-mvc/src/test/kotlin/com/baeldung/springbootkotlin/KotlinDemoApplicationIntegrationTest.kt b/spring-5-mvc/src/test/kotlin/com/baeldung/springbootkotlin/KotlinDemoApplicationIntegrationTest.kt deleted file mode 100644 index d0667177c8..0000000000 --- a/spring-5-mvc/src/test/kotlin/com/baeldung/springbootkotlin/KotlinDemoApplicationIntegrationTest.kt +++ /dev/null @@ -1,52 +0,0 @@ -package com.baeldung.springbootkotlin - -import org.junit.Assert.assertEquals -import org.junit.Assert.assertNotNull -import org.junit.Test -import org.junit.runner.RunWith -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.test.context.SpringBootTest -import org.springframework.boot.test.web.client.TestRestTemplate -import org.springframework.http.HttpStatus -import org.springframework.test.context.junit4.SpringRunner - -@RunWith(SpringRunner::class) -@SpringBootTest( - classes = arrayOf(KotlinDemoApplication::class), - webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -class KotlinDemoApplicationIntegrationTest { - - @Autowired - lateinit var testRestTemplate: TestRestTemplate - - @Test - fun whenCalled_thenShouldReturnHello() { - val result = testRestTemplate.withBasicAuth("user", "pass") - .getForEntity("/hello", String::class.java) - - assertNotNull(result) - assertEquals(HttpStatus.OK, result?.statusCode) - assertEquals("hello world", result?.body) - } - - @Test - fun whenCalled_thenShouldReturnHelloService() { - val result = testRestTemplate.withBasicAuth("user", "pass") - .getForEntity("/hello-service", String::class.java) - - assertNotNull(result) - assertEquals(HttpStatus.OK, result?.statusCode) - assertEquals(result?.body, "hello service") - } - - @Test - fun whenCalled_thenShouldReturnJson() { - val result = testRestTemplate.withBasicAuth("user", "pass") - .getForEntity("/hello-dto", HelloDto::class.java) - - assertNotNull(result) - assertEquals(HttpStatus.OK, result?.statusCode) - assertEquals(result?.body, HelloDto("Hello from the dto")) - } - -} diff --git a/spring-security-modules/pom.xml b/spring-security-modules/pom.xml index 0fc2b49fa7..e32fadd671 100644 --- a/spring-security-modules/pom.xml +++ b/spring-security-modules/pom.xml @@ -38,7 +38,6 @@ spring-security-oauth2-sso spring-security-web-thymeleaf spring-security-web-x509 - spring-security-kotlin-dsl diff --git a/spring-security-modules/spring-security-kotlin-dsl/README.md b/spring-security-modules/spring-security-kotlin-dsl/README.md deleted file mode 100644 index 39e521d84e..0000000000 --- a/spring-security-modules/spring-security-kotlin-dsl/README.md +++ /dev/null @@ -1,3 +0,0 @@ -### Relevant Articles: - -- [Spring Security with Kotlin DSL](https://www.baeldung.com/kotlin/spring-security-dsl) diff --git a/spring-security-modules/spring-security-kotlin-dsl/pom.xml b/spring-security-modules/spring-security-kotlin-dsl/pom.xml deleted file mode 100644 index 24e99decfb..0000000000 --- a/spring-security-modules/spring-security-kotlin-dsl/pom.xml +++ /dev/null @@ -1,87 +0,0 @@ - - - 4.0.0 - - com.baeldung - parent-boot-2 - 0.0.1-SNAPSHOT - ../../parent-boot-2 - - - com.baeldung.spring.security.dsl - spring-security-kotlin-dsl - 1.0 - spring-security-kotlin-dsl - Spring Security Kotlin DSL - - - - org.springframework.boot - spring-boot-starter-security - - - org.springframework.boot - spring-boot-starter-web - - - com.fasterxml.jackson.module - jackson-module-kotlin - - - org.jetbrains.kotlin - kotlin-reflect - - - org.jetbrains.kotlin - kotlin-stdlib-jdk8 - - - - org.projectlombok - lombok - true - - - org.springframework.boot - spring-boot-starter-test - test - - - - - ${project.basedir}/src/main/kotlin - ${project.basedir}/src/test/kotlin - - - org.springframework.boot - spring-boot-maven-plugin - - - org.jetbrains.kotlin - kotlin-maven-plugin - - - -Xjsr305=strict - - - spring - - - - - org.jetbrains.kotlin - kotlin-maven-allopen - ${kotlin.version} - - - - - - - - 11 - 1.3.72 - - - diff --git a/spring-security-modules/spring-security-kotlin-dsl/src/main/kotlin/com/baeldung/security/kotlin/dsl/SpringSecurityKotlinApplication.kt b/spring-security-modules/spring-security-kotlin-dsl/src/main/kotlin/com/baeldung/security/kotlin/dsl/SpringSecurityKotlinApplication.kt deleted file mode 100644 index 27cc41c1e5..0000000000 --- a/spring-security-modules/spring-security-kotlin-dsl/src/main/kotlin/com/baeldung/security/kotlin/dsl/SpringSecurityKotlinApplication.kt +++ /dev/null @@ -1,71 +0,0 @@ -package com.baeldung.security.kotlin.dsl - -import org.springframework.boot.autoconfigure.SpringBootApplication -import org.springframework.boot.runApplication -import org.springframework.context.annotation.Configuration -import org.springframework.context.support.beans -import org.springframework.core.annotation.Order -import org.springframework.security.config.annotation.web.builders.HttpSecurity -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter -import org.springframework.security.config.web.servlet.invoke -import org.springframework.security.core.userdetails.User -import org.springframework.security.provisioning.InMemoryUserDetailsManager -import org.springframework.web.servlet.function.ServerResponse -import org.springframework.web.servlet.function.router - -@EnableWebSecurity -@SpringBootApplication -class SpringSecurityKotlinApplication - -@Order(1) -@Configuration -class AdminSecurityConfiguration : WebSecurityConfigurerAdapter() { - override fun configure(http: HttpSecurity?) { - http { - authorizeRequests { - authorize("/greetings/**", hasAuthority("ROLE_ADMIN")) - } - httpBasic {} - } - } -} - -@Configuration -class BasicSecurityConfiguration : WebSecurityConfigurerAdapter() { - override fun configure(http: HttpSecurity?) { - http { - authorizeRequests { - authorize("/**", permitAll) - } - httpBasic {} - } - } -} - -fun main(args: Array) { - runApplication(*args) { - addInitializers( beans { - bean { - fun user(user: String, password: String, vararg roles: String) = - User - .withDefaultPasswordEncoder() - .username(user) - .password(password) - .roles(*roles) - .build() - - InMemoryUserDetailsManager(user("user", "password", "USER") - , user("admin", "password", "USER", "ADMIN")) - } - - bean { - router { - GET("/greetings") { - request -> request.principal().map { it.name }.map { ServerResponse.ok().body(mapOf("greeting" to "Hello $it")) }.orElseGet { ServerResponse.badRequest().build() } - } - } - } - }) - } -} diff --git a/spring-security-modules/spring-security-kotlin-dsl/src/main/resources/application.properties b/spring-security-modules/spring-security-kotlin-dsl/src/main/resources/application.properties deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/spring-security-modules/spring-security-kotlin-dsl/src/test/kotlin/com/spring/security/kotlin/dsl/SpringSecurityKotlinApplicationTests.kt b/spring-security-modules/spring-security-kotlin-dsl/src/test/kotlin/com/spring/security/kotlin/dsl/SpringSecurityKotlinApplicationTests.kt deleted file mode 100644 index 3da8110feb..0000000000 --- a/spring-security-modules/spring-security-kotlin-dsl/src/test/kotlin/com/spring/security/kotlin/dsl/SpringSecurityKotlinApplicationTests.kt +++ /dev/null @@ -1,35 +0,0 @@ -package com.spring.security.kotlin.dsl - -import org.junit.jupiter.api.Test -import org.junit.runner.RunWith -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc -import org.springframework.boot.test.context.SpringBootTest -import org.springframework.security.test.context.support.WithMockUser -import org.springframework.test.context.junit4.SpringRunner -import org.springframework.test.web.servlet.MockMvc -import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestBuilders.* -import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user -import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.httpBasic -import org.springframework.security.test.web.servlet.response.SecurityMockMvcResultMatchers.authenticated -import org.springframework.security.test.web.servlet.response.SecurityMockMvcResultMatchers.unauthenticated -import org.springframework.test.web.servlet.get -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.* -import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status - -@RunWith(SpringRunner::class) -@SpringBootTest -@AutoConfigureMockMvc -class SpringSecurityKotlinApplicationTests { - - @Autowired - private lateinit var mockMvc: MockMvc - - @Test - fun `ordinary user not permitted to access the endpoint`() { - this.mockMvc - .perform(get("/greetings") - .with(httpBasic("user", "password"))) - .andExpect(unauthenticated()) - } -}