From f55bd014f9704d5fbb18fb5a9f227f571fa30a39 Mon Sep 17 00:00:00 2001 From: Thoughtscript Date: Tue, 21 Nov 2017 06:44:51 +0000 Subject: [PATCH 01/65] BAEL-1175 - Using a Spring Cloud App Starter Bash --- spring-cloud/README.md | 1 + .../bash/hadoop.sh | 42 +++++++++++++++++++ .../hdfs/application.properties | 1 + .../spring-cloud-stream-starters/hdfs/hdfs.sh | 14 +++++++ .../twitter/application.properties | 4 ++ .../twitter/twitter.sh | 15 +++++++ 6 files changed, 77 insertions(+) create mode 100644 spring-cloud/spring-cloud-stream-starters/bash/hadoop.sh create mode 100644 spring-cloud/spring-cloud-stream-starters/hdfs/application.properties create mode 100644 spring-cloud/spring-cloud-stream-starters/hdfs/hdfs.sh create mode 100644 spring-cloud/spring-cloud-stream-starters/twitter/application.properties create mode 100644 spring-cloud/spring-cloud-stream-starters/twitter/twitter.sh diff --git a/spring-cloud/README.md b/spring-cloud/README.md index 1b793144b1..523cf683c3 100644 --- a/spring-cloud/README.md +++ b/spring-cloud/README.md @@ -19,3 +19,4 @@ ### Relevant Articles: - [Introduction to Spring Cloud Rest Client with Netflix Ribbon](http://www.baeldung.com/spring-cloud-rest-client-with-netflix-ribbon) [An Introduction to Spring Cloud Zookeeper](http://www.baeldung.com/spring-cloud-zookeeper) + [Using a Spring Cloud App Starter](http://www.baeldung.com/using-a-spring-cloud-app-starter) \ No newline at end of file diff --git a/spring-cloud/spring-cloud-stream-starters/bash/hadoop.sh b/spring-cloud/spring-cloud-stream-starters/bash/hadoop.sh new file mode 100644 index 0000000000..5eebcca426 --- /dev/null +++ b/spring-cloud/spring-cloud-stream-starters/bash/hadoop.sh @@ -0,0 +1,42 @@ +# For Ubuntu 14.04 +# Inspired from: https://github.com/curran/setupHadoop/blob/master/setupHadoop.sh +# Use from the user directory + +# Install Java +sudo apt-get update +sudo add-apt-repository -y ppa:webupd8team/java +sudo apt-get install -y oracle-java8-installer + +# Install Hadoop +curl -O http://mirror.cogentco.com/pub/apache/hadoop/common/hadoop-2.8.2/hadoop-2.8.2.tar.gz +tar xfz hadoop-2.8.2.tar.gz +sudo mv hadoop-2.8.2 /usr/local/hadoop +rm hadoop-2.8.2.tar.gz + +# Environmental Variables +echo export JAVA_HOME=/usr/lib/jvm/java-8-oracle >> ~/.bashrc +echo export HADOOP_PREFIX=/usr/local/hadoop >> ~/.bashrc +echo export PATH=\$PATH:/usr/local/hadoop/bin >> ~/.bashrc +echo export PATH=\$PATH:/usr/local/hadoop/sbin >> ~/.bashrc +source ~/.bashrc + +# Copy configuration files +cp master/* /usr/local/hadoop/etc/hadoop/ + +# Format HDFS +hdfs namenode -format + +# SSH keys for Hadoop to use. +ssh-keygen -t rsa -P 'password' -f ~/.ssh/id_rsa.pub +sudo mv ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys + +# SSH +ssh localhost +# Authenticate with local user + +# Start NameNode daemon and DataNode daemon +start-dfs.sh +# stop-dfs.sh + +# Install Maven +sudo apt-get install maven diff --git a/spring-cloud/spring-cloud-stream-starters/hdfs/application.properties b/spring-cloud/spring-cloud-stream-starters/hdfs/application.properties new file mode 100644 index 0000000000..8b421f954c --- /dev/null +++ b/spring-cloud/spring-cloud-stream-starters/hdfs/application.properties @@ -0,0 +1 @@ +hdfs.fs-uri=http://osboxes:50075 \ No newline at end of file diff --git a/spring-cloud/spring-cloud-stream-starters/hdfs/hdfs.sh b/spring-cloud/spring-cloud-stream-starters/hdfs/hdfs.sh new file mode 100644 index 0000000000..3c45391f75 --- /dev/null +++ b/spring-cloud/spring-cloud-stream-starters/hdfs/hdfs.sh @@ -0,0 +1,14 @@ +# Git spring-cloud-stream-app-starters +git clone https://github.com/spring-cloud/spring-cloud-stream-app-starters.git + +# Navigate to HDFS +cd /hdfs + +# Navigate to the the app configuration settings +cd /spring-cloud-starter-stream-sink-hdfs/src/main/java/org/springframework/cloud/stream/app/hdfs/sink/HdfsSinkProperties.java +# Specify the properties you want there +# or inject the application.properties file before building the app + +# Then build the customized starter app +cd ../../../../../../../../../../../../../ +mvn clean install \ No newline at end of file diff --git a/spring-cloud/spring-cloud-stream-starters/twitter/application.properties b/spring-cloud/spring-cloud-stream-starters/twitter/application.properties new file mode 100644 index 0000000000..5cfedee80e --- /dev/null +++ b/spring-cloud/spring-cloud-stream-starters/twitter/application.properties @@ -0,0 +1,4 @@ +twitter.credentials.access-token=932486336086286336-2HURQbA2cYzX5hixgAshIBy2Dhefupn +twitter.credentials.access-token-secret=0pyZ7etHvro8x85QSXxsqYFzYk63bK6DS5nNYy0R3l1io +twitter.credentials.consumer-key=10xCXkRYi5xLFYq3P0ymWGEwJ +twitter.credentials.consumer-secret=VfyCUcGfAQ2aWcd3uTg8GmVGyhUfAcNJU6ksG09TAtPMqhmWTS \ No newline at end of file diff --git a/spring-cloud/spring-cloud-stream-starters/twitter/twitter.sh b/spring-cloud/spring-cloud-stream-starters/twitter/twitter.sh new file mode 100644 index 0000000000..c3d16bb92e --- /dev/null +++ b/spring-cloud/spring-cloud-stream-starters/twitter/twitter.sh @@ -0,0 +1,15 @@ +# Git spring-cloud-stream-app-starters +git clone https://github.com/spring-cloud/spring-cloud-stream-app-starters.git + +# Navigate to Twitter +cd /twitter + +# Navigate to the the app configuration settings +cd /spring-cloud-starter-stream-source-twitterstream/src/main/java/org/springframework/cloud/stream/app/twitterstream/source/TwitterStreamProperties.java +cd /spring-cloud-stream-app-starters/app-starters-common/app-starters-twitter-common/src/main/java/org/springframework/cloud/stream/app/twitter/TwitterCredentials.java +# Specify the properties you want there +# or inject the application.properties file before building the app + +# Then build the customized starter app +cd ../../../../../../../../../../../../ +mvn clean install \ No newline at end of file From 4e8b83721b04f92daffc9c3f7c9284b1387a3014 Mon Sep 17 00:00:00 2001 From: Thoughtscript Date: Thu, 23 Nov 2017 00:54:45 +0000 Subject: [PATCH 02/65] BAEL-1175 - Updating scripts post-1.1.0 RC1 --- .../spring-cloud-stream-starters/hdfs/hdfs.sh | 19 +++++++---------- .../twitter/twitter.sh | 21 ++++++++----------- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/spring-cloud/spring-cloud-stream-starters/hdfs/hdfs.sh b/spring-cloud/spring-cloud-stream-starters/hdfs/hdfs.sh index 3c45391f75..a9df476ef4 100644 --- a/spring-cloud/spring-cloud-stream-starters/hdfs/hdfs.sh +++ b/spring-cloud/spring-cloud-stream-starters/hdfs/hdfs.sh @@ -1,14 +1,11 @@ # Git spring-cloud-stream-app-starters -git clone https://github.com/spring-cloud/spring-cloud-stream-app-starters.git +# https://github.com/spring-cloud-stream-app-starters/hdfs/blob/master/spring-cloud-starter-stream-sink-hdfs/README.adoc +git clone https://github.com/spring-cloud-stream-app-starters/hdfs.git -# Navigate to HDFS -cd /hdfs +# Build it +./mvnw clean install -PgenerateApps -# Navigate to the the app configuration settings -cd /spring-cloud-starter-stream-sink-hdfs/src/main/java/org/springframework/cloud/stream/app/hdfs/sink/HdfsSinkProperties.java -# Specify the properties you want there -# or inject the application.properties file before building the app - -# Then build the customized starter app -cd ../../../../../../../../../../../../../ -mvn clean install \ No newline at end of file +# RUn it +cd apps +# Optionally inject application.properties prior to build +java -jar hdfs-sink.jar --fsUri=http://osboxes:50075 \ No newline at end of file diff --git a/spring-cloud/spring-cloud-stream-starters/twitter/twitter.sh b/spring-cloud/spring-cloud-stream-starters/twitter/twitter.sh index c3d16bb92e..994d40dd4c 100644 --- a/spring-cloud/spring-cloud-stream-starters/twitter/twitter.sh +++ b/spring-cloud/spring-cloud-stream-starters/twitter/twitter.sh @@ -1,15 +1,12 @@ # Git spring-cloud-stream-app-starters -git clone https://github.com/spring-cloud/spring-cloud-stream-app-starters.git +# https://github.com/spring-cloud-stream-app-starters/hdfs/blob/master/spring-cloud-starter-stream-sink-hdfs/README.adoc +git clone https://github.com/spring-cloud-stream-app-starters/twitter.git -# Navigate to Twitter -cd /twitter +# Build it +./mvnw clean install -PgenerateApps -# Navigate to the the app configuration settings -cd /spring-cloud-starter-stream-source-twitterstream/src/main/java/org/springframework/cloud/stream/app/twitterstream/source/TwitterStreamProperties.java -cd /spring-cloud-stream-app-starters/app-starters-common/app-starters-twitter-common/src/main/java/org/springframework/cloud/stream/app/twitter/TwitterCredentials.java -# Specify the properties you want there -# or inject the application.properties file before building the app - -# Then build the customized starter app -cd ../../../../../../../../../../../../ -mvn clean install \ No newline at end of file +# RUn it +cd apps +# Optionally inject application.properties prior to build +java -jar twitter_stream_source.jar --consumerKey= --consumerSecret= \ + --accessToken= --accessTokenSecret= \ No newline at end of file From c174946f855ff445c787c8ddac683b73e26a0378 Mon Sep 17 00:00:00 2001 From: Alessio Stalla Date: Mon, 8 Jan 2018 22:12:47 +0100 Subject: [PATCH 03/65] Code for Alessio Stalla's evaluation article (Different Types of Bean Injection in Spring) --- .../baeldung/typesofbeaninjection/Config.java | 16 +++++ .../typesofbeaninjection/domain/Car.java | 24 ++++++++ .../typesofbeaninjection/domain/Engine.java | 24 ++++++++ .../domain/autowired/constructor/Car.java | 30 ++++++++++ .../domain/autowired/properties/Car.java | 30 ++++++++++ .../typesofbeaninjection-context.xml | 19 ++++++ .../TypeOfBeanInjectionUnitTest.java | 58 +++++++++++++++++++ 7 files changed, 201 insertions(+) create mode 100644 spring-core/src/main/java/com/baeldung/typesofbeaninjection/Config.java create mode 100644 spring-core/src/main/java/com/baeldung/typesofbeaninjection/domain/Car.java create mode 100644 spring-core/src/main/java/com/baeldung/typesofbeaninjection/domain/Engine.java create mode 100644 spring-core/src/main/java/com/baeldung/typesofbeaninjection/domain/autowired/constructor/Car.java create mode 100644 spring-core/src/main/java/com/baeldung/typesofbeaninjection/domain/autowired/properties/Car.java create mode 100644 spring-core/src/main/resources/typesofbeaninjection-context.xml create mode 100644 spring-core/src/test/java/com/baeldung/typesofbeaninjection/TypeOfBeanInjectionUnitTest.java diff --git a/spring-core/src/main/java/com/baeldung/typesofbeaninjection/Config.java b/spring-core/src/main/java/com/baeldung/typesofbeaninjection/Config.java new file mode 100644 index 0000000000..a967a63005 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/typesofbeaninjection/Config.java @@ -0,0 +1,16 @@ +package com.baeldung.typesofbeaninjection; + +import com.baeldung.typesofbeaninjection.domain.Engine; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +@Configuration +@ComponentScan("com.baeldung.typesofbeaninjection") +public class Config { + + @Bean + public Engine engine() { + return new Engine("V8", 5); + } +} diff --git a/spring-core/src/main/java/com/baeldung/typesofbeaninjection/domain/Car.java b/spring-core/src/main/java/com/baeldung/typesofbeaninjection/domain/Car.java new file mode 100644 index 0000000000..878f369c8e --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/typesofbeaninjection/domain/Car.java @@ -0,0 +1,24 @@ +package com.baeldung.typesofbeaninjection.domain; + +public class Car { + private Engine engine; + + public Car() {} + + public Car(Engine engine) { + this.engine = engine; + } + + public Engine getEngine() { + return engine; + } + + public void setEngine(Engine engine) { + this.engine = engine; + } + + @Override + public String toString() { + return String.format("Car with %s engine", engine); + } +} diff --git a/spring-core/src/main/java/com/baeldung/typesofbeaninjection/domain/Engine.java b/spring-core/src/main/java/com/baeldung/typesofbeaninjection/domain/Engine.java new file mode 100644 index 0000000000..79e7a9856d --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/typesofbeaninjection/domain/Engine.java @@ -0,0 +1,24 @@ +package com.baeldung.typesofbeaninjection.domain; + +public class Engine { + private final String type; + private final int volume; + + public Engine(String type, int volume) { + this.type = type; + this.volume = volume; + } + + public String getType() { + return type; + } + + public int getVolume() { + return volume; + } + + @Override + public String toString() { + return String.format("%s %d", type, volume); + } +} diff --git a/spring-core/src/main/java/com/baeldung/typesofbeaninjection/domain/autowired/constructor/Car.java b/spring-core/src/main/java/com/baeldung/typesofbeaninjection/domain/autowired/constructor/Car.java new file mode 100644 index 0000000000..33fadf8d2b --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/typesofbeaninjection/domain/autowired/constructor/Car.java @@ -0,0 +1,30 @@ +package com.baeldung.typesofbeaninjection.domain.autowired.constructor; + +import com.baeldung.typesofbeaninjection.domain.Engine; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component("car-autowired-by-constructor") +public class Car { + private Engine engine; + + public Car() {} + + @Autowired + public Car(Engine engine) { + this.engine = engine; + } + + public Engine getEngine() { + return engine; + } + + public void setEngine(Engine engine) { + this.engine = engine; + } + + @Override + public String toString() { + return String.format("Car with %s engine", engine); + } +} diff --git a/spring-core/src/main/java/com/baeldung/typesofbeaninjection/domain/autowired/properties/Car.java b/spring-core/src/main/java/com/baeldung/typesofbeaninjection/domain/autowired/properties/Car.java new file mode 100644 index 0000000000..1df33f5062 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/typesofbeaninjection/domain/autowired/properties/Car.java @@ -0,0 +1,30 @@ +package com.baeldung.typesofbeaninjection.domain.autowired.properties; + +import com.baeldung.typesofbeaninjection.domain.Engine; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component("car-autowired-by-properties") +public class Car { + private Engine engine; + + public Car() {} + + public Car(Engine engine) { + this.engine = engine; + } + + public Engine getEngine() { + return engine; + } + + @Autowired + public void setEngine(Engine engine) { + this.engine = engine; + } + + @Override + public String toString() { + return String.format("Car with %s engine", engine); + } +} diff --git a/spring-core/src/main/resources/typesofbeaninjection-context.xml b/spring-core/src/main/resources/typesofbeaninjection-context.xml new file mode 100644 index 0000000000..5a9a0b59d7 --- /dev/null +++ b/spring-core/src/main/resources/typesofbeaninjection-context.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-core/src/test/java/com/baeldung/typesofbeaninjection/TypeOfBeanInjectionUnitTest.java b/spring-core/src/test/java/com/baeldung/typesofbeaninjection/TypeOfBeanInjectionUnitTest.java new file mode 100644 index 0000000000..1b1319e001 --- /dev/null +++ b/spring-core/src/test/java/com/baeldung/typesofbeaninjection/TypeOfBeanInjectionUnitTest.java @@ -0,0 +1,58 @@ +package com.baeldung.typesofbeaninjection; + +import com.baeldung.typesofbeaninjection.domain.Car; +import com.baeldung.typesofbeaninjection.domain.Engine; +import org.junit.Test; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class TypeOfBeanInjectionUnitTest { + + @Test + public void whenConstructionInjectionInXML_thenCarHasEngine() { + ApplicationContext applicationContext + = new ClassPathXmlApplicationContext("/typesofbeaninjection-context.xml"); + Car car = applicationContext.getBean("alices-car", Car.class); + + checkEngine(car.getEngine()); + } + + @Test + public void whenPropertyInjectionInXML_thenCarHasEngine() { + ApplicationContext applicationContext + = new ClassPathXmlApplicationContext("/typesofbeaninjection-context.xml"); + Car car = applicationContext.getBean("bobs-car", Car.class); + + checkEngine(car.getEngine()); + } + + @Test + public void whenConstructionInjectionAnnotations_thenCarHasEngine() { + ApplicationContext applicationContext = new AnnotationConfigApplicationContext(Config.class); + com.baeldung.typesofbeaninjection.domain.autowired.constructor.Car car + = applicationContext.getBean(com.baeldung.typesofbeaninjection.domain.autowired.constructor.Car.class); + + checkEngine(car.getEngine()); + } + + @Test + public void whenPropertyInjectionAnnotations_thenCarHasEngine() { + ApplicationContext applicationContext = new AnnotationConfigApplicationContext(Config.class); + com.baeldung.typesofbeaninjection.domain.autowired.properties.Car car + = applicationContext.getBean(com.baeldung.typesofbeaninjection.domain.autowired.properties.Car.class); + + checkEngine(car.getEngine()); + } + + private void checkEngine(Engine engine) { + assertNotNull(engine); + assertEquals("V8", engine.getType()); + assertEquals(5, engine.getVolume()); + } + + +} From 7420aa7f6fd5c7661f69cea55e1ffc1d325e6848 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sat, 13 Jan 2018 18:18:41 +0200 Subject: [PATCH 04/65] move actuator 2 to spring-5-reactive --- spring-5-reactive/pom.xml | 4 ++++ .../actuator/DownstreamServiceReactiveHealthIndicator.java | 2 +- .../com/baeldung/reactive}/actuator/FeaturesEndpoint.java | 2 +- .../reactive}/actuator/InfoWebEndpointExtension.java | 2 +- .../src/main/resources/application.properties | 5 ++++- .../reactive}/actuator/ActuatorInfoIntegrationTest.java | 7 ++++--- spring-5/pom.xml | 4 ---- .../main/java/com/baeldung/security/SecurityConfig.java | 1 - spring-5/src/main/resources/application.properties | 2 -- 9 files changed, 15 insertions(+), 14 deletions(-) rename {spring-5/src/main/java/com/baeldung => spring-5-reactive/src/main/java/com/baeldung/reactive}/actuator/DownstreamServiceReactiveHealthIndicator.java (94%) rename {spring-5/src/main/java/com/baeldung => spring-5-reactive/src/main/java/com/baeldung/reactive}/actuator/FeaturesEndpoint.java (96%) rename {spring-5/src/main/java/com/baeldung => spring-5-reactive/src/main/java/com/baeldung/reactive}/actuator/InfoWebEndpointExtension.java (96%) rename {spring-5/src/test/java/com/baeldung => spring-5-reactive/src/test/java/com/baeldung/reactive}/actuator/ActuatorInfoIntegrationTest.java (88%) diff --git a/spring-5-reactive/pom.xml b/spring-5-reactive/pom.xml index e5b35de2f5..ec4312ab21 100644 --- a/spring-5-reactive/pom.xml +++ b/spring-5-reactive/pom.xml @@ -43,6 +43,10 @@ javax.json.bind javax.json.bind-api + + org.springframework.boot + spring-boot-starter-actuator + diff --git a/spring-5/src/main/java/com/baeldung/actuator/DownstreamServiceReactiveHealthIndicator.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/actuator/DownstreamServiceReactiveHealthIndicator.java similarity index 94% rename from spring-5/src/main/java/com/baeldung/actuator/DownstreamServiceReactiveHealthIndicator.java rename to spring-5-reactive/src/main/java/com/baeldung/reactive/actuator/DownstreamServiceReactiveHealthIndicator.java index 5f36330ff6..7360def71e 100644 --- a/spring-5/src/main/java/com/baeldung/actuator/DownstreamServiceReactiveHealthIndicator.java +++ b/spring-5-reactive/src/main/java/com/baeldung/reactive/actuator/DownstreamServiceReactiveHealthIndicator.java @@ -1,4 +1,4 @@ -package com.baeldung.actuator; +package com.baeldung.reactive.actuator; import org.springframework.boot.actuate.health.Health; import org.springframework.boot.actuate.health.ReactiveHealthIndicator; diff --git a/spring-5/src/main/java/com/baeldung/actuator/FeaturesEndpoint.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/actuator/FeaturesEndpoint.java similarity index 96% rename from spring-5/src/main/java/com/baeldung/actuator/FeaturesEndpoint.java rename to spring-5-reactive/src/main/java/com/baeldung/reactive/actuator/FeaturesEndpoint.java index 2ed32501ae..b2bc1e037f 100644 --- a/spring-5/src/main/java/com/baeldung/actuator/FeaturesEndpoint.java +++ b/spring-5-reactive/src/main/java/com/baeldung/reactive/actuator/FeaturesEndpoint.java @@ -1,4 +1,4 @@ -package com.baeldung.actuator; +package com.baeldung.reactive.actuator; import org.springframework.boot.actuate.endpoint.annotation.*; import org.springframework.stereotype.Component; diff --git a/spring-5/src/main/java/com/baeldung/actuator/InfoWebEndpointExtension.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/actuator/InfoWebEndpointExtension.java similarity index 96% rename from spring-5/src/main/java/com/baeldung/actuator/InfoWebEndpointExtension.java rename to spring-5-reactive/src/main/java/com/baeldung/reactive/actuator/InfoWebEndpointExtension.java index acd92d1846..86502f0ab3 100644 --- a/spring-5/src/main/java/com/baeldung/actuator/InfoWebEndpointExtension.java +++ b/spring-5-reactive/src/main/java/com/baeldung/reactive/actuator/InfoWebEndpointExtension.java @@ -1,4 +1,4 @@ -package com.baeldung.actuator; +package com.baeldung.reactive.actuator; import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; import org.springframework.boot.actuate.endpoint.web.WebEndpointResponse; diff --git a/spring-5-reactive/src/main/resources/application.properties b/spring-5-reactive/src/main/resources/application.properties index 4b49e8e8a2..5b9a0ae1ce 100644 --- a/spring-5-reactive/src/main/resources/application.properties +++ b/spring-5-reactive/src/main/resources/application.properties @@ -1 +1,4 @@ -logging.level.root=INFO \ No newline at end of file +logging.level.root=INFO + +management.endpoints.web.expose=* +info.app.name=Spring Boot 2 actuator Application \ No newline at end of file diff --git a/spring-5/src/test/java/com/baeldung/actuator/ActuatorInfoIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/reactive/actuator/ActuatorInfoIntegrationTest.java similarity index 88% rename from spring-5/src/test/java/com/baeldung/actuator/ActuatorInfoIntegrationTest.java rename to spring-5-reactive/src/test/java/com/baeldung/reactive/actuator/ActuatorInfoIntegrationTest.java index 964cf1a1ea..3020e86723 100644 --- a/spring-5/src/test/java/com/baeldung/actuator/ActuatorInfoIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/reactive/actuator/ActuatorInfoIntegrationTest.java @@ -1,6 +1,5 @@ -package com.baeldung.actuator; +package com.baeldung.reactive.actuator; -import com.baeldung.jsonb.Spring5Application; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -10,12 +9,14 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.test.context.junit4.SpringRunner; +import com.baeldung.reactive.Spring5ReactiveApplication; + import java.io.IOException; import static org.junit.Assert.assertEquals; @RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Spring5Application.class) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Spring5ReactiveApplication.class) public class ActuatorInfoIntegrationTest { @Autowired diff --git a/spring-5/pom.xml b/spring-5/pom.xml index 4c2df68f1b..19dd65d78f 100644 --- a/spring-5/pom.xml +++ b/spring-5/pom.xml @@ -43,10 +43,6 @@ org.springframework.boot spring-boot-starter-hateoas - - org.springframework.boot - spring-boot-starter-actuator - org.projectreactor reactor-spring diff --git a/spring-5/src/main/java/com/baeldung/security/SecurityConfig.java b/spring-5/src/main/java/com/baeldung/security/SecurityConfig.java index d31f1552fc..a9e44a2eee 100644 --- a/spring-5/src/main/java/com/baeldung/security/SecurityConfig.java +++ b/spring-5/src/main/java/com/baeldung/security/SecurityConfig.java @@ -17,7 +17,6 @@ public class SecurityConfig { public SecurityWebFilterChain securitygWebFilterChain(ServerHttpSecurity http) { return http.authorizeExchange() .pathMatchers("/admin").hasAuthority("ROLE_ADMIN") - .pathMatchers("/actuator/**").permitAll() .anyExchange().authenticated() .and().formLogin() .and().build(); diff --git a/spring-5/src/main/resources/application.properties b/spring-5/src/main/resources/application.properties index a7e3ec0d5a..ccec014c2b 100644 --- a/spring-5/src/main/resources/application.properties +++ b/spring-5/src/main/resources/application.properties @@ -1,5 +1,3 @@ server.port=8081 -management.endpoints.web.expose=* -info.app.name=Spring Boot 2 actuator Application logging.level.root=INFO \ No newline at end of file From 5a40e7ec48d0b6949054109b0fe2d7eb144cd24f Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sat, 13 Jan 2018 18:39:56 +0200 Subject: [PATCH 05/65] Update pom.xml --- spring-5-reactive/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-5-reactive/pom.xml b/spring-5-reactive/pom.xml index ec4312ab21..36eaaa1530 100644 --- a/spring-5-reactive/pom.xml +++ b/spring-5-reactive/pom.xml @@ -202,4 +202,5 @@ 1.0 + From cd4b5267895f64478140876b485d352fc3fb96ee Mon Sep 17 00:00:00 2001 From: Denis Date: Sat, 13 Jan 2018 19:57:53 +0300 Subject: [PATCH 06/65] BAEL-1451 Writing a Jenkins plugin (#3396) * BAEL-1451 Writing a Jenkins plugin A sample Jenkins plugin which builds basic project stats * BAEL-1451 Writing a Jenkins plugin Formatting --- jenkins/hello-world/pom.xml | 89 +++++++++++++ .../jenkins/helloworld/ProjectStats.java | 20 +++ .../helloworld/ProjectStatsBuildWrapper.java | 123 ++++++++++++++++++ .../hello-world/src/main/resources/stats.html | 20 +++ 4 files changed, 252 insertions(+) create mode 100644 jenkins/hello-world/pom.xml create mode 100644 jenkins/hello-world/src/main/java/com/baeldung/jenkins/helloworld/ProjectStats.java create mode 100644 jenkins/hello-world/src/main/java/com/baeldung/jenkins/helloworld/ProjectStatsBuildWrapper.java create mode 100644 jenkins/hello-world/src/main/resources/stats.html diff --git a/jenkins/hello-world/pom.xml b/jenkins/hello-world/pom.xml new file mode 100644 index 0000000000..15cf2f8e34 --- /dev/null +++ b/jenkins/hello-world/pom.xml @@ -0,0 +1,89 @@ + + + 4.0.0 + + org.jenkins-ci.plugins + plugin + 2.33 + + + jenkins-hello-world + 1.0-SNAPSHOT + hpi + + + 2.7.3 + + Hello World Plugin + A sample Jenkins Hello World plugin + https://wiki.jenkins-ci.org/display/JENKINS/TODO+Plugin + + + MIT License + http://opensource.org/licenses/MIT + + + + + org.jenkins-ci.plugins + structs + 1.7 + + + org.jenkins-ci.plugins.workflow + workflow-step-api + 2.12 + test + + + org.jenkins-ci.plugins.workflow + workflow-cps + 2.39 + test + + + org.jenkins-ci.plugins.workflow + workflow-job + 2.11.2 + test + + + org.jenkins-ci.plugins.workflow + workflow-basic-steps + 2.6 + test + + + org.jenkins-ci.plugins.workflow + workflow-durable-task-step + 2.13 + test + + + org.jenkins-ci.plugins.workflow + workflow-api + 2.20 + test + + + org.jenkins-ci.plugins.workflow + workflow-support + 2.14 + test + + + + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + diff --git a/jenkins/hello-world/src/main/java/com/baeldung/jenkins/helloworld/ProjectStats.java b/jenkins/hello-world/src/main/java/com/baeldung/jenkins/helloworld/ProjectStats.java new file mode 100644 index 0000000000..67af636bb4 --- /dev/null +++ b/jenkins/hello-world/src/main/java/com/baeldung/jenkins/helloworld/ProjectStats.java @@ -0,0 +1,20 @@ +package com.baeldung.jenkins.helloworld; + +public class ProjectStats { + + private final int classesNumber; + private final int linesNumber; + + public ProjectStats(int classesNumber, int linesNumber) { + this.classesNumber = classesNumber; + this.linesNumber = linesNumber; + } + + public int getClassesNumber() { + return classesNumber; + } + + public int getLinesNumber() { + return linesNumber; + } +} diff --git a/jenkins/hello-world/src/main/java/com/baeldung/jenkins/helloworld/ProjectStatsBuildWrapper.java b/jenkins/hello-world/src/main/java/com/baeldung/jenkins/helloworld/ProjectStatsBuildWrapper.java new file mode 100644 index 0000000000..9a7213c76f --- /dev/null +++ b/jenkins/hello-world/src/main/java/com/baeldung/jenkins/helloworld/ProjectStatsBuildWrapper.java @@ -0,0 +1,123 @@ +package com.baeldung.jenkins.helloworld; + +import hudson.Extension; +import hudson.FilePath; +import hudson.Launcher; +import hudson.model.AbstractBuild; +import hudson.model.AbstractProject; +import hudson.model.BuildListener; +import hudson.tasks.BuildWrapper; +import hudson.tasks.BuildWrapperDescriptor; +import org.kohsuke.stapler.DataBoundConstructor; + +import javax.annotation.Nonnull; +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.util.Stack; + +public class ProjectStatsBuildWrapper extends BuildWrapper { + + private static final String REPORT_TEMPLATE_PATH = "/stats.html"; + private static final String PROJECT_NAME_VAR = "$PROJECT_NAME$"; + private static final String CLASSES_NUMBER_VAR = "$CLASSES_NUMBER$"; + private static final String LINES_NUMBER_VAR = "$LINES_NUMBER$"; + + @DataBoundConstructor + public ProjectStatsBuildWrapper() { + } + + @Override + public Environment setUp(AbstractBuild build, final Launcher launcher, BuildListener listener) { + return new Environment() { + @Override + public boolean tearDown(AbstractBuild build, BuildListener listener) + throws IOException, InterruptedException + { + ProjectStats stats = buildStats(build.getWorkspace()); + String report = generateReport(build.getProject().getDisplayName(), stats); + File artifactsDir = build.getArtifactsDir(); + if (!artifactsDir.isDirectory()) { + boolean success = artifactsDir.mkdirs(); + if (!success) { + listener.getLogger().println("Can't create artifacts directory at " + + artifactsDir.getAbsolutePath()); + } + } + String path = artifactsDir.getCanonicalPath() + REPORT_TEMPLATE_PATH; + try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path), + StandardCharsets.UTF_8))) { + writer.write(report); + } + return super.tearDown(build, listener); + } + }; + } + + private static ProjectStats buildStats(FilePath root) throws IOException, InterruptedException { + int classesNumber = 0; + int linesNumber = 0; + Stack toProcess = new Stack<>(); + toProcess.push(root); + while (!toProcess.isEmpty()) { + FilePath path = toProcess.pop(); + if (path.isDirectory()) { + toProcess.addAll(path.list()); + } else if (path.getName().endsWith(".java")) { + classesNumber++; + linesNumber += countLines(path); + } + } + return new ProjectStats(classesNumber, linesNumber); + } + + private static int countLines(FilePath path) throws IOException, InterruptedException { + byte[] buffer = new byte[1024]; + int result = 1; + try (InputStream in = path.read()) { + while (true) { + int read = in.read(buffer); + if (read < 0) { + return result; + } + for (int i = 0; i < read; i++) { + if (buffer[i] == '\n') { + result++; + } + } + } + } + } + + private static String generateReport(String projectName, ProjectStats stats) throws IOException { + ByteArrayOutputStream bOut = new ByteArrayOutputStream(); + try (InputStream in = ProjectStatsBuildWrapper.class.getResourceAsStream(REPORT_TEMPLATE_PATH)) { + byte[] buffer = new byte[1024]; + int read; + while ((read = in.read(buffer)) >= 0) { + bOut.write(buffer, 0, read); + } + } + String content = new String(bOut.toByteArray(), StandardCharsets.UTF_8); + content = content.replace(PROJECT_NAME_VAR, projectName); + content = content.replace(CLASSES_NUMBER_VAR, String.valueOf(stats.getClassesNumber())); + content = content.replace(LINES_NUMBER_VAR, String.valueOf(stats.getLinesNumber())); + return content; + } + + @Extension + public static final class DescriptorImpl extends BuildWrapperDescriptor { + + @Override + public boolean isApplicable(AbstractProject item) { + return true; + } + + @Nonnull + @Override + public String getDisplayName() { + return "Construct project stats during build"; + } + + } + +} diff --git a/jenkins/hello-world/src/main/resources/stats.html b/jenkins/hello-world/src/main/resources/stats.html new file mode 100644 index 0000000000..2a14b5de3f --- /dev/null +++ b/jenkins/hello-world/src/main/resources/stats.html @@ -0,0 +1,20 @@ + + + + + $PROJECT_NAME$ + + +Project $PROJECT_NAME$: + + + + + + + + + +
Classes numberLines number
$CLASSES_NUMBER$$LINES_NUMBER$
+ + \ No newline at end of file From b41ebab6b8dc0c7a95873329633dc68cd649db24 Mon Sep 17 00:00:00 2001 From: felipeazv Date: Fri, 12 Jan 2018 23:04:21 +0100 Subject: [PATCH 07/65] BAEL-1475: Reactive WebSockets with Spring 5 --- spring-reactive-websocket/pom.xml | 92 +++++++++++++++++++ .../src/main/java/com/baeldung/Event.java | 11 +++ .../ReactiveWebSocketApplication.java | 38 ++++++++ .../ReactiveWebSocketConfiguration.java | 34 +++++++ .../baeldung/ReactiveWebSocketHandler.java | 71 ++++++++++++++ .../resources/static/client-websocket.html | 34 +++++++ 6 files changed, 280 insertions(+) create mode 100644 spring-reactive-websocket/pom.xml create mode 100644 spring-reactive-websocket/src/main/java/com/baeldung/Event.java create mode 100644 spring-reactive-websocket/src/main/java/com/baeldung/ReactiveWebSocketApplication.java create mode 100644 spring-reactive-websocket/src/main/java/com/baeldung/ReactiveWebSocketConfiguration.java create mode 100644 spring-reactive-websocket/src/main/java/com/baeldung/ReactiveWebSocketHandler.java create mode 100644 spring-reactive-websocket/src/main/resources/static/client-websocket.html diff --git a/spring-reactive-websocket/pom.xml b/spring-reactive-websocket/pom.xml new file mode 100644 index 0000000000..b234e0345e --- /dev/null +++ b/spring-reactive-websocket/pom.xml @@ -0,0 +1,92 @@ + + + 4.0.0 + + spring-reactive-websocket + 0.0.1-SNAPSHOT + jar + + spring-reactive-websocket + Example from article: Reactive WebSockets with Spring 5 + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + + UTF-8 + UTF-8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter-integration + 2.0.0.M7 + + + org.springframework.boot + spring-boot-starter-webflux + 2.0.0.M7 + + + org.projectlombok + lombok + compile + RELEASE + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + true + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + true + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + + + diff --git a/spring-reactive-websocket/src/main/java/com/baeldung/Event.java b/spring-reactive-websocket/src/main/java/com/baeldung/Event.java new file mode 100644 index 0000000000..20d678c214 --- /dev/null +++ b/spring-reactive-websocket/src/main/java/com/baeldung/Event.java @@ -0,0 +1,11 @@ +package com.baeldung; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class Event { + private String eventId; + private String eventDt; +} diff --git a/spring-reactive-websocket/src/main/java/com/baeldung/ReactiveWebSocketApplication.java b/spring-reactive-websocket/src/main/java/com/baeldung/ReactiveWebSocketApplication.java new file mode 100644 index 0000000000..f8952d750d --- /dev/null +++ b/spring-reactive-websocket/src/main/java/com/baeldung/ReactiveWebSocketApplication.java @@ -0,0 +1,38 @@ +package com.baeldung; + +import java.net.URI; +import java.time.Duration; + +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.web.reactive.socket.WebSocketMessage; +import org.springframework.web.reactive.socket.client.ReactorNettyWebSocketClient; +import org.springframework.web.reactive.socket.client.WebSocketClient; + +import reactor.core.publisher.Mono; + +@SpringBootApplication +public class ReactiveWebSocketApplication { + public static void main(String[] args) { + SpringApplication.run(ReactiveWebSocketApplication.class, args); + } + + /** + * Spring Reactive WebSocket Client + * **/ + @Bean + CommandLineRunner runner() { + return run -> { + WebSocketClient client = new ReactorNettyWebSocketClient(); + client.execute(URI.create("ws://localhost:8080/event-emitter"), session -> session.send(Mono.just(session.textMessage("event-me-from-spring-reactive-client"))) + .thenMany(session.receive() + .map(WebSocketMessage::getPayloadAsText) + .log()) + .then()) + .block(); +// .block(Duration.ofSeconds(10L));//force timeout after given duration + }; + } +} diff --git a/spring-reactive-websocket/src/main/java/com/baeldung/ReactiveWebSocketConfiguration.java b/spring-reactive-websocket/src/main/java/com/baeldung/ReactiveWebSocketConfiguration.java new file mode 100644 index 0000000000..6729e09273 --- /dev/null +++ b/spring-reactive-websocket/src/main/java/com/baeldung/ReactiveWebSocketConfiguration.java @@ -0,0 +1,34 @@ +package com.baeldung; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.reactive.HandlerMapping; +import org.springframework.web.reactive.handler.SimpleUrlHandlerMapping; +import org.springframework.web.reactive.socket.WebSocketHandler; +import org.springframework.web.reactive.socket.server.support.WebSocketHandlerAdapter; +import java.util.HashMap; +import java.util.Map; + +@Configuration +public class ReactiveWebSocketConfiguration { + + @Autowired + private WebSocketHandler webSocketHandler; + + @Bean + public HandlerMapping webSocketHandlerMapping() { + Map map = new HashMap<>(); + map.put("/event-emitter", webSocketHandler); + + SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping(); + handlerMapping.setOrder(1); + handlerMapping.setUrlMap(map); + return handlerMapping; + } + + @Bean + public WebSocketHandlerAdapter handlerAdapter() { + return new WebSocketHandlerAdapter(); + } +} \ No newline at end of file diff --git a/spring-reactive-websocket/src/main/java/com/baeldung/ReactiveWebSocketHandler.java b/spring-reactive-websocket/src/main/java/com/baeldung/ReactiveWebSocketHandler.java new file mode 100644 index 0000000000..4a548322b3 --- /dev/null +++ b/spring-reactive-websocket/src/main/java/com/baeldung/ReactiveWebSocketHandler.java @@ -0,0 +1,71 @@ +package com.baeldung; + +import org.springframework.web.reactive.socket.WebSocketSession; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +import org.springframework.stereotype.Component; +import org.springframework.web.reactive.socket.WebSocketHandler; +import org.springframework.web.reactive.socket.WebSocketMessage; + +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +import javax.annotation.PostConstruct; +import java.time.Duration; +import java.time.LocalDateTime; +import java.util.UUID; + +@Component +public class ReactiveWebSocketHandler implements WebSocketHandler { + + private Flux eventFlux; + private Flux intervalFlux; + + /** + * Here we prepare a Flux that will emit a message every second + */ + @PostConstruct + private void init() throws InterruptedException { + + eventFlux = Flux.generate(e -> { + Event event = new Event(UUID.randomUUID() + .toString(), + LocalDateTime.now() + .toString()); + e.next(event); + }); + + intervalFlux = Flux.interval(Duration.ofMillis(1000L)) + .zipWith(eventFlux, (time, event) -> event); + + } + + /** + * On each new client session, send the message flux to the client. + * Spring subscribes to the flux and send every new flux event to the WebSocketSession object + * @param session + * @return Mono + */ + @Override + public Mono handle(WebSocketSession webSocketSession) { + ObjectMapper json = new ObjectMapper(); + return webSocketSession.send(intervalFlux.map(event -> { + try { + String jsonEvent = json.writeValueAsString(event); + System.out.println(jsonEvent); + return jsonEvent; + } catch (JsonProcessingException e) { + e.printStackTrace(); + return ""; + } + }) + .map(webSocketSession::textMessage)) + + .and(webSocketSession.receive() + .map(WebSocketMessage::getPayloadAsText) + .log()); + } + +} diff --git a/spring-reactive-websocket/src/main/resources/static/client-websocket.html b/spring-reactive-websocket/src/main/resources/static/client-websocket.html new file mode 100644 index 0000000000..3f840e8bd4 --- /dev/null +++ b/spring-reactive-websocket/src/main/resources/static/client-websocket.html @@ -0,0 +1,34 @@ + + + + +Baeldung: Spring 5 Reactive Client WebSocket (Browser) + + + +
+ + + \ No newline at end of file From 466340e96f49897519ffe0d94eef2ccd3320fa2a Mon Sep 17 00:00:00 2001 From: felipeazv Date: Fri, 12 Jan 2018 23:12:20 +0100 Subject: [PATCH 08/65] BAEL-1475: Reactive WebSockets with Spring 5 --- spring-reactive-websocket/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-reactive-websocket/pom.xml b/spring-reactive-websocket/pom.xml index b234e0345e..846cece177 100644 --- a/spring-reactive-websocket/pom.xml +++ b/spring-reactive-websocket/pom.xml @@ -8,7 +8,7 @@ jar spring-reactive-websocket - Example from article: Reactive WebSockets with Spring 5 + Reactive WebSockets with Spring 5 com.baeldung From 33f7b1a3b983157dbfb17f14272e190ec792f7f7 Mon Sep 17 00:00:00 2001 From: Nikhil Khatwani Date: Sun, 14 Jan 2018 04:26:24 +0530 Subject: [PATCH 09/65] Changes for BAEL-1469 Upgrade the Spring MVC article (#3407) --- spring-mvc-xml/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-mvc-xml/pom.xml b/spring-mvc-xml/pom.xml index 2131609ff6..049a3fec82 100644 --- a/spring-mvc-xml/pom.xml +++ b/spring-mvc-xml/pom.xml @@ -110,7 +110,7 @@ - 4.3.4.RELEASE + 5.0.2.RELEASE 4.2.0.RELEASE @@ -142,4 +142,4 @@ - \ No newline at end of file + From a4c02d6275f238d4dc948702ebbbfaa8149a08cc Mon Sep 17 00:00:00 2001 From: Eugen Paraschiv Date: Sun, 14 Jan 2018 00:59:55 +0200 Subject: [PATCH 10/65] minor formatting cleanup --- .../java/com/baeldung/jsp/ExampleOne.java | 30 +++++++------------ .../java/com/baeldung/jsp/ExampleThree.java | 22 ++++++-------- .../spring/controller/ErrorController.java | 9 +++--- .../controller/GeoIPTestController.java | 12 ++++---- .../spring/controller/ImageController.java | 1 - .../java/com/baeldung/spring/form/GeoIP.java | 10 +++---- .../RawDBDemoGeoIPLocationService.java | 8 ++--- .../baeldung/geoip/GeoIpIntegrationTest.java | 11 ++++--- 8 files changed, 43 insertions(+), 60 deletions(-) diff --git a/spring-mvc-xml/src/main/java/com/baeldung/jsp/ExampleOne.java b/spring-mvc-xml/src/main/java/com/baeldung/jsp/ExampleOne.java index 0b153bf8ec..6744570639 100644 --- a/spring-mvc-xml/src/main/java/com/baeldung/jsp/ExampleOne.java +++ b/spring-mvc-xml/src/main/java/com/baeldung/jsp/ExampleOne.java @@ -8,24 +8,14 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class ExampleOne extends HttpServlet { - - private static final long serialVersionUID = 1L; - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - response.setContentType("text/html"); - PrintWriter out = response.getWriter(); - out.println( - "" + - "" + - "" + - "HTML Rendered by Servlet" + - "" + - "" + - "

HTML Rendered by Servlet


" + - "

This page was rendered by the ExampleOne Servlet!

" + - "" + - "" - ); - } + + private static final long serialVersionUID = 1L; + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + response.setContentType("text/html"); + PrintWriter out = response.getWriter(); + out.println("" + "" + "" + "HTML Rendered by Servlet" + "" + "" + "

HTML Rendered by Servlet


" + "

This page was rendered by the ExampleOne Servlet!

" + + "" + ""); + } } \ No newline at end of file diff --git a/spring-mvc-xml/src/main/java/com/baeldung/jsp/ExampleThree.java b/spring-mvc-xml/src/main/java/com/baeldung/jsp/ExampleThree.java index 49fefcffde..7269f917b4 100644 --- a/spring-mvc-xml/src/main/java/com/baeldung/jsp/ExampleThree.java +++ b/spring-mvc-xml/src/main/java/com/baeldung/jsp/ExampleThree.java @@ -7,18 +7,14 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -@WebServlet( - name = "ExampleThree", - description = "JSP Servlet With Annotations", - urlPatterns = {"/ExampleThree"} -) +@WebServlet(name = "ExampleThree", description = "JSP Servlet With Annotations", urlPatterns = { "/ExampleThree" }) public class ExampleThree extends HttpServlet { - private static final long serialVersionUID = 1L; - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - String message = request.getParameter("message"); - request.setAttribute("text", message); - request.getRequestDispatcher("/jsp/ExampleThree.jsp").forward(request, response); - } + private static final long serialVersionUID = 1L; + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + String message = request.getParameter("message"); + request.setAttribute("text", message); + request.getRequestDispatcher("/jsp/ExampleThree.jsp").forward(request, response); + } } diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ErrorController.java b/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ErrorController.java index 96556bd5b1..6ae1023374 100644 --- a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ErrorController.java +++ b/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ErrorController.java @@ -9,7 +9,7 @@ import org.springframework.web.servlet.ModelAndView; @Controller public class ErrorController { - + @RequestMapping(value = "500Error", method = RequestMethod.GET) public void throwRuntimeException() { throw new NullPointerException("Throwing a null pointer exception"); @@ -34,19 +34,18 @@ public class ErrorController { errorMsg = "Http Error Code : 404. Resource not found"; break; } - // Handle other 4xx error codes. + // Handle other 4xx error codes. case 500: { errorMsg = "Http Error Code : 500. Internal Server Error"; break; } - // Handle other 5xx error codes. + // Handle other 5xx error codes. } errorPage.addObject("errorMsg", errorMsg); return errorPage; } private int getErrorCode(HttpServletRequest httpRequest) { - return (Integer) httpRequest - .getAttribute("javax.servlet.error.status_code"); + return (Integer) httpRequest.getAttribute("javax.servlet.error.status_code"); } } diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/GeoIPTestController.java b/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/GeoIPTestController.java index 16de4e56f5..eeaddcf8e0 100644 --- a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/GeoIPTestController.java +++ b/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/GeoIPTestController.java @@ -14,15 +14,15 @@ import com.baeldung.spring.service.RawDBDemoGeoIPLocationService; @Controller public class GeoIPTestController { private RawDBDemoGeoIPLocationService locationService; + public GeoIPTestController() throws IOException { - locationService - = new RawDBDemoGeoIPLocationService(); + locationService = new RawDBDemoGeoIPLocationService(); } - @RequestMapping(value="/GeoIPTest", method = RequestMethod.POST) + + @RequestMapping(value = "/GeoIPTest", method = RequestMethod.POST) @ResponseBody - public GeoIP getLocation( - @RequestParam(value="ipAddress", required=true) String ipAddress) throws Exception { - + public GeoIP getLocation(@RequestParam(value = "ipAddress", required = true) String ipAddress) throws Exception { + return locationService.getLocation(ipAddress); } } diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ImageController.java b/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ImageController.java index ef8d1214df..fc46c07e06 100644 --- a/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ImageController.java +++ b/spring-mvc-xml/src/main/java/com/baeldung/spring/controller/ImageController.java @@ -12,7 +12,6 @@ import org.springframework.web.context.support.ServletContextResource; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletResponse; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/form/GeoIP.java b/spring-mvc-xml/src/main/java/com/baeldung/spring/form/GeoIP.java index 19f56867a1..4373303107 100644 --- a/spring-mvc-xml/src/main/java/com/baeldung/spring/form/GeoIP.java +++ b/spring-mvc-xml/src/main/java/com/baeldung/spring/form/GeoIP.java @@ -5,15 +5,15 @@ public class GeoIP { private String city; private String latitude; private String longitude; - + public GeoIP() { - + } - + public GeoIP(String ipAddress) { this.ipAddress = ipAddress; } - + public GeoIP(String ipAddress, String city, String latitude, String longitude) { this.ipAddress = ipAddress; this.city = city; @@ -52,5 +52,5 @@ public class GeoIP { public void setLongitude(String longitude) { this.longitude = longitude; } - + } diff --git a/spring-mvc-xml/src/main/java/com/baeldung/spring/service/RawDBDemoGeoIPLocationService.java b/spring-mvc-xml/src/main/java/com/baeldung/spring/service/RawDBDemoGeoIPLocationService.java index af3ce8cfb3..04443466c9 100644 --- a/spring-mvc-xml/src/main/java/com/baeldung/spring/service/RawDBDemoGeoIPLocationService.java +++ b/spring-mvc-xml/src/main/java/com/baeldung/spring/service/RawDBDemoGeoIPLocationService.java @@ -9,18 +9,18 @@ import com.maxmind.geoip2.DatabaseReader; import com.maxmind.geoip2.exception.GeoIp2Exception; import com.maxmind.geoip2.model.CityResponse; -public class RawDBDemoGeoIPLocationService{ +public class RawDBDemoGeoIPLocationService { private DatabaseReader dbReader; - + public RawDBDemoGeoIPLocationService() throws IOException { File database = new File("your-path-to-db-file"); dbReader = new DatabaseReader.Builder(database).build(); } - + public GeoIP getLocation(String ip) throws IOException, GeoIp2Exception { InetAddress ipAddress = InetAddress.getByName(ip); CityResponse response = dbReader.city(ipAddress); - + String cityName = response.getCity().getName(); String latitude = response.getLocation().getLatitude().toString(); String longitude = response.getLocation().getLongitude().toString(); diff --git a/spring-mvc-xml/src/test/java/com/baeldung/geoip/GeoIpIntegrationTest.java b/spring-mvc-xml/src/test/java/com/baeldung/geoip/GeoIpIntegrationTest.java index 2edaa125b7..0e957f3400 100644 --- a/spring-mvc-xml/src/test/java/com/baeldung/geoip/GeoIpIntegrationTest.java +++ b/spring-mvc-xml/src/test/java/com/baeldung/geoip/GeoIpIntegrationTest.java @@ -10,22 +10,21 @@ import com.maxmind.geoip2.DatabaseReader; import com.maxmind.geoip2.exception.GeoIp2Exception; import com.maxmind.geoip2.model.CityResponse; - public class GeoIpIntegrationTest { - + @Test public void givenIP_whenFetchingCity_thenReturnsCityData() throws IOException, GeoIp2Exception { File database = new File("your-path-to-db-file"); DatabaseReader dbReader = new DatabaseReader.Builder(database).build(); - + InetAddress ipAddress = InetAddress.getByName("your-public-ip"); CityResponse response = dbReader.city(ipAddress); - + String countryName = response.getCountry().getName(); String cityName = response.getCity().getName(); String postal = response.getPostal().getCode(); String state = response.getLeastSpecificSubdivision().getName(); - + } - + } From 5b8e84b26ccb063e67e9f21be53d0740820ed808 Mon Sep 17 00:00:00 2001 From: Nikhil Khatwani Date: Sun, 14 Jan 2018 20:30:32 +0530 Subject: [PATCH 11/65] Refaactoring-Thread Interrupt (#3412) --- .../com/baeldung/concurrent/stopping/ControlSubThread.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core-java-concurrency/src/main/java/com/baeldung/concurrent/stopping/ControlSubThread.java b/core-java-concurrency/src/main/java/com/baeldung/concurrent/stopping/ControlSubThread.java index 0e72821a88..e6522168bb 100644 --- a/core-java-concurrency/src/main/java/com/baeldung/concurrent/stopping/ControlSubThread.java +++ b/core-java-concurrency/src/main/java/com/baeldung/concurrent/stopping/ControlSubThread.java @@ -43,8 +43,9 @@ public class ControlSubThread implements Runnable { try { Thread.sleep(interval); } catch (InterruptedException e) { - // no-op, just loop again - } + Thread.currentThread().interrupt(); + System.out.println("Thread was interrupted, Failed to complete operation"); + } // do something } stopped.set(true); From fb141b9b3fac840db0292199c95a269745e02a3f Mon Sep 17 00:00:00 2001 From: Nikhil Khatwani Date: Mon, 15 Jan 2018 00:33:18 +0530 Subject: [PATCH 12/65] Bael 1469 (#3414) * Changes for BAEL-1469 Upgrade the Spring MVC article * web.xml changes for servlet 3.1 --- spring-mvc-xml/src/main/webapp/WEB-INF/web.xml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/web.xml b/spring-mvc-xml/src/main/webapp/WEB-INF/web.xml index 1ea3051426..6ff435b84b 100644 --- a/spring-mvc-xml/src/main/webapp/WEB-INF/web.xml +++ b/spring-mvc-xml/src/main/webapp/WEB-INF/web.xml @@ -1,10 +1,9 @@ - - Spring MVC XML Application @@ -65,4 +64,4 @@ /errors - \ No newline at end of file + From 0d4a49f4f1ea17d6acbb42fd0935193df374fb9f Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sun, 14 Jan 2018 22:27:54 +0200 Subject: [PATCH 13/65] Create README.md --- spring-5-security/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 spring-5-security/README.md diff --git a/spring-5-security/README.md b/spring-5-security/README.md new file mode 100644 index 0000000000..1c9fad65e4 --- /dev/null +++ b/spring-5-security/README.md @@ -0,0 +1,3 @@ +## Relevant articles: + +- [Spring Security 5 -OAuth2 Login](http://www.baeldung.com/spring-security-5-oauth2-login) From 22dbf2c8cd363c25220e03a194e31f8c3502f536 Mon Sep 17 00:00:00 2001 From: Eric Goebelbecker Date: Sun, 14 Jan 2018 16:48:42 -0500 Subject: [PATCH 14/65] Bael-1364 - Introduction to Lettuce (#3415) --- .../influxdb/InfluxDBConnectionLiveTest.java | 2 +- persistence-modules/redis/README.md | 2 + persistence-modules/redis/pom.xml | 7 + .../baeldung/LettuceIntegrationLiveTest.java | 312 ++++++++++++++++++ 4 files changed, 322 insertions(+), 1 deletion(-) create mode 100644 persistence-modules/redis/src/test/java/com/baeldung/LettuceIntegrationLiveTest.java diff --git a/influxdb/src/test/java/com/baeldung/influxdb/InfluxDBConnectionLiveTest.java b/influxdb/src/test/java/com/baeldung/influxdb/InfluxDBConnectionLiveTest.java index 50d35b9b1c..6c7a03cb70 100644 --- a/influxdb/src/test/java/com/baeldung/influxdb/InfluxDBConnectionLiveTest.java +++ b/influxdb/src/test/java/com/baeldung/influxdb/InfluxDBConnectionLiveTest.java @@ -55,7 +55,7 @@ public class InfluxDBConnectionLiveTest { InfluxDB connection = connectDatabase(); - // Create "baeldung and check for it + // Create "baeldung" and check for it connection.createDatabase("baeldung"); assertTrue(connection.databaseExists("baeldung")); diff --git a/persistence-modules/redis/README.md b/persistence-modules/redis/README.md index d179b80c33..dd655ca7aa 100644 --- a/persistence-modules/redis/README.md +++ b/persistence-modules/redis/README.md @@ -1,3 +1,5 @@ ### Relevant Articles: - [Intro to Jedis – the Java Redis Client Library](http://www.baeldung.com/jedis-java-redis-client-library) - [A Guide to Redis with Redisson](http://www.baeldung.com/redis-redisson) +- [Intro to Lettuce – the Java Redis Client Library](http://www.baeldung.com/lettuce-java-redis-client-library) + diff --git a/persistence-modules/redis/pom.xml b/persistence-modules/redis/pom.xml index 4321b491eb..1f27faa09a 100644 --- a/persistence-modules/redis/pom.xml +++ b/persistence-modules/redis/pom.xml @@ -36,6 +36,13 @@ redisson 3.3.0
+ + + io.lettuce + lettuce-core + 5.0.1.RELEASE + + diff --git a/persistence-modules/redis/src/test/java/com/baeldung/LettuceIntegrationLiveTest.java b/persistence-modules/redis/src/test/java/com/baeldung/LettuceIntegrationLiveTest.java new file mode 100644 index 0000000000..eb879d1d21 --- /dev/null +++ b/persistence-modules/redis/src/test/java/com/baeldung/LettuceIntegrationLiveTest.java @@ -0,0 +1,312 @@ +package com.baeldung; + +import io.lettuce.core.LettuceFutures; +import io.lettuce.core.RedisClient; +import io.lettuce.core.RedisFuture; +import io.lettuce.core.TransactionResult; +import io.lettuce.core.api.StatefulRedisConnection; +import io.lettuce.core.api.async.RedisAsyncCommands; +import io.lettuce.core.api.sync.RedisCommands; +import io.lettuce.core.pubsub.RedisPubSubListener; +import io.lettuce.core.pubsub.StatefulRedisPubSubConnection; +import io.lettuce.core.pubsub.api.async.RedisPubSubAsyncCommands; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import static org.junit.Assert.assertTrue; + +public class LettuceIntegrationLiveTest { + + private static Logger log = LoggerFactory.getLogger(LettuceIntegrationLiveTest.class); + + private static StatefulRedisConnection redisConnection; + + private static RedisClient redisClient; + + @BeforeClass + public static void setUp() { + // Docker defaults to mapping redis port to 32768 + redisClient = RedisClient.create("redis://localhost:32768/"); + redisConnection = redisClient.connect(); + } + + @AfterClass + public static void destroy() { + redisConnection.close(); + } + + @Test + public void givenAString_thenSaveItAsRedisStringsSync() { + + RedisCommands syncCommands = redisConnection.sync(); + + String key = "key"; + String value = "value"; + + syncCommands.set(key, value); + String response = syncCommands.get(key); + + Assert.assertEquals(value, response); + } + + @Test + public void givenValues_thenSaveAsRedisHashSync() { + + RedisCommands syncCommands = redisConnection.sync(); + + String recordName = "record1"; + String name = "FirstName"; + String value = "John"; + String surname = "LastName"; + String value1 = "Smith"; + + syncCommands.hset(recordName, name, value); + syncCommands.hset(recordName, surname, value1); + Map record = syncCommands.hgetall(recordName); + + Assert.assertEquals(record.get(name), value); + Assert.assertEquals(record.get(surname), value1); + } + + @Test + public void givenAString_thenSaveItAsRedisStringsAsync() throws Exception { + + RedisAsyncCommands asyncCommands = redisConnection.async(); + + String key = "key"; + String value = "value"; + + asyncCommands.set(key, value); + RedisFuture redisFuture = asyncCommands.get(key); + + String response = redisFuture.get(); + + Assert.assertEquals(value, response); + } + + @Test + public void givenValues_thenSaveAsRedisHashAsync() throws Exception { + + RedisAsyncCommands asyncCommands = redisConnection.async(); + + String recordName = "record1"; + String name = "FirstName"; + String value = "John"; + String surname = "LastName"; + String value1 = "Smith"; + + asyncCommands.hset(recordName, name, value); + asyncCommands.hset(recordName, surname, value1); + RedisFuture> redisFuture = asyncCommands.hgetall(recordName); + + Map record = redisFuture.get(); + + Assert.assertEquals(record.get(name), value); + Assert.assertEquals(record.get(surname), value1); + } + + @Test + public void givenValues_thenSaveAsRedisListAsync() throws Exception { + + RedisAsyncCommands asyncCommands = redisConnection.async(); + + String listName = "tasks"; + String firstTask = "firstTask"; + String secondTask = "secondTask"; + + asyncCommands.del(listName); + + asyncCommands.lpush(listName, firstTask); + asyncCommands.lpush(listName, secondTask); + RedisFuture redisFuture = asyncCommands.rpop(listName); + + String nextTask = redisFuture.get(); + + Assert.assertEquals(firstTask, nextTask); + + asyncCommands.del(listName); + + asyncCommands.lpush(listName, firstTask); + asyncCommands.lpush(listName, secondTask); + + redisFuture = asyncCommands.lpop(listName); + + nextTask = redisFuture.get(); + + Assert.assertEquals(secondTask, nextTask); + + } + + @Test + public void givenSetElements_thenSaveThemInRedisSetAsync() throws Exception { + + RedisAsyncCommands asyncCommands = redisConnection.async(); + + String countries = "countries"; + + String countryOne = "Spain"; + String countryTwo = "Ireland"; + String countryThree = "Ireland"; + + asyncCommands.sadd(countries, countryOne); + + RedisFuture> countriesSetFuture = asyncCommands.smembers(countries); + Assert.assertEquals(2, countriesSetFuture.get().size()); + + asyncCommands.sadd(countries, countryTwo); + countriesSetFuture = asyncCommands.smembers(countries); + Assert.assertEquals(2, countriesSetFuture.get().size()); + + asyncCommands.sadd(countries, countryThree); + countriesSetFuture = asyncCommands.smembers(countries); + Assert.assertEquals(2, countriesSetFuture.get().size()); + + RedisFuture exists = asyncCommands.sismember(countries, countryThree); + assertTrue(exists.get()); + } + + @Test + public void givenARanking_thenSaveItInRedisSortedSetAsync() throws Exception { + + RedisAsyncCommands asyncCommands = redisConnection.async(); + + String key = "sortedset"; + + asyncCommands.zadd(key, 1, "one"); + asyncCommands.zadd(key, 4, "zero"); + asyncCommands.zadd(key, 2, "two"); + + RedisFuture> values = asyncCommands.zrevrange(key, 0, 3); + Assert.assertEquals("zero", values.get().get(0)); + + values = asyncCommands.zrange(key, 0, 3); + Assert.assertEquals("one", values.get().get(0)); + } + + @Test + public void givenMultipleOperationsThatNeedToBeExecutedAtomically_thenWrapThemInATransaction() throws Exception { + + RedisAsyncCommands asyncCommands = redisConnection.async(); + + // Start a transaction + asyncCommands.multi(); + + // Add three sets to it, and save the future responses + RedisFuture result1 = asyncCommands.set("key1", "value1"); + RedisFuture result2 = asyncCommands.set("key2", "value2"); + RedisFuture result3 = asyncCommands.set("key3", "value3"); + + // Execute it + RedisFuture execResult = asyncCommands.exec(); + + TransactionResult transactionResult = execResult.get(); + + // Get the three results in the transaction return + String firstResult = transactionResult.get(0); + String secondResult = transactionResult.get(0); + String thirdResult = transactionResult.get(0); + + // Our results are in both! + assertTrue(firstResult.equals("OK")); + assertTrue(secondResult.equals("OK")); + assertTrue(thirdResult.equals("OK")); + + assertTrue(result1.get().equals("OK")); + assertTrue(result2.get().equals("OK")); + assertTrue(result3.get().equals("OK")); + } + + @Test + public void givenMultipleIndependentOperations_whenNetworkOptimizationIsImportant_thenFlushManually() throws Exception { + + int iterations = 50; + + RedisAsyncCommands asyncCommands = redisConnection.async(); + + asyncCommands.setAutoFlushCommands(false); + + List> futures = new ArrayList<>(); + for (int i = 0; i < iterations; i++) { + futures.add(asyncCommands.set("key" + i, "value" + i)); + } + + asyncCommands.flushCommands(); + + // Wait until all futures complete + boolean result = LettuceFutures.awaitAll(5, TimeUnit.SECONDS, futures.toArray(new RedisFuture[futures.size()])); + + asyncCommands.setAutoFlushCommands(true); + + } + + @Test + public void givenPubSubChannel_whenMessage_thenMessageReceived() throws Exception { + + Listener listener = new Listener(); + StatefulRedisPubSubConnection connection = redisClient.connectPubSub(); + StatefulRedisPubSubConnection pubconnection = redisClient.connectPubSub(); + connection.addListener(listener); + + RedisPubSubAsyncCommands async = connection.async(); + async.subscribe("channel"); + + RedisPubSubAsyncCommands pubasync = pubconnection.async(); + RedisFuture result = pubasync.publish("channel", "hithere"); + + // Need a long wait for publish to complete, depending on system. + result.get(15, TimeUnit.SECONDS); + assertTrue(listener.getMessage().equals("hithere")); + + } + + private static class Listener implements RedisPubSubListener { + + private String message; + + String getMessage() { + return message; + } + + @Override + public void message(String channel, String message) { + log.debug("Got {} on {}", message, channel); + this.message = message; + } + + @Override + public void message(String pattern, String channel, String message) { + + } + + @Override + public void subscribed(String channel, long count) { + log.debug("Subscribed to {}", channel); + } + + @Override + public void psubscribed(String pattern, long count) { + + } + + @Override + public void unsubscribed(String channel, long count) { + + } + + @Override + public void punsubscribed(String pattern, long count) { + + } + } + +} From a758fd9cef9fb4ad945d623eab443e0bd1bfd901 Mon Sep 17 00:00:00 2001 From: Alessio Stalla Date: Sun, 14 Jan 2018 22:50:55 +0100 Subject: [PATCH 15/65] BAEL-1402 code for the article: Try-with-resources in Kotlin --- core-kotlin/pom.xml | 5 ++ .../kotlin/com/baeldung/kotlin/UseTest.kt | 67 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 core-kotlin/src/test/kotlin/com/baeldung/kotlin/UseTest.kt diff --git a/core-kotlin/pom.xml b/core-kotlin/pom.xml index b511f0dd7b..2cd5275eeb 100644 --- a/core-kotlin/pom.xml +++ b/core-kotlin/pom.xml @@ -44,6 +44,11 @@ kotlin-stdlib ${kotlin-stdlib.version} + + org.jetbrains.kotlin + kotlin-stdlib-jre8 + ${kotlin-stdlib.version} + org.jetbrains.kotlin kotlin-test-junit diff --git a/core-kotlin/src/test/kotlin/com/baeldung/kotlin/UseTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/kotlin/UseTest.kt new file mode 100644 index 0000000000..15bdfcafd8 --- /dev/null +++ b/core-kotlin/src/test/kotlin/com/baeldung/kotlin/UseTest.kt @@ -0,0 +1,67 @@ +package com.baeldung.kotlin + +import org.junit.Test +import java.beans.ExceptionListener +import java.beans.XMLEncoder +import java.io.* +import java.lang.Exception +import kotlin.test.assertEquals +import kotlin.test.assertTrue +import kotlin.test.fail + +class UseTest { + + @Test + fun givenCloseable_whenUseIsCalled_thenItIsClosed() { + val stringWriter = StringWriter() + val writer = BufferedWriter(stringWriter) //Using a BufferedWriter because after close() it throws. + writer.use { + assertEquals(writer, it) + + it.write("something") + } + try { + writer.write("something else") + + fail("write() should have thrown an exception because the writer is closed.") + } catch (e: IOException) { + //Ok + } + + assertEquals("something", stringWriter.toString()) + } + + @Test + fun givenAutoCloseable_whenUseIsCalled_thenItIsClosed() { + val baos = ByteArrayOutputStream() + val encoder = XMLEncoder(PrintStream(baos)) //XMLEncoder is AutoCloseable but not Closeable. + //Here, we use a PrintStream because after close() it throws. + encoder.exceptionListener = ThrowingExceptionListener() + encoder.use { + assertEquals(encoder, it) + + it.writeObject("something") + } + try { + encoder.writeObject("something else") + encoder.flush() + + fail("write() should have thrown an exception because the encoder is closed.") + } catch (e: IOException) { + //Ok + } + } + + @Test + fun whenSimpleFormIsUsed_thenItWorks() { + StringWriter().use { it.write("something") } + } +} + +class ThrowingExceptionListener : ExceptionListener { + override fun exceptionThrown(e: Exception?) { + if(e != null) { + throw e + } + } +} \ No newline at end of file From ee3c3a6237dfdc488dbca0d0e33fc6749d9530fc Mon Sep 17 00:00:00 2001 From: Alessio Stalla Date: Mon, 15 Jan 2018 01:32:47 +0100 Subject: [PATCH 16/65] BAEL-1402 code for the article: Try-with-resources in Kotlin (#3418) --- core-kotlin/pom.xml | 5 ++ .../kotlin/com/baeldung/kotlin/UseTest.kt | 67 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 core-kotlin/src/test/kotlin/com/baeldung/kotlin/UseTest.kt diff --git a/core-kotlin/pom.xml b/core-kotlin/pom.xml index b511f0dd7b..2cd5275eeb 100644 --- a/core-kotlin/pom.xml +++ b/core-kotlin/pom.xml @@ -44,6 +44,11 @@ kotlin-stdlib ${kotlin-stdlib.version} + + org.jetbrains.kotlin + kotlin-stdlib-jre8 + ${kotlin-stdlib.version} + org.jetbrains.kotlin kotlin-test-junit diff --git a/core-kotlin/src/test/kotlin/com/baeldung/kotlin/UseTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/kotlin/UseTest.kt new file mode 100644 index 0000000000..15bdfcafd8 --- /dev/null +++ b/core-kotlin/src/test/kotlin/com/baeldung/kotlin/UseTest.kt @@ -0,0 +1,67 @@ +package com.baeldung.kotlin + +import org.junit.Test +import java.beans.ExceptionListener +import java.beans.XMLEncoder +import java.io.* +import java.lang.Exception +import kotlin.test.assertEquals +import kotlin.test.assertTrue +import kotlin.test.fail + +class UseTest { + + @Test + fun givenCloseable_whenUseIsCalled_thenItIsClosed() { + val stringWriter = StringWriter() + val writer = BufferedWriter(stringWriter) //Using a BufferedWriter because after close() it throws. + writer.use { + assertEquals(writer, it) + + it.write("something") + } + try { + writer.write("something else") + + fail("write() should have thrown an exception because the writer is closed.") + } catch (e: IOException) { + //Ok + } + + assertEquals("something", stringWriter.toString()) + } + + @Test + fun givenAutoCloseable_whenUseIsCalled_thenItIsClosed() { + val baos = ByteArrayOutputStream() + val encoder = XMLEncoder(PrintStream(baos)) //XMLEncoder is AutoCloseable but not Closeable. + //Here, we use a PrintStream because after close() it throws. + encoder.exceptionListener = ThrowingExceptionListener() + encoder.use { + assertEquals(encoder, it) + + it.writeObject("something") + } + try { + encoder.writeObject("something else") + encoder.flush() + + fail("write() should have thrown an exception because the encoder is closed.") + } catch (e: IOException) { + //Ok + } + } + + @Test + fun whenSimpleFormIsUsed_thenItWorks() { + StringWriter().use { it.write("something") } + } +} + +class ThrowingExceptionListener : ExceptionListener { + override fun exceptionThrown(e: Exception?) { + if(e != null) { + throw e + } + } +} \ No newline at end of file From 11bcac71591140d2288abb19af873b2e4c2db791 Mon Sep 17 00:00:00 2001 From: Thoughtscript Date: Mon, 15 Jan 2018 05:01:38 +0000 Subject: [PATCH 17/65] BAEL-1175 - Finalized example and improved scripts --- .../bash/hadoop.sh | 6 +- .../boot/.gitignore | 3 + .../spring-cloud-stream-starters/boot/pom.xml | 55 +++++++++++++++++++ .../twitterhdfs/aggregate/AggregateApp.java | 18 ++++++ .../twitterhdfs/processor/ProcessorApp.java | 20 +++++++ .../baeldung/twitterhdfs/sink/SinkApp.java | 22 ++++++++ .../twitterhdfs/source/SourceApp.java | 26 +++++++++ .../src/main/resources/application.properties | 6 ++ .../spring-cloud-stream-starters/hdfs/hdfs.sh | 2 +- .../twitter/application.properties | 8 +-- .../twitter/twitter.sh | 2 +- 11 files changed, 161 insertions(+), 7 deletions(-) create mode 100644 spring-cloud/spring-cloud-stream-starters/boot/.gitignore create mode 100644 spring-cloud/spring-cloud-stream-starters/boot/pom.xml create mode 100644 spring-cloud/spring-cloud-stream-starters/boot/src/main/java/com/baeldung/twitterhdfs/aggregate/AggregateApp.java create mode 100644 spring-cloud/spring-cloud-stream-starters/boot/src/main/java/com/baeldung/twitterhdfs/processor/ProcessorApp.java create mode 100644 spring-cloud/spring-cloud-stream-starters/boot/src/main/java/com/baeldung/twitterhdfs/sink/SinkApp.java create mode 100644 spring-cloud/spring-cloud-stream-starters/boot/src/main/java/com/baeldung/twitterhdfs/source/SourceApp.java create mode 100644 spring-cloud/spring-cloud-stream-starters/boot/src/main/resources/application.properties diff --git a/spring-cloud/spring-cloud-stream-starters/bash/hadoop.sh b/spring-cloud/spring-cloud-stream-starters/bash/hadoop.sh index 5eebcca426..ca8298430b 100644 --- a/spring-cloud/spring-cloud-stream-starters/bash/hadoop.sh +++ b/spring-cloud/spring-cloud-stream-starters/bash/hadoop.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + # For Ubuntu 14.04 # Inspired from: https://github.com/curran/setupHadoop/blob/master/setupHadoop.sh # Use from the user directory @@ -32,7 +34,7 @@ sudo mv ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys # SSH ssh localhost -# Authenticate with local user +# authenticate with osboxes.org # Start NameNode daemon and DataNode daemon start-dfs.sh @@ -40,3 +42,5 @@ start-dfs.sh # Install Maven sudo apt-get install maven + +# Access Hadoop - http://localhost:50070 \ No newline at end of file diff --git a/spring-cloud/spring-cloud-stream-starters/boot/.gitignore b/spring-cloud/spring-cloud-stream-starters/boot/.gitignore new file mode 100644 index 0000000000..e4b82e1c0f --- /dev/null +++ b/spring-cloud/spring-cloud-stream-starters/boot/.gitignore @@ -0,0 +1,3 @@ +.idea +*/target/* +*.iml diff --git a/spring-cloud/spring-cloud-stream-starters/boot/pom.xml b/spring-cloud/spring-cloud-stream-starters/boot/pom.xml new file mode 100644 index 0000000000..3e6bc134e3 --- /dev/null +++ b/spring-cloud/spring-cloud-stream-starters/boot/pom.xml @@ -0,0 +1,55 @@ + + + 4.0.0 + com.baeldung.twitterhdfs + twitterhdfs + jar + 1.0.0 + + twitterhdfs + + + UTF-8 + UTF-8 + 1.8 + + + + org.springframework.boot + spring-boot-starter-parent + 1.5.8.RELEASE + + + + + + org.springframework.cloud.stream.app + spring-cloud-starter-stream-source-twitterstream + 1.3.1.RELEASE + + + org.springframework.cloud.stream.app + spring-cloud-starter-stream-sink-hdfs + 1.3.1.RELEASE + + + + + javax.servlet + jstl + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + twitterhdfs + + \ No newline at end of file diff --git a/spring-cloud/spring-cloud-stream-starters/boot/src/main/java/com/baeldung/twitterhdfs/aggregate/AggregateApp.java b/spring-cloud/spring-cloud-stream-starters/boot/src/main/java/com/baeldung/twitterhdfs/aggregate/AggregateApp.java new file mode 100644 index 0000000000..8b9ca6dc62 --- /dev/null +++ b/spring-cloud/spring-cloud-stream-starters/boot/src/main/java/com/baeldung/twitterhdfs/aggregate/AggregateApp.java @@ -0,0 +1,18 @@ +package com.baeldung.twitterhdfs.aggregate; + +import com.baeldung.twitterhdfs.processor.ProcessorApp; +import com.baeldung.twitterhdfs.source.SourceApp; +import com.baeldung.twitterhdfs.sink.SinkApp; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.stream.aggregate.AggregateApplicationBuilder; + +@SpringBootApplication +public class AggregateApp { + public static void main(String[] args) { + new AggregateApplicationBuilder() + .from(SourceApp.class).args("--fixedDelay=5000") + .via(ProcessorApp.class) + .to(SinkApp.class).args("--debug=true") + .run(args); + } +} \ No newline at end of file diff --git a/spring-cloud/spring-cloud-stream-starters/boot/src/main/java/com/baeldung/twitterhdfs/processor/ProcessorApp.java b/spring-cloud/spring-cloud-stream-starters/boot/src/main/java/com/baeldung/twitterhdfs/processor/ProcessorApp.java new file mode 100644 index 0000000000..e3bd1197f6 --- /dev/null +++ b/spring-cloud/spring-cloud-stream-starters/boot/src/main/java/com/baeldung/twitterhdfs/processor/ProcessorApp.java @@ -0,0 +1,20 @@ +package com.baeldung.twitterhdfs.processor; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.stream.annotation.EnableBinding; +import org.springframework.cloud.stream.messaging.Processor; +import org.springframework.integration.annotation.Transformer; + +@SpringBootApplication +@EnableBinding(Processor.class) +public class ProcessorApp { + Logger log = LoggerFactory.getLogger(ProcessorApp.class); + + @Transformer(inputChannel = Processor.INPUT, outputChannel = Processor.OUTPUT) + public String processMessage(String payload) { + log.info("Payload received!"); + return payload; + } +} \ No newline at end of file diff --git a/spring-cloud/spring-cloud-stream-starters/boot/src/main/java/com/baeldung/twitterhdfs/sink/SinkApp.java b/spring-cloud/spring-cloud-stream-starters/boot/src/main/java/com/baeldung/twitterhdfs/sink/SinkApp.java new file mode 100644 index 0000000000..c0c1e287d3 --- /dev/null +++ b/spring-cloud/spring-cloud-stream-starters/boot/src/main/java/com/baeldung/twitterhdfs/sink/SinkApp.java @@ -0,0 +1,22 @@ +package com.baeldung.twitterhdfs.sink; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.stream.annotation.EnableBinding; +import org.springframework.cloud.stream.app.hdfs.sink.HdfsSinkConfiguration; +import org.springframework.cloud.stream.messaging.Sink; +import org.springframework.context.annotation.Import; +import org.springframework.integration.annotation.ServiceActivator; + +@SpringBootApplication +@EnableBinding(Sink.class) +@Import(HdfsSinkConfiguration.class) +public class SinkApp { + Logger log = LoggerFactory.getLogger(SinkApp.class); + + @ServiceActivator(inputChannel= Sink.INPUT) + public void loggerSink(Object payload) { + log.info("Received: " + payload); + } +} \ No newline at end of file diff --git a/spring-cloud/spring-cloud-stream-starters/boot/src/main/java/com/baeldung/twitterhdfs/source/SourceApp.java b/spring-cloud/spring-cloud-stream-starters/boot/src/main/java/com/baeldung/twitterhdfs/source/SourceApp.java new file mode 100644 index 0000000000..f9b220561b --- /dev/null +++ b/spring-cloud/spring-cloud-stream-starters/boot/src/main/java/com/baeldung/twitterhdfs/source/SourceApp.java @@ -0,0 +1,26 @@ +package com.baeldung.twitterhdfs.source; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.stream.annotation.EnableBinding; +import org.springframework.cloud.stream.app.twitterstream.source.TwitterstreamSourceConfiguration; +import org.springframework.cloud.stream.messaging.Source; +import org.springframework.context.annotation.Import; +import org.springframework.integration.annotation.InboundChannelAdapter; + +import java.text.SimpleDateFormat; +import java.util.Date; + +@SpringBootApplication +@EnableBinding(Source.class) +@Import(TwitterstreamSourceConfiguration.class) +public class SourceApp { + Logger log = LoggerFactory.getLogger(SourceApp.class); + + @InboundChannelAdapter(value = Source.OUTPUT) + public String timerMessageSource() { + return new SimpleDateFormat().format(new Date()); + } + +} diff --git a/spring-cloud/spring-cloud-stream-starters/boot/src/main/resources/application.properties b/spring-cloud/spring-cloud-stream-starters/boot/src/main/resources/application.properties new file mode 100644 index 0000000000..298a8ebf4d --- /dev/null +++ b/spring-cloud/spring-cloud-stream-starters/boot/src/main/resources/application.properties @@ -0,0 +1,6 @@ +hdfs.fs-uri=hdfs://127.0.0.1:50010/ + +twitter.credentials.access-token= +twitter.credentials.access-token-secret= +twitter.credentials.consumer-key= +twitter.credentials.consumer-secret= \ No newline at end of file diff --git a/spring-cloud/spring-cloud-stream-starters/hdfs/hdfs.sh b/spring-cloud/spring-cloud-stream-starters/hdfs/hdfs.sh index a9df476ef4..a6e6678feb 100644 --- a/spring-cloud/spring-cloud-stream-starters/hdfs/hdfs.sh +++ b/spring-cloud/spring-cloud-stream-starters/hdfs/hdfs.sh @@ -5,7 +5,7 @@ git clone https://github.com/spring-cloud-stream-app-starters/hdfs.git # Build it ./mvnw clean install -PgenerateApps -# RUn it +# Run it cd apps # Optionally inject application.properties prior to build java -jar hdfs-sink.jar --fsUri=http://osboxes:50075 \ No newline at end of file diff --git a/spring-cloud/spring-cloud-stream-starters/twitter/application.properties b/spring-cloud/spring-cloud-stream-starters/twitter/application.properties index 5cfedee80e..e38612d25e 100644 --- a/spring-cloud/spring-cloud-stream-starters/twitter/application.properties +++ b/spring-cloud/spring-cloud-stream-starters/twitter/application.properties @@ -1,4 +1,4 @@ -twitter.credentials.access-token=932486336086286336-2HURQbA2cYzX5hixgAshIBy2Dhefupn -twitter.credentials.access-token-secret=0pyZ7etHvro8x85QSXxsqYFzYk63bK6DS5nNYy0R3l1io -twitter.credentials.consumer-key=10xCXkRYi5xLFYq3P0ymWGEwJ -twitter.credentials.consumer-secret=VfyCUcGfAQ2aWcd3uTg8GmVGyhUfAcNJU6ksG09TAtPMqhmWTS \ No newline at end of file +twitter.credentials.access-token= +twitter.credentials.access-token-secret= +twitter.credentials.consumer-key= +twitter.credentials.consumer-secret= \ No newline at end of file diff --git a/spring-cloud/spring-cloud-stream-starters/twitter/twitter.sh b/spring-cloud/spring-cloud-stream-starters/twitter/twitter.sh index 994d40dd4c..4c76fe637b 100644 --- a/spring-cloud/spring-cloud-stream-starters/twitter/twitter.sh +++ b/spring-cloud/spring-cloud-stream-starters/twitter/twitter.sh @@ -5,7 +5,7 @@ git clone https://github.com/spring-cloud-stream-app-starters/twitter.git # Build it ./mvnw clean install -PgenerateApps -# RUn it +# Run it cd apps # Optionally inject application.properties prior to build java -jar twitter_stream_source.jar --consumerKey= --consumerSecret= \ From 68b4eddc977f3d7ad85c885d81f550ad842f53a7 Mon Sep 17 00:00:00 2001 From: Thoughtscript Date: Mon, 15 Jan 2018 05:05:00 +0000 Subject: [PATCH 18/65] BAEL-1175 - Corrected HDFS URI --- .../spring-cloud-stream-starters/hdfs/application.properties | 2 +- spring-cloud/spring-cloud-stream-starters/hdfs/hdfs.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-cloud/spring-cloud-stream-starters/hdfs/application.properties b/spring-cloud/spring-cloud-stream-starters/hdfs/application.properties index 8b421f954c..1f4aaf88dd 100644 --- a/spring-cloud/spring-cloud-stream-starters/hdfs/application.properties +++ b/spring-cloud/spring-cloud-stream-starters/hdfs/application.properties @@ -1 +1 @@ -hdfs.fs-uri=http://osboxes:50075 \ No newline at end of file +hdfs.fs-uri=hdfs://127.0.0.1:50010/ \ No newline at end of file diff --git a/spring-cloud/spring-cloud-stream-starters/hdfs/hdfs.sh b/spring-cloud/spring-cloud-stream-starters/hdfs/hdfs.sh index a6e6678feb..577a25dd6e 100644 --- a/spring-cloud/spring-cloud-stream-starters/hdfs/hdfs.sh +++ b/spring-cloud/spring-cloud-stream-starters/hdfs/hdfs.sh @@ -8,4 +8,4 @@ git clone https://github.com/spring-cloud-stream-app-starters/hdfs.git # Run it cd apps # Optionally inject application.properties prior to build -java -jar hdfs-sink.jar --fsUri=http://osboxes:50075 \ No newline at end of file +java -jar hdfs-sink.jar --fsUri=hdfs://127.0.0.1:50010/ \ No newline at end of file From 7e5940b578b9d516dcb8d4fb714c72c4fb1ebf44 Mon Sep 17 00:00:00 2001 From: Tarang Bhalodia Date: Tue, 16 Jan 2018 01:11:38 +0530 Subject: [PATCH 19/65] tarangbhalodia@gmail.com [BAEL-1282: geospatial support elasticsearch] (#3421) * BAEL-1422: measure performance of Random and ThreadLocalRandom using JMH * BAEL-1422: updated benchmarking examples of Random and ThreadLocalRandom to use newWorkStealingPool that leverages ForkJoinPool * BAEL-1422: refactored benchmarking examples for comparing performance of ThreadLocalRandom and Random - initialised the collection of Callable before running benchmarking - removed for loop for submitting task and instead used executor.invokeAll(collection_of_callable) * BAEL-1282: added TDD type junit tests for geospatial queries elasticsearch --- spring-data-elasticsearch/pom.xml | 18 ++ .../elasticsearch/GeoQueriesTest.java | 179 ++++++++++++++++++ 2 files changed, 197 insertions(+) create mode 100644 spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/GeoQueriesTest.java diff --git a/spring-data-elasticsearch/pom.xml b/spring-data-elasticsearch/pom.xml index 520707a432..688506450f 100644 --- a/spring-data-elasticsearch/pom.xml +++ b/spring-data-elasticsearch/pom.xml @@ -45,6 +45,24 @@ ${spring-data-elasticsearch.version} + + com.spatial4j + spatial4j + 0.4.1 + + + + com.vividsolutions + jts + 1.13 + + + xerces + xercesImpl + + + + org.springframework spring-test diff --git a/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/GeoQueriesTest.java b/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/GeoQueriesTest.java new file mode 100644 index 0000000000..19514ce4c2 --- /dev/null +++ b/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/GeoQueriesTest.java @@ -0,0 +1,179 @@ +package com.baeldung.elasticsearch; + +import static org.junit.Assert.assertTrue; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; +import org.elasticsearch.action.index.IndexResponse; +import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.client.Client; +import org.elasticsearch.common.geo.ShapeRelation; +import org.elasticsearch.common.geo.builders.ShapeBuilder; +import org.elasticsearch.common.unit.DistanceUnit; +import org.elasticsearch.index.query.QueryBuilder; +import org.elasticsearch.index.query.QueryBuilders; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.baeldung.spring.data.es.config.Config; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = Config.class) +public class GeoQueriesTest { + + public static final String WONDERS_OF_WORLD = "wonders-of-world"; + public static final String WONDERS = "Wonders"; + @Autowired + private ElasticsearchTemplate elasticsearchTemplate; + + @Autowired + private Client client; + + @Before + public void setUp() { + String jsonObject = "{\"Wonders\":{\"properties\":{\"name\":{\"type\":\"string\",\"index\":\"not_analyzed\"},\"region\":{\"type\":\"geo_shape\",\"tree\":\"quadtree\",\"precision\":\"1m\"},\"location\":{\"type\":\"geo_point\"}}}}"; + CreateIndexRequest req = new CreateIndexRequest(WONDERS_OF_WORLD); + req.mapping(WONDERS, jsonObject); + client.admin() + .indices() + .create(req) + .actionGet(); + } + + @Test + public void givenGeoShapeData_whenExecutedGeoShapeQuery_thenResultNonEmpty() { + String jsonObject = "{\"name\":\"Agra\",\"region\":{\"type\":\"envelope\",\"coordinates\":[[75,25],[80.1,30.2]]}}"; + IndexResponse response = client.prepareIndex(WONDERS_OF_WORLD, WONDERS) + .setSource(jsonObject) + .get(); + String tajMahalId = response.getId(); + client.admin() + .indices() + .prepareRefresh(WONDERS_OF_WORLD) + .get(); + + QueryBuilder qb = QueryBuilders.geoShapeQuery("region", ShapeBuilder.newEnvelope() + .topLeft(74.00, 24.0) + .bottomRight(81.1, 31.2)) + .relation(ShapeRelation.WITHIN); + + SearchResponse searchResponse = client.prepareSearch(WONDERS_OF_WORLD) + .setTypes(WONDERS) + .setQuery(qb) + .execute() + .actionGet(); + List ids = Arrays.stream(searchResponse.getHits() + .getHits()) + .map(hit -> { + return hit.getId(); + }) + .collect(Collectors.toList()); + assertTrue(ids.contains(tajMahalId)); + } + + @Test + public void givenGeoPointData_whenExecutedGeoBoundingBoxQuery_thenResultNonEmpty() { + String jsonObject = "{\"name\":\"Pyramids of Giza\",\"location\":[31.131302,29.976480]}"; + IndexResponse response = client.prepareIndex(WONDERS_OF_WORLD, WONDERS) + .setSource(jsonObject) + .get(); + String pyramidsOfGizaId = response.getId(); + client.admin() + .indices() + .prepareRefresh(WONDERS_OF_WORLD) + .get(); + + QueryBuilder qb = QueryBuilders.geoBoundingBoxQuery("location") + .bottomLeft(28, 30) + .topRight(31, 32); + + SearchResponse searchResponse = client.prepareSearch(WONDERS_OF_WORLD) + .setTypes(WONDERS) + .setQuery(qb) + .execute() + .actionGet(); + List ids = Arrays.stream(searchResponse.getHits() + .getHits()) + .map(hit -> { + return hit.getId(); + }) + .collect(Collectors.toList()); + assertTrue(ids.contains(pyramidsOfGizaId)); + } + + @Test + public void givenGeoPointData_whenExecutedGeoDistanceQuery_thenResultNonEmpty() { + String jsonObject = "{\"name\":\"Lighthouse of alexandria\",\"location\":[31.131302,29.976480]}"; + IndexResponse response = client.prepareIndex(WONDERS_OF_WORLD, WONDERS) + .setSource(jsonObject) + .get(); + String lighthouseOfAlexandriaId = response.getId(); + client.admin() + .indices() + .prepareRefresh(WONDERS_OF_WORLD) + .get(); + + QueryBuilder qb = QueryBuilders.geoDistanceQuery("location") + .point(29.976, 31.131) + .distance(10, DistanceUnit.MILES); + + SearchResponse searchResponse = client.prepareSearch(WONDERS_OF_WORLD) + .setTypes(WONDERS) + .setQuery(qb) + .execute() + .actionGet(); + List ids = Arrays.stream(searchResponse.getHits() + .getHits()) + .map(hit -> { + return hit.getId(); + }) + .collect(Collectors.toList()); + assertTrue(ids.contains(lighthouseOfAlexandriaId)); + } + + @Test + public void givenGeoPointData_whenExecutedGeoPolygonQuery_thenResultNonEmpty() { + String jsonObject = "{\"name\":\"The Great Rann of Kutch\",\"location\":[69.859741,23.733732]}"; + IndexResponse response = client.prepareIndex(WONDERS_OF_WORLD, WONDERS) + .setSource(jsonObject) + .get(); + String greatRannOfKutchid = response.getId(); + client.admin() + .indices() + .prepareRefresh(WONDERS_OF_WORLD) + .get(); + + QueryBuilder qb = QueryBuilders.geoPolygonQuery("location") + .addPoint(22.733, 68.859) + .addPoint(24.733, 68.859) + .addPoint(23, 70.859); + + SearchResponse searchResponse = client.prepareSearch(WONDERS_OF_WORLD) + .setTypes(WONDERS) + .setQuery(qb) + .execute() + .actionGet(); + List ids = Arrays.stream(searchResponse.getHits() + .getHits()) + .map(hit -> { + return hit.getId(); + }) + .collect(Collectors.toList()); + assertTrue(ids.contains(greatRannOfKutchid)); + } + + @After + public void destroy() { + elasticsearchTemplate.deleteIndex(WONDERS_OF_WORLD); + } + +} From 293968321eb980e6599dd4f81b002b85e64308ad Mon Sep 17 00:00:00 2001 From: Antonio David Perez Morales Date: Mon, 15 Jan 2018 21:00:21 +0100 Subject: [PATCH 20/65] BAEL-1428: Adding example for manually set authenticated user (#3423) --- .../web/controller/LoginController.java | 43 ++++++++++++++ .../web/controller/PrintUserController.java | 27 +++++++++ .../security/spring/ManualSecurityConfig.java | 58 +++++++++++++++++++ .../spring/ManualSecurityIntegrationTest.java | 58 +++++++++++++++++++ 4 files changed, 186 insertions(+) create mode 100644 spring-security-mvc-custom/src/main/java/org/baeldung/web/controller/LoginController.java create mode 100644 spring-security-mvc-custom/src/main/java/org/baeldung/web/controller/PrintUserController.java create mode 100644 spring-security-mvc-custom/src/test/java/org/baeldung/security/spring/ManualSecurityConfig.java create mode 100644 spring-security-mvc-custom/src/test/java/org/baeldung/security/spring/ManualSecurityIntegrationTest.java diff --git a/spring-security-mvc-custom/src/main/java/org/baeldung/web/controller/LoginController.java b/spring-security-mvc-custom/src/main/java/org/baeldung/web/controller/LoginController.java new file mode 100644 index 0000000000..c67a6f667e --- /dev/null +++ b/spring-security-mvc-custom/src/main/java/org/baeldung/web/controller/LoginController.java @@ -0,0 +1,43 @@ +package org.baeldung.web.controller; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContext; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; + +@Controller +@RequestMapping(value = "/custom") +public class LoginController { + + @Autowired + private AuthenticationManager authManager; + + public LoginController() { + super(); + } + + // API + + // custom login + + @RequestMapping(value = "/login", method = RequestMethod.POST) + public void login(@RequestParam("username") final String username, @RequestParam("password") final String password, final HttpServletRequest request) { + UsernamePasswordAuthenticationToken authReq = + new UsernamePasswordAuthenticationToken(username, password); + Authentication auth = authManager.authenticate(authReq); + SecurityContext sc = SecurityContextHolder.getContext(); + sc.setAuthentication(auth); + HttpSession session = request.getSession(true); + session.setAttribute("SPRING_SECURITY_CONTEXT", sc); + } + +} \ No newline at end of file diff --git a/spring-security-mvc-custom/src/main/java/org/baeldung/web/controller/PrintUserController.java b/spring-security-mvc-custom/src/main/java/org/baeldung/web/controller/PrintUserController.java new file mode 100644 index 0000000000..78f164c7f1 --- /dev/null +++ b/spring-security-mvc-custom/src/main/java/org/baeldung/web/controller/PrintUserController.java @@ -0,0 +1,27 @@ +package org.baeldung.web.controller; + +import org.springframework.security.core.context.SecurityContext; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +@Controller +@RequestMapping(value = "/custom") +public class PrintUserController { + + public PrintUserController() { + super(); + } + + // API + + // print user + + @RequestMapping(value = "/print", method = RequestMethod.GET) + public void printUser() { + SecurityContext sc = SecurityContextHolder.getContext(); + System.out.println("Logged User: "+sc.getAuthentication().getName()); + } + +} \ No newline at end of file diff --git a/spring-security-mvc-custom/src/test/java/org/baeldung/security/spring/ManualSecurityConfig.java b/spring-security-mvc-custom/src/test/java/org/baeldung/security/spring/ManualSecurityConfig.java new file mode 100644 index 0000000000..874856095c --- /dev/null +++ b/spring-security-mvc-custom/src/test/java/org/baeldung/security/spring/ManualSecurityConfig.java @@ -0,0 +1,58 @@ +package org.baeldung.security.spring; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.config.BeanIds; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +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; + +@Configuration +@EnableWebSecurity +@EnableGlobalMethodSecurity(prePostEnabled = true) +public class ManualSecurityConfig extends WebSecurityConfigurerAdapter { + + public ManualSecurityConfig() { + super(); + } + + // java config + + @Override + protected void configure(final AuthenticationManagerBuilder auth) throws Exception { + auth.inMemoryAuthentication().withUser("user1").password("user1Pass").authorities("ROLE_USER").and().withUser("admin").password("adminPass").authorities("ROLE_ADMIN"); + } + + @Override + public void configure(final WebSecurity web) throws Exception { + web.ignoring().antMatchers("/resources/**"); + } + + @Bean(name = BeanIds.AUTHENTICATION_MANAGER) + @Override + public AuthenticationManager authenticationManagerBean() throws Exception { + return super.authenticationManagerBean(); + } + + @Override + protected void configure(final HttpSecurity http) throws Exception { + // @formatter:off + http + .authorizeRequests() + .mvcMatchers("/custom/login").permitAll() + .anyRequest().authenticated() + .and() + .httpBasic() + .and() + .headers().cacheControl().disable() + .and() + .csrf().disable() + ; + // @formatter:on + } + +} diff --git a/spring-security-mvc-custom/src/test/java/org/baeldung/security/spring/ManualSecurityIntegrationTest.java b/spring-security-mvc-custom/src/test/java/org/baeldung/security/spring/ManualSecurityIntegrationTest.java new file mode 100644 index 0000000000..afc86bd74c --- /dev/null +++ b/spring-security-mvc-custom/src/test/java/org/baeldung/security/spring/ManualSecurityIntegrationTest.java @@ -0,0 +1,58 @@ +package org.baeldung.security.spring; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import javax.servlet.http.HttpSession; + +import org.baeldung.spring.MvcConfig; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.MockitoAnnotations; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.mock.web.MockHttpSession; +import org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + +@RunWith(SpringJUnit4ClassRunner.class) +@WebAppConfiguration +@ContextConfiguration(classes = { MvcConfig.class, ManualSecurityConfig.class }) +public class ManualSecurityIntegrationTest { + + @Autowired + WebApplicationContext wac; + + private MockMvc mockMvc; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + mockMvc = MockMvcBuilders.webAppContextSetup(wac).apply(SecurityMockMvcConfigurers.springSecurity()).build(); + } + + /** + * Execute custom login and access the endpoint + */ + @Test + public void whenLoginIsSuccessFulThenEndpointCanBeAccessedAndCurrentUserPrinted() throws Exception { + + mockMvc.perform(get("/custom/print")) + .andExpect(status().isUnauthorized()); + + HttpSession session = mockMvc.perform(post("/custom/login").param("username", "user1").param("password", "user1Pass")) + .andExpect(status().isOk()) + .andReturn() + .getRequest() + .getSession(); + + mockMvc.perform(get("/custom/print").session((MockHttpSession) session)) + .andExpect(status().is2xxSuccessful()); + } + +} From f993bc0435953a345abd9047a64bd8a047f0c23b Mon Sep 17 00:00:00 2001 From: Bogdan Stoean <4540392+BogdanStoean@users.noreply.github.com> Date: Mon, 15 Jan 2018 23:05:19 +0200 Subject: [PATCH 21/65] [BAEL-1410] Spring Boot OAuth2 Support (#3409) * initial setup with spring boot/ spring data jpa/ flyway * BAEL-1315 - added flyway test extensions for spring * BAEL-1315 - added flyway test extensions for spring * BAEL-1315 - created multiple migration scripts and locations * BAEL-1315 - test insert after schema creation * cleanup * BAEL-1315 - test data changes by a migration * [BAEL-1410] Spring Boot Security Auto-Configuration * [BAEL-1410] Added some tests for incorrect credentials use case * [BAEL-1410] Added readme and some code improvements * [BAEL-1410] removed form based auth config because is redundant added oauth2 server auto-configuration sample with test * [BAEL-1410] added custom Authorization Server Config * [BAEL-1410] update README * [BAEL-1410]refactor tests * [BAEL-1410]oauth2 resource server * [BAEL-1410]oauth2 sso sample with facebook * [BAEL-1410]remove spring-flyway --- spring-boot-security/README.md | 8 +- spring-boot-security/pom.xml | 4 + .../SpringBootSecurityApplication.java | 4 +- .../config/BasicAuthConfiguration.java} | 6 +- .../config/FormLoginConfiguration.java | 39 ------- .../SpringBootOAuth2ResourceApplication.java | 30 +++++ ...ingBootAuthorizationServerApplication.java | 30 +++++ .../config/AuthorizationServerConfig.java | 39 +++++++ .../SpringBootOAuth2SsoApplication.java | 18 +++ .../resources/application-authz.properties | 3 + .../resources/application-resource.properties | 2 + .../main/resources/application-sso.properties | 9 ++ .../src/main/resources/application.properties | 6 +- .../FormConfigurationIntegrationTest.java | 106 ------------------ ...asicAuthConfigurationIntegrationTest.java} | 9 +- ...figAuthorizationServerIntegrationTest.java | 75 +++++++++++++ ...figAuthorizationServerIntegrationTest.java | 44 ++++++++ 17 files changed, 270 insertions(+), 162 deletions(-) rename spring-boot-security/src/main/java/com/baeldung/springbootsecurity/{ => basic_auth}/SpringBootSecurityApplication.java (80%) rename spring-boot-security/src/main/java/com/baeldung/springbootsecurity/{config/BasicConfiguration.java => basic_auth/config/BasicAuthConfiguration.java} (84%) delete mode 100644 spring-boot-security/src/main/java/com/baeldung/springbootsecurity/config/FormLoginConfiguration.java create mode 100644 spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2resource/SpringBootOAuth2ResourceApplication.java create mode 100644 spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2server/SpringBootAuthorizationServerApplication.java create mode 100644 spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2server/config/AuthorizationServerConfig.java create mode 100644 spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2sso/SpringBootOAuth2SsoApplication.java create mode 100644 spring-boot-security/src/main/resources/application-authz.properties create mode 100644 spring-boot-security/src/main/resources/application-resource.properties create mode 100644 spring-boot-security/src/main/resources/application-sso.properties delete mode 100644 spring-boot-security/src/test/java/com/baeldung/springbootsecurity/FormConfigurationIntegrationTest.java rename spring-boot-security/src/test/java/com/baeldung/springbootsecurity/{BasicConfigurationIntegrationTest.java => basic_auth/BasicAuthConfigurationIntegrationTest.java} (86%) create mode 100644 spring-boot-security/src/test/java/com/baeldung/springbootsecurity/oauth2server/CustomConfigAuthorizationServerIntegrationTest.java create mode 100644 spring-boot-security/src/test/java/com/baeldung/springbootsecurity/oauth2server/DefaultConfigAuthorizationServerIntegrationTest.java diff --git a/spring-boot-security/README.md b/spring-boot-security/README.md index 26ab8b2337..a0ddb8de7b 100644 --- a/spring-boot-security/README.md +++ b/spring-boot-security/README.md @@ -1,6 +1,8 @@ ### Spring Boot Security Auto-Configuration - mvn clean install -- uncomment in application.properties spring.profiles.active=basic # for basic auth config -- uncomment in application.properties spring.profiles.active=form # for form based auth config -- uncomment actuator dependency simultaneously with the line from main class +- uncomment actuator dependency simultaneously with the line from basic auth main class +- uncomment security properties for easy testing. If not random will be generated. + +### CURL commands +- curl -X POST -u baeldung-admin:baeldung -d grant_type=client_credentials -d username=baeldung-admin -d password=baeldung http://localhost:8080/oauth/token diff --git a/spring-boot-security/pom.xml b/spring-boot-security/pom.xml index c35191a7fc..c1ec14ff64 100644 --- a/spring-boot-security/pom.xml +++ b/spring-boot-security/pom.xml @@ -43,6 +43,10 @@ org.springframework.boot spring-boot-starter-security + + org.springframework.security.oauth + spring-security-oauth2 + org.springframework.boot spring-boot-starter-web diff --git a/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/SpringBootSecurityApplication.java b/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/basic_auth/SpringBootSecurityApplication.java similarity index 80% rename from spring-boot-security/src/main/java/com/baeldung/springbootsecurity/SpringBootSecurityApplication.java rename to spring-boot-security/src/main/java/com/baeldung/springbootsecurity/basic_auth/SpringBootSecurityApplication.java index 3a85da72e5..2ecad4ae35 100644 --- a/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/SpringBootSecurityApplication.java +++ b/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/basic_auth/SpringBootSecurityApplication.java @@ -1,4 +1,4 @@ -package com.baeldung.springbootsecurity; +package com.baeldung.springbootsecurity.basic_auth; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -7,7 +7,7 @@ import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration @SpringBootApplication(exclude = { SecurityAutoConfiguration.class // ,ManagementWebSecurityAutoConfiguration.class -}) +}, scanBasePackages = "com.baeldung.springbootsecurity.basic_auth") public class SpringBootSecurityApplication { public static void main(String[] args) { diff --git a/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/config/BasicConfiguration.java b/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/basic_auth/config/BasicAuthConfiguration.java similarity index 84% rename from spring-boot-security/src/main/java/com/baeldung/springbootsecurity/config/BasicConfiguration.java rename to spring-boot-security/src/main/java/com/baeldung/springbootsecurity/basic_auth/config/BasicAuthConfiguration.java index 1b08e5ee22..993c573fb0 100644 --- a/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/config/BasicConfiguration.java +++ b/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/basic_auth/config/BasicAuthConfiguration.java @@ -1,7 +1,6 @@ -package com.baeldung.springbootsecurity.config; +package com.baeldung.springbootsecurity.basic_auth.config; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; @@ -9,8 +8,7 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur @Configuration @EnableWebSecurity -@Profile("basic") -public class BasicConfiguration extends WebSecurityConfigurerAdapter { +public class BasicAuthConfiguration extends WebSecurityConfigurerAdapter { @Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { diff --git a/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/config/FormLoginConfiguration.java b/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/config/FormLoginConfiguration.java deleted file mode 100644 index b4902a9ffc..0000000000 --- a/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/config/FormLoginConfiguration.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.baeldung.springbootsecurity.config; - -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; -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; - -@Configuration -@EnableWebSecurity -@Profile("form") -public class FormLoginConfiguration extends WebSecurityConfigurerAdapter { - - @Override - protected void configure(AuthenticationManagerBuilder auth) throws Exception { - auth - .inMemoryAuthentication() - .withUser("user") - .password("password") - .roles("USER") - .and() - .withUser("admin") - .password("password") - .roles("USER", "ADMIN"); - } - - @Override - protected void configure(HttpSecurity http) throws Exception { - http - .authorizeRequests() - .anyRequest() - .authenticated() - .and() - .formLogin() - .and() - .httpBasic(); - } -} diff --git a/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2resource/SpringBootOAuth2ResourceApplication.java b/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2resource/SpringBootOAuth2ResourceApplication.java new file mode 100644 index 0000000000..56231a28bd --- /dev/null +++ b/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2resource/SpringBootOAuth2ResourceApplication.java @@ -0,0 +1,30 @@ +package com.baeldung.springbootsecurity.oauth2resource; + +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@EnableResourceServer +@SpringBootApplication(scanBasePackages = "com.baeldung.springbootsecurity.oauth2resource") +public class SpringBootOAuth2ResourceApplication { + + public static void main(String[] args) { + new SpringApplicationBuilder() + .profiles("resource") + .sources(SpringBootOAuth2ResourceApplication.class) + .build() + .run(args); + } + + @RestController + class SecuredResourceController { + + @GetMapping("/securedResource") + public String securedResource() { + return "Baeldung Secured Resource OK"; + } + + } +} diff --git a/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2server/SpringBootAuthorizationServerApplication.java b/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2server/SpringBootAuthorizationServerApplication.java new file mode 100644 index 0000000000..44dabefbb8 --- /dev/null +++ b/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2server/SpringBootAuthorizationServerApplication.java @@ -0,0 +1,30 @@ +package com.baeldung.springbootsecurity.oauth2server; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; +import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.security.Principal; + +@EnableResourceServer +@EnableAuthorizationServer +@SpringBootApplication(scanBasePackages = "com.baeldung.springbootsecurity.oauth2server") +public class SpringBootAuthorizationServerApplication { + + public static void main(String[] args) { + SpringApplication.run(SpringBootAuthorizationServerApplication.class, args); + } + + @RestController + class UserController { + + @GetMapping("/user") + public Principal user(Principal user) { + return user; + } + + } +} diff --git a/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2server/config/AuthorizationServerConfig.java b/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2server/config/AuthorizationServerConfig.java new file mode 100644 index 0000000000..b403feb5c1 --- /dev/null +++ b/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2server/config/AuthorizationServerConfig.java @@ -0,0 +1,39 @@ +package com.baeldung.springbootsecurity.oauth2server.config; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer; +import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter; +import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer; + +@Configuration +@Profile("authz") +public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter { + + @Autowired + private AuthenticationManager authenticationManager; + + @Override + public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { + endpoints.authenticationManager(authenticationManager); + } + + @Override + public void configure(ClientDetailsServiceConfigurer clients) throws Exception { + clients + .inMemory() + .withClient("baeldung") + .secret("baeldung") + .authorizedGrantTypes("client_credentials", "password", "authorization_code") + .scopes("openid", "read") + .autoApprove(true) + .and() + .withClient("baeldung-admin") + .secret("baeldung") + .authorizedGrantTypes("authorization_code", "client_credentials", "refresh_token") + .scopes("read", "write") + .autoApprove(true); + } +} diff --git a/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2sso/SpringBootOAuth2SsoApplication.java b/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2sso/SpringBootOAuth2SsoApplication.java new file mode 100644 index 0000000000..b1cd580f08 --- /dev/null +++ b/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2sso/SpringBootOAuth2SsoApplication.java @@ -0,0 +1,18 @@ +package com.baeldung.springbootsecurity.oauth2sso; + +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso; +import org.springframework.boot.builder.SpringApplicationBuilder; + +@EnableOAuth2Sso +@SpringBootApplication(scanBasePackages = "com.baeldung.springbootsecurity.oauth2sso") +public class SpringBootOAuth2SsoApplication { + + public static void main(String[] args) { + new SpringApplicationBuilder() + .profiles("sso") + .sources(SpringBootOAuth2SsoApplication.class) + .build() + .run(args); + } +} diff --git a/spring-boot-security/src/main/resources/application-authz.properties b/spring-boot-security/src/main/resources/application-authz.properties new file mode 100644 index 0000000000..d29b0cdd3c --- /dev/null +++ b/spring-boot-security/src/main/resources/application-authz.properties @@ -0,0 +1,3 @@ +security.user.password=password +security.oauth2.client.client-id=client +security.oauth2.client.client-secret=secret diff --git a/spring-boot-security/src/main/resources/application-resource.properties b/spring-boot-security/src/main/resources/application-resource.properties new file mode 100644 index 0000000000..b157b01d51 --- /dev/null +++ b/spring-boot-security/src/main/resources/application-resource.properties @@ -0,0 +1,2 @@ +server.port=8081 +security.oauth2.resource.userInfoUri=http://localhost:8080/user \ No newline at end of file diff --git a/spring-boot-security/src/main/resources/application-sso.properties b/spring-boot-security/src/main/resources/application-sso.properties new file mode 100644 index 0000000000..ac6ae0cc93 --- /dev/null +++ b/spring-boot-security/src/main/resources/application-sso.properties @@ -0,0 +1,9 @@ +server.port=8082 +security.oauth2.client.clientId= +security.oauth2.client.clientSecret= +security.oauth2.client.accessTokenUri=https://graph.facebook.com/oauth/access_token +security.oauth2.client.userAuthorizationUri=https://www.facebook.com/dialog/oauth +security.oauth2.client.tokenName=oauth_token +security.oauth2.client.authenticationScheme=query +security.oauth2.client.clientAuthenticationScheme=form +security.oauth2.resource.userInfoUri=https://graph.facebook.com/me \ No newline at end of file diff --git a/spring-boot-security/src/main/resources/application.properties b/spring-boot-security/src/main/resources/application.properties index 6ca2edb175..c2b8d70dc6 100644 --- a/spring-boot-security/src/main/resources/application.properties +++ b/spring-boot-security/src/main/resources/application.properties @@ -1,4 +1,4 @@ #spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration -#spring.profiles.active=form -#spring.profiles.active=basic -#security.user.password=password \ No newline at end of file +#security.user.password=password +#security.oauth2.client.client-id=client +#security.oauth2.client.client-secret=secret diff --git a/spring-boot-security/src/test/java/com/baeldung/springbootsecurity/FormConfigurationIntegrationTest.java b/spring-boot-security/src/test/java/com/baeldung/springbootsecurity/FormConfigurationIntegrationTest.java deleted file mode 100644 index 697a4f2868..0000000000 --- a/spring-boot-security/src/test/java/com/baeldung/springbootsecurity/FormConfigurationIntegrationTest.java +++ /dev/null @@ -1,106 +0,0 @@ -package com.baeldung.springbootsecurity; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.embedded.LocalServerPort; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.*; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.util.MultiValueMap; - -import java.util.Collections; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import static org.junit.Assert.*; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = RANDOM_PORT) -@ActiveProfiles("form") -public class FormConfigurationIntegrationTest { - - @Autowired TestRestTemplate restTemplate; - @LocalServerPort int port; - - @Test - public void whenLoginPageIsRequested_ThenSuccess() { - HttpHeaders httpHeaders = new HttpHeaders(); - httpHeaders.setAccept(Collections.singletonList(MediaType.TEXT_HTML)); - ResponseEntity responseEntity = restTemplate.exchange("/login", HttpMethod.GET, new HttpEntity(httpHeaders), String.class); - assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); - assertTrue(responseEntity - .getBody() - .contains("_csrf")); - } - - @Test - public void whenTryingToLoginWithCorrectCredentials_ThenAuthenticateWithSuccess() { - HttpHeaders httpHeaders = getHeaders(); - httpHeaders.setAccept(Collections.singletonList(MediaType.TEXT_HTML)); - httpHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED); - MultiValueMap form = getFormSubmitCorrectCredentials(); - ResponseEntity responseEntity = this.restTemplate.exchange("/login", HttpMethod.POST, new HttpEntity<>(form, httpHeaders), String.class); - assertEquals(responseEntity.getStatusCode(), HttpStatus.FOUND); - assertTrue(responseEntity - .getHeaders() - .getLocation() - .toString() - .endsWith(this.port + "/")); - assertNotNull(responseEntity - .getHeaders() - .get("Set-Cookie")); - } - - @Test - public void whenTryingToLoginWithInorrectCredentials_ThenAuthenticationFailed() { - HttpHeaders httpHeaders = getHeaders(); - httpHeaders.setAccept(Collections.singletonList(MediaType.TEXT_HTML)); - httpHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED); - MultiValueMap form = getFormSubmitIncorrectCredentials(); - ResponseEntity responseEntity = this.restTemplate.exchange("/login", HttpMethod.POST, new HttpEntity<>(form, httpHeaders), String.class); - assertEquals(responseEntity.getStatusCode(), HttpStatus.FOUND); - assertTrue(responseEntity - .getHeaders() - .getLocation() - .toString() - .endsWith(this.port + "/login?error")); - assertNull(responseEntity - .getHeaders() - .get("Set-Cookie")); - } - - private MultiValueMap getFormSubmitCorrectCredentials() { - MultiValueMap form = new LinkedMultiValueMap<>(); - form.set("username", "user"); - form.set("password", "password"); - return form; - } - - private MultiValueMap getFormSubmitIncorrectCredentials() { - MultiValueMap form = new LinkedMultiValueMap<>(); - form.set("username", "user"); - form.set("password", "wrongpassword"); - return form; - } - - private HttpHeaders getHeaders() { - HttpHeaders headers = new HttpHeaders(); - ResponseEntity page = this.restTemplate.getForEntity("/login", String.class); - assertEquals(page.getStatusCode(), HttpStatus.OK); - String cookie = page - .getHeaders() - .getFirst("Set-Cookie"); - headers.set("Cookie", cookie); - Pattern pattern = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*"); - Matcher matcher = pattern.matcher(page.getBody()); - assertTrue(matcher.matches()); - headers.set("X-CSRF-TOKEN", matcher.group(1)); - return headers; - } - -} diff --git a/spring-boot-security/src/test/java/com/baeldung/springbootsecurity/BasicConfigurationIntegrationTest.java b/spring-boot-security/src/test/java/com/baeldung/springbootsecurity/basic_auth/BasicAuthConfigurationIntegrationTest.java similarity index 86% rename from spring-boot-security/src/test/java/com/baeldung/springbootsecurity/BasicConfigurationIntegrationTest.java rename to spring-boot-security/src/test/java/com/baeldung/springbootsecurity/basic_auth/BasicAuthConfigurationIntegrationTest.java index 63e1c2ac73..4e4244abb7 100644 --- a/spring-boot-security/src/test/java/com/baeldung/springbootsecurity/BasicConfigurationIntegrationTest.java +++ b/spring-boot-security/src/test/java/com/baeldung/springbootsecurity/basic_auth/BasicAuthConfigurationIntegrationTest.java @@ -1,5 +1,6 @@ -package com.baeldung.springbootsecurity; +package com.baeldung.springbootsecurity.basic_auth; +import com.baeldung.springbootsecurity.basic_auth.SpringBootSecurityApplication; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -8,7 +9,6 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; import java.io.IOException; @@ -20,9 +20,8 @@ import static org.junit.Assert.assertTrue; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; @RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = RANDOM_PORT) -@ActiveProfiles("basic") -public class BasicConfigurationIntegrationTest { +@SpringBootTest(webEnvironment = RANDOM_PORT, classes = SpringBootSecurityApplication.class) +public class BasicAuthConfigurationIntegrationTest { TestRestTemplate restTemplate; URL base; diff --git a/spring-boot-security/src/test/java/com/baeldung/springbootsecurity/oauth2server/CustomConfigAuthorizationServerIntegrationTest.java b/spring-boot-security/src/test/java/com/baeldung/springbootsecurity/oauth2server/CustomConfigAuthorizationServerIntegrationTest.java new file mode 100644 index 0000000000..09df9ce645 --- /dev/null +++ b/spring-boot-security/src/test/java/com/baeldung/springbootsecurity/oauth2server/CustomConfigAuthorizationServerIntegrationTest.java @@ -0,0 +1,75 @@ +package com.baeldung.springbootsecurity.oauth2server; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.security.oauth2.client.DefaultOAuth2ClientContext; +import org.springframework.security.oauth2.client.OAuth2RestTemplate; +import org.springframework.security.oauth2.client.resource.OAuth2AccessDeniedException; +import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails; +import org.springframework.security.oauth2.common.OAuth2AccessToken; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + +import static java.lang.String.format; +import static java.util.Collections.singletonList; +import static org.junit.Assert.assertNotNull; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = RANDOM_PORT, classes = SpringBootAuthorizationServerApplication.class) +@ActiveProfiles("authz") +public class CustomConfigAuthorizationServerIntegrationTest { + + @Value("${local.server.port}") protected int port; + + @Test + public void whenAccessTokenIsRequested_ThenAccessTokenValueIsNotNull() { + ClientCredentialsResourceDetails resourceDetails = getClientCredentialsResourceDetails(); + resourceDetails.setClientId("baeldung"); + resourceDetails.setClientSecret("baeldung"); + resourceDetails.setScope(singletonList("read")); + DefaultOAuth2ClientContext clientContext = new DefaultOAuth2ClientContext(); + OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(resourceDetails, clientContext); + restTemplate.setMessageConverters(singletonList(new MappingJackson2HttpMessageConverter())); + OAuth2AccessToken accessToken = restTemplate.getAccessToken(); + assertNotNull(accessToken); + + } + + @Test(expected = OAuth2AccessDeniedException.class) + public void whenAccessTokenIsRequestedWithInvalidException_ThenExceptionIsThrown() { + ClientCredentialsResourceDetails resourceDetails = getClientCredentialsResourceDetails(); + resourceDetails.setClientId("baeldung"); + resourceDetails.setClientSecret("baeldung"); + resourceDetails.setScope(singletonList("write")); + DefaultOAuth2ClientContext clientContext = new DefaultOAuth2ClientContext(); + OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(resourceDetails, clientContext); + restTemplate.setMessageConverters(singletonList(new MappingJackson2HttpMessageConverter())); + restTemplate.getAccessToken(); + } + + @Test + public void whenAccessTokenIsRequestedByClientWithWriteScope_ThenAccessTokenIsNotNull() { + ClientCredentialsResourceDetails resourceDetails = getClientCredentialsResourceDetails(); + resourceDetails.setClientId("baeldung-admin"); + resourceDetails.setClientSecret("baeldung"); + resourceDetails.setScope(singletonList("write")); + DefaultOAuth2ClientContext clientContext = new DefaultOAuth2ClientContext(); + OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(resourceDetails, clientContext); + restTemplate.setMessageConverters(singletonList(new MappingJackson2HttpMessageConverter())); + OAuth2AccessToken accessToken = restTemplate.getAccessToken(); + assertNotNull(accessToken); + } + + private ClientCredentialsResourceDetails getClientCredentialsResourceDetails() { + ClientCredentialsResourceDetails resourceDetails = new ClientCredentialsResourceDetails(); + resourceDetails.setAccessTokenUri(format("http://localhost:%d/oauth/token", port)); + resourceDetails.setGrantType("client_credentials"); + return resourceDetails; + } + +} + diff --git a/spring-boot-security/src/test/java/com/baeldung/springbootsecurity/oauth2server/DefaultConfigAuthorizationServerIntegrationTest.java b/spring-boot-security/src/test/java/com/baeldung/springbootsecurity/oauth2server/DefaultConfigAuthorizationServerIntegrationTest.java new file mode 100644 index 0000000000..c7b1b4ef6c --- /dev/null +++ b/spring-boot-security/src/test/java/com/baeldung/springbootsecurity/oauth2server/DefaultConfigAuthorizationServerIntegrationTest.java @@ -0,0 +1,44 @@ +package com.baeldung.springbootsecurity.oauth2server; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.security.oauth2.client.DefaultOAuth2ClientContext; +import org.springframework.security.oauth2.client.OAuth2RestTemplate; +import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails; +import org.springframework.security.oauth2.common.OAuth2AccessToken; +import org.springframework.test.context.junit4.SpringRunner; + +import static java.lang.String.format; +import static java.util.Arrays.asList; +import static java.util.Collections.singletonList; +import static org.junit.Assert.assertNotNull; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = RANDOM_PORT, classes = SpringBootAuthorizationServerApplication.class, + properties = { "security.oauth2.client.client-id=client", "security.oauth2.client.client-secret=secret" }) +public class DefaultConfigAuthorizationServerIntegrationTest { + + @Value("${local.server.port}") protected int port; + + @Test + public void whenAccessTokenIsRequested_ThenAccessTokenValueIsNotNull() { + ClientCredentialsResourceDetails resourceDetails = new ClientCredentialsResourceDetails(); + resourceDetails.setAccessTokenUri(format("http://localhost:%d/oauth/token", port)); + resourceDetails.setClientId("client"); + resourceDetails.setClientSecret("secret"); + resourceDetails.setGrantType("client_credentials"); + resourceDetails.setScope(asList("read", "write")); + DefaultOAuth2ClientContext clientContext = new DefaultOAuth2ClientContext(); + OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(resourceDetails, clientContext); + restTemplate.setMessageConverters(singletonList(new MappingJackson2HttpMessageConverter())); + OAuth2AccessToken accessToken = restTemplate.getAccessToken(); + assertNotNull(accessToken); + + } + +} + From c12ba1bf26907c66b3a38a2f883c7e42218172f6 Mon Sep 17 00:00:00 2001 From: abirkhan04 Date: Tue, 16 Jan 2018 22:02:54 +0600 Subject: [PATCH 22/65] Spring-cloud-security project is added here. --- spring-cloud-security/README.md | 29 +++++ spring-cloud-security/alias.rtf | 28 +++++ spring-cloud-security/authserver/pom.xml | 42 ++++++++ .../com/cloudsecurity/auth/AuthServer.java | 15 +++ .../auth/config/AuthServerConfigurer.java | 77 +++++++++++++ .../auth/config/ResourceServerConfigurer.java | 24 +++++ .../auth/config/WebMvcConfigurer.java | 15 +++ .../auth/config/WebSecurityConfigurer.java | 56 ++++++++++ .../auth/controller/ResourceController.java | 20 ++++ .../src/main/resources/application.yml | 21 ++++ .../main/resources/certificate/mykeystore.jks | Bin 0 -> 2255 bytes .../src/main/resources/templates/login.html | 29 +++++ spring-cloud-security/mykeystore.jks | Bin 0 -> 2255 bytes spring-cloud-security/personservice.zip | Bin 0 -> 50761 bytes spring-cloud-security/personservice/pom.xml | 74 +++++++++++++ .../com/baeldung/service/model/Person.java | 51 +++++++++ .../PersonserviceApplication.java | 12 +++ .../config/ResourceConfigurer.java | 25 +++++ .../controller/PersonInfoController.java | 31 ++++++ .../src/main/resources/application.properties | 0 .../src/main/resources/application.yml | 25 +++++ .../PersonserviceApplicationTests.java | 16 +++ spring-cloud-security/pubkey.txt | 30 ++++++ .../springoath2client/pom.xml | 102 ++++++++++++++++++ .../com/cloud/springwebsite/CloudSite.java | 24 +++++ .../config/SiteSecurityConfigurer.java | 49 +++++++++ .../controller/CloudSiteController.java | 39 +++++++ .../cloudsite/filters/pre/SimpleFilter.java | 39 +++++++ .../src/main/resources/application.properties | 0 .../src/main/resources/application.yml | 37 +++++++ .../src/main/resources/static/index.html | 60 +++++++++++ .../main/resources/templates/personinfo.html | 32 ++++++ .../Springoath2ApplicationTests.java | 16 +++ 33 files changed, 1018 insertions(+) create mode 100644 spring-cloud-security/README.md create mode 100644 spring-cloud-security/alias.rtf create mode 100644 spring-cloud-security/authserver/pom.xml create mode 100644 spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/AuthServer.java create mode 100644 spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/AuthServerConfigurer.java create mode 100644 spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/ResourceServerConfigurer.java create mode 100644 spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/WebMvcConfigurer.java create mode 100644 spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/WebSecurityConfigurer.java create mode 100644 spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/controller/ResourceController.java create mode 100644 spring-cloud-security/authserver/src/main/resources/application.yml create mode 100644 spring-cloud-security/authserver/src/main/resources/certificate/mykeystore.jks create mode 100644 spring-cloud-security/authserver/src/main/resources/templates/login.html create mode 100644 spring-cloud-security/mykeystore.jks create mode 100644 spring-cloud-security/personservice.zip create mode 100644 spring-cloud-security/personservice/pom.xml create mode 100644 spring-cloud-security/personservice/src/main/java/com/baeldung/service/model/Person.java create mode 100644 spring-cloud-security/personservice/src/main/java/com/baeldung/service/personservice/PersonserviceApplication.java create mode 100644 spring-cloud-security/personservice/src/main/java/com/baeldung/service/personservice/config/ResourceConfigurer.java create mode 100644 spring-cloud-security/personservice/src/main/java/com/baeldung/service/personservice/controller/PersonInfoController.java create mode 100644 spring-cloud-security/personservice/src/main/resources/application.properties create mode 100644 spring-cloud-security/personservice/src/main/resources/application.yml create mode 100644 spring-cloud-security/personservice/src/test/java/com/baeldung/service/personservice/PersonserviceApplicationTests.java create mode 100644 spring-cloud-security/pubkey.txt create mode 100644 spring-cloud-security/springoath2client/pom.xml create mode 100644 spring-cloud-security/springoath2client/src/main/java/com/cloud/springwebsite/CloudSite.java create mode 100644 spring-cloud-security/springoath2client/src/main/java/com/cloud/springwebsite/config/SiteSecurityConfigurer.java create mode 100644 spring-cloud-security/springoath2client/src/main/java/com/cloud/springwebsite/controller/CloudSiteController.java create mode 100644 spring-cloud-security/springoath2client/src/main/java/com/cloudsite/filters/pre/SimpleFilter.java create mode 100644 spring-cloud-security/springoath2client/src/main/resources/application.properties create mode 100644 spring-cloud-security/springoath2client/src/main/resources/application.yml create mode 100644 spring-cloud-security/springoath2client/src/main/resources/static/index.html create mode 100644 spring-cloud-security/springoath2client/src/main/resources/templates/personinfo.html create mode 100644 spring-cloud-security/springoath2client/src/test/java/com/example/springoath2/Springoath2ApplicationTests.java diff --git a/spring-cloud-security/README.md b/spring-cloud-security/README.md new file mode 100644 index 0000000000..39af52c077 --- /dev/null +++ b/spring-cloud-security/README.md @@ -0,0 +1,29 @@ +# README # + +This README would normally document whatever steps are necessary to get your application up and running. + +### What is this repository for? ### + +* Quick summary +* Version +* [Learn Markdown](https://bitbucket.org/tutorials/markdowndemo) + +### How do I get set up? ### + +* Summary of set up +* Configuration +* Dependencies +* Database configuration +* How to run tests +* Deployment instructions + +### Contribution guidelines ### + +* Writing tests +* Code review +* Other guidelines + +### Who do I talk to? ### + +* Repo owner or admin +* Other community or team contact \ No newline at end of file diff --git a/spring-cloud-security/alias.rtf b/spring-cloud-security/alias.rtf new file mode 100644 index 0000000000..15509e1c83 --- /dev/null +++ b/spring-cloud-security/alias.rtf @@ -0,0 +1,28 @@ +myauthkey + + +security: + oauth2: + resource: + jwt: + keyValue: | + -----BEGIN PUBLIC KEY----- + MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjj4JDMgT4OoaXisEd8Nz + uiLwum9mh8BH1l9Atpe+uZkepf3Vnv0Bhxn0BGR+kYGwEHZPVpWsHEyTfIRdinaQ + vlPaxWJquQW25yYstrCuQTKJvFjSO/cX/V4OGi1RUj76mOpwzkm1Kui3R7Sfh8Zo + WO0GiWIFJqNBsZ9b1wOfBMXnge+A+u/qxVNnTFpwCVj6k2Yb4YUsmLNCmND7E3Ra + BnrNQWqMU2numhV+ADpmVH08m/+pWdZ896uYu/tvQnz3agvZPcFsEst7LcNAWQFT + eNLkfwVfepKWa9jPELemtTLf1MkMppU+Lj1UNCr8x4Y6EupRDZhplVNtqYsPNDpO + 7wIDAQAB + -----END PUBLIC KEY----- + + + +jwt: + certificate: + store: + file: classpath:/certificate/my-auth-server.jks + password: storepassword + key: + alias: myauthserver + password: keypassword \ No newline at end of file diff --git a/spring-cloud-security/authserver/pom.xml b/spring-cloud-security/authserver/pom.xml new file mode 100644 index 0000000000..ab30f3f2ec --- /dev/null +++ b/spring-cloud-security/authserver/pom.xml @@ -0,0 +1,42 @@ + + + 4.0.0 + + com.baeldung + auth-server + 0.0.1-SNAPSHOT + + + + org.springframework.boot + spring-boot-starter-parent + 1.5.9.RELEASE + + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-devtools + true + + + org.springframework.boot + spring-boot-starter-tomcat + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + org.springframework.cloud + spring-cloud-starter-oauth2 + 1.1.2.RELEASE + + + \ No newline at end of file diff --git a/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/AuthServer.java b/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/AuthServer.java new file mode 100644 index 0000000000..33b2391437 --- /dev/null +++ b/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/AuthServer.java @@ -0,0 +1,15 @@ +package com.cloudsecurity.auth; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.*; + + +@SpringBootApplication +public class AuthServer { + + public static void main(String[] args) { + // TODO Auto-generated method stub + SpringApplication.run( + AuthServer.class, args); + } +} \ No newline at end of file diff --git a/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/AuthServerConfigurer.java b/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/AuthServerConfigurer.java new file mode 100644 index 0000000000..78bae59b7d --- /dev/null +++ b/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/AuthServerConfigurer.java @@ -0,0 +1,77 @@ +package com.cloudsecurity.auth.config; + +import java.security.KeyPair; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.annotation.Order; +import org.springframework.core.io.Resource; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer; +import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter; +import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; +import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer; +import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; +import org.springframework.security.oauth2.provider.token.store.KeyStoreKeyFactory; + +@Configuration +@EnableAuthorizationServer +@Order(6) +public class AuthServerConfigurer + extends + AuthorizationServerConfigurerAdapter { + + @Value("${jwt.certificate.store.file}") + private Resource keystore; + + @Value("${jwt.certificate.store.password}") + private String keystorePassword; + + @Value("${jwt.certificate.key.alias}") + private String keyAlias; + + @Value("${jwt.certificate.key.password}") + private String keyPassword; + + @Autowired + private UserDetailsService userDetailsService; + + @Override + public void configure( + ClientDetailsServiceConfigurer clients) + throws Exception { + clients + .inMemory() + .withClient("authserver") + .secret("passwordforauthserver") + .redirectUris("http://localhost:8080/") + .authorizedGrantTypes("authorization_code", + "refresh_token") + .scopes("myscope") + .autoApprove(true) + .accessTokenValiditySeconds(30) + .refreshTokenValiditySeconds(1800); + } + + @Override + public void configure( + AuthorizationServerEndpointsConfigurer endpoints) + throws Exception { + endpoints + .accessTokenConverter(jwtAccessTokenConverter()) + .userDetailsService(userDetailsService); + } + + @Bean + public JwtAccessTokenConverter jwtAccessTokenConverter() { + KeyStoreKeyFactory keyStoreKeyFactory = new KeyStoreKeyFactory( + keystore, keystorePassword.toCharArray()); + KeyPair keyPair = keyStoreKeyFactory.getKeyPair( + keyAlias, keyPassword.toCharArray()); + JwtAccessTokenConverter converter = new JwtAccessTokenConverter(); + converter.setKeyPair(keyPair); + return converter; + } +} \ No newline at end of file diff --git a/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/ResourceServerConfigurer.java b/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/ResourceServerConfigurer.java new file mode 100644 index 0000000000..06a4679f8b --- /dev/null +++ b/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/ResourceServerConfigurer.java @@ -0,0 +1,24 @@ +package com.cloudsecurity.auth.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; +import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; + +/** + * Our configuration for the OAuth2 User Info Resource Server. + */ +@Configuration +@EnableResourceServer +public class ResourceServerConfigurer extends ResourceServerConfigurerAdapter { + + + + @Override + public void configure(HttpSecurity http) throws Exception { + http.antMatcher("/user") + .authorizeRequests() + .anyRequest() + .authenticated(); + } +} diff --git a/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/WebMvcConfigurer.java b/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/WebMvcConfigurer.java new file mode 100644 index 0000000000..839908fcc2 --- /dev/null +++ b/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/WebMvcConfigurer.java @@ -0,0 +1,15 @@ +package com.cloudsecurity.auth.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; + + +@Configuration +public class WebMvcConfigurer extends WebMvcConfigurerAdapter { + + @Override + public void addViewControllers(ViewControllerRegistry registry) { + registry.addViewController("login").setViewName("login"); + } +} diff --git a/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/WebSecurityConfigurer.java b/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/WebSecurityConfigurer.java new file mode 100644 index 0000000000..eb81e65196 --- /dev/null +++ b/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/WebSecurityConfigurer.java @@ -0,0 +1,56 @@ +package com.cloudsecurity.auth.config; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +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.core.userdetails.UserDetailsService; +import org.springframework.security.oauth2.client.OAuth2ClientContext; +import org.springframework.security.oauth2.config.annotation.web.configuration.EnableOAuth2Client; + +@Configuration +@EnableWebSecurity +@EnableOAuth2Client +public class WebSecurityConfigurer + extends + WebSecurityConfigurerAdapter { + + @Autowired + private OAuth2ClientContext oauth2ClientContext; + + @Override + protected void configure(HttpSecurity http) + throws Exception { + http + .authorizeRequests() + .antMatchers("/login**").permitAll() + .anyRequest().authenticated() + .and().csrf() + .and().formLogin().loginPage("/login"); + } + + @Override + protected void configure( + AuthenticationManagerBuilder auth) throws Exception { + auth + .inMemoryAuthentication() + .withUser("user").password("user") + .roles("USER") + .and() + .withUser("admin").password("admin") + .roles("USER", "ADMIN"); + } + + @Override + @Bean(name = "userDetailsService") + public UserDetailsService userDetailsServiceBean() + throws Exception { + return super.userDetailsServiceBean(); + } + + +} \ No newline at end of file diff --git a/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/controller/ResourceController.java b/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/controller/ResourceController.java new file mode 100644 index 0000000000..684181fcbb --- /dev/null +++ b/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/controller/ResourceController.java @@ -0,0 +1,20 @@ +package com.cloudsecurity.auth.controller; + +import java.security.Principal; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * Because this application is also a User Info Resource Server, we expose info about the logged in user at: + * + * http://localhost:9090/auth/user + */ +@RestController +public class ResourceController { + + @RequestMapping("/user") + public Principal user(Principal user) { + return user; + } + +} diff --git a/spring-cloud-security/authserver/src/main/resources/application.yml b/spring-cloud-security/authserver/src/main/resources/application.yml new file mode 100644 index 0000000000..1dc63d3f0e --- /dev/null +++ b/spring-cloud-security/authserver/src/main/resources/application.yml @@ -0,0 +1,21 @@ +# Make the application available at http://localhost:7070/authserver +server: + port: 7070 + contextPath: /authserver + +# Our certificate settings for enabling JWT tokens +jwt: + certificate: + store: + file: classpath:/certificate/mykeystore.jks + password: abirkhan04 + key: + alias: myauthkey + password: abirkhan04 + + +security: + oauth2: + resource: + filter-order: 3 + \ No newline at end of file diff --git a/spring-cloud-security/authserver/src/main/resources/certificate/mykeystore.jks b/spring-cloud-security/authserver/src/main/resources/certificate/mykeystore.jks new file mode 100644 index 0000000000000000000000000000000000000000..9cf25e32249812febce1d7d829885bb575018e1d GIT binary patch literal 2255 zcmc(g`8$*i7su~=hOwJ6b`uIyJgR%fHY9slk_jPMC(8^*vP?y*$;g&TwiFT-!&oMY z>{^gzO4=-GG1jp}Wo&s~J=gWV*Yh8|Kb#*vpP$b4J?A=SV|HT}007u#f&Y|9Xf%-; zMGgsw-ZZ|c2yr<85QITAfelC!A^H~r6ackgTR~6|5TFT6SGFInS~D}!mckURzCxe# zGjUqg$L;Vh<_+9z4BQ_jow{#7ocA?`e8C#7^-!@`xMzmKi7Ec(-ej$fqzHq%FS56@ z^t~rK3RPyK!yjw4X)-#QjoG^u4|32YjQnVo?%30Kt;B_%`cQt@P)@|mYHo;8iYsFK zxldHl`TNtlSP@%_5Ig*LSj;xnNwoX2qsfe|+}SreHX2`-R(42fSnplD9M2J)b`&+Y zymlDKIpWdB?l)zjxIw2fk^Q``qcPY9+?AeU3!t zvUGM&dI`_Ulhh-yO;>gX2cujHT`867Cikj_kk?HT9OqaK;?&_lU_>DcV4NelUp z9m0D*9OsycI1i@!#l$XWb=1qNXZxNeYwtn~HDL1H*saHCE;XssahYDvSn!~=UQvNN zziH>;PS}hzEI#LF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H=E)rMJ9vT8-$<7KL@`M#XQ?~098dDt6{(1R>#HeWC9a%ypBY?Bn6PRL zO~-oNE?asiM^9I!8fe2>9Zje6+$Zm~FQ5~zAUVq3Wntr{gks5P?o%1dOD)rBE~*#Q zeyG`0oU(fVf-s8Hvre8C+tHc4V4F4Coy + + + + Baeldung Spring cloud Security + + + +

Login

+ + +
+
+

Username and Password:

+

+ + +

+

+ + +

+

+ +

+
+
+ + \ No newline at end of file diff --git a/spring-cloud-security/mykeystore.jks b/spring-cloud-security/mykeystore.jks new file mode 100644 index 0000000000000000000000000000000000000000..9cf25e32249812febce1d7d829885bb575018e1d GIT binary patch literal 2255 zcmc(g`8$*i7su~=hOwJ6b`uIyJgR%fHY9slk_jPMC(8^*vP?y*$;g&TwiFT-!&oMY z>{^gzO4=-GG1jp}Wo&s~J=gWV*Yh8|Kb#*vpP$b4J?A=SV|HT}007u#f&Y|9Xf%-; zMGgsw-ZZ|c2yr<85QITAfelC!A^H~r6ackgTR~6|5TFT6SGFInS~D}!mckURzCxe# zGjUqg$L;Vh<_+9z4BQ_jow{#7ocA?`e8C#7^-!@`xMzmKi7Ec(-ej$fqzHq%FS56@ z^t~rK3RPyK!yjw4X)-#QjoG^u4|32YjQnVo?%30Kt;B_%`cQt@P)@|mYHo;8iYsFK zxldHl`TNtlSP@%_5Ig*LSj;xnNwoX2qsfe|+}SreHX2`-R(42fSnplD9M2J)b`&+Y zymlDKIpWdB?l)zjxIw2fk^Q``qcPY9+?AeU3!t zvUGM&dI`_Ulhh-yO;>gX2cujHT`867Cikj_kk?HT9OqaK;?&_lU_>DcV4NelUp z9m0D*9OsycI1i@!#l$XWb=1qNXZxNeYwtn~HDL1H*saHCE;XssahYDvSn!~=UQvNN zziH>;PS}hzEI#LFPh{c2P-dm;^2(yRm$Q?kw|JPR6TKbgp}WLZeLzq$?_^6^BwgLt ztE`r_Io^Hms@J#xiGi)oi z@5LwnOkl?~X7RF|_h59Xn$5gTq zxk5Mb4ymikKKpSyN$gz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3I5c5LT;N*+=~FJ%S%FY zz)J8!<|)XBeKmZ*80P!Df0RYZ?DgUMIuL|z3bpKCL_tEZ`ZmbUj zf7kuDqV=x;nEx=~7eMmg1OBLb{|fZaBl!gi`WMizknmUSQGYX}@!z)pTS)mU2-a_q zlm86)TU`1p(wE;zL{NY3*nf?1e?=qvji&$qK>J6${3|ToZ`jiR2Kz@C{wqAsZ}`Xm z3;uU+{3~U6zbR9K{*N90&!G5MxZm9=@!#V97Wn=O^1C~Y{%6R4=}y2f|L*91kHddu z*YEDc_y0iqKe$uqe}nz+-D&avg8xtM^!LCzIg0CTON>_h<6&UX(5Gl&#?Zf nrNCF9{og71{W||Y9_~N$Eg5kT&|gY1K3?e`=}Ah*udV+Nfq1kU literal 0 HcmV?d00001 diff --git a/spring-cloud-security/personservice/pom.xml b/spring-cloud-security/personservice/pom.xml new file mode 100644 index 0000000000..74bd67d031 --- /dev/null +++ b/spring-cloud-security/personservice/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + com.baeldung.service + personservice + 0.0.1-SNAPSHOT + jar + + personservice + Demo project for Spring Boot + + + org.springframework.boot + spring-boot-starter-parent + 1.5.8.RELEASE + + + + + UTF-8 + UTF-8 + 1.8 + Edgware.RELEASE + + + + + org.springframework.security.oauth + spring-security-oauth2 + + + org.springframework.cloud + spring-cloud-starter-security + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.security + spring-security-jwt + + + com.google.code.gson + gson + + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + diff --git a/spring-cloud-security/personservice/src/main/java/com/baeldung/service/model/Person.java b/spring-cloud-security/personservice/src/main/java/com/baeldung/service/model/Person.java new file mode 100644 index 0000000000..58e36faaa7 --- /dev/null +++ b/spring-cloud-security/personservice/src/main/java/com/baeldung/service/model/Person.java @@ -0,0 +1,51 @@ +package com.baeldung.service.model; + +public class Person { + + private String name; + private String city; + private String country; + private Integer age; + private String sex; + + public Person(String name, String city, String country, Integer age, String sex){ + this.name = name; + this.city = city; + this.country = country; + this.age = age; + this.sex = sex; + } + + + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public String getCity() { + return city; + } + public void setCity(String city) { + this.city = city; + } + public String getCountry() { + return country; + } + public void setCountry(String country) { + this.country = country; + } + public Integer getAge() { + return age; + } + public void setAge(Integer age) { + this.age = age; + } + public String getSex() { + return sex; + } + public void setSex(String sex) { + this.sex = sex; + } + +} \ No newline at end of file diff --git a/spring-cloud-security/personservice/src/main/java/com/baeldung/service/personservice/PersonserviceApplication.java b/spring-cloud-security/personservice/src/main/java/com/baeldung/service/personservice/PersonserviceApplication.java new file mode 100644 index 0000000000..0fc14db64f --- /dev/null +++ b/spring-cloud-security/personservice/src/main/java/com/baeldung/service/personservice/PersonserviceApplication.java @@ -0,0 +1,12 @@ +package com.baeldung.service.personservice; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class PersonserviceApplication { + + public static void main(String[] args) { + SpringApplication.run(PersonserviceApplication.class, args); + } +} \ No newline at end of file diff --git a/spring-cloud-security/personservice/src/main/java/com/baeldung/service/personservice/config/ResourceConfigurer.java b/spring-cloud-security/personservice/src/main/java/com/baeldung/service/personservice/config/ResourceConfigurer.java new file mode 100644 index 0000000000..807aa95736 --- /dev/null +++ b/spring-cloud-security/personservice/src/main/java/com/baeldung/service/personservice/config/ResourceConfigurer.java @@ -0,0 +1,25 @@ +package com.baeldung.service.personservice.config; + +import org.springframework.context.annotation.Configuration; +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.configuration.EnableWebSecurity; +import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; +import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; + +/** + * REST API Resource Server. + */ +@Configuration +@EnableWebSecurity +@EnableResourceServer +@EnableGlobalMethodSecurity(prePostEnabled = true) // Allow method annotations like @PreAuthorize +public class ResourceConfigurer extends ResourceServerConfigurerAdapter { + + @Override + public void configure(HttpSecurity http) throws Exception { + http.httpBasic().disable(); + http.authorizeRequests().anyRequest().authenticated(); + } + +} diff --git a/spring-cloud-security/personservice/src/main/java/com/baeldung/service/personservice/controller/PersonInfoController.java b/spring-cloud-security/personservice/src/main/java/com/baeldung/service/personservice/controller/PersonInfoController.java new file mode 100644 index 0000000000..59351ed621 --- /dev/null +++ b/spring-cloud-security/personservice/src/main/java/com/baeldung/service/personservice/controller/PersonInfoController.java @@ -0,0 +1,31 @@ +package com.baeldung.service.personservice.controller; + +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; + +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +import com.baeldung.service.model.Person; +import com.google.gson.Gson; + +@RestController +public class PersonInfoController { + + @RequestMapping(value = "/currenttime") + @PreAuthorize("hasAnyRole('ADMIN', 'USER')") + public String currentTime(){ + return LocalTime.now().format(DateTimeFormatter.ISO_LOCAL_TIME); + } + + + @RequestMapping(value = "/person") + @PreAuthorize("hasAnyRole('ADMIN', 'USER')") + public @ResponseBody String personInfo(){ + Gson gson = new Gson(); + String person = gson.toJson(new Person("abir","Dhaka", "Bangladesh",29,"Male")); + return person; + } +} \ No newline at end of file diff --git a/spring-cloud-security/personservice/src/main/resources/application.properties b/spring-cloud-security/personservice/src/main/resources/application.properties new file mode 100644 index 0000000000..e69de29bb2 diff --git a/spring-cloud-security/personservice/src/main/resources/application.yml b/spring-cloud-security/personservice/src/main/resources/application.yml new file mode 100644 index 0000000000..38dc22c2cd --- /dev/null +++ b/spring-cloud-security/personservice/src/main/resources/application.yml @@ -0,0 +1,25 @@ +# Make the application available at http://localhost:9000 +#spring: +# session: +# store-type: redis + +server: + port: 9000 + +# Configure the public key to use for verifying the incoming JWT tokens +security: + sessions: NEVER + oauth2: + resource: + userInfoUri: http://localhost:7070/authserver/user + jwt: + keyValue: | + -----BEGIN PUBLIC KEY----- + MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAhiiifKv6Otf5PyqIE+LQ + EiJRRh6q8piPY9Okq+RfRu9Bue0D8hq7aFxcgkLZ6Bg9CAS+w1KdaE5MMeOCVVxv + rpRETzVpAsh6GL5nBc679jSqMzjr3V4uty46ilL4VHKSxlZh5Nmz5EMHPI5iwpNs + 8U5n3QiwsTk514FXad54xPSPH3i/pDzGSZHrVcwDVaOKn7gFiIqP86vkJB47JZv8 + T6P5RK7Rj06zoG45DMGWG3DQv6o1/Jm4IJQWj0AUD3bSHqzXkPr7qyMYvkE4kyMH + 6aVAsAYMxilZFlJMv2b8N883gdi3LEeOJo8zZr5IWyyROfepdeOL7UkAXddAj+dL + WQIDAQAB + -----END PUBLIC KEY----- \ No newline at end of file diff --git a/spring-cloud-security/personservice/src/test/java/com/baeldung/service/personservice/PersonserviceApplicationTests.java b/spring-cloud-security/personservice/src/test/java/com/baeldung/service/personservice/PersonserviceApplicationTests.java new file mode 100644 index 0000000000..6e246bc363 --- /dev/null +++ b/spring-cloud-security/personservice/src/test/java/com/baeldung/service/personservice/PersonserviceApplicationTests.java @@ -0,0 +1,16 @@ +package com.baeldung.service.personservice; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class PersonserviceApplicationTests { + + @Test + public void contextLoads() { + } + +} diff --git a/spring-cloud-security/pubkey.txt b/spring-cloud-security/pubkey.txt new file mode 100644 index 0000000000..2c391ba2dd --- /dev/null +++ b/spring-cloud-security/pubkey.txt @@ -0,0 +1,30 @@ +-----BEGIN PUBLIC KEY----- +MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQ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K7Rj06zoG45DMGWG3DQv6o1/Jm4IJQWj0AUD3bSHqzXkPr7qyMY +vkE4kyMH6aVAsAYMxilZFlJMv2b8N883gdi3LEeOJo8zZr5IWyyROfepdeOL7UkA +XddAj+dLWQIDAQABoyEwHzAdBgNVHQ4EFgQUHLFYkq36Wami5qsVRe/1eQedmdgw +DQYJKoZIhvcNAQELBQADggEBABL3lYyuRd6Hv8DPus/zQL0bRl6gVsEzczwmWMUA +3NJZbUHAD/KC732aArvKIKykkbLG6K/Mhnfuu8YBfWzTvGgY3Ww+ka2sJFOsUW7r +sa6OBtNHh4zhDYN2Weza+4jnRLxtkzFbm6v2sheFkyB1NywCwFE/6p1Z6KTG8RyJ +gw/OHl6rb+Y/T6cOeeTCFUN/v+qRVSB9I/MjSK5wRNbFT+MyNUeL6gsiyIvxSZbj +y4vrjGHkXasSmwkfvgw67mJMk4XTGrVLjIXUTyzbdSmodcv8N6nrsIk4SBYCnTrI +E/5NtNgbOFGwovde5yNrZIjjAC1VGOmVFhcxFJpwT6ZkSks= +-----END CERTIFICATE----- diff --git a/spring-cloud-security/springoath2client/pom.xml b/spring-cloud-security/springoath2client/pom.xml new file mode 100644 index 0000000000..833a377410 --- /dev/null +++ b/spring-cloud-security/springoath2client/pom.xml @@ -0,0 +1,102 @@ + + + 4.0.0 + com.example + springoath2 + 0.0.1-SNAPSHOT + jar + + springoath2 + Demo project for Spring Boot + + + org.springframework.boot + spring-boot-starter-parent + 1.5.8.RELEASE + + + + + + + org.springframework.cloud + spring-cloud-dependencies + Dalston.SR4 + pom + import + + + + + + + + UTF-8 + UTF-8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.cloud + spring-cloud-starter-oauth2 + + + org.springframework.cloud + spring-cloud-starter-zuul + + + org.springframework.boot + spring-boot-starter-test + test + + + org.webjars + jquery + + + org.webjars + bootstrap + + + org.webjars + webjars-locator + + + + org.springframework.boot + spring-boot-starter-security + + + org.webjars + js-cookie + 2.1.0 + + + + org.springframework.boot + spring-boot-devtools + true + + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + diff --git a/spring-cloud-security/springoath2client/src/main/java/com/cloud/springwebsite/CloudSite.java b/spring-cloud-security/springoath2client/src/main/java/com/cloud/springwebsite/CloudSite.java new file mode 100644 index 0000000000..9cfea2faea --- /dev/null +++ b/spring-cloud-security/springoath2client/src/main/java/com/cloud/springwebsite/CloudSite.java @@ -0,0 +1,24 @@ +package com.cloud.springwebsite; + + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.netflix.zuul.EnableZuulProxy; +import org.springframework.context.annotation.Bean; + +import com.cloudsite.filters.pre.SimpleFilter; + + +@SpringBootApplication +public class CloudSite { + public static void main(String[] args) { + SpringApplication.run(CloudSite.class, args); + } + + + @Bean + public SimpleFilter simpleFilter() { + return new SimpleFilter(); + } + +} diff --git a/spring-cloud-security/springoath2client/src/main/java/com/cloud/springwebsite/config/SiteSecurityConfigurer.java b/spring-cloud-security/springoath2client/src/main/java/com/cloud/springwebsite/config/SiteSecurityConfigurer.java new file mode 100644 index 0000000000..af002080be --- /dev/null +++ b/spring-cloud-security/springoath2client/src/main/java/com/cloud/springwebsite/config/SiteSecurityConfigurer.java @@ -0,0 +1,49 @@ +package com.cloud.springwebsite.config; + +import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso; +import org.springframework.cloud.netflix.zuul.EnableZuulProxy; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.oauth2.client.OAuth2ClientContext; +import org.springframework.security.oauth2.client.OAuth2RestOperations; +import org.springframework.security.oauth2.client.OAuth2RestTemplate; +import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails; +import org.springframework.security.web.csrf.CookieCsrfTokenRepository; + +@EnableZuulProxy +@Configuration +@EnableOAuth2Sso +public class SiteSecurityConfigurer + extends + WebSecurityConfigurerAdapter { + + @Override + protected void configure(HttpSecurity http) + throws Exception { + http.antMatcher("/**") + .authorizeRequests() + .antMatchers("/", "/webjars/**") + .permitAll() + .anyRequest() + .authenticated() + .and() + .logout() + .logoutSuccessUrl("/") + .permitAll() + .and() + .csrf() + .csrfTokenRepository( + CookieCsrfTokenRepository + .withHttpOnlyFalse()); + } + + @Bean + public OAuth2RestOperations restOperations( + OAuth2ProtectedResourceDetails resource, + OAuth2ClientContext context) { + return new OAuth2RestTemplate(resource, context); + } + +} diff --git a/spring-cloud-security/springoath2client/src/main/java/com/cloud/springwebsite/controller/CloudSiteController.java b/spring-cloud-security/springoath2client/src/main/java/com/cloud/springwebsite/controller/CloudSiteController.java new file mode 100644 index 0000000000..829648b43f --- /dev/null +++ b/spring-cloud-security/springoath2client/src/main/java/com/cloud/springwebsite/controller/CloudSiteController.java @@ -0,0 +1,39 @@ +package com.cloud.springwebsite.controller; + +import java.net.URI; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.RestOperations; +import org.springframework.web.servlet.ModelAndView; + +@RestController +public class CloudSiteController { + + @Autowired + private RestOperations restOperations; + + + @Value("${person.url}") + private String personUrl; + + + @RequestMapping("/") + @ResponseBody + public String helloFromBaeldung() { + return "Hello From Baeldung!"; + } + + + @RequestMapping("/person") + public ModelAndView person(){ + ModelAndView mav = new ModelAndView("personinfo"); + mav.addObject("person",restOperations.getForObject(personUrl, String.class)); + return mav; + } + +} \ No newline at end of file diff --git a/spring-cloud-security/springoath2client/src/main/java/com/cloudsite/filters/pre/SimpleFilter.java b/spring-cloud-security/springoath2client/src/main/java/com/cloudsite/filters/pre/SimpleFilter.java new file mode 100644 index 0000000000..e9412b5ab6 --- /dev/null +++ b/spring-cloud-security/springoath2client/src/main/java/com/cloudsite/filters/pre/SimpleFilter.java @@ -0,0 +1,39 @@ +package com.cloudsite.filters.pre; + +import javax.servlet.http.HttpServletRequest; +import com.netflix.zuul.context.RequestContext; +import com.netflix.zuul.ZuulFilter; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SimpleFilter extends ZuulFilter { + + private static Logger log = LoggerFactory.getLogger(SimpleFilter.class); + + @Override + public String filterType() { + return "pre"; + } + + @Override + public int filterOrder() { + return 1; + } + + @Override + public boolean shouldFilter() { + return true; + } + + @Override + public Object run() { + RequestContext ctx = RequestContext.getCurrentContext(); + HttpServletRequest request = ctx.getRequest(); + + log.info(String.format("%s request to %s", request.getMethod(), request.getRequestURL().toString())); + + return null; + } + +} \ No newline at end of file diff --git a/spring-cloud-security/springoath2client/src/main/resources/application.properties b/spring-cloud-security/springoath2client/src/main/resources/application.properties new file mode 100644 index 0000000000..e69de29bb2 diff --git a/spring-cloud-security/springoath2client/src/main/resources/application.yml b/spring-cloud-security/springoath2client/src/main/resources/application.yml new file mode 100644 index 0000000000..06a950d270 --- /dev/null +++ b/spring-cloud-security/springoath2client/src/main/resources/application.yml @@ -0,0 +1,37 @@ +# Make the application available at http://localhost:8080 +# These are default settings, but we add them for clarity. +server: + port: 8080 + contextPath: / + +# Configure the Authorization Server and User Info Resource Server details +security: + oauth2: + client: + accessTokenUri: http://localhost:7070/authserver/oauth/token + userAuthorizationUri: http://localhost:7070/authserver/oauth/authorize + clientId: authserver + clientSecret: passwordforauthserver + resource: + userInfoUri: http://localhost:7070/authserver/user + +person: + url: http://localhost:9000/person + +# Proxies the calls to http://localhost:8080/api/* to our REST service at http://localhost:8081/* +# and automatically includes our OAuth2 token in the request headers +zuul: + routes: + resource: + path: /api/** + url: http://localhost:9000 + user: + path: /user/** + url: http://localhost:7070/authserver/user + +# Make sure the OAuth2 token is only relayed when using the internal API, +# do not pass any authentication to the external API +proxy: + auth: + routes: + api: oauth2 \ No newline at end of file diff --git a/spring-cloud-security/springoath2client/src/main/resources/static/index.html b/spring-cloud-security/springoath2client/src/main/resources/static/index.html new file mode 100644 index 0000000000..f304980bb1 --- /dev/null +++ b/spring-cloud-security/springoath2client/src/main/resources/static/index.html @@ -0,0 +1,60 @@ + + + + + +Demo + + + + + + + + + +

Demo

+
+ With Facebook: click here +
+ + + + + + + \ No newline at end of file diff --git a/spring-cloud-security/springoath2client/src/main/resources/templates/personinfo.html b/spring-cloud-security/springoath2client/src/main/resources/templates/personinfo.html new file mode 100644 index 0000000000..9ed0c3cb4f --- /dev/null +++ b/spring-cloud-security/springoath2client/src/main/resources/templates/personinfo.html @@ -0,0 +1,32 @@ + + + + +My Website - Current time + + + +

Providing Person Information

+

+ Person's information: +

+

+ The current time is: +

+ + + + \ No newline at end of file diff --git a/spring-cloud-security/springoath2client/src/test/java/com/example/springoath2/Springoath2ApplicationTests.java b/spring-cloud-security/springoath2client/src/test/java/com/example/springoath2/Springoath2ApplicationTests.java new file mode 100644 index 0000000000..5fa51a61c3 --- /dev/null +++ b/spring-cloud-security/springoath2client/src/test/java/com/example/springoath2/Springoath2ApplicationTests.java @@ -0,0 +1,16 @@ +package com.example.springoath2; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class Springoath2ApplicationTests { + + @Test + public void contextLoads() { + } + +} From a9d5b406a5da7e5478dacc1f560e5a5cc6c9af1c Mon Sep 17 00:00:00 2001 From: ShyamVeda Date: Wed, 17 Jan 2018 02:21:01 +0530 Subject: [PATCH 23/65] Added port number to response (#3431) --- .../cloud/eureka/client/EurekaClientApplication.java | 7 ++++++- .../eureka-client/src/main/resources/application.yml | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-client/src/main/java/com/baeldung/spring/cloud/eureka/client/EurekaClientApplication.java b/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-client/src/main/java/com/baeldung/spring/cloud/eureka/client/EurekaClientApplication.java index 906d6e4cfd..9bbb121408 100644 --- a/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-client/src/main/java/com/baeldung/spring/cloud/eureka/client/EurekaClientApplication.java +++ b/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-client/src/main/java/com/baeldung/spring/cloud/eureka/client/EurekaClientApplication.java @@ -21,12 +21,17 @@ public class EurekaClientApplication implements GreetingController { @Value("${spring.application.name}") private String appName; + @Value("${server.port}") + private String portNumber; + public static void main(String[] args) { SpringApplication.run(EurekaClientApplication.class, args); } @Override public String greeting() { - return String.format("Hello from '%s'!", eurekaClient.getApplication(appName).getName()); + System.out.println("Request received on port number " + portNumber); + return String.format("Hello from '%s with Port Number %s'!", eurekaClient.getApplication(appName) + .getName(), portNumber); } } diff --git a/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-client/src/main/resources/application.yml b/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-client/src/main/resources/application.yml index 08624aa159..9fa929e16b 100644 --- a/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-client/src/main/resources/application.yml +++ b/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-client/src/main/resources/application.yml @@ -3,7 +3,7 @@ spring: name: spring-cloud-eureka-client server: - port: 0 + port: 8081 eureka: client: From bc8caf3266848c6c6530cfbf2f754d1c0bc395a6 Mon Sep 17 00:00:00 2001 From: abirkhan04 Date: Wed, 17 Jan 2018 16:42:26 +0600 Subject: [PATCH 24/65] 1. Unnecessary file and code removed. 2. Project is relocated to spring-cloud folder --- spring-cloud-security/personservice.zip | Bin 50761 -> 0 bytes .../src/main/resources/static/index.html | 60 ------------------ .../spring-cloud-security}/README.md | 0 .../spring-cloud-security}/alias.rtf | 0 .../spring-cloud-security}/authserver/pom.xml | 0 .../com/cloudsecurity/auth/AuthServer.java | 0 .../auth/config/AuthServerConfigurer.java | 0 .../auth/config/ResourceServerConfigurer.java | 0 .../auth/config/WebMvcConfigurer.java | 0 .../auth/config/WebSecurityConfigurer.java | 4 +- .../auth/controller/ResourceController.java | 0 .../src/main/resources/application.yml | 0 .../main/resources/certificate/mykeystore.jks | Bin .../src/main/resources/templates/login.html | 0 .../spring-cloud-security}/mykeystore.jks | Bin .../personservice/pom.xml | 0 .../com/baeldung/service/model/Person.java | 0 .../PersonserviceApplication.java | 0 .../config/ResourceConfigurer.java | 0 .../controller/PersonInfoController.java | 0 .../src/main/resources/application.properties | 0 .../src/main/resources/application.yml | 0 .../PersonserviceApplicationTests.java | 0 .../spring-cloud-security}/pubkey.txt | 0 .../springoath2client/pom.xml | 0 .../com/cloud/springwebsite/CloudSite.java | 0 .../config/SiteSecurityConfigurer.java | 0 .../controller/CloudSiteController.java | 0 .../cloudsite/filters/pre/SimpleFilter.java | 0 .../src/main/resources/application.properties | 0 .../src/main/resources/application.yml | 0 .../main/resources/templates/personinfo.html | 2 +- .../Springoath2ApplicationTests.java | 0 33 files changed, 3 insertions(+), 63 deletions(-) delete mode 100644 spring-cloud-security/personservice.zip delete mode 100644 spring-cloud-security/springoath2client/src/main/resources/static/index.html rename {spring-cloud-security => spring-cloud/spring-cloud-security}/README.md (100%) rename {spring-cloud-security => spring-cloud/spring-cloud-security}/alias.rtf (100%) rename {spring-cloud-security => spring-cloud/spring-cloud-security}/authserver/pom.xml (100%) rename {spring-cloud-security => spring-cloud/spring-cloud-security}/authserver/src/main/java/com/cloudsecurity/auth/AuthServer.java (100%) rename {spring-cloud-security => spring-cloud/spring-cloud-security}/authserver/src/main/java/com/cloudsecurity/auth/config/AuthServerConfigurer.java (100%) rename {spring-cloud-security => spring-cloud/spring-cloud-security}/authserver/src/main/java/com/cloudsecurity/auth/config/ResourceServerConfigurer.java (100%) rename {spring-cloud-security => spring-cloud/spring-cloud-security}/authserver/src/main/java/com/cloudsecurity/auth/config/WebMvcConfigurer.java (100%) rename {spring-cloud-security => spring-cloud/spring-cloud-security}/authserver/src/main/java/com/cloudsecurity/auth/config/WebSecurityConfigurer.java (96%) rename {spring-cloud-security => spring-cloud/spring-cloud-security}/authserver/src/main/java/com/cloudsecurity/auth/controller/ResourceController.java (100%) rename {spring-cloud-security => spring-cloud/spring-cloud-security}/authserver/src/main/resources/application.yml (100%) rename {spring-cloud-security => spring-cloud/spring-cloud-security}/authserver/src/main/resources/certificate/mykeystore.jks (100%) rename {spring-cloud-security => spring-cloud/spring-cloud-security}/authserver/src/main/resources/templates/login.html (100%) rename {spring-cloud-security => spring-cloud/spring-cloud-security}/mykeystore.jks (100%) rename {spring-cloud-security => spring-cloud/spring-cloud-security}/personservice/pom.xml (100%) rename {spring-cloud-security => spring-cloud/spring-cloud-security}/personservice/src/main/java/com/baeldung/service/model/Person.java (100%) rename {spring-cloud-security => spring-cloud/spring-cloud-security}/personservice/src/main/java/com/baeldung/service/personservice/PersonserviceApplication.java (100%) rename {spring-cloud-security => spring-cloud/spring-cloud-security}/personservice/src/main/java/com/baeldung/service/personservice/config/ResourceConfigurer.java (100%) rename {spring-cloud-security => spring-cloud/spring-cloud-security}/personservice/src/main/java/com/baeldung/service/personservice/controller/PersonInfoController.java (100%) rename {spring-cloud-security => spring-cloud/spring-cloud-security}/personservice/src/main/resources/application.properties (100%) rename {spring-cloud-security => spring-cloud/spring-cloud-security}/personservice/src/main/resources/application.yml (100%) rename {spring-cloud-security => spring-cloud/spring-cloud-security}/personservice/src/test/java/com/baeldung/service/personservice/PersonserviceApplicationTests.java (100%) rename {spring-cloud-security => spring-cloud/spring-cloud-security}/pubkey.txt (100%) rename {spring-cloud-security => spring-cloud/spring-cloud-security}/springoath2client/pom.xml (100%) rename {spring-cloud-security => spring-cloud/spring-cloud-security}/springoath2client/src/main/java/com/cloud/springwebsite/CloudSite.java (100%) rename {spring-cloud-security => spring-cloud/spring-cloud-security}/springoath2client/src/main/java/com/cloud/springwebsite/config/SiteSecurityConfigurer.java (100%) rename {spring-cloud-security => spring-cloud/spring-cloud-security}/springoath2client/src/main/java/com/cloud/springwebsite/controller/CloudSiteController.java (100%) rename {spring-cloud-security => spring-cloud/spring-cloud-security}/springoath2client/src/main/java/com/cloudsite/filters/pre/SimpleFilter.java (100%) rename {spring-cloud-security => spring-cloud/spring-cloud-security}/springoath2client/src/main/resources/application.properties (100%) rename {spring-cloud-security => spring-cloud/spring-cloud-security}/springoath2client/src/main/resources/application.yml (100%) rename {spring-cloud-security => spring-cloud/spring-cloud-security}/springoath2client/src/main/resources/templates/personinfo.html (93%) rename {spring-cloud-security => spring-cloud/spring-cloud-security}/springoath2client/src/test/java/com/example/springoath2/Springoath2ApplicationTests.java (100%) diff --git a/spring-cloud-security/personservice.zip b/spring-cloud-security/personservice.zip deleted file mode 100644 index 9c6c9e2ef583448b52fd8acb7c57d1304bbdc30d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 50761 zcmbTc1C;38x+Pk+ZPzZlcG5%!UO<70zmmcu+}a%u7Cgt|8e$j(Z7*@N41)@MjtO4CQuUJ+q$`VLawon&eyW&H@t>QkwLZPC}|c#@Y4RN~velQ-Ke*kTZ9= zmHZX@w}0EipTzhS9#RHUWbvu=+uMa$(J?J@aZ`J&HzLUWFqe$4M(zGeB@|Jl$@&6w z7$UkDB-G6kNHhVexIr~>_GI}2?Sh^p5sy;OB_8uRa)|UT_$K3ly9a`FKayGI*d^|0 z0`XU$Kj4vZ0T9rNgMdM=P(EWugRS8J?es2kT$G9NVw9SCBe~)UlQHK{Z(i3>g;m&<_S~&CK5(fn@6}i+ zEI9auau%?3-jcweE8DbUlXy-m`-sG_gd(yc<@5floZlL?SM+KboOKX65}2e$#vM-Nm|0lPr5Ikx_j2`hVXb6aEy!@FF}lKbbzEu zNwQTxG1${3-G~c?L^Cjlmue{@Tx6`k(IEd}g=vvX_&A+A6N5xb#2u+Tf1BtZ)9sml zX1eB{X_;PBZ*KV3F2( z5J9JOW(~zUb0s;1><43-CL&guABYo#N2a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c-Be zweFv2g^{SMx?N}&D~qq z5JR-_RBOUn6OE_3F8ryNc-$t;SqURF~5;i3wF000{Q;?wqa`X4E>sTGZxu9Gf} zzO^Ndp01&Vfuof%%^&IX@5!~y|4y}eZEP$|^>rOgt*xkk0e)Q?zx4c)UpjwDU^E?U zFD@a|urMGvU6&%HAAt=Fo3mG^| zJ0Z}Cctth03E$OaMF6Lpepz_qaN`q+A=YC|TN=zf(i20M8?S1}d?Mx7NS&~PVaIvG zd5X=1Ko)SUPRLF9c=KFPXx@ybAuEk-Sef!k_-m2SPzws7`pWX1c=r}a10<&4R|;)jx;|*Q-+S-Z5&X|J4#4uCd(Y0$-rCVl-_V}sqw4ram;7FB{6hVb zKX5>Qst~Lwp9p(C{%-Wqfx7=zm4l(Z!~gFSrSJi<|Hs+-rR z3~=;{#Ie?!f^8-b=LH$|USPFv$Htv!8IIt^Y~lsSFH|Ms3I5c5LT;N*+=~FJ%S%FY zz)J8!<|)XBeKmZ*80P!Df0RYZ?DgUMIuL|z3bpKCL_tEZ`ZmbUj zf7kuDqV=x;nEx=~7eMmg1OBLb{|fZaBl!gi`WMizknmUSQGYX}@!z)pTS)mU2-a_q zlm86)TU`1p(wE;zL{NY3*nf?1e?=qvji&$qK>J6${3|ToZ`jiR2Kz@C{wqAsZ}`Xm z3;uU+{3~U6zbR9K{*N90&!G5MxZm9=@!#V97Wn=O^1C~Y{%6R4=}y2f|L*91kHddu z*YEDc_y0iqKe$uqe}nz+-D&avg8xtM^!LCzIg0CTON>_h<6&UX(5Gl&#?Zf nrNCF9{og71{W||Y9_~N$Eg5kT&|gY1K3?e`=}Ah*udV+Nfq1kU diff --git a/spring-cloud-security/springoath2client/src/main/resources/static/index.html b/spring-cloud-security/springoath2client/src/main/resources/static/index.html deleted file mode 100644 index f304980bb1..0000000000 --- a/spring-cloud-security/springoath2client/src/main/resources/static/index.html +++ /dev/null @@ -1,60 +0,0 @@ - - - - - -Demo - - - - - - - - - -

Demo

-
- With Facebook: click here -
- - - - - - - \ No newline at end of file diff --git a/spring-cloud-security/README.md b/spring-cloud/spring-cloud-security/README.md similarity index 100% rename from spring-cloud-security/README.md rename to spring-cloud/spring-cloud-security/README.md diff --git a/spring-cloud-security/alias.rtf b/spring-cloud/spring-cloud-security/alias.rtf similarity index 100% rename from spring-cloud-security/alias.rtf rename to spring-cloud/spring-cloud-security/alias.rtf diff --git a/spring-cloud-security/authserver/pom.xml b/spring-cloud/spring-cloud-security/authserver/pom.xml similarity index 100% rename from spring-cloud-security/authserver/pom.xml rename to spring-cloud/spring-cloud-security/authserver/pom.xml diff --git a/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/AuthServer.java b/spring-cloud/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/AuthServer.java similarity index 100% rename from spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/AuthServer.java rename to spring-cloud/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/AuthServer.java diff --git a/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/AuthServerConfigurer.java b/spring-cloud/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/AuthServerConfigurer.java similarity index 100% rename from spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/AuthServerConfigurer.java rename to spring-cloud/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/AuthServerConfigurer.java diff --git a/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/ResourceServerConfigurer.java b/spring-cloud/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/ResourceServerConfigurer.java similarity index 100% rename from spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/ResourceServerConfigurer.java rename to spring-cloud/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/ResourceServerConfigurer.java diff --git a/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/WebMvcConfigurer.java b/spring-cloud/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/WebMvcConfigurer.java similarity index 100% rename from spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/WebMvcConfigurer.java rename to spring-cloud/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/WebMvcConfigurer.java diff --git a/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/WebSecurityConfigurer.java b/spring-cloud/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/WebSecurityConfigurer.java similarity index 96% rename from spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/WebSecurityConfigurer.java rename to spring-cloud/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/WebSecurityConfigurer.java index eb81e65196..9014aa4954 100644 --- a/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/WebSecurityConfigurer.java +++ b/spring-cloud/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/WebSecurityConfigurer.java @@ -19,8 +19,8 @@ public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter { - @Autowired - private OAuth2ClientContext oauth2ClientContext; +// @Autowired +// private OAuth2ClientContext oauth2ClientContext; @Override protected void configure(HttpSecurity http) diff --git a/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/controller/ResourceController.java b/spring-cloud/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/controller/ResourceController.java similarity index 100% rename from spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/controller/ResourceController.java rename to spring-cloud/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/controller/ResourceController.java diff --git a/spring-cloud-security/authserver/src/main/resources/application.yml b/spring-cloud/spring-cloud-security/authserver/src/main/resources/application.yml similarity index 100% rename from spring-cloud-security/authserver/src/main/resources/application.yml rename to spring-cloud/spring-cloud-security/authserver/src/main/resources/application.yml diff --git a/spring-cloud-security/authserver/src/main/resources/certificate/mykeystore.jks b/spring-cloud/spring-cloud-security/authserver/src/main/resources/certificate/mykeystore.jks similarity index 100% rename from spring-cloud-security/authserver/src/main/resources/certificate/mykeystore.jks rename to spring-cloud/spring-cloud-security/authserver/src/main/resources/certificate/mykeystore.jks diff --git a/spring-cloud-security/authserver/src/main/resources/templates/login.html b/spring-cloud/spring-cloud-security/authserver/src/main/resources/templates/login.html similarity index 100% rename from spring-cloud-security/authserver/src/main/resources/templates/login.html rename to spring-cloud/spring-cloud-security/authserver/src/main/resources/templates/login.html diff --git a/spring-cloud-security/mykeystore.jks b/spring-cloud/spring-cloud-security/mykeystore.jks similarity index 100% rename from spring-cloud-security/mykeystore.jks rename to spring-cloud/spring-cloud-security/mykeystore.jks diff --git a/spring-cloud-security/personservice/pom.xml b/spring-cloud/spring-cloud-security/personservice/pom.xml similarity index 100% rename from spring-cloud-security/personservice/pom.xml rename to spring-cloud/spring-cloud-security/personservice/pom.xml diff --git a/spring-cloud-security/personservice/src/main/java/com/baeldung/service/model/Person.java b/spring-cloud/spring-cloud-security/personservice/src/main/java/com/baeldung/service/model/Person.java similarity index 100% rename from spring-cloud-security/personservice/src/main/java/com/baeldung/service/model/Person.java rename to spring-cloud/spring-cloud-security/personservice/src/main/java/com/baeldung/service/model/Person.java diff --git a/spring-cloud-security/personservice/src/main/java/com/baeldung/service/personservice/PersonserviceApplication.java b/spring-cloud/spring-cloud-security/personservice/src/main/java/com/baeldung/service/personservice/PersonserviceApplication.java similarity index 100% rename from spring-cloud-security/personservice/src/main/java/com/baeldung/service/personservice/PersonserviceApplication.java rename to spring-cloud/spring-cloud-security/personservice/src/main/java/com/baeldung/service/personservice/PersonserviceApplication.java diff --git a/spring-cloud-security/personservice/src/main/java/com/baeldung/service/personservice/config/ResourceConfigurer.java b/spring-cloud/spring-cloud-security/personservice/src/main/java/com/baeldung/service/personservice/config/ResourceConfigurer.java similarity index 100% rename from spring-cloud-security/personservice/src/main/java/com/baeldung/service/personservice/config/ResourceConfigurer.java rename to spring-cloud/spring-cloud-security/personservice/src/main/java/com/baeldung/service/personservice/config/ResourceConfigurer.java diff --git a/spring-cloud-security/personservice/src/main/java/com/baeldung/service/personservice/controller/PersonInfoController.java b/spring-cloud/spring-cloud-security/personservice/src/main/java/com/baeldung/service/personservice/controller/PersonInfoController.java similarity index 100% rename from spring-cloud-security/personservice/src/main/java/com/baeldung/service/personservice/controller/PersonInfoController.java rename to spring-cloud/spring-cloud-security/personservice/src/main/java/com/baeldung/service/personservice/controller/PersonInfoController.java diff --git a/spring-cloud-security/personservice/src/main/resources/application.properties b/spring-cloud/spring-cloud-security/personservice/src/main/resources/application.properties similarity index 100% rename from spring-cloud-security/personservice/src/main/resources/application.properties rename to spring-cloud/spring-cloud-security/personservice/src/main/resources/application.properties diff --git a/spring-cloud-security/personservice/src/main/resources/application.yml b/spring-cloud/spring-cloud-security/personservice/src/main/resources/application.yml similarity index 100% rename from spring-cloud-security/personservice/src/main/resources/application.yml rename to spring-cloud/spring-cloud-security/personservice/src/main/resources/application.yml diff --git a/spring-cloud-security/personservice/src/test/java/com/baeldung/service/personservice/PersonserviceApplicationTests.java b/spring-cloud/spring-cloud-security/personservice/src/test/java/com/baeldung/service/personservice/PersonserviceApplicationTests.java similarity index 100% rename from spring-cloud-security/personservice/src/test/java/com/baeldung/service/personservice/PersonserviceApplicationTests.java rename to spring-cloud/spring-cloud-security/personservice/src/test/java/com/baeldung/service/personservice/PersonserviceApplicationTests.java diff --git a/spring-cloud-security/pubkey.txt b/spring-cloud/spring-cloud-security/pubkey.txt similarity index 100% rename from spring-cloud-security/pubkey.txt rename to spring-cloud/spring-cloud-security/pubkey.txt diff --git a/spring-cloud-security/springoath2client/pom.xml b/spring-cloud/spring-cloud-security/springoath2client/pom.xml similarity index 100% rename from spring-cloud-security/springoath2client/pom.xml rename to spring-cloud/spring-cloud-security/springoath2client/pom.xml diff --git a/spring-cloud-security/springoath2client/src/main/java/com/cloud/springwebsite/CloudSite.java b/spring-cloud/spring-cloud-security/springoath2client/src/main/java/com/cloud/springwebsite/CloudSite.java similarity index 100% rename from spring-cloud-security/springoath2client/src/main/java/com/cloud/springwebsite/CloudSite.java rename to spring-cloud/spring-cloud-security/springoath2client/src/main/java/com/cloud/springwebsite/CloudSite.java diff --git a/spring-cloud-security/springoath2client/src/main/java/com/cloud/springwebsite/config/SiteSecurityConfigurer.java b/spring-cloud/spring-cloud-security/springoath2client/src/main/java/com/cloud/springwebsite/config/SiteSecurityConfigurer.java similarity index 100% rename from spring-cloud-security/springoath2client/src/main/java/com/cloud/springwebsite/config/SiteSecurityConfigurer.java rename to spring-cloud/spring-cloud-security/springoath2client/src/main/java/com/cloud/springwebsite/config/SiteSecurityConfigurer.java diff --git a/spring-cloud-security/springoath2client/src/main/java/com/cloud/springwebsite/controller/CloudSiteController.java b/spring-cloud/spring-cloud-security/springoath2client/src/main/java/com/cloud/springwebsite/controller/CloudSiteController.java similarity index 100% rename from spring-cloud-security/springoath2client/src/main/java/com/cloud/springwebsite/controller/CloudSiteController.java rename to spring-cloud/spring-cloud-security/springoath2client/src/main/java/com/cloud/springwebsite/controller/CloudSiteController.java diff --git a/spring-cloud-security/springoath2client/src/main/java/com/cloudsite/filters/pre/SimpleFilter.java b/spring-cloud/spring-cloud-security/springoath2client/src/main/java/com/cloudsite/filters/pre/SimpleFilter.java similarity index 100% rename from spring-cloud-security/springoath2client/src/main/java/com/cloudsite/filters/pre/SimpleFilter.java rename to spring-cloud/spring-cloud-security/springoath2client/src/main/java/com/cloudsite/filters/pre/SimpleFilter.java diff --git a/spring-cloud-security/springoath2client/src/main/resources/application.properties b/spring-cloud/spring-cloud-security/springoath2client/src/main/resources/application.properties similarity index 100% rename from spring-cloud-security/springoath2client/src/main/resources/application.properties rename to spring-cloud/spring-cloud-security/springoath2client/src/main/resources/application.properties diff --git a/spring-cloud-security/springoath2client/src/main/resources/application.yml b/spring-cloud/spring-cloud-security/springoath2client/src/main/resources/application.yml similarity index 100% rename from spring-cloud-security/springoath2client/src/main/resources/application.yml rename to spring-cloud/spring-cloud-security/springoath2client/src/main/resources/application.yml diff --git a/spring-cloud-security/springoath2client/src/main/resources/templates/personinfo.html b/spring-cloud/spring-cloud-security/springoath2client/src/main/resources/templates/personinfo.html similarity index 93% rename from spring-cloud-security/springoath2client/src/main/resources/templates/personinfo.html rename to spring-cloud/spring-cloud-security/springoath2client/src/main/resources/templates/personinfo.html index 9ed0c3cb4f..4f8eedfb6a 100644 --- a/spring-cloud-security/springoath2client/src/main/resources/templates/personinfo.html +++ b/spring-cloud/spring-cloud-security/springoath2client/src/main/resources/templates/personinfo.html @@ -2,7 +2,7 @@ -My Website - Current time +My Website - Getting Personal Information - - -

Providing Person Information

-

- Person's information: -

-

- The current time is: -

- - - - \ No newline at end of file From aa0785ca16d22fea0e459ea797f53309afe9220c Mon Sep 17 00:00:00 2001 From: Doha2012 Date: Wed, 17 Jan 2018 22:59:15 +0200 Subject: [PATCH 30/65] upgrade opened to spring boot 2 (#3441) * upgrade opened to spring boot 2 --- spring-security-openid/pom.xml | 37 +++++++++++++++---- .../config/SpringOpenidApplication.java | 2 +- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/spring-security-openid/pom.xml b/spring-security-openid/pom.xml index 2149334a5c..4c8112a163 100644 --- a/spring-security-openid/pom.xml +++ b/spring-security-openid/pom.xml @@ -11,12 +11,12 @@ spring-security-openid Spring OpenID sample project - - parent-boot-5 - com.baeldung - 0.0.1-SNAPSHOT - ../parent-boot-5 - + + org.springframework.boot + spring-boot-starter-parent + 2.0.0.M7 + + @@ -37,13 +37,36 @@ org.springframework.security.oauth spring-security-oauth2 + 2.2.1.RELEASE org.springframework.security spring-security-jwt + 1.0.9.RELEASE - + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + diff --git a/spring-security-openid/src/main/java/org/baeldung/config/SpringOpenidApplication.java b/spring-security-openid/src/main/java/org/baeldung/config/SpringOpenidApplication.java index ed57088c56..1acdba0623 100644 --- a/spring-security-openid/src/main/java/org/baeldung/config/SpringOpenidApplication.java +++ b/spring-security-openid/src/main/java/org/baeldung/config/SpringOpenidApplication.java @@ -2,7 +2,7 @@ package org.baeldung.config; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.web.support.SpringBootServletInitializer; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; @SpringBootApplication public class SpringOpenidApplication extends SpringBootServletInitializer { From a8f6c9f9fb36e3479546948d7aa50e766e4dd0a2 Mon Sep 17 00:00:00 2001 From: BineshNarayanan Date: Thu, 18 Jan 2018 12:22:06 +0800 Subject: [PATCH 31/65] BAEL-1276 | Adding example of ActiveJDBC --- activejdbc/pom.xml | 129 ++++++++++++++++++ .../main/java/com/baeldung/ActiveJDBCApp.java | 61 +++++++++ .../java/com/baeldung/model/Employee.java | 19 +++ .../main/java/com/baeldung/model/Role.java | 18 +++ .../src/main/migration/_create_tables.sql | 25 ++++ .../src/main/resources/database.properties | 10 ++ .../java/com/baeldung/ActiveJDBCAppTest.java | 51 +++++++ 7 files changed, 313 insertions(+) create mode 100644 activejdbc/pom.xml create mode 100644 activejdbc/src/main/java/com/baeldung/ActiveJDBCApp.java create mode 100644 activejdbc/src/main/java/com/baeldung/model/Employee.java create mode 100644 activejdbc/src/main/java/com/baeldung/model/Role.java create mode 100644 activejdbc/src/main/migration/_create_tables.sql create mode 100644 activejdbc/src/main/resources/database.properties create mode 100644 activejdbc/src/test/java/com/baeldung/ActiveJDBCAppTest.java diff --git a/activejdbc/pom.xml b/activejdbc/pom.xml new file mode 100644 index 0000000000..7a49d37411 --- /dev/null +++ b/activejdbc/pom.xml @@ -0,0 +1,129 @@ + + 4.0.0 + com.baeldung + activejdbc + 1.0-SNAPSHOT + jar + activejdbc + http://maven.apache.org + + UTF-8 + 1.4.13 + development.test,development + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.0 + + 1.8 + 1.8 + UTF-8 + + + + org.javalite + activejdbc-instrumentation + ${activejdbc.version} + + + process-classes + + instrument + + + + + + org.javalite + db-migrator-maven-plugin + ${activejdbc.version} + + ${project.basedir}/src/main/resources/database.properties + ${environments} + + + + mysql + mysql-connector-java + 5.1.34 + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.18.1 + + brief + true + false + + **/*Spec*.java + **/*Test*.java + + + **/helpers/* + **/*$* + + + + + + + + junit + junit + 4.12 + test + + + org.javalite + activejdbc + ${activejdbc.version} + + + opensymphony + oscache + + + + + mysql + mysql-connector-java + 5.1.34 + + + org.slf4j + slf4j-simple + 1.7.9 + + + + + snapshots1 + JavaLite Snapshots1 + http://repo.javalite.io/ + + true + always + warn + + + + + + snapshots2 + JavaLite Snapshots2 + http://repo.javalite.io/ + + true + always + warn + + + + diff --git a/activejdbc/src/main/java/com/baeldung/ActiveJDBCApp.java b/activejdbc/src/main/java/com/baeldung/ActiveJDBCApp.java new file mode 100644 index 0000000000..8906d3e759 --- /dev/null +++ b/activejdbc/src/main/java/com/baeldung/ActiveJDBCApp.java @@ -0,0 +1,61 @@ +package com.baeldung; + + +import com.baeldung.model.Employee; +import com.baeldung.model.Role; +import org.javalite.activejdbc.Base; +import org.javalite.activejdbc.LazyList; +import org.javalite.activejdbc.Model; + +public class ActiveJDBCApp +{ + public static void main( String[] args ) + { + try { + Base.open(); + ActiveJDBCApp app = new ActiveJDBCApp(); + app.create(); + app.update(); + app.delete(); + app.deleteCascade(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + Base.close(); + } + } + + protected void create() { + Employee employee = new Employee("Hugo","C","M","BN"); + employee.saveIt(); + employee.add(new Role("Java Developer","BN")); + LazyList all = Employee.findAll(); + System.out.println(all.size()); + } + + protected void update() { + Employee employee = Employee.findFirst("first_name = ?","Hugo"); + employee.set("last_namea","Choi").saveIt(); + employee = Employee.findFirst("last_name = ?","Choi"); + System.out.println(employee.getString("first_name") + " " + employee.getString("last_name")); + } + + protected void delete() { + Employee employee = Employee.findFirst("first_name = ?","Hugo"); + employee.delete(); + employee = Employee.findFirst("last_name = ?","Choi"); + if(null == employee){ + System.out.println("No such Employee found!"); + } + } + + protected void deleteCascade() { + create(); + Employee employee = Employee.findFirst("first_name = ?","Hugo"); + employee.deleteCascade(); + employee = Employee.findFirst("last_name = ?","C"); + if(null == employee){ + System.out.println("No such Employee found!"); + } + } +} diff --git a/activejdbc/src/main/java/com/baeldung/model/Employee.java b/activejdbc/src/main/java/com/baeldung/model/Employee.java new file mode 100644 index 0000000000..b7fa8aaf1f --- /dev/null +++ b/activejdbc/src/main/java/com/baeldung/model/Employee.java @@ -0,0 +1,19 @@ +package com.baeldung.model; + + +import org.javalite.activejdbc.Model; + +public class Employee extends Model { + + public Employee(){ + + } + + public Employee(String firstName, String lastName, String gender, String createdBy) { + set("first_name1",firstName); + set("last_name",lastName); + set("gender",gender); + set("created_by",createdBy); + } + +} diff --git a/activejdbc/src/main/java/com/baeldung/model/Role.java b/activejdbc/src/main/java/com/baeldung/model/Role.java new file mode 100644 index 0000000000..3f425dbe6b --- /dev/null +++ b/activejdbc/src/main/java/com/baeldung/model/Role.java @@ -0,0 +1,18 @@ +package com.baeldung.model; + + +import org.javalite.activejdbc.Model; +import org.javalite.activejdbc.annotations.Table; + +@Table("EMP_ROLES") +public class Role extends Model { + + public Role(){ + + } + + public Role(String role,String createdBy){ + set("role_name",role); + set("created_by",createdBy); + } +} diff --git a/activejdbc/src/main/migration/_create_tables.sql b/activejdbc/src/main/migration/_create_tables.sql new file mode 100644 index 0000000000..19fc1e72d7 --- /dev/null +++ b/activejdbc/src/main/migration/_create_tables.sql @@ -0,0 +1,25 @@ +# noinspection SqlNoDataSourceInspectionForFile + +create table organisation.employees +( + id int not null auto_increment + primary key, + first_name varchar(100) not null, + last_name varchar(100) not null, + gender varchar(1) not null, + created_at datetime not null, + updated_at datetime null, + created_by varchar(100) not null, + updated_by varchar(100) null +)ENGINE = InnoDB DEFAULT CHARSET = utf8; + +create table organisation.emp_roles +( + id int not null auto_increment primary key, + employee_id int not null, + role_name varchar(100) not null, + created_at datetime not null, + updated_at datetime null, + created_by varchar(100) not null, + updated_by varchar(100) null +)ENGINE = InnoDB DEFAULT CHARSET = utf8; diff --git a/activejdbc/src/main/resources/database.properties b/activejdbc/src/main/resources/database.properties new file mode 100644 index 0000000000..7e665fe8a1 --- /dev/null +++ b/activejdbc/src/main/resources/database.properties @@ -0,0 +1,10 @@ +development.driver=com.mysql.jdbc.Driver +development.username=root +development.password=123456 +development.url=jdbc:mysql://localhost/organisation + + +development.test.driver=com.mysql.jdbc.Driver +development.test.username=root +development.test.password=123456 +development.test.url=jdbc:mysql://localhost/organisation_test \ No newline at end of file diff --git a/activejdbc/src/test/java/com/baeldung/ActiveJDBCAppTest.java b/activejdbc/src/test/java/com/baeldung/ActiveJDBCAppTest.java new file mode 100644 index 0000000000..316dc34712 --- /dev/null +++ b/activejdbc/src/test/java/com/baeldung/ActiveJDBCAppTest.java @@ -0,0 +1,51 @@ +package com.baeldung; + +import com.baeldung.model.Employee; +import com.baeldung.model.Role; +import org.javalite.activejdbc.test.DBSpec; +import org.junit.Test; + +import java.util.List; + +public class ActiveJDBCAppTest extends DBSpec +{ + @Test + public void ifEmployeeCreated_thenIsValid() { + Employee employee = new Employee("B", "N", "M", "BN"); + the(employee).shouldBe("valid"); + } + + @Test + public void ifEmployeeCreatedWithRoles_thenShouldPersist() { + Employee employee = new Employee("B", "N", "M", "BN"); + employee.saveIt(); + employee.add(new Role("Java Developer","BN")); + employee.add(new Role("Lead Java Developer","BN")); + a(Role.count()).shouldBeEqual(2); + List roles = employee.getAll(Role.class).orderBy("created_at"); + the(roles.get(0).getRoleName()).shouldBeEqual("Java Developer"); + the(roles.get(1).getRoleName()).shouldBeEqual("Lead Java Developer"); + } + + @Test + public void ifEmployeeCreatedWithRoles_whenNameUpdated_thenShouldShowNewName() { + Employee employee = new Employee("Binesh", "N", "M", "BN"); + employee.saveIt(); + employee.add(new Role("Java Developer","BN")); + employee.add(new Role("Lead Java Developer","BN")); + employee = Employee.findFirst("first_name = ?", "Binesh"); + employee.set("last_name","Narayanan").saveIt(); + Employee updated = Employee.findFirst("first_name = ?", "Binesh"); + the(updated.getLastName()).shouldBeEqual("Narayanan"); + } + + @Test + public void ifEmployeeCreatedWithRoles_whenDeleted_thenShouldNotBeFound() { + Employee employee = new Employee("Binesh", "N", "M", "BN"); + employee.saveIt(); + employee.add(new Role("Java Developer","BN")); + employee.delete(); + employee = Employee.findFirst("first_name = ?", "Binesh"); + the(employee).shouldBeNull(); + } +} From bff1f7ba12c62f79180854a1e39c87fc40b67bf4 Mon Sep 17 00:00:00 2001 From: chrisoberle Date: Thu, 18 Jan 2018 05:13:33 -0500 Subject: [PATCH 32/65] BAEL-1418 - spring security with extra login fields (#3413) * BAEL-1418 - spring security with extra login fields * change delimeter for username/domain concatenation * remove unnecessary class * move source to spring-5-security module * finish moving example code to spring-5-security module * fix formatting in pom * adjust spacing --- spring-5-security/pom.xml | 19 ++++ .../CustomAuthenticationFilter.java | 54 +++++++++ .../CustomUserDetailsService.java | 32 ++++++ .../CustomUserRepository.java | 26 +++++ .../securityextrafields/SecurityConfig.java | 65 +++++++++++ .../SpringExtraLoginFieldsApplication.java | 13 +++ .../baeldung/securityextrafields/User.java | 23 ++++ .../securityextrafields/UserRepository.java | 7 ++ .../securityextrafields/WebController.java | 51 +++++++++ .../application-extrafields.properties | 1 + .../src/main/resources/static/css/main.css | 18 +++ .../resources/templatesextrafields/index.html | 24 ++++ .../resources/templatesextrafields/login.html | 23 ++++ .../templatesextrafields/user/index.html | 13 +++ .../SecurityExtraFieldsTest.java | 103 ++++++++++++++++++ 15 files changed, 472 insertions(+) create mode 100644 spring-5-security/src/main/java/com/baeldung/securityextrafields/CustomAuthenticationFilter.java create mode 100644 spring-5-security/src/main/java/com/baeldung/securityextrafields/CustomUserDetailsService.java create mode 100644 spring-5-security/src/main/java/com/baeldung/securityextrafields/CustomUserRepository.java create mode 100644 spring-5-security/src/main/java/com/baeldung/securityextrafields/SecurityConfig.java create mode 100644 spring-5-security/src/main/java/com/baeldung/securityextrafields/SpringExtraLoginFieldsApplication.java create mode 100644 spring-5-security/src/main/java/com/baeldung/securityextrafields/User.java create mode 100644 spring-5-security/src/main/java/com/baeldung/securityextrafields/UserRepository.java create mode 100644 spring-5-security/src/main/java/com/baeldung/securityextrafields/WebController.java create mode 100644 spring-5-security/src/main/resources/application-extrafields.properties create mode 100644 spring-5-security/src/main/resources/static/css/main.css create mode 100644 spring-5-security/src/main/resources/templatesextrafields/index.html create mode 100644 spring-5-security/src/main/resources/templatesextrafields/login.html create mode 100644 spring-5-security/src/main/resources/templatesextrafields/user/index.html create mode 100644 spring-5-security/src/test/java/com/baeldung/securityextrafields/SecurityExtraFieldsTest.java diff --git a/spring-5-security/pom.xml b/spring-5-security/pom.xml index c0f73b1bdd..0a1d1f5df0 100644 --- a/spring-5-security/pom.xml +++ b/spring-5-security/pom.xml @@ -30,6 +30,10 @@ org.springframework.boot spring-boot-starter-thymeleaf
+ + org.thymeleaf.extras + thymeleaf-extras-springsecurity4 + @@ -40,6 +44,21 @@ org.springframework.security spring-security-oauth2-jose + + + org.springframework + spring-test + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.security + spring-security-test + test + diff --git a/spring-5-security/src/main/java/com/baeldung/securityextrafields/CustomAuthenticationFilter.java b/spring-5-security/src/main/java/com/baeldung/securityextrafields/CustomAuthenticationFilter.java new file mode 100644 index 0000000000..b5d628628d --- /dev/null +++ b/spring-5-security/src/main/java/com/baeldung/securityextrafields/CustomAuthenticationFilter.java @@ -0,0 +1,54 @@ +package com.baeldung.securityextrafields; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.security.authentication.AuthenticationServiceException; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; + +public class CustomAuthenticationFilter extends UsernamePasswordAuthenticationFilter { + + public static final String SPRING_SECURITY_FORM_DOMAIN_KEY = "domain"; + + @Override + public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) + throws AuthenticationException { + + if (!request.getMethod() + .equals("POST")) { + throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod()); + } + + UsernamePasswordAuthenticationToken authRequest = getAuthRequest(request); + setDetails(request, authRequest); + return this.getAuthenticationManager() + .authenticate(authRequest); + } + + private UsernamePasswordAuthenticationToken getAuthRequest(HttpServletRequest request) { + String username = obtainUsername(request); + String password = obtainPassword(request); + String domain = obtainDomain(request); + + if (username == null) { + username = ""; + } + if (password == null) { + password = ""; + } + if (domain == null) { + domain = ""; + } + + String usernameDomain = String.format("%s%s%s", username.trim(), + String.valueOf(Character.LINE_SEPARATOR), domain); + return new UsernamePasswordAuthenticationToken(usernameDomain, password); + } + + private String obtainDomain(HttpServletRequest request) { + return request.getParameter(SPRING_SECURITY_FORM_DOMAIN_KEY); + } +} diff --git a/spring-5-security/src/main/java/com/baeldung/securityextrafields/CustomUserDetailsService.java b/spring-5-security/src/main/java/com/baeldung/securityextrafields/CustomUserDetailsService.java new file mode 100644 index 0000000000..be02834852 --- /dev/null +++ b/spring-5-security/src/main/java/com/baeldung/securityextrafields/CustomUserDetailsService.java @@ -0,0 +1,32 @@ +package com.baeldung.securityextrafields; + +import org.apache.commons.lang3.StringUtils; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.stereotype.Service; + +@Service("userDetailsService") +public class CustomUserDetailsService implements UserDetailsService { + + private final UserRepository userRepository; + + public CustomUserDetailsService(UserRepository userRepository) { + this.userRepository = userRepository; + } + + @Override + public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { + String[] usernameAndDomain = StringUtils.split(username, String.valueOf(Character.LINE_SEPARATOR)); + if (usernameAndDomain == null || usernameAndDomain.length != 2) { + throw new UsernameNotFoundException("Username and domain must be provided"); + } + User user = userRepository.findUser(usernameAndDomain[0], usernameAndDomain[1]); + if (user == null) { + throw new UsernameNotFoundException( + String.format("Username not found for domain, username=%s, domain=%s", + usernameAndDomain[0], usernameAndDomain[1])); + } + return user; + } +} diff --git a/spring-5-security/src/main/java/com/baeldung/securityextrafields/CustomUserRepository.java b/spring-5-security/src/main/java/com/baeldung/securityextrafields/CustomUserRepository.java new file mode 100644 index 0000000000..c86769b016 --- /dev/null +++ b/spring-5-security/src/main/java/com/baeldung/securityextrafields/CustomUserRepository.java @@ -0,0 +1,26 @@ +package com.baeldung.securityextrafields; + +import java.util.ArrayList; +import java.util.Collection; + +import org.apache.commons.lang3.StringUtils; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.stereotype.Repository; + +@Repository("userRepository") +public class CustomUserRepository implements UserRepository { + + @Override + public User findUser(String username, String domain) { + if (StringUtils.isAnyBlank(username, domain)) { + return null; + } else { + Collection authorities = new ArrayList<>(); + User user = new User(username, domain, + "$2a$10$U3GhSMpsMSOE8Kqsbn58/edxDBKlVuYMh7qk/7ErApYFjJzi2VG5K", true, + true, true, true, authorities); + return user; + } + } + +} diff --git a/spring-5-security/src/main/java/com/baeldung/securityextrafields/SecurityConfig.java b/spring-5-security/src/main/java/com/baeldung/securityextrafields/SecurityConfig.java new file mode 100644 index 0000000000..429f6df972 --- /dev/null +++ b/spring-5-security/src/main/java/com/baeldung/securityextrafields/SecurityConfig.java @@ -0,0 +1,65 @@ +package com.baeldung.securityextrafields; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.PropertySource; +import org.springframework.security.authentication.AuthenticationProvider; +import org.springframework.security.authentication.dao.DaoAuthenticationProvider; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +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.core.userdetails.UserDetailsService; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler; +import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; + +@EnableWebSecurity +@PropertySource("classpath:/application-extrafields.properties") +public class SecurityConfig extends WebSecurityConfigurerAdapter { + + @Autowired + private UserDetailsService userDetailsService; + + @Override + protected void configure(HttpSecurity http) throws Exception { + + http + .addFilterBefore(authenticationFilter(), UsernamePasswordAuthenticationFilter.class) + .authorizeRequests() + .antMatchers("/css/**", "/index").permitAll() + .antMatchers("/user/**").authenticated() + .and() + .formLogin().loginPage("/login") + .and() + .logout() + .logoutUrl("/logout"); + } + + public CustomAuthenticationFilter authenticationFilter() throws Exception { + CustomAuthenticationFilter filter = new CustomAuthenticationFilter(); + filter.setAuthenticationManager(authenticationManagerBean()); + filter.setAuthenticationFailureHandler(failureHandler()); + return filter; + } + + @Autowired + public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { + auth.authenticationProvider(authProvider()); + } + + public AuthenticationProvider authProvider() { + DaoAuthenticationProvider provider = new DaoAuthenticationProvider(); + provider.setUserDetailsService(userDetailsService); + provider.setPasswordEncoder(passwordEncoder()); + return provider; + } + + public SimpleUrlAuthenticationFailureHandler failureHandler() { + return new SimpleUrlAuthenticationFailureHandler("/login?error=true"); + } + + public PasswordEncoder passwordEncoder() { + return new BCryptPasswordEncoder(); + } +} diff --git a/spring-5-security/src/main/java/com/baeldung/securityextrafields/SpringExtraLoginFieldsApplication.java b/spring-5-security/src/main/java/com/baeldung/securityextrafields/SpringExtraLoginFieldsApplication.java new file mode 100644 index 0000000000..a779acc75e --- /dev/null +++ b/spring-5-security/src/main/java/com/baeldung/securityextrafields/SpringExtraLoginFieldsApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.securityextrafields; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SpringExtraLoginFieldsApplication { + + public static void main(String[] args) { + SpringApplication.run(SpringExtraLoginFieldsApplication.class, args); + } + +} diff --git a/spring-5-security/src/main/java/com/baeldung/securityextrafields/User.java b/spring-5-security/src/main/java/com/baeldung/securityextrafields/User.java new file mode 100644 index 0000000000..a5b3a434ae --- /dev/null +++ b/spring-5-security/src/main/java/com/baeldung/securityextrafields/User.java @@ -0,0 +1,23 @@ +package com.baeldung.securityextrafields; + +import java.util.Collection; + +import org.springframework.security.core.GrantedAuthority; + +public class User extends org.springframework.security.core.userdetails.User { + + private static final long serialVersionUID = 1L; + + private final String domain; + + public User(String username, String domain, String password, boolean enabled, + boolean accountNonExpired, boolean credentialsNonExpired, + boolean accountNonLocked, Collection authorities) { + super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities); + this.domain = domain; + } + + public String getDomain() { + return domain; + } +} diff --git a/spring-5-security/src/main/java/com/baeldung/securityextrafields/UserRepository.java b/spring-5-security/src/main/java/com/baeldung/securityextrafields/UserRepository.java new file mode 100644 index 0000000000..4ca65b13d5 --- /dev/null +++ b/spring-5-security/src/main/java/com/baeldung/securityextrafields/UserRepository.java @@ -0,0 +1,7 @@ +package com.baeldung.securityextrafields; + +public interface UserRepository { + + public User findUser(String username, String domain); + +} diff --git a/spring-5-security/src/main/java/com/baeldung/securityextrafields/WebController.java b/spring-5-security/src/main/java/com/baeldung/securityextrafields/WebController.java new file mode 100644 index 0000000000..4a8abb4a83 --- /dev/null +++ b/spring-5-security/src/main/java/com/baeldung/securityextrafields/WebController.java @@ -0,0 +1,51 @@ +package com.baeldung.securityextrafields; + +import java.util.Optional; + +import org.springframework.security.authentication.AnonymousAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestMapping; + +@Controller +public class WebController { + + @RequestMapping("/") + public String root() { + return "redirect:/index"; + } + + @RequestMapping("/index") + public String index(Model model) { + getDomain().ifPresent(d -> { + model.addAttribute("domain", d); + }); + return "index"; + } + + @RequestMapping("/user/index") + public String userIndex(Model model) { + getDomain().ifPresent(d -> { + model.addAttribute("domain", d); + }); + return "user/index"; + } + + @RequestMapping("/login") + public String login() { + return "login"; + } + + private Optional getDomain() { + Authentication auth = SecurityContextHolder.getContext() + .getAuthentication(); + String domain = null; + if (auth != null && !auth.getClass().equals(AnonymousAuthenticationToken.class)) { + User user = (User) auth.getPrincipal(); + domain = user.getDomain(); + } + return Optional.ofNullable(domain); + } +} diff --git a/spring-5-security/src/main/resources/application-extrafields.properties b/spring-5-security/src/main/resources/application-extrafields.properties new file mode 100644 index 0000000000..ab4134ce3e --- /dev/null +++ b/spring-5-security/src/main/resources/application-extrafields.properties @@ -0,0 +1 @@ +spring.thymeleaf.prefix = classpath:/templatesextrafields/ \ No newline at end of file diff --git a/spring-5-security/src/main/resources/static/css/main.css b/spring-5-security/src/main/resources/static/css/main.css new file mode 100644 index 0000000000..9299ee6158 --- /dev/null +++ b/spring-5-security/src/main/resources/static/css/main.css @@ -0,0 +1,18 @@ +body { + font-family: sans; + font-size: 1em; +} + +p.error { + font-weight: bold; + color: red; +} + +div.logout { + float: right; +} + +.formfield { + margin: 0.5em; + padding: 0.3em; +} \ No newline at end of file diff --git a/spring-5-security/src/main/resources/templatesextrafields/index.html b/spring-5-security/src/main/resources/templatesextrafields/index.html new file mode 100644 index 0000000000..52f6224dfb --- /dev/null +++ b/spring-5-security/src/main/resources/templatesextrafields/index.html @@ -0,0 +1,24 @@ + + + + Spring Security - Login With Extra Fields + + + + +
+ Logged in user: | + domain: Some Domain +
+
+ +
+
+
+

Hello Spring Security

+

This is an unsecured page, but you can access the secured pages after authenticating.

+ + + diff --git a/spring-5-security/src/main/resources/templatesextrafields/login.html b/spring-5-security/src/main/resources/templatesextrafields/login.html new file mode 100644 index 0000000000..cafec89c15 --- /dev/null +++ b/spring-5-security/src/main/resources/templatesextrafields/login.html @@ -0,0 +1,23 @@ + + + + Login page + + + + +

Login page

+

Example: user / domain / password

+

Invalid user, password, or domain

+
+ : +
+ : +
+ : +
+ +
+

Back to home page

+ + diff --git a/spring-5-security/src/main/resources/templatesextrafields/user/index.html b/spring-5-security/src/main/resources/templatesextrafields/user/index.html new file mode 100644 index 0000000000..a4c1535100 --- /dev/null +++ b/spring-5-security/src/main/resources/templatesextrafields/user/index.html @@ -0,0 +1,13 @@ + + + + Spring Security - Login With Extra Fields + + + + +
+

This is a secured page!

+

Back to home page

+ + diff --git a/spring-5-security/src/test/java/com/baeldung/securityextrafields/SecurityExtraFieldsTest.java b/spring-5-security/src/test/java/com/baeldung/securityextrafields/SecurityExtraFieldsTest.java new file mode 100644 index 0000000000..cf0701708d --- /dev/null +++ b/spring-5-security/src/test/java/com/baeldung/securityextrafields/SecurityExtraFieldsTest.java @@ -0,0 +1,103 @@ +package com.baeldung.securityextrafields; + +import static org.junit.Assert.assertEquals; +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; +import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrlPattern; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import java.util.ArrayList; +import java.util.Collection; + +import org.junit.Before; +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.mock.web.MockHttpSession; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.context.SecurityContext; +import org.springframework.security.web.FilterChainProxy; +import org.springframework.security.web.context.HttpSessionSecurityContextRepository; +import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; +import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + +@RunWith(SpringRunner.class) +@SpringJUnitWebConfig +@SpringBootTest(classes = SpringExtraLoginFieldsApplication.class) +public class SecurityExtraFieldsTest { + + @Autowired + private FilterChainProxy springSecurityFilterChain; + + @Autowired + private WebApplicationContext wac; + + private MockMvc mockMvc; + + @Before + public void setup() { + this.mockMvc = MockMvcBuilders.webAppContextSetup(wac) + .apply(springSecurity(springSecurityFilterChain)).build(); + } + + @Test + public void givenRootPathAccess_thenRedirectToIndex() throws Exception { + this.mockMvc.perform(get("/")) + .andExpect(status().is3xxRedirection()) + .andExpect(redirectedUrlPattern("/index*")); + } + + @Test + public void givenSecuredResource_whenAccessUnauthenticated_thenRequiresAuthentication() throws Exception { + this.mockMvc.perform(get("/user/index")) + .andExpect(status().is3xxRedirection()) + .andExpect(redirectedUrlPattern("**/login")); + } + + @Test + public void givenAccessSecuredResource_whenAuthenticated_thenAuthHasExtraFields() throws Exception { + MockHttpServletRequestBuilder securedResourceAccess = get("/user/index"); + MvcResult unauthenticatedResult = mockMvc.perform(securedResourceAccess) + .andExpect(status().is3xxRedirection()) + .andReturn(); + + MockHttpSession session = (MockHttpSession) unauthenticatedResult.getRequest() + .getSession(); + String loginUrl = unauthenticatedResult.getResponse() + .getRedirectedUrl(); + + User user = getUser(); + + mockMvc.perform(post(loginUrl) + .param("username", user.getUsername()) + .param("password", user.getPassword()) + .param("domain", user.getDomain()) + .session(session) + .with(csrf())) + .andExpect(status().is3xxRedirection()) + .andExpect(redirectedUrlPattern("**/user/index")) + .andReturn(); + + mockMvc.perform(securedResourceAccess.session(session)) + .andExpect(status().isOk()); + + SecurityContext securityContext + = (SecurityContext) session.getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY); + Authentication auth = securityContext.getAuthentication(); + assertEquals(((User)auth.getPrincipal()).getDomain(), user.getDomain()); + } + + private User getUser() { + Collection authorities = new ArrayList<>(); + return new User("myusername", "mydomain", "password", true, true, true, true, authorities); + } +} From 1d29f9be8be57954a598ddb007ff8ec3d155ba48 Mon Sep 17 00:00:00 2001 From: Sergey Petunin Date: Thu, 18 Jan 2018 11:50:38 +0100 Subject: [PATCH 33/65] BAEL-1414 Learn to Fully Leverage Java Server Faces (#3446) --- guest/deep-jsf/README.md | 15 ++++++ guest/deep-jsf/pom.xml | 40 ++++++++++++++++ .../stackify/deepjsf/GreetControllerBean.java | 14 ++++++ .../stackify/deepjsf/PhaseListenerBean.java | 47 ++++++++++++++++++ .../java/com/stackify/deepjsf/UserBean.java | 48 +++++++++++++++++++ .../stackify/deepjsf/UserControllerBean.java | 14 ++++++ .../src/main/webapp/WEB-INF/faces-config.xml | 15 ++++++ guest/deep-jsf/src/main/webapp/greet.xhtml | 11 +++++ guest/deep-jsf/src/main/webapp/hello.xhtml | 10 ++++ guest/deep-jsf/src/main/webapp/index.xhtml | 18 +++++++ guest/deep-jsf/src/main/webapp/register.xhtml | 31 ++++++++++++ 11 files changed, 263 insertions(+) create mode 100644 guest/deep-jsf/README.md create mode 100644 guest/deep-jsf/pom.xml create mode 100644 guest/deep-jsf/src/main/java/com/stackify/deepjsf/GreetControllerBean.java create mode 100644 guest/deep-jsf/src/main/java/com/stackify/deepjsf/PhaseListenerBean.java create mode 100644 guest/deep-jsf/src/main/java/com/stackify/deepjsf/UserBean.java create mode 100644 guest/deep-jsf/src/main/java/com/stackify/deepjsf/UserControllerBean.java create mode 100644 guest/deep-jsf/src/main/webapp/WEB-INF/faces-config.xml create mode 100644 guest/deep-jsf/src/main/webapp/greet.xhtml create mode 100644 guest/deep-jsf/src/main/webapp/hello.xhtml create mode 100644 guest/deep-jsf/src/main/webapp/index.xhtml create mode 100644 guest/deep-jsf/src/main/webapp/register.xhtml diff --git a/guest/deep-jsf/README.md b/guest/deep-jsf/README.md new file mode 100644 index 0000000000..b5f532535b --- /dev/null +++ b/guest/deep-jsf/README.md @@ -0,0 +1,15 @@ +## Building + +To build the module, use Maven's `package` goal: + +``` +mvn clean package +``` + +The `war` file will be available at `target/deep-jsf.war` + +## Running + +The `war` application is deployed to a Java EE 7 compliant application server, for example, to GlassFish 4 or later. + +The example then will be accessible at http://localhost:8080/deep-jsf/index.xhtml \ No newline at end of file diff --git a/guest/deep-jsf/pom.xml b/guest/deep-jsf/pom.xml new file mode 100644 index 0000000000..68801ba010 --- /dev/null +++ b/guest/deep-jsf/pom.xml @@ -0,0 +1,40 @@ + + 4.0.0 + + com.stackify + deep-jsf + 0.0.1-SNAPSHOT + war + + + false + + + + + + javax + javaee-api + 7.0 + provided + + + + + + deep-jsf + + + org.apache.maven.plugins + maven-compiler-plugin + 3.7.0 + + 1.8 + 1.8 + + + + + + \ No newline at end of file diff --git a/guest/deep-jsf/src/main/java/com/stackify/deepjsf/GreetControllerBean.java b/guest/deep-jsf/src/main/java/com/stackify/deepjsf/GreetControllerBean.java new file mode 100644 index 0000000000..7f5cf99781 --- /dev/null +++ b/guest/deep-jsf/src/main/java/com/stackify/deepjsf/GreetControllerBean.java @@ -0,0 +1,14 @@ +package com.stackify.deepjsf; + +import javax.faces.bean.ManagedBean; +import javax.faces.bean.RequestScoped; + +@ManagedBean +@RequestScoped +public class GreetControllerBean { + + public String greet() { + return "greet"; + } + +} diff --git a/guest/deep-jsf/src/main/java/com/stackify/deepjsf/PhaseListenerBean.java b/guest/deep-jsf/src/main/java/com/stackify/deepjsf/PhaseListenerBean.java new file mode 100644 index 0000000000..d4f6a6e815 --- /dev/null +++ b/guest/deep-jsf/src/main/java/com/stackify/deepjsf/PhaseListenerBean.java @@ -0,0 +1,47 @@ +package com.stackify.deepjsf; + +import javax.faces.bean.ManagedBean; +import javax.faces.bean.RequestScoped; +import javax.faces.component.UIComponent; +import javax.faces.component.UIViewRoot; +import javax.faces.component.visit.VisitContext; +import javax.faces.component.visit.VisitResult; +import javax.faces.event.PhaseEvent; +import javax.faces.event.PhaseId; +import javax.servlet.http.HttpServletRequest; + +@ManagedBean +@RequestScoped +public class PhaseListenerBean { + + public void beforeListener(PhaseEvent event) { + if (!event.getPhaseId().equals(PhaseId.RENDER_RESPONSE)) { + return; + } + UIViewRoot root = event.getFacesContext().getViewRoot(); + + boolean showNewFeature = showNewFeatureForIp(event); + + processComponentTree(root, event, showNewFeature); + } + + private boolean showNewFeatureForIp(PhaseEvent event) { + HttpServletRequest request = (HttpServletRequest) event.getFacesContext() + .getExternalContext().getRequest(); + String ip = request.getRemoteAddr(); + return !ip.startsWith("127.0"); + } + + private void processComponentTree(UIComponent component, PhaseEvent event, boolean show) { + component.visitTree(VisitContext.createVisitContext(event.getFacesContext()), + (context, target) -> { + if (target.getId() != null + && target.getId().startsWith("new-feature-") + && !show) { + target.setRendered(false); + } + return VisitResult.ACCEPT; + }); + } + +} diff --git a/guest/deep-jsf/src/main/java/com/stackify/deepjsf/UserBean.java b/guest/deep-jsf/src/main/java/com/stackify/deepjsf/UserBean.java new file mode 100644 index 0000000000..f6c94e87b8 --- /dev/null +++ b/guest/deep-jsf/src/main/java/com/stackify/deepjsf/UserBean.java @@ -0,0 +1,48 @@ +package com.stackify.deepjsf; + +import javax.faces.bean.ManagedBean; +import javax.faces.bean.SessionScoped; +import javax.faces.event.ValueChangeEvent; + +@ManagedBean +@SessionScoped +public class UserBean { + + private String name = ""; + + private String lastName = ""; + + private String proposedLogin = ""; + + public void nameChanged(ValueChangeEvent event) { + this.proposedLogin = event.getNewValue() + "-" + lastName; + } + + public void lastNameChanged(ValueChangeEvent event) { + this.proposedLogin = name + "-" + event.getNewValue(); + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getProposedLogin() { + return proposedLogin; + } + + public void setProposedLogin(String proposedLogin) { + this.proposedLogin = proposedLogin; + } +} diff --git a/guest/deep-jsf/src/main/java/com/stackify/deepjsf/UserControllerBean.java b/guest/deep-jsf/src/main/java/com/stackify/deepjsf/UserControllerBean.java new file mode 100644 index 0000000000..c2a46a019a --- /dev/null +++ b/guest/deep-jsf/src/main/java/com/stackify/deepjsf/UserControllerBean.java @@ -0,0 +1,14 @@ +package com.stackify.deepjsf; + +import javax.faces.bean.ManagedBean; +import javax.faces.bean.RequestScoped; + +@ManagedBean +@RequestScoped +public class UserControllerBean { + + public String register() { + return "register-success"; + } + +} diff --git a/guest/deep-jsf/src/main/webapp/WEB-INF/faces-config.xml b/guest/deep-jsf/src/main/webapp/WEB-INF/faces-config.xml new file mode 100644 index 0000000000..264e60065c --- /dev/null +++ b/guest/deep-jsf/src/main/webapp/WEB-INF/faces-config.xml @@ -0,0 +1,15 @@ + + + + + /register.xhtml + + register-success + /hello.xhtml + + + + \ No newline at end of file diff --git a/guest/deep-jsf/src/main/webapp/greet.xhtml b/guest/deep-jsf/src/main/webapp/greet.xhtml new file mode 100644 index 0000000000..50c79c64e1 --- /dev/null +++ b/guest/deep-jsf/src/main/webapp/greet.xhtml @@ -0,0 +1,11 @@ + + + + + + + + diff --git a/guest/deep-jsf/src/main/webapp/hello.xhtml b/guest/deep-jsf/src/main/webapp/hello.xhtml new file mode 100644 index 0000000000..f9c3745dca --- /dev/null +++ b/guest/deep-jsf/src/main/webapp/hello.xhtml @@ -0,0 +1,10 @@ + + + + + + + diff --git a/guest/deep-jsf/src/main/webapp/index.xhtml b/guest/deep-jsf/src/main/webapp/index.xhtml new file mode 100644 index 0000000000..de99b89815 --- /dev/null +++ b/guest/deep-jsf/src/main/webapp/index.xhtml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + diff --git a/guest/deep-jsf/src/main/webapp/register.xhtml b/guest/deep-jsf/src/main/webapp/register.xhtml new file mode 100644 index 0000000000..ba1b8e0233 --- /dev/null +++ b/guest/deep-jsf/src/main/webapp/register.xhtml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + From 3a5804aaa846d2f41501eab538d3f7fa6ed1676c Mon Sep 17 00:00:00 2001 From: Alessio Stalla Date: Thu, 18 Jan 2018 12:54:55 +0100 Subject: [PATCH 34/65] Revert "Code for Alessio Stalla's evaluation article (Different Types of Bean Injection in Spring)" This reverts commit c174946f855ff445c787c8ddac683b73e26a0378. --- .../baeldung/typesofbeaninjection/Config.java | 16 ----- .../typesofbeaninjection/domain/Car.java | 24 -------- .../typesofbeaninjection/domain/Engine.java | 24 -------- .../domain/autowired/constructor/Car.java | 30 ---------- .../domain/autowired/properties/Car.java | 30 ---------- .../typesofbeaninjection-context.xml | 19 ------ .../TypeOfBeanInjectionUnitTest.java | 58 ------------------- 7 files changed, 201 deletions(-) delete mode 100644 spring-core/src/main/java/com/baeldung/typesofbeaninjection/Config.java delete mode 100644 spring-core/src/main/java/com/baeldung/typesofbeaninjection/domain/Car.java delete mode 100644 spring-core/src/main/java/com/baeldung/typesofbeaninjection/domain/Engine.java delete mode 100644 spring-core/src/main/java/com/baeldung/typesofbeaninjection/domain/autowired/constructor/Car.java delete mode 100644 spring-core/src/main/java/com/baeldung/typesofbeaninjection/domain/autowired/properties/Car.java delete mode 100644 spring-core/src/main/resources/typesofbeaninjection-context.xml delete mode 100644 spring-core/src/test/java/com/baeldung/typesofbeaninjection/TypeOfBeanInjectionUnitTest.java diff --git a/spring-core/src/main/java/com/baeldung/typesofbeaninjection/Config.java b/spring-core/src/main/java/com/baeldung/typesofbeaninjection/Config.java deleted file mode 100644 index a967a63005..0000000000 --- a/spring-core/src/main/java/com/baeldung/typesofbeaninjection/Config.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.baeldung.typesofbeaninjection; - -import com.baeldung.typesofbeaninjection.domain.Engine; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; - -@Configuration -@ComponentScan("com.baeldung.typesofbeaninjection") -public class Config { - - @Bean - public Engine engine() { - return new Engine("V8", 5); - } -} diff --git a/spring-core/src/main/java/com/baeldung/typesofbeaninjection/domain/Car.java b/spring-core/src/main/java/com/baeldung/typesofbeaninjection/domain/Car.java deleted file mode 100644 index 878f369c8e..0000000000 --- a/spring-core/src/main/java/com/baeldung/typesofbeaninjection/domain/Car.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.baeldung.typesofbeaninjection.domain; - -public class Car { - private Engine engine; - - public Car() {} - - public Car(Engine engine) { - this.engine = engine; - } - - public Engine getEngine() { - return engine; - } - - public void setEngine(Engine engine) { - this.engine = engine; - } - - @Override - public String toString() { - return String.format("Car with %s engine", engine); - } -} diff --git a/spring-core/src/main/java/com/baeldung/typesofbeaninjection/domain/Engine.java b/spring-core/src/main/java/com/baeldung/typesofbeaninjection/domain/Engine.java deleted file mode 100644 index 79e7a9856d..0000000000 --- a/spring-core/src/main/java/com/baeldung/typesofbeaninjection/domain/Engine.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.baeldung.typesofbeaninjection.domain; - -public class Engine { - private final String type; - private final int volume; - - public Engine(String type, int volume) { - this.type = type; - this.volume = volume; - } - - public String getType() { - return type; - } - - public int getVolume() { - return volume; - } - - @Override - public String toString() { - return String.format("%s %d", type, volume); - } -} diff --git a/spring-core/src/main/java/com/baeldung/typesofbeaninjection/domain/autowired/constructor/Car.java b/spring-core/src/main/java/com/baeldung/typesofbeaninjection/domain/autowired/constructor/Car.java deleted file mode 100644 index 33fadf8d2b..0000000000 --- a/spring-core/src/main/java/com/baeldung/typesofbeaninjection/domain/autowired/constructor/Car.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.baeldung.typesofbeaninjection.domain.autowired.constructor; - -import com.baeldung.typesofbeaninjection.domain.Engine; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -@Component("car-autowired-by-constructor") -public class Car { - private Engine engine; - - public Car() {} - - @Autowired - public Car(Engine engine) { - this.engine = engine; - } - - public Engine getEngine() { - return engine; - } - - public void setEngine(Engine engine) { - this.engine = engine; - } - - @Override - public String toString() { - return String.format("Car with %s engine", engine); - } -} diff --git a/spring-core/src/main/java/com/baeldung/typesofbeaninjection/domain/autowired/properties/Car.java b/spring-core/src/main/java/com/baeldung/typesofbeaninjection/domain/autowired/properties/Car.java deleted file mode 100644 index 1df33f5062..0000000000 --- a/spring-core/src/main/java/com/baeldung/typesofbeaninjection/domain/autowired/properties/Car.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.baeldung.typesofbeaninjection.domain.autowired.properties; - -import com.baeldung.typesofbeaninjection.domain.Engine; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -@Component("car-autowired-by-properties") -public class Car { - private Engine engine; - - public Car() {} - - public Car(Engine engine) { - this.engine = engine; - } - - public Engine getEngine() { - return engine; - } - - @Autowired - public void setEngine(Engine engine) { - this.engine = engine; - } - - @Override - public String toString() { - return String.format("Car with %s engine", engine); - } -} diff --git a/spring-core/src/main/resources/typesofbeaninjection-context.xml b/spring-core/src/main/resources/typesofbeaninjection-context.xml deleted file mode 100644 index 5a9a0b59d7..0000000000 --- a/spring-core/src/main/resources/typesofbeaninjection-context.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/spring-core/src/test/java/com/baeldung/typesofbeaninjection/TypeOfBeanInjectionUnitTest.java b/spring-core/src/test/java/com/baeldung/typesofbeaninjection/TypeOfBeanInjectionUnitTest.java deleted file mode 100644 index 1b1319e001..0000000000 --- a/spring-core/src/test/java/com/baeldung/typesofbeaninjection/TypeOfBeanInjectionUnitTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.baeldung.typesofbeaninjection; - -import com.baeldung.typesofbeaninjection.domain.Car; -import com.baeldung.typesofbeaninjection.domain.Engine; -import org.junit.Test; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -public class TypeOfBeanInjectionUnitTest { - - @Test - public void whenConstructionInjectionInXML_thenCarHasEngine() { - ApplicationContext applicationContext - = new ClassPathXmlApplicationContext("/typesofbeaninjection-context.xml"); - Car car = applicationContext.getBean("alices-car", Car.class); - - checkEngine(car.getEngine()); - } - - @Test - public void whenPropertyInjectionInXML_thenCarHasEngine() { - ApplicationContext applicationContext - = new ClassPathXmlApplicationContext("/typesofbeaninjection-context.xml"); - Car car = applicationContext.getBean("bobs-car", Car.class); - - checkEngine(car.getEngine()); - } - - @Test - public void whenConstructionInjectionAnnotations_thenCarHasEngine() { - ApplicationContext applicationContext = new AnnotationConfigApplicationContext(Config.class); - com.baeldung.typesofbeaninjection.domain.autowired.constructor.Car car - = applicationContext.getBean(com.baeldung.typesofbeaninjection.domain.autowired.constructor.Car.class); - - checkEngine(car.getEngine()); - } - - @Test - public void whenPropertyInjectionAnnotations_thenCarHasEngine() { - ApplicationContext applicationContext = new AnnotationConfigApplicationContext(Config.class); - com.baeldung.typesofbeaninjection.domain.autowired.properties.Car car - = applicationContext.getBean(com.baeldung.typesofbeaninjection.domain.autowired.properties.Car.class); - - checkEngine(car.getEngine()); - } - - private void checkEngine(Engine engine) { - assertNotNull(engine); - assertEquals("V8", engine.getType()); - assertEquals(5, engine.getVolume()); - } - - -} From fe1105a526a2bc3326244dc00004936034e63b3f Mon Sep 17 00:00:00 2001 From: felipeazv Date: Thu, 18 Jan 2018 13:04:56 +0100 Subject: [PATCH 35/65] change module --- spring-5-reactive/pom.xml | 8 +- .../baeldung/reactive/websocket}/Event.java | 2 +- .../ReactiveJavaClientWebSocket.java | 23 +++++ .../ReactiveWebSocketApplication.java | 11 +++ .../ReactiveWebSocketConfiguration.java | 2 +- .../websocket}/ReactiveWebSocketHandler.java | 2 +- .../resources/static/client-websocket.html | 0 spring-reactive-websocket/pom.xml | 92 ------------------- .../ReactiveWebSocketApplication.java | 38 -------- 9 files changed, 44 insertions(+), 134 deletions(-) rename {spring-reactive-websocket/src/main/java/com/baeldung => spring-5-reactive/src/main/java/com/baeldung/reactive/websocket}/Event.java (79%) create mode 100644 spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveJavaClientWebSocket.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveWebSocketApplication.java rename {spring-reactive-websocket/src/main/java/com/baeldung => spring-5-reactive/src/main/java/com/baeldung/reactive/websocket}/ReactiveWebSocketConfiguration.java (96%) rename {spring-reactive-websocket/src/main/java/com/baeldung => spring-5-reactive/src/main/java/com/baeldung/reactive/websocket}/ReactiveWebSocketHandler.java (98%) rename {spring-reactive-websocket => spring-5-reactive}/src/main/resources/static/client-websocket.html (100%) delete mode 100644 spring-reactive-websocket/pom.xml delete mode 100644 spring-reactive-websocket/src/main/java/com/baeldung/ReactiveWebSocketApplication.java diff --git a/spring-5-reactive/pom.xml b/spring-5-reactive/pom.xml index 36eaaa1530..5065457c4b 100644 --- a/spring-5-reactive/pom.xml +++ b/spring-5-reactive/pom.xml @@ -60,7 +60,13 @@ - + + + org.projectlombok + lombok + compile + + org.apache.geronimo.specs geronimo-json_1.1_spec diff --git a/spring-reactive-websocket/src/main/java/com/baeldung/Event.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/Event.java similarity index 79% rename from spring-reactive-websocket/src/main/java/com/baeldung/Event.java rename to spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/Event.java index 20d678c214..90f83a566f 100644 --- a/spring-reactive-websocket/src/main/java/com/baeldung/Event.java +++ b/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/Event.java @@ -1,4 +1,4 @@ -package com.baeldung; +package com.baeldung.reactive.websocket; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveJavaClientWebSocket.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveJavaClientWebSocket.java new file mode 100644 index 0000000000..3e25e2a29c --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveJavaClientWebSocket.java @@ -0,0 +1,23 @@ +package com.baeldung.reactive.websocket; + +import java.net.URI; +import java.time.Duration; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.web.reactive.socket.WebSocketMessage; +import org.springframework.web.reactive.socket.client.ReactorNettyWebSocketClient; +import org.springframework.web.reactive.socket.client.WebSocketClient; + +import reactor.core.publisher.Mono; + +@SpringBootApplication +public class ReactiveJavaClientWebSocket { + public static void main(String[] args) throws InterruptedException { + WebSocketClient client = new ReactorNettyWebSocketClient(); + client.execute(URI.create("ws://localhost:8080/event-emitter"), session -> session.send(Mono.just(session.textMessage("event-me-from-spring-reactive-client"))) + .thenMany(session.receive() + .map(WebSocketMessage::getPayloadAsText) + .log()) + .then()) + .block(Duration.ofSeconds(10L)); + } +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveWebSocketApplication.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveWebSocketApplication.java new file mode 100644 index 0000000000..43b5e50387 --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveWebSocketApplication.java @@ -0,0 +1,11 @@ +package com.baeldung.reactive.websocket; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class ReactiveWebSocketApplication { + public static void main(String[] args) { + SpringApplication.run(ReactiveWebSocketApplication.class, args); + } +} diff --git a/spring-reactive-websocket/src/main/java/com/baeldung/ReactiveWebSocketConfiguration.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveWebSocketConfiguration.java similarity index 96% rename from spring-reactive-websocket/src/main/java/com/baeldung/ReactiveWebSocketConfiguration.java rename to spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveWebSocketConfiguration.java index 6729e09273..974def5a91 100644 --- a/spring-reactive-websocket/src/main/java/com/baeldung/ReactiveWebSocketConfiguration.java +++ b/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveWebSocketConfiguration.java @@ -1,4 +1,4 @@ -package com.baeldung; +package com.baeldung.reactive.websocket; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; diff --git a/spring-reactive-websocket/src/main/java/com/baeldung/ReactiveWebSocketHandler.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveWebSocketHandler.java similarity index 98% rename from spring-reactive-websocket/src/main/java/com/baeldung/ReactiveWebSocketHandler.java rename to spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveWebSocketHandler.java index 4a548322b3..7f74e714f6 100644 --- a/spring-reactive-websocket/src/main/java/com/baeldung/ReactiveWebSocketHandler.java +++ b/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveWebSocketHandler.java @@ -1,4 +1,4 @@ -package com.baeldung; +package com.baeldung.reactive.websocket; import org.springframework.web.reactive.socket.WebSocketSession; diff --git a/spring-reactive-websocket/src/main/resources/static/client-websocket.html b/spring-5-reactive/src/main/resources/static/client-websocket.html similarity index 100% rename from spring-reactive-websocket/src/main/resources/static/client-websocket.html rename to spring-5-reactive/src/main/resources/static/client-websocket.html diff --git a/spring-reactive-websocket/pom.xml b/spring-reactive-websocket/pom.xml deleted file mode 100644 index 846cece177..0000000000 --- a/spring-reactive-websocket/pom.xml +++ /dev/null @@ -1,92 +0,0 @@ - - - 4.0.0 - - spring-reactive-websocket - 0.0.1-SNAPSHOT - jar - - spring-reactive-websocket - Reactive WebSockets with Spring 5 - - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - - - - UTF-8 - UTF-8 - 1.8 - - - - - org.springframework.boot - spring-boot-starter-integration - 2.0.0.M7 - - - org.springframework.boot - spring-boot-starter-webflux - 2.0.0.M7 - - - org.projectlombok - lombok - compile - RELEASE - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - - - spring-snapshots - Spring Snapshots - https://repo.spring.io/snapshot - - true - - - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - - false - - - - - - - spring-snapshots - Spring Snapshots - https://repo.spring.io/snapshot - - true - - - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - - false - - - - - - diff --git a/spring-reactive-websocket/src/main/java/com/baeldung/ReactiveWebSocketApplication.java b/spring-reactive-websocket/src/main/java/com/baeldung/ReactiveWebSocketApplication.java deleted file mode 100644 index f8952d750d..0000000000 --- a/spring-reactive-websocket/src/main/java/com/baeldung/ReactiveWebSocketApplication.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.baeldung; - -import java.net.URI; -import java.time.Duration; - -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; -import org.springframework.web.reactive.socket.WebSocketMessage; -import org.springframework.web.reactive.socket.client.ReactorNettyWebSocketClient; -import org.springframework.web.reactive.socket.client.WebSocketClient; - -import reactor.core.publisher.Mono; - -@SpringBootApplication -public class ReactiveWebSocketApplication { - public static void main(String[] args) { - SpringApplication.run(ReactiveWebSocketApplication.class, args); - } - - /** - * Spring Reactive WebSocket Client - * **/ - @Bean - CommandLineRunner runner() { - return run -> { - WebSocketClient client = new ReactorNettyWebSocketClient(); - client.execute(URI.create("ws://localhost:8080/event-emitter"), session -> session.send(Mono.just(session.textMessage("event-me-from-spring-reactive-client"))) - .thenMany(session.receive() - .map(WebSocketMessage::getPayloadAsText) - .log()) - .then()) - .block(); -// .block(Duration.ofSeconds(10L));//force timeout after given duration - }; - } -} From a25ea6372a080c56cc49cc2ea0be73a7a801c605 Mon Sep 17 00:00:00 2001 From: felipeazv Date: Thu, 18 Jan 2018 13:40:33 +0100 Subject: [PATCH 36/65] moving module --- .../reactive/websocket/ReactiveJavaClientWebSocket.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveJavaClientWebSocket.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveJavaClientWebSocket.java index 3e25e2a29c..74e2d7daca 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveJavaClientWebSocket.java +++ b/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveJavaClientWebSocket.java @@ -13,7 +13,7 @@ import reactor.core.publisher.Mono; public class ReactiveJavaClientWebSocket { public static void main(String[] args) throws InterruptedException { WebSocketClient client = new ReactorNettyWebSocketClient(); - client.execute(URI.create("ws://localhost:8080/event-emitter"), session -> session.send(Mono.just(session.textMessage("event-me-from-spring-reactive-client"))) + client.execute(URI.create("ws://localhost:8080/event-emitter"), session -> session.send(Mono.just(session.textMessage("event-me-from-spring-reactive-client"))) .thenMany(session.receive() .map(WebSocketMessage::getPayloadAsText) .log()) From 16fe0c8eca150e8d6d2abe8984d069f326176021 Mon Sep 17 00:00:00 2001 From: Dassi orleando Date: Thu, 18 Jan 2018 23:42:48 +0100 Subject: [PATCH 37/65] BAEL-976: Update spring rest article (#3455) * BAEL-1216: improve tests * BAEL-1448: Update Spring 5 articles to use the release version * Setting up the Maven Wrapper on a maven project * Add Maven Wrapper on spring-boot module * simple add * BAEL-976: Update spring version --- spring-rest-embedded-tomcat/pom.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spring-rest-embedded-tomcat/pom.xml b/spring-rest-embedded-tomcat/pom.xml index cee9933c0d..3622e84101 100644 --- a/spring-rest-embedded-tomcat/pom.xml +++ b/spring-rest-embedded-tomcat/pom.xml @@ -84,14 +84,13 @@ **/JdbcTest.java **/*LiveTest.java -
- 5.0.1.RELEASE + 5.0.2.RELEASE 2.19.1 4.12 2.9.2 From b6f6e9dbc41ac9e07a744cfa510985b6f2f6dec9 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Fri, 19 Jan 2018 10:02:27 +0200 Subject: [PATCH 38/65] exclude metrics until tests are fixed --- pom.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pom.xml b/pom.xml index 9bf12725c0..6321b0333e 100644 --- a/pom.xml +++ b/pom.xml @@ -113,7 +113,9 @@ lombok mapstruct + mesos-marathon testing-modules/mockito testing-modules/mockito-2 From 7e7ccc7eb391bf9ac2b99f904a5c90a4a15abff4 Mon Sep 17 00:00:00 2001 From: aietcn Date: Sat, 20 Jan 2018 17:09:55 +0800 Subject: [PATCH 39/65] BAEL-1416 quick guide to kong (#3448) * BAEL-1416 quick guide to kong * refactor kong samples --- .../com/baeldung/kong/QueryController.java | 32 ++++ .../main/java/com/baeldung/kong/StockApp.java | 13 ++ .../src/main/resources/application.properties | 2 +- .../baeldung/kong/KongAdminAPILiveTest.java | 165 ++++++++++++++++++ .../kong/KongLoadBalanceLiveTest.java | 68 ++++++++ .../com/baeldung/kong/domain/APIObject.java | 54 ++++++ .../baeldung/kong/domain/ConsumerObject.java | 35 ++++ .../baeldung/kong/domain/KeyAuthObject.java | 21 +++ .../baeldung/kong/domain/PluginObject.java | 30 ++++ .../baeldung/kong/domain/TargetObject.java | 31 ++++ .../baeldung/kong/domain/UpstreamObject.java | 21 +++ 11 files changed, 471 insertions(+), 1 deletion(-) create mode 100644 spring-boot/src/main/java/com/baeldung/kong/QueryController.java create mode 100644 spring-boot/src/main/java/com/baeldung/kong/StockApp.java create mode 100644 spring-boot/src/test/java/com/baeldung/kong/KongAdminAPILiveTest.java create mode 100644 spring-boot/src/test/java/com/baeldung/kong/KongLoadBalanceLiveTest.java create mode 100644 spring-boot/src/test/java/com/baeldung/kong/domain/APIObject.java create mode 100644 spring-boot/src/test/java/com/baeldung/kong/domain/ConsumerObject.java create mode 100644 spring-boot/src/test/java/com/baeldung/kong/domain/KeyAuthObject.java create mode 100644 spring-boot/src/test/java/com/baeldung/kong/domain/PluginObject.java create mode 100644 spring-boot/src/test/java/com/baeldung/kong/domain/TargetObject.java create mode 100644 spring-boot/src/test/java/com/baeldung/kong/domain/UpstreamObject.java diff --git a/spring-boot/src/main/java/com/baeldung/kong/QueryController.java b/spring-boot/src/main/java/com/baeldung/kong/QueryController.java new file mode 100644 index 0000000000..af63a7e8a1 --- /dev/null +++ b/spring-boot/src/main/java/com/baeldung/kong/QueryController.java @@ -0,0 +1,32 @@ +package com.baeldung.kong; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author aiet + */ +@RestController +@RequestMapping("/stock") +public class QueryController { + + private static int REQUEST_COUNTER = 0; + + @GetMapping("/reqcount") + public int getReqCount(){ + return REQUEST_COUNTER; + } + + @GetMapping("/{code}") + public String getStockPrice(@PathVariable String code){ + REQUEST_COUNTER++; + if("BTC".equalsIgnoreCase(code)) + return "10000"; + else return "N/A"; + } + + + +} diff --git a/spring-boot/src/main/java/com/baeldung/kong/StockApp.java b/spring-boot/src/main/java/com/baeldung/kong/StockApp.java new file mode 100644 index 0000000000..f901592938 --- /dev/null +++ b/spring-boot/src/main/java/com/baeldung/kong/StockApp.java @@ -0,0 +1,13 @@ +package com.baeldung.kong; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class StockApp { + + public static void main(String[] args) { + SpringApplication.run(StockApp.class, args); + } + +} diff --git a/spring-boot/src/main/resources/application.properties b/spring-boot/src/main/resources/application.properties index 458b4e0d46..059a6c96be 100644 --- a/spring-boot/src/main/resources/application.properties +++ b/spring-boot/src/main/resources/application.properties @@ -1,4 +1,4 @@ -server.port=8080 +server.port=9090 server.contextPath=/springbootapp management.port=8081 management.address=127.0.0.1 diff --git a/spring-boot/src/test/java/com/baeldung/kong/KongAdminAPILiveTest.java b/spring-boot/src/test/java/com/baeldung/kong/KongAdminAPILiveTest.java new file mode 100644 index 0000000000..f399806a65 --- /dev/null +++ b/spring-boot/src/test/java/com/baeldung/kong/KongAdminAPILiveTest.java @@ -0,0 +1,165 @@ +package com.baeldung.kong; + +import com.baeldung.kong.domain.APIObject; +import com.baeldung.kong.domain.ConsumerObject; +import com.baeldung.kong.domain.KeyAuthObject; +import com.baeldung.kong.domain.PluginObject; +import org.junit.Before; +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.*; +import org.springframework.test.context.junit4.SpringRunner; + +import java.net.URI; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.DEFINED_PORT; + +/** + * @author aiet + */ +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = DEFINED_PORT, classes = StockApp.class) +public class KongAdminAPILiveTest { + + private String getStockPrice(String code) { + try { + return restTemplate.getForObject(new URI("http://localhost:8080/stock/" + code), String.class); + } catch (Exception ignored) { + } + return null; + } + + @Before + public void init() { + System.setProperty("sun.net.http.allowRestrictedHeaders", "true"); + } + + @Autowired TestRestTemplate restTemplate; + + @Test + public void givenEndpoint_whenQueryStockPrice_thenPriceCorrect() { + String response = getStockPrice("btc"); + assertEquals("10000", response); + + response = getStockPrice("eth"); + assertEquals("N/A", response); + } + + @Test + public void givenKongAdminAPI_whenAddAPI_thenAPIAccessibleViaKong() throws Exception { + restTemplate.delete("http://localhost:8001/apis/stock-api"); + + APIObject stockAPI = new APIObject("stock-api", "stock.api", "http://localhost:8080", "/"); + HttpEntity apiEntity = new HttpEntity<>(stockAPI); + ResponseEntity addAPIResp = restTemplate.postForEntity("http://localhost:8001/apis", apiEntity, String.class); + + assertEquals(HttpStatus.CREATED, addAPIResp.getStatusCode()); + + addAPIResp = restTemplate.postForEntity("http://localhost:8001/apis", apiEntity, String.class); + assertEquals(HttpStatus.CONFLICT, addAPIResp.getStatusCode()); + String apiListResp = restTemplate.getForObject("http://localhost:8001/apis/", String.class); + + assertTrue(apiListResp.contains("stock-api")); + + HttpHeaders headers = new HttpHeaders(); + headers.set("Host", "stock.api"); + RequestEntity requestEntity = new RequestEntity<>(headers, HttpMethod.GET, new URI("http://localhost:8000/stock/btc")); + ResponseEntity stockPriceResp = restTemplate.exchange(requestEntity, String.class); + + assertEquals("10000", stockPriceResp.getBody()); + } + + @Test + public void givenKongAdminAPI_whenAddAPIConsumer_thenAdded() { + restTemplate.delete("http://localhost:8001/consumers/eugenp"); + + ConsumerObject consumer = new ConsumerObject("eugenp"); + HttpEntity addConsumerEntity = new HttpEntity<>(consumer); + ResponseEntity addConsumerResp = restTemplate.postForEntity("http://localhost:8001/consumers/", addConsumerEntity, String.class); + + assertEquals(HttpStatus.CREATED, addConsumerResp.getStatusCode()); + + addConsumerResp = restTemplate.postForEntity("http://localhost:8001/consumers", addConsumerEntity, String.class); + assertEquals(HttpStatus.CONFLICT, addConsumerResp.getStatusCode()); + + String consumerListResp = restTemplate.getForObject("http://localhost:8001/consumers/", String.class); + assertTrue(consumerListResp.contains("eugenp")); + } + + @Test + public void givenAPI_whenEnableAuth_thenAnonymousDenied() throws Exception { + String apiListResp = restTemplate.getForObject("http://localhost:8001/apis/", String.class); + if (!apiListResp.contains("stock-api")) { + givenKongAdminAPI_whenAddAPI_thenAPIAccessibleViaKong(); + } + + PluginObject authPlugin = new PluginObject("key-auth"); + ResponseEntity enableAuthResp = restTemplate.postForEntity("http://localhost:8001/apis/stock-api/plugins", new HttpEntity<>(authPlugin), String.class); + + assertTrue(HttpStatus.CREATED == enableAuthResp.getStatusCode() || HttpStatus.CONFLICT == enableAuthResp.getStatusCode()); + + String pluginsResp = restTemplate.getForObject("http://localhost:8001/apis/stock-api/plugins", String.class); + assertTrue(pluginsResp.contains("key-auth")); + + HttpHeaders headers = new HttpHeaders(); + headers.set("Host", "stock.api"); + RequestEntity requestEntity = new RequestEntity<>(headers, HttpMethod.GET, new URI("http://localhost:8000/stock/btc")); + ResponseEntity stockPriceResp = restTemplate.exchange(requestEntity, String.class); + assertEquals(HttpStatus.UNAUTHORIZED, stockPriceResp.getStatusCode()); + } + + @Test + public void givenAPIAuthEnabled_whenAddKey_thenAccessAllowed() throws Exception { + String apiListResp = restTemplate.getForObject("http://localhost:8001/apis/", String.class); + if (!apiListResp.contains("stock-api")) { + givenKongAdminAPI_whenAddAPI_thenAPIAccessibleViaKong(); + } + + String consumerListResp = restTemplate.getForObject("http://localhost:8001/consumers/", String.class); + if (!consumerListResp.contains("eugenp")) { + givenKongAdminAPI_whenAddAPIConsumer_thenAdded(); + } + + final String consumerKey = "eugenp.pass"; + KeyAuthObject keyAuth = new KeyAuthObject(consumerKey); + ResponseEntity keyAuthResp = restTemplate.postForEntity("http://localhost:8001/consumers/eugenp/key-auth", new HttpEntity<>(keyAuth), String.class); + + assertTrue(HttpStatus.CREATED == keyAuthResp.getStatusCode() || HttpStatus.CONFLICT == keyAuthResp.getStatusCode()); + + HttpHeaders headers = new HttpHeaders(); + headers.set("Host", "stock.api"); + headers.set("apikey", consumerKey); + RequestEntity requestEntity = new RequestEntity<>(headers, HttpMethod.GET, new URI("http://localhost:8000/stock/btc")); + ResponseEntity stockPriceResp = restTemplate.exchange(requestEntity, String.class); + + assertEquals("10000", stockPriceResp.getBody()); + + headers.set("apikey", "wrongpass"); + requestEntity = new RequestEntity<>(headers, HttpMethod.GET, new URI("http://localhost:8000/stock/btc")); + stockPriceResp = restTemplate.exchange(requestEntity, String.class); + assertEquals(HttpStatus.FORBIDDEN, stockPriceResp.getStatusCode()); + } + + @Test + public void givenAdminAPIProxy_whenAddAPIViaProxy_thenAPIAdded() throws Exception { + APIObject adminAPI = new APIObject("admin-api", "admin.api", "http://localhost:8001", "/admin-api"); + HttpEntity apiEntity = new HttpEntity<>(adminAPI); + ResponseEntity addAPIResp = restTemplate.postForEntity("http://localhost:8001/apis", apiEntity, String.class); + + assertTrue(HttpStatus.CREATED == addAPIResp.getStatusCode() || HttpStatus.CONFLICT == addAPIResp.getStatusCode()); + + HttpHeaders headers = new HttpHeaders(); + headers.set("Host", "admin.api"); + APIObject baeldungAPI = new APIObject("baeldung-api", "baeldung.com", "http://ww.baeldung.com", "/"); + RequestEntity requestEntity = new RequestEntity<>(baeldungAPI, headers, HttpMethod.POST, new URI("http://localhost:8000/admin-api/apis")); + addAPIResp = restTemplate.exchange(requestEntity, String.class); + + assertTrue(HttpStatus.CREATED == addAPIResp.getStatusCode() || HttpStatus.CONFLICT == addAPIResp.getStatusCode()); + } + +} diff --git a/spring-boot/src/test/java/com/baeldung/kong/KongLoadBalanceLiveTest.java b/spring-boot/src/test/java/com/baeldung/kong/KongLoadBalanceLiveTest.java new file mode 100644 index 0000000000..f8090e4c86 --- /dev/null +++ b/spring-boot/src/test/java/com/baeldung/kong/KongLoadBalanceLiveTest.java @@ -0,0 +1,68 @@ +package com.baeldung.kong; + +import com.baeldung.kong.domain.APIObject; +import com.baeldung.kong.domain.TargetObject; +import com.baeldung.kong.domain.UpstreamObject; +import org.junit.Before; +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.*; +import org.springframework.test.context.junit4.SpringRunner; + +import java.net.URI; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.DEFINED_PORT; + +/** + * @author aiet + */ +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = DEFINED_PORT, classes = StockApp.class) +public class KongLoadBalanceLiveTest { + + @Before + public void init() { + System.setProperty("sun.net.http.allowRestrictedHeaders", "true"); + } + + @Autowired TestRestTemplate restTemplate; + + @Test + public void givenKongAdminAPI_whenAddAPI_thenAPIAccessibleViaKong() throws Exception { + UpstreamObject upstream = new UpstreamObject("stock.api.service"); + ResponseEntity addUpstreamResp = restTemplate.postForEntity("http://localhost:8001/upstreams", new HttpEntity<>(upstream), String.class); + assertTrue(HttpStatus.CREATED == addUpstreamResp.getStatusCode() || HttpStatus.CONFLICT == addUpstreamResp.getStatusCode()); + + TargetObject testTarget = new TargetObject("localhost:8080", 10); + ResponseEntity addTargetResp = restTemplate.postForEntity("http://localhost:8001/upstreams/stock.api.service/targets", new HttpEntity<>(testTarget), String.class); + assertTrue(HttpStatus.CREATED == addTargetResp.getStatusCode() || HttpStatus.CONFLICT == addTargetResp.getStatusCode()); + + TargetObject releaseTarget = new TargetObject("localhost:9090", 40); + addTargetResp = restTemplate.postForEntity("http://localhost:8001/upstreams/stock.api.service/targets", new HttpEntity<>(releaseTarget), String.class); + assertTrue(HttpStatus.CREATED == addTargetResp.getStatusCode() || HttpStatus.CONFLICT == addTargetResp.getStatusCode()); + + APIObject stockAPI = new APIObject("balanced-stock-api", "balanced.stock.api", "http://stock.api.service", "/"); + HttpEntity apiEntity = new HttpEntity<>(stockAPI); + ResponseEntity addAPIResp = restTemplate.postForEntity("http://localhost:8001/apis", apiEntity, String.class); + assertTrue(HttpStatus.CREATED == addAPIResp.getStatusCode() || HttpStatus.CONFLICT == addAPIResp.getStatusCode()); + + HttpHeaders headers = new HttpHeaders(); + headers.set("Host", "balanced.stock.api"); + for (int i = 0; i < 1000; i++) { + RequestEntity requestEntity = new RequestEntity<>(headers, HttpMethod.GET, new URI("http://localhost:8000/stock/btc")); + ResponseEntity stockPriceResp = restTemplate.exchange(requestEntity, String.class); + assertEquals("10000", stockPriceResp.getBody()); + } + + int releaseCount = restTemplate.getForObject("http://localhost:9090/stock/reqcount", Integer.class); + int testCount = restTemplate.getForObject("http://localhost:8080/stock/reqcount", Integer.class); + + assertTrue(Math.round(releaseCount * 1.0 / testCount) == 4); + } + +} diff --git a/spring-boot/src/test/java/com/baeldung/kong/domain/APIObject.java b/spring-boot/src/test/java/com/baeldung/kong/domain/APIObject.java new file mode 100644 index 0000000000..f386712444 --- /dev/null +++ b/spring-boot/src/test/java/com/baeldung/kong/domain/APIObject.java @@ -0,0 +1,54 @@ +package com.baeldung.kong.domain; + +/** + * @author aiet + */ +public class APIObject { + + public APIObject() { + } + + public APIObject(String name, String hosts, String upstream_url, String uris) { + this.name = name; + this.hosts = hosts; + this.upstream_url = upstream_url; + this.uris = uris; + } + + private String name; + private String hosts; + private String upstream_url; + private String uris; + + public String getUris() { + return uris; + } + + public void setUris(String uris) { + this.uris = uris; + } + + public String getUpstream_url() { + return upstream_url; + } + + public void setUpstream_url(String upstream_url) { + this.upstream_url = upstream_url; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getHosts() { + return hosts; + } + + public void setHosts(String hosts) { + this.hosts = hosts; + } +} diff --git a/spring-boot/src/test/java/com/baeldung/kong/domain/ConsumerObject.java b/spring-boot/src/test/java/com/baeldung/kong/domain/ConsumerObject.java new file mode 100644 index 0000000000..74bef8f2d1 --- /dev/null +++ b/spring-boot/src/test/java/com/baeldung/kong/domain/ConsumerObject.java @@ -0,0 +1,35 @@ +package com.baeldung.kong.domain; + +/** + * @author aiet + */ +public class ConsumerObject { + + private String username; + private String custom_id; + + public ConsumerObject(String username) { + this.username = username; + } + + public ConsumerObject(String username, String custom_id) { + this.username = username; + this.custom_id = custom_id; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getCustom_id() { + return custom_id; + } + + public void setCustom_id(String custom_id) { + this.custom_id = custom_id; + } +} diff --git a/spring-boot/src/test/java/com/baeldung/kong/domain/KeyAuthObject.java b/spring-boot/src/test/java/com/baeldung/kong/domain/KeyAuthObject.java new file mode 100644 index 0000000000..80de6bfcd9 --- /dev/null +++ b/spring-boot/src/test/java/com/baeldung/kong/domain/KeyAuthObject.java @@ -0,0 +1,21 @@ +package com.baeldung.kong.domain; + +/** + * @author aiet + */ +public class KeyAuthObject { + + public KeyAuthObject(String key) { + this.key = key; + } + + private String key; + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } +} diff --git a/spring-boot/src/test/java/com/baeldung/kong/domain/PluginObject.java b/spring-boot/src/test/java/com/baeldung/kong/domain/PluginObject.java new file mode 100644 index 0000000000..c161fc9b54 --- /dev/null +++ b/spring-boot/src/test/java/com/baeldung/kong/domain/PluginObject.java @@ -0,0 +1,30 @@ +package com.baeldung.kong.domain; + +/** + * @author aiet + */ +public class PluginObject { + + private String name; + private String consumer_id; + + public PluginObject(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getConsumer_id() { + return consumer_id; + } + + public void setConsumer_id(String consumer_id) { + this.consumer_id = consumer_id; + } +} diff --git a/spring-boot/src/test/java/com/baeldung/kong/domain/TargetObject.java b/spring-boot/src/test/java/com/baeldung/kong/domain/TargetObject.java new file mode 100644 index 0000000000..79653e2846 --- /dev/null +++ b/spring-boot/src/test/java/com/baeldung/kong/domain/TargetObject.java @@ -0,0 +1,31 @@ +package com.baeldung.kong.domain; + +/** + * @author aiet + */ +public class TargetObject { + + public TargetObject(String target, int weight) { + this.target = target; + this.weight = weight; + } + + private String target; + private int weight; + + public String getTarget() { + return target; + } + + public void setTarget(String target) { + this.target = target; + } + + public int getWeight() { + return weight; + } + + public void setWeight(int weight) { + this.weight = weight; + } +} diff --git a/spring-boot/src/test/java/com/baeldung/kong/domain/UpstreamObject.java b/spring-boot/src/test/java/com/baeldung/kong/domain/UpstreamObject.java new file mode 100644 index 0000000000..6461381ac5 --- /dev/null +++ b/spring-boot/src/test/java/com/baeldung/kong/domain/UpstreamObject.java @@ -0,0 +1,21 @@ +package com.baeldung.kong.domain; + +/** + * @author aiet + */ +public class UpstreamObject { + + public UpstreamObject(String name) { + this.name = name; + } + + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} From 0293c65f7744e95b4fb9937be61fd8c35293960e Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Sat, 20 Jan 2018 11:54:24 +0100 Subject: [PATCH 40/65] Trie Examples (#3466) * Implement Trie * Implement TrieTest * Delete testDelete method * Refactorings * Refactor Trie * Refactor TrieNode * Refactor Trie --- .../src/main/java/com/baeldung/trie/Trie.java | 76 +++++++++++++++++++ .../main/java/com/baeldung/trie/TrieNode.java | 31 ++++++++ .../test/java/com/baeldung/trie/TrieTest.java | 68 +++++++++++++++++ 3 files changed, 175 insertions(+) create mode 100644 core-java/src/main/java/com/baeldung/trie/Trie.java create mode 100644 core-java/src/main/java/com/baeldung/trie/TrieNode.java create mode 100644 core-java/src/test/java/com/baeldung/trie/TrieTest.java diff --git a/core-java/src/main/java/com/baeldung/trie/Trie.java b/core-java/src/main/java/com/baeldung/trie/Trie.java new file mode 100644 index 0000000000..2c4119df71 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/trie/Trie.java @@ -0,0 +1,76 @@ +package com.baeldung.trie; + +public class Trie { + private TrieNode root; + + Trie() { + root = new TrieNode(); + } + + public void insert(String word) { + TrieNode current = root; + for (int i = 0; i < word.length(); i++) { + char ch = word.charAt(i); + TrieNode node = current.getChildren() + .get(ch); + if (node == null) { + node = new TrieNode(); + current.getChildren() + .put(ch, node); + } + current = node; + } + current.setEndOfWord(true); + } + + public boolean find(String word) { + TrieNode current = root; + for (int i = 0; i < word.length(); i++) { + char ch = word.charAt(i); + TrieNode node = current.getChildren() + .get(ch); + if (node == null) { + return false; + } + current = node; + } + return current.isEndOfWord(); + } + + public void delete(String word) { + delete(root, word, 0); + } + + private boolean delete(TrieNode current, String word, int index) { + if (index == word.length()) { + if (!current.isEndOfWord()) { + return false; + } + current.setEndOfWord(false); + return current.getChildren() + .size() == 0; + } + char ch = word.charAt(index); + TrieNode node = current.getChildren() + .get(ch); + if (node == null) { + return false; + } + boolean shouldDeleteCurrentNode = delete(node, word, index + 1); + + if (shouldDeleteCurrentNode) { + current.getChildren() + .remove(ch); + return current.getChildren().isEmpty(); + } + return false; + } + + public boolean containsNode(String word) { + return find(word); + } + + public boolean isEmpty() { + return root == null; + } +} \ No newline at end of file diff --git a/core-java/src/main/java/com/baeldung/trie/TrieNode.java b/core-java/src/main/java/com/baeldung/trie/TrieNode.java new file mode 100644 index 0000000000..25dc753950 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/trie/TrieNode.java @@ -0,0 +1,31 @@ +package com.baeldung.trie; + +import java.util.HashMap; +import java.util.Map; + +class TrieNode { + private Map children; + private boolean endOfWord; + + public TrieNode() { + children = new HashMap<>(); + endOfWord = false; + } + + public Map getChildren() { + return children; + } + + public void setChildren(Map children) { + this.children = children; + } + + public boolean isEndOfWord() { + return endOfWord; + } + + public void setEndOfWord(boolean endOfWord) { + this.endOfWord = endOfWord; + } + +} \ No newline at end of file diff --git a/core-java/src/test/java/com/baeldung/trie/TrieTest.java b/core-java/src/test/java/com/baeldung/trie/TrieTest.java new file mode 100644 index 0000000000..be7e5575d8 --- /dev/null +++ b/core-java/src/test/java/com/baeldung/trie/TrieTest.java @@ -0,0 +1,68 @@ +package com.baeldung.trie; + +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class TrieTest { + + @Test + public void whenEmptyTrie_thenNoElements() { + Trie trie = new Trie(); + + assertFalse(trie.isEmpty()); + } + + @Test + public void givenATrie_whenAddingElements_thenTrieNotEmpty() { + Trie trie = createExampleTrie(); + + assertFalse(trie.isEmpty()); + } + + @Test + public void givenATrie_whenAddingElements_thenTrieHasThoseElements() { + Trie trie = createExampleTrie(); + + assertFalse(trie.containsNode("3")); + assertFalse(trie.containsNode("vida")); + + assertTrue(trie.containsNode("Programming")); + assertTrue(trie.containsNode("is")); + assertTrue(trie.containsNode("a")); + assertTrue(trie.containsNode("way")); + assertTrue(trie.containsNode("of")); + assertTrue(trie.containsNode("life")); + } + + @Test + public void givenATrie_whenLookingForNonExistingElement_thenReturnsFalse() { + Trie trie = createExampleTrie(); + + assertFalse(trie.containsNode("99")); + } + + @Test + public void givenATrie_whenDeletingElements_thenTreeDoesNotContainThoseElements() { + + Trie trie = createExampleTrie(); + + assertTrue(trie.containsNode("Programming")); + trie.delete("Programming"); + assertFalse(trie.containsNode("Programming")); + } + + private Trie createExampleTrie() { + Trie trie = new Trie(); + + trie.insert("Programming"); + trie.insert("is"); + trie.insert("a"); + trie.insert("way"); + trie.insert("of"); + trie.insert("life"); + + return trie; + } +} From b1520c93fd73be57276c419a37c2713de6a1c974 Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Sat, 20 Jan 2018 11:54:39 +0100 Subject: [PATCH 41/65] Update README.md (#3443) --- core-java-concurrency/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-concurrency/README.md b/core-java-concurrency/README.md index dc048495e4..8122c71bcb 100644 --- a/core-java-concurrency/README.md +++ b/core-java-concurrency/README.md @@ -33,4 +33,4 @@ - [Daemon Threads in Java](http://www.baeldung.com/java-daemon-thread) - [Implementing a Runnable vs Extending a Thread](http://www.baeldung.com/java-runnable-vs-extending-thread) - [How to Kill a Java Thread](http://www.baeldung.com/java-thread-stop) -- [How to Wait for Threads to Finish in the ExecutorService](http://www.baeldung.com/java-executor-wait-for-threads) +- [ExecutorService - Waiting for Threads to Finish](http://www.baeldung.com/java-executor-wait-for-threads) From d64468eddcb36a88c57fff01b2c09029ef27d762 Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Sat, 20 Jan 2018 13:33:02 +0100 Subject: [PATCH 42/65] Refactor elastic (#3467) --- .../com/baeldung/elasticsearch/Person.java | 3 +- .../ElasticSearchManualTest.java | 19 +-- .../elasticsearch/GeoQueriesTest.java | 150 +++++++++--------- .../data/es/ElasticSearchIntegrationTest.java | 42 ++--- .../es/ElasticSearchQueryIntegrationTest.java | 83 ++++++---- 5 files changed, 153 insertions(+), 144 deletions(-) diff --git a/spring-data-elasticsearch/src/main/java/com/baeldung/elasticsearch/Person.java b/spring-data-elasticsearch/src/main/java/com/baeldung/elasticsearch/Person.java index b8ad59e2e2..09b971fdc2 100644 --- a/spring-data-elasticsearch/src/main/java/com/baeldung/elasticsearch/Person.java +++ b/spring-data-elasticsearch/src/main/java/com/baeldung/elasticsearch/Person.java @@ -11,10 +11,9 @@ public class Person { private Date dateOfBirth; public Person() { - } - public Person(int age, String fullName, Date dateOfBirth) { + Person(int age, String fullName, Date dateOfBirth) { super(); this.age = age; this.fullName = fullName; diff --git a/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/ElasticSearchManualTest.java b/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/ElasticSearchManualTest.java index 1fb1ae76f7..285c164869 100644 --- a/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/ElasticSearchManualTest.java +++ b/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/ElasticSearchManualTest.java @@ -19,6 +19,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.List; +import java.util.stream.Collectors; import static org.elasticsearch.node.NodeBuilder.nodeBuilder; import static org.junit.Assert.assertEquals; @@ -78,12 +79,9 @@ public class ElasticSearchManualTest { SearchHit[] searchHits = response .getHits() .getHits(); - List results = new ArrayList<>(); - for (SearchHit hit : searchHits) { - String sourceAsString = hit.getSourceAsString(); - Person person = JSON.parseObject(sourceAsString, Person.class); - results.add(person); - } + List results = Arrays.stream(searchHits) + .map(hit -> JSON.parseObject(hit.getSourceAsString(), Person.class)) + .collect(Collectors.toList()); } @Test @@ -125,11 +123,10 @@ public class ElasticSearchManualTest { .actionGet(); response2.getHits(); response3.getHits(); - List searchHits = Arrays.asList(response - .getHits() - .getHits()); - final List results = new ArrayList<>(); - searchHits.forEach(hit -> results.add(JSON.parseObject(hit.getSourceAsString(), Person.class))); + + final List results = Arrays.stream(response.getHits().getHits()) + .map(hit -> JSON.parseObject(hit.getSourceAsString(), Person.class)) + .collect(Collectors.toList()); } @Test diff --git a/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/GeoQueriesTest.java b/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/GeoQueriesTest.java index 19514ce4c2..aa20913637 100644 --- a/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/GeoQueriesTest.java +++ b/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/GeoQueriesTest.java @@ -1,11 +1,6 @@ package com.baeldung.elasticsearch; -import static org.junit.Assert.assertTrue; - -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - +import com.baeldung.spring.data.es.config.Config; import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; import org.elasticsearch.action.index.IndexResponse; import org.elasticsearch.action.search.SearchResponse; @@ -15,6 +10,7 @@ import org.elasticsearch.common.geo.builders.ShapeBuilder; import org.elasticsearch.common.unit.DistanceUnit; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.search.SearchHit; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -24,14 +20,19 @@ import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.baeldung.spring.data.es.config.Config; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import static org.junit.Assert.assertTrue; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = Config.class) public class GeoQueriesTest { - public static final String WONDERS_OF_WORLD = "wonders-of-world"; - public static final String WONDERS = "Wonders"; + private static final String WONDERS_OF_WORLD = "wonders-of-world"; + private static final String WONDERS = "Wonders"; + @Autowired private ElasticsearchTemplate elasticsearchTemplate; @@ -44,39 +45,37 @@ public class GeoQueriesTest { CreateIndexRequest req = new CreateIndexRequest(WONDERS_OF_WORLD); req.mapping(WONDERS, jsonObject); client.admin() - .indices() - .create(req) - .actionGet(); + .indices() + .create(req) + .actionGet(); } @Test public void givenGeoShapeData_whenExecutedGeoShapeQuery_thenResultNonEmpty() { String jsonObject = "{\"name\":\"Agra\",\"region\":{\"type\":\"envelope\",\"coordinates\":[[75,25],[80.1,30.2]]}}"; IndexResponse response = client.prepareIndex(WONDERS_OF_WORLD, WONDERS) - .setSource(jsonObject) - .get(); + .setSource(jsonObject) + .get(); String tajMahalId = response.getId(); client.admin() - .indices() - .prepareRefresh(WONDERS_OF_WORLD) - .get(); + .indices() + .prepareRefresh(WONDERS_OF_WORLD) + .get(); QueryBuilder qb = QueryBuilders.geoShapeQuery("region", ShapeBuilder.newEnvelope() - .topLeft(74.00, 24.0) - .bottomRight(81.1, 31.2)) - .relation(ShapeRelation.WITHIN); + .topLeft(74.00, 24.0) + .bottomRight(81.1, 31.2)) + .relation(ShapeRelation.WITHIN); SearchResponse searchResponse = client.prepareSearch(WONDERS_OF_WORLD) - .setTypes(WONDERS) - .setQuery(qb) - .execute() - .actionGet(); + .setTypes(WONDERS) + .setQuery(qb) + .execute() + .actionGet(); List ids = Arrays.stream(searchResponse.getHits() - .getHits()) - .map(hit -> { - return hit.getId(); - }) - .collect(Collectors.toList()); + .getHits()) + .map(SearchHit::getId) + .collect(Collectors.toList()); assertTrue(ids.contains(tajMahalId)); } @@ -84,29 +83,27 @@ public class GeoQueriesTest { public void givenGeoPointData_whenExecutedGeoBoundingBoxQuery_thenResultNonEmpty() { String jsonObject = "{\"name\":\"Pyramids of Giza\",\"location\":[31.131302,29.976480]}"; IndexResponse response = client.prepareIndex(WONDERS_OF_WORLD, WONDERS) - .setSource(jsonObject) - .get(); + .setSource(jsonObject) + .get(); String pyramidsOfGizaId = response.getId(); client.admin() - .indices() - .prepareRefresh(WONDERS_OF_WORLD) - .get(); + .indices() + .prepareRefresh(WONDERS_OF_WORLD) + .get(); QueryBuilder qb = QueryBuilders.geoBoundingBoxQuery("location") - .bottomLeft(28, 30) - .topRight(31, 32); + .bottomLeft(28, 30) + .topRight(31, 32); SearchResponse searchResponse = client.prepareSearch(WONDERS_OF_WORLD) - .setTypes(WONDERS) - .setQuery(qb) - .execute() - .actionGet(); + .setTypes(WONDERS) + .setQuery(qb) + .execute() + .actionGet(); List ids = Arrays.stream(searchResponse.getHits() - .getHits()) - .map(hit -> { - return hit.getId(); - }) - .collect(Collectors.toList()); + .getHits()) + .map(SearchHit::getId) + .collect(Collectors.toList()); assertTrue(ids.contains(pyramidsOfGizaId)); } @@ -114,29 +111,27 @@ public class GeoQueriesTest { public void givenGeoPointData_whenExecutedGeoDistanceQuery_thenResultNonEmpty() { String jsonObject = "{\"name\":\"Lighthouse of alexandria\",\"location\":[31.131302,29.976480]}"; IndexResponse response = client.prepareIndex(WONDERS_OF_WORLD, WONDERS) - .setSource(jsonObject) - .get(); + .setSource(jsonObject) + .get(); String lighthouseOfAlexandriaId = response.getId(); client.admin() - .indices() - .prepareRefresh(WONDERS_OF_WORLD) - .get(); + .indices() + .prepareRefresh(WONDERS_OF_WORLD) + .get(); QueryBuilder qb = QueryBuilders.geoDistanceQuery("location") - .point(29.976, 31.131) - .distance(10, DistanceUnit.MILES); + .point(29.976, 31.131) + .distance(10, DistanceUnit.MILES); SearchResponse searchResponse = client.prepareSearch(WONDERS_OF_WORLD) - .setTypes(WONDERS) - .setQuery(qb) - .execute() - .actionGet(); + .setTypes(WONDERS) + .setQuery(qb) + .execute() + .actionGet(); List ids = Arrays.stream(searchResponse.getHits() - .getHits()) - .map(hit -> { - return hit.getId(); - }) - .collect(Collectors.toList()); + .getHits()) + .map(SearchHit::getId) + .collect(Collectors.toList()); assertTrue(ids.contains(lighthouseOfAlexandriaId)); } @@ -144,30 +139,28 @@ public class GeoQueriesTest { public void givenGeoPointData_whenExecutedGeoPolygonQuery_thenResultNonEmpty() { String jsonObject = "{\"name\":\"The Great Rann of Kutch\",\"location\":[69.859741,23.733732]}"; IndexResponse response = client.prepareIndex(WONDERS_OF_WORLD, WONDERS) - .setSource(jsonObject) - .get(); + .setSource(jsonObject) + .get(); String greatRannOfKutchid = response.getId(); client.admin() - .indices() - .prepareRefresh(WONDERS_OF_WORLD) - .get(); + .indices() + .prepareRefresh(WONDERS_OF_WORLD) + .get(); QueryBuilder qb = QueryBuilders.geoPolygonQuery("location") - .addPoint(22.733, 68.859) - .addPoint(24.733, 68.859) - .addPoint(23, 70.859); + .addPoint(22.733, 68.859) + .addPoint(24.733, 68.859) + .addPoint(23, 70.859); SearchResponse searchResponse = client.prepareSearch(WONDERS_OF_WORLD) - .setTypes(WONDERS) - .setQuery(qb) - .execute() - .actionGet(); + .setTypes(WONDERS) + .setQuery(qb) + .execute() + .actionGet(); List ids = Arrays.stream(searchResponse.getHits() - .getHits()) - .map(hit -> { - return hit.getId(); - }) - .collect(Collectors.toList()); + .getHits()) + .map(SearchHit::getId) + .collect(Collectors.toList()); assertTrue(ids.contains(greatRannOfKutchid)); } @@ -175,5 +168,4 @@ public class GeoQueriesTest { public void destroy() { elasticsearchTemplate.deleteIndex(WONDERS_OF_WORLD); } - } diff --git a/spring-data-elasticsearch/src/test/java/com/baeldung/spring/data/es/ElasticSearchIntegrationTest.java b/spring-data-elasticsearch/src/test/java/com/baeldung/spring/data/es/ElasticSearchIntegrationTest.java index 1280c8e1de..be31de724d 100644 --- a/spring-data-elasticsearch/src/test/java/com/baeldung/spring/data/es/ElasticSearchIntegrationTest.java +++ b/spring-data-elasticsearch/src/test/java/com/baeldung/spring/data/es/ElasticSearchIntegrationTest.java @@ -1,15 +1,9 @@ package com.baeldung.spring.data.es; -import static java.util.Arrays.asList; -import static org.elasticsearch.index.query.MatchQueryBuilder.Operator.AND; -import static org.elasticsearch.index.query.QueryBuilders.fuzzyQuery; -import static org.elasticsearch.index.query.QueryBuilders.matchQuery; -import static org.elasticsearch.index.query.QueryBuilders.regexpQuery; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.util.List; - +import com.baeldung.spring.data.es.config.Config; +import com.baeldung.spring.data.es.model.Article; +import com.baeldung.spring.data.es.model.Author; +import com.baeldung.spring.data.es.service.ArticleService; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -22,10 +16,15 @@ import org.springframework.data.elasticsearch.core.query.SearchQuery; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.baeldung.spring.data.es.config.Config; -import com.baeldung.spring.data.es.model.Article; -import com.baeldung.spring.data.es.model.Author; -import com.baeldung.spring.data.es.service.ArticleService; +import java.util.List; + +import static java.util.Arrays.asList; +import static org.elasticsearch.index.query.MatchQueryBuilder.Operator.AND; +import static org.elasticsearch.index.query.QueryBuilders.fuzzyQuery; +import static org.elasticsearch.index.query.QueryBuilders.matchQuery; +import static org.elasticsearch.index.query.QueryBuilders.regexpQuery; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = Config.class) @@ -72,21 +71,24 @@ public class ElasticSearchIntegrationTest { @Test public void givenPersistedArticles_whenSearchByAuthorsName_thenRightFound() { - final Page
articleByAuthorName = articleService.findByAuthorName(johnSmith.getName(), new PageRequest(0, 10)); + final Page
articleByAuthorName = articleService + .findByAuthorName(johnSmith.getName(), new PageRequest(0, 10)); assertEquals(2L, articleByAuthorName.getTotalElements()); } @Test public void givenCustomQuery_whenSearchByAuthorsName_thenArticleIsFound() { - final Page
articleByAuthorName = articleService.findByAuthorNameUsingCustomQuery("John Smith", new PageRequest(0, 10)); + final Page
articleByAuthorName = articleService + .findByAuthorNameUsingCustomQuery("John Smith", new PageRequest(0, 10)); assertEquals(3L, articleByAuthorName.getTotalElements()); } @Test public void givenPersistedArticles_whenUseRegexQuery_thenRightArticlesFound() { - final SearchQuery searchQuery = new NativeSearchQueryBuilder().withFilter(regexpQuery("title", ".*data.*")).build(); + final SearchQuery searchQuery = new NativeSearchQueryBuilder().withFilter(regexpQuery("title", ".*data.*")) + .build(); final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); assertEquals(1, articles.size()); @@ -112,7 +114,8 @@ public class ElasticSearchIntegrationTest { final String articleTitle = "Spring Data Elasticsearch"; - final SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery("title", articleTitle).minimumShouldMatch("75%")).build(); + final SearchQuery searchQuery = new NativeSearchQueryBuilder() + .withQuery(matchQuery("title", articleTitle).minimumShouldMatch("75%")).build(); final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); assertEquals(1, articles.size()); final long count = articleService.count(); @@ -124,7 +127,8 @@ public class ElasticSearchIntegrationTest { @Test public void givenSavedDoc_whenOneTermMatches_thenFindByTitle() { - final SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery("title", "Search engines").operator(AND)).build(); + final SearchQuery searchQuery = new NativeSearchQueryBuilder() + .withQuery(matchQuery("title", "Search engines").operator(AND)).build(); final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); assertEquals(1, articles.size()); } diff --git a/spring-data-elasticsearch/src/test/java/com/baeldung/spring/data/es/ElasticSearchQueryIntegrationTest.java b/spring-data-elasticsearch/src/test/java/com/baeldung/spring/data/es/ElasticSearchQueryIntegrationTest.java index cc4bce0c75..7a9ac2de06 100644 --- a/spring-data-elasticsearch/src/test/java/com/baeldung/spring/data/es/ElasticSearchQueryIntegrationTest.java +++ b/spring-data-elasticsearch/src/test/java/com/baeldung/spring/data/es/ElasticSearchQueryIntegrationTest.java @@ -1,20 +1,9 @@ package com.baeldung.spring.data.es; -import static java.util.Arrays.asList; -import static java.util.stream.Collectors.toList; -import static org.elasticsearch.index.query.MatchQueryBuilder.Operator.AND; -import static org.elasticsearch.index.query.QueryBuilders.boolQuery; -import static org.elasticsearch.index.query.QueryBuilders.matchPhraseQuery; -import static org.elasticsearch.index.query.QueryBuilders.matchQuery; -import static org.elasticsearch.index.query.QueryBuilders.multiMatchQuery; -import static org.elasticsearch.index.query.QueryBuilders.nestedQuery; -import static org.elasticsearch.index.query.QueryBuilders.termQuery; -import static org.junit.Assert.assertEquals; - -import java.util.Collections; -import java.util.List; -import java.util.Map; - +import com.baeldung.spring.data.es.config.Config; +import com.baeldung.spring.data.es.model.Article; +import com.baeldung.spring.data.es.model.Author; +import com.baeldung.spring.data.es.service.ArticleService; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.client.Client; import org.elasticsearch.common.unit.Fuzziness; @@ -22,6 +11,7 @@ import org.elasticsearch.index.query.MultiMatchQueryBuilder; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.search.aggregations.Aggregation; import org.elasticsearch.search.aggregations.AggregationBuilders; +import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; import org.elasticsearch.search.aggregations.bucket.terms.StringTerms; import org.elasticsearch.search.aggregations.bucket.terms.Terms; import org.elasticsearch.search.aggregations.bucket.terms.TermsBuilder; @@ -35,10 +25,20 @@ import org.springframework.data.elasticsearch.core.query.SearchQuery; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.baeldung.spring.data.es.config.Config; -import com.baeldung.spring.data.es.model.Article; -import com.baeldung.spring.data.es.model.Author; -import com.baeldung.spring.data.es.service.ArticleService; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import static java.util.Arrays.asList; +import static java.util.stream.Collectors.toList; +import static org.elasticsearch.index.query.MatchQueryBuilder.Operator.AND; +import static org.elasticsearch.index.query.QueryBuilders.boolQuery; +import static org.elasticsearch.index.query.QueryBuilders.matchPhraseQuery; +import static org.elasticsearch.index.query.QueryBuilders.matchQuery; +import static org.elasticsearch.index.query.QueryBuilders.multiMatchQuery; +import static org.elasticsearch.index.query.QueryBuilders.nestedQuery; +import static org.elasticsearch.index.query.QueryBuilders.termQuery; +import static org.junit.Assert.assertEquals; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = Config.class) @@ -86,14 +86,16 @@ public class ElasticSearchQueryIntegrationTest { @Test public void givenFullTitle_whenRunMatchQuery_thenDocIsFound() { - final SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery("title", "Search engines").operator(AND)).build(); + final SearchQuery searchQuery = new NativeSearchQueryBuilder() + .withQuery(matchQuery("title", "Search engines").operator(AND)).build(); final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); assertEquals(1, articles.size()); } @Test public void givenOneTermFromTitle_whenRunMatchQuery_thenDocIsFound() { - final SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery("title", "Engines Solutions")).build(); + final SearchQuery searchQuery = new NativeSearchQueryBuilder() + .withQuery(matchQuery("title", "Engines Solutions")).build(); final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); assertEquals(1, articles.size()); assertEquals("Search engines", articles.get(0).getTitle()); @@ -101,18 +103,21 @@ public class ElasticSearchQueryIntegrationTest { @Test public void givenPartTitle_whenRunMatchQuery_thenDocIsFound() { - final SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery("title", "elasticsearch data")).build(); + final SearchQuery searchQuery = new NativeSearchQueryBuilder() + .withQuery(matchQuery("title", "elasticsearch data")).build(); final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); assertEquals(3, articles.size()); } @Test public void givenFullTitle_whenRunMatchQueryOnVerbatimField_thenDocIsFound() { - SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery("title.verbatim", "Second Article About Elasticsearch")).build(); + SearchQuery searchQuery = new NativeSearchQueryBuilder() + .withQuery(matchQuery("title.verbatim", "Second Article About Elasticsearch")).build(); List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); assertEquals(1, articles.size()); - searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery("title.verbatim", "Second Article About")).build(); + searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery("title.verbatim", "Second Article About")) + .build(); articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); assertEquals(0, articles.size()); } @@ -130,38 +135,48 @@ public class ElasticSearchQueryIntegrationTest { @Test public void givenAnalyzedQuery_whenMakeAggregationOnTermCount_thenEachTokenCountsSeparately() { final TermsBuilder aggregation = AggregationBuilders.terms("top_tags").field("title"); - final SearchResponse response = client.prepareSearch("blog").setTypes("article").addAggregation(aggregation).execute().actionGet(); + final SearchResponse response = client.prepareSearch("blog").setTypes("article").addAggregation(aggregation) + .execute().actionGet(); final Map results = response.getAggregations().asMap(); final StringTerms topTags = (StringTerms) results.get("top_tags"); - final List keys = topTags.getBuckets().stream().map(b -> b.getKeyAsString()).collect(toList()); - Collections.sort(keys); + final List keys = topTags.getBuckets().stream() + .map(MultiBucketsAggregation.Bucket::getKeyAsString) + .sorted() + .collect(toList()); assertEquals(asList("about", "article", "data", "elasticsearch", "engines", "search", "second", "spring", "tutorial"), keys); } @Test public void givenNotAnalyzedQuery_whenMakeAggregationOnTermCount_thenEachTermCountsIndividually() { - final TermsBuilder aggregation = AggregationBuilders.terms("top_tags").field("tags").order(Terms.Order.aggregation("_count", false)); - final SearchResponse response = client.prepareSearch("blog").setTypes("article").addAggregation(aggregation).execute().actionGet(); + final TermsBuilder aggregation = AggregationBuilders.terms("top_tags").field("tags") + .order(Terms.Order.aggregation("_count", false)); + final SearchResponse response = client.prepareSearch("blog").setTypes("article").addAggregation(aggregation) + .execute().actionGet(); final Map results = response.getAggregations().asMap(); final StringTerms topTags = (StringTerms) results.get("top_tags"); - final List keys = topTags.getBuckets().stream().map(b -> b.getKeyAsString()).collect(toList()); + final List keys = topTags.getBuckets().stream() + .map(MultiBucketsAggregation.Bucket::getKeyAsString) + .collect(toList()); assertEquals(asList("elasticsearch", "spring data", "search engines", "tutorial"), keys); } @Test public void givenNotExactPhrase_whenUseSlop_thenQueryMatches() { - final SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchPhraseQuery("title", "spring elasticsearch").slop(1)).build(); + final SearchQuery searchQuery = new NativeSearchQueryBuilder() + .withQuery(matchPhraseQuery("title", "spring elasticsearch").slop(1)).build(); final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); assertEquals(1, articles.size()); } @Test public void givenPhraseWithType_whenUseFuzziness_thenQueryMatches() { - final SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery("title", "spring date elasticserch").operator(AND).fuzziness(Fuzziness.ONE).prefixLength(3)).build(); + final SearchQuery searchQuery = new NativeSearchQueryBuilder() + .withQuery(matchQuery("title", "spring date elasticserch").operator(AND).fuzziness(Fuzziness.ONE) + .prefixLength(3)).build(); final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); assertEquals(1, articles.size()); @@ -169,7 +184,9 @@ public class ElasticSearchQueryIntegrationTest { @Test public void givenMultimatchQuery_whenDoSearch_thenAllProvidedFieldsMatch() { - final SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(multiMatchQuery("tutorial").field("title").field("tags").type(MultiMatchQueryBuilder.Type.BEST_FIELDS)).build(); + final SearchQuery searchQuery = new NativeSearchQueryBuilder() + .withQuery(multiMatchQuery("tutorial").field("title").field("tags") + .type(MultiMatchQueryBuilder.Type.BEST_FIELDS)).build(); final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); assertEquals(2, articles.size()); From 99040c49f15daf4ee416094db71d783d47bf112a Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sat, 20 Jan 2018 15:27:28 +0200 Subject: [PATCH 43/65] remove gson --- spring-cloud/spring-cloud-security/personresource/pom.xml | 4 ---- .../java/com/baeldung/controller/PersonInfoController.java | 4 +--- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/spring-cloud/spring-cloud-security/personresource/pom.xml b/spring-cloud/spring-cloud-security/personresource/pom.xml index 783fd41e66..ca1ff82515 100644 --- a/spring-cloud/spring-cloud-security/personresource/pom.xml +++ b/spring-cloud/spring-cloud-security/personresource/pom.xml @@ -43,10 +43,6 @@ org.springframework.security spring-security-jwt - - com.google.code.gson - gson - diff --git a/spring-cloud/spring-cloud-security/personresource/src/main/java/com/baeldung/controller/PersonInfoController.java b/spring-cloud/spring-cloud-security/personresource/src/main/java/com/baeldung/controller/PersonInfoController.java index 15ffc557fc..f2beec927d 100644 --- a/spring-cloud/spring-cloud-security/personresource/src/main/java/com/baeldung/controller/PersonInfoController.java +++ b/spring-cloud/spring-cloud-security/personresource/src/main/java/com/baeldung/controller/PersonInfoController.java @@ -14,8 +14,6 @@ public class PersonInfoController { @GetMapping("/personResource") @PreAuthorize("hasAnyRole('ADMIN', 'USER')") public @ResponseBody String personInfo() { - Gson gson = new Gson(); - String person = gson.toJson(new Person("abir", "Dhaka", "Bangladesh", 29, "Male")); - return person; + return new Person("abir", "Dhaka", "Bangladesh", 29, "Male"); } } \ No newline at end of file From 43b26b0ef93a7a91a806a6625e2c614f1e0bb870 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sat, 20 Jan 2018 15:30:28 +0200 Subject: [PATCH 44/65] remove gson --- .../java/com/baeldung/controller/PersonInfoController.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spring-cloud/spring-cloud-security/personresource/src/main/java/com/baeldung/controller/PersonInfoController.java b/spring-cloud/spring-cloud-security/personresource/src/main/java/com/baeldung/controller/PersonInfoController.java index f2beec927d..9e5420da5a 100644 --- a/spring-cloud/spring-cloud-security/personresource/src/main/java/com/baeldung/controller/PersonInfoController.java +++ b/spring-cloud/spring-cloud-security/personresource/src/main/java/com/baeldung/controller/PersonInfoController.java @@ -6,14 +6,13 @@ import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import com.baeldung.model.Person; -import com.google.gson.Gson; @RestController public class PersonInfoController { @GetMapping("/personResource") @PreAuthorize("hasAnyRole('ADMIN', 'USER')") - public @ResponseBody String personInfo() { + public @ResponseBody Person personInfo() { return new Person("abir", "Dhaka", "Bangladesh", 29, "Male"); } } \ No newline at end of file From 7bd1fbf7349426fe730c8f483a2f996399736d7d Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Sat, 20 Jan 2018 15:05:41 +0100 Subject: [PATCH 45/65] Refactor Trie (#3469) --- .../src/main/java/com/baeldung/trie/Trie.java | 42 +++++++------------ 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/core-java/src/main/java/com/baeldung/trie/Trie.java b/core-java/src/main/java/com/baeldung/trie/Trie.java index 2c4119df71..dd51d97b2d 100644 --- a/core-java/src/main/java/com/baeldung/trie/Trie.java +++ b/core-java/src/main/java/com/baeldung/trie/Trie.java @@ -9,26 +9,23 @@ public class Trie { public void insert(String word) { TrieNode current = root; + for (int i = 0; i < word.length(); i++) { - char ch = word.charAt(i); - TrieNode node = current.getChildren() - .get(ch); - if (node == null) { - node = new TrieNode(); - current.getChildren() - .put(ch, node); - } - current = node; + current = current.getChildren().computeIfAbsent(word.charAt(i), c -> new TrieNode()); } current.setEndOfWord(true); } - public boolean find(String word) { + public boolean delete(String word) { + return delete(root, word, 0); + } + + public boolean containsNode(String word) { TrieNode current = root; + for (int i = 0; i < word.length(); i++) { char ch = word.charAt(i); - TrieNode node = current.getChildren() - .get(ch); + TrieNode node = current.getChildren().get(ch); if (node == null) { return false; } @@ -37,8 +34,8 @@ public class Trie { return current.isEndOfWord(); } - public void delete(String word) { - delete(root, word, 0); + public boolean isEmpty() { + return root == null; } private boolean delete(TrieNode current, String word, int index) { @@ -47,30 +44,19 @@ public class Trie { return false; } current.setEndOfWord(false); - return current.getChildren() - .size() == 0; + return current.getChildren().isEmpty(); } char ch = word.charAt(index); - TrieNode node = current.getChildren() - .get(ch); + TrieNode node = current.getChildren().get(ch); if (node == null) { return false; } boolean shouldDeleteCurrentNode = delete(node, word, index + 1); if (shouldDeleteCurrentNode) { - current.getChildren() - .remove(ch); + current.getChildren().remove(ch); return current.getChildren().isEmpty(); } return false; } - - public boolean containsNode(String word) { - return find(word); - } - - public boolean isEmpty() { - return root == null; - } } \ No newline at end of file From 740073b6ad52550ee0f799a913d46f9ba5d17d94 Mon Sep 17 00:00:00 2001 From: Miguel Rivero Date: Sat, 20 Jan 2018 16:35:48 +0100 Subject: [PATCH 46/65] BAEL-1230: Get Java Logs into the JSON Format (#3381) * Added code for BAEL-1230: Getting log in JSON format * Added code for BAEL-1230: Getting log in JSON format * Improved tests to check correct JSON format in logs * Renamed Test classes to make clear what they do * Fixed wrong indentation --- logging-modules/log4j2/pom.xml | 4 +- .../logging/log4j2/tests/JSONLayoutTest.java | 45 ++++++++++++++ .../log4j2/src/test/resources/log4j2.xml | 62 ++++++++++++------- logging-modules/logback/pom.xml | 20 +++++- .../com/baeldung/logback/JSONLayoutTest.java | 45 ++++++++++++++ .../src/test/resources/logback-test.xml | 25 ++++++-- 6 files changed, 169 insertions(+), 32 deletions(-) create mode 100644 logging-modules/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/JSONLayoutTest.java create mode 100644 logging-modules/logback/src/test/java/com/baeldung/logback/JSONLayoutTest.java diff --git a/logging-modules/log4j2/pom.xml b/logging-modules/log4j2/pom.xml index 48608fbc80..46b8b80597 100644 --- a/logging-modules/log4j2/pom.xml +++ b/logging-modules/log4j2/pom.xml @@ -59,10 +59,10 @@ - 2.8.5 + 2.9.3 1.4.193 2.1.1 - 2.7 + 2.10.0 diff --git a/logging-modules/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/JSONLayoutTest.java b/logging-modules/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/JSONLayoutTest.java new file mode 100644 index 0000000000..9493c32094 --- /dev/null +++ b/logging-modules/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/JSONLayoutTest.java @@ -0,0 +1,45 @@ +package com.baeldung.logging.log4j2.tests; + +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.junit.Before; +import org.junit.Test; + +import com.fasterxml.jackson.databind.ObjectMapper; + +public class JSONLayoutTest { + + private static Logger logger; + private ByteArrayOutputStream consoleOutput = new ByteArrayOutputStream(); + private PrintStream ps = new PrintStream(consoleOutput); + + @Before + public void setUp() { + // Redirect console output to our stream + System.setOut(ps); + logger = LogManager.getLogger("CONSOLE_JSON_APPENDER"); + } + + @Test + public void whenLogLayoutInJSON_thenOutputIsCorrectJSON() { + logger.debug("Debug message"); + String currentLog = consoleOutput.toString(); + assertTrue(!currentLog.isEmpty() && isValidJSON(currentLog)); + } + + public static boolean isValidJSON(String jsonInString) { + try { + final ObjectMapper mapper = new ObjectMapper(); + mapper.readTree(jsonInString); + return true; + } catch (IOException e) { + return false; + } + } +} \ No newline at end of file diff --git a/logging-modules/log4j2/src/test/resources/log4j2.xml b/logging-modules/log4j2/src/test/resources/log4j2.xml index 21fd1da446..4dcb7cce5a 100644 --- a/logging-modules/log4j2/src/test/resources/log4j2.xml +++ b/logging-modules/log4j2/src/test/resources/log4j2.xml @@ -1,16 +1,25 @@ - + - + - + - + + + + + + @@ -19,53 +28,58 @@ - + - + - + - + - + - + - + - + - + + + + diff --git a/logging-modules/logback/pom.xml b/logging-modules/logback/pom.xml index 8169134442..cd0d3758cc 100644 --- a/logging-modules/logback/pom.xml +++ b/logging-modules/logback/pom.xml @@ -1,6 +1,6 @@ 4.0.0 @@ -12,6 +12,8 @@ UTF-8 1.2.3 + 0.1.5 + 2.9.3 @@ -28,7 +30,21 @@ logback-classic ${logback.version} - + + ch.qos.logback.contrib + logback-json-classic + ${logback.contrib.version} + + + ch.qos.logback.contrib + logback-jackson + ${logback.contrib.version} + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + diff --git a/logging-modules/logback/src/test/java/com/baeldung/logback/JSONLayoutTest.java b/logging-modules/logback/src/test/java/com/baeldung/logback/JSONLayoutTest.java new file mode 100644 index 0000000000..ca3c4b3457 --- /dev/null +++ b/logging-modules/logback/src/test/java/com/baeldung/logback/JSONLayoutTest.java @@ -0,0 +1,45 @@ +package com.baeldung.logback; + +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; + +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.fasterxml.jackson.databind.ObjectMapper; + +public class JSONLayoutTest { + + private static Logger logger; + private ByteArrayOutputStream consoleOutput = new ByteArrayOutputStream(); + private PrintStream ps = new PrintStream(consoleOutput); + + @Before + public void setUp() { + // Redirect console output to our stream + System.setOut(ps); + logger = LoggerFactory.getLogger("jsonLogger"); + } + + @Test + public void whenLogLayoutInJSON_thenOutputIsCorrectJSON() { + logger.debug("Debug message"); + String currentLog = consoleOutput.toString(); + assertTrue(!currentLog.isEmpty() && isValidJSON(currentLog)); + } + + public static boolean isValidJSON(String jsonInString) { + try { + final ObjectMapper mapper = new ObjectMapper(); + mapper.readTree(jsonInString); + return true; + } catch (IOException e) { + return false; + } + } +} diff --git a/logging-modules/logback/src/test/resources/logback-test.xml b/logging-modules/logback/src/test/resources/logback-test.xml index 8254e6ac80..df81f18cc2 100644 --- a/logging-modules/logback/src/test/resources/logback-test.xml +++ b/logging-modules/logback/src/test/resources/logback-test.xml @@ -1,14 +1,31 @@ - + + + test - + + + # JSON appender + + + + true + + yyyy-MM-dd' 'HH:mm:ss.SSS + + + + + + - - + + \ No newline at end of file From 6923d3accd1a9c4a235e1dc1fa73281c0227d35a Mon Sep 17 00:00:00 2001 From: Seun Matt Date: Sat, 20 Jan 2018 18:18:01 +0100 Subject: [PATCH 47/65] Example Code for Exceptions in Netty (#3406) * added updated example codes * updated example code StringToCharStream * deleted StringToCharStream.java locally * removed redundant file * added code for apache commons collection SetUtils * refactored example code * added example code for bytebuddy * added example code for PCollections * update pom * refactored tests for PCollections * spring security xml config * spring security xml config * remove redundant comment * example code for apache-shiro * updated example code for Vavr Collections * updated Vavr's Collection example * updated Vavr Collection file * updated example code for Apache Shiro * updated Vavr Collections example * added example code for N1QL * update example code for N1QL * added integration test for N1QL * update N1QL Example code * update the N1QL example Code * rename module to couchbase * rename module to couchbase * change module name in parent module and pom * added cas-server module * added cas secured app for Spring SSO with CAS * refactor cas modules into cas folder * updated files * removed redundant files * refactor the config for cas-server * added sql file to generate tables and database * added source code for VRaptor * update source code for VRaptor article * update pom and reformat code * add example code for BAEL-1439 * updated code for netty exceptions --- .../com/baeldung/netty/ChannelHandlerA.java | 22 +++++++++ .../com/baeldung/netty/ChannelHandlerB.java | 20 ++++++++ .../java/com/baeldung/netty/NettyServerB.java | 47 +++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 libraries/src/main/java/com/baeldung/netty/ChannelHandlerA.java create mode 100644 libraries/src/main/java/com/baeldung/netty/ChannelHandlerB.java create mode 100644 libraries/src/main/java/com/baeldung/netty/NettyServerB.java diff --git a/libraries/src/main/java/com/baeldung/netty/ChannelHandlerA.java b/libraries/src/main/java/com/baeldung/netty/ChannelHandlerA.java new file mode 100644 index 0000000000..c919bdb09c --- /dev/null +++ b/libraries/src/main/java/com/baeldung/netty/ChannelHandlerA.java @@ -0,0 +1,22 @@ +package com.baeldung.netty; + +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelInboundHandlerAdapter; + +import java.util.logging.Logger; + +public class ChannelHandlerA extends ChannelInboundHandlerAdapter { + + private Logger logger = Logger.getLogger(getClass().getName()); + + @Override + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { + throw new Exception("Ooops"); + } + + @Override + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { + logger.info("Exception Occurred in ChannelHandler A"); + ctx.fireExceptionCaught(cause); + } +} diff --git a/libraries/src/main/java/com/baeldung/netty/ChannelHandlerB.java b/libraries/src/main/java/com/baeldung/netty/ChannelHandlerB.java new file mode 100644 index 0000000000..c5bdeb1013 --- /dev/null +++ b/libraries/src/main/java/com/baeldung/netty/ChannelHandlerB.java @@ -0,0 +1,20 @@ +package com.baeldung.netty; + +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelInboundHandlerAdapter; + +import java.util.logging.Logger; + + +public class ChannelHandlerB extends ChannelInboundHandlerAdapter { + + private Logger logger = Logger.getLogger(getClass().getName()); + + @Override + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { + logger.info("Exception Handled in ChannelHandler B"); + logger.info(cause.getLocalizedMessage()); + //do more exception handling + ctx.close(); + } +} diff --git a/libraries/src/main/java/com/baeldung/netty/NettyServerB.java b/libraries/src/main/java/com/baeldung/netty/NettyServerB.java new file mode 100644 index 0000000000..c8004623c2 --- /dev/null +++ b/libraries/src/main/java/com/baeldung/netty/NettyServerB.java @@ -0,0 +1,47 @@ +package com.baeldung.netty; + +import io.netty.bootstrap.ServerBootstrap; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelInitializer; +import io.netty.channel.ChannelOption; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.SocketChannel; +import io.netty.channel.socket.nio.NioServerSocketChannel; + +public class NettyServerB { + + private int port; + + private NettyServerB(int port) { + this.port = port; + } + + private void run() throws Exception { + + EventLoopGroup bossGroup = new NioEventLoopGroup(); + EventLoopGroup workerGroup = new NioEventLoopGroup(); + + try { + ServerBootstrap b = new ServerBootstrap(); + b.group(bossGroup, workerGroup) + .channel(NioServerSocketChannel.class) + .childHandler(new ChannelInitializer() { + public void initChannel(SocketChannel ch) throws Exception { + ch.pipeline().addLast(new ChannelHandlerA(), new ChannelHandlerB()); + } + }) + .option(ChannelOption.SO_BACKLOG, 128) + .childOption(ChannelOption.SO_KEEPALIVE, true); + ChannelFuture f = b.bind(port).sync(); // (7) + f.channel().closeFuture().sync(); + } finally { + workerGroup.shutdownGracefully(); + bossGroup.shutdownGracefully(); + } + } + + public static void main(String[] args) throws Exception { + new NettyServerB(8080).run(); + } +} From 30321eb8018ef6ced42df32e1532e38ef87a88c2 Mon Sep 17 00:00:00 2001 From: Nam Thai Nguyen Date: Sun, 21 Jan 2018 23:37:11 +0700 Subject: [PATCH 48/65] initial commit for the BAEL-1479 --- .../baeldung/finalize/CloseableResource.java | 30 +++++++++++++++++++ .../com/baeldung/finalize/Finalizable.java | 30 +++++++++++++++++++ .../baeldung/finalize/FinalizeUnitTest.java | 23 ++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 core-java/src/main/java/com/baeldung/finalize/CloseableResource.java create mode 100644 core-java/src/main/java/com/baeldung/finalize/Finalizable.java create mode 100644 core-java/src/test/java/com/baeldung/finalize/FinalizeUnitTest.java diff --git a/core-java/src/main/java/com/baeldung/finalize/CloseableResource.java b/core-java/src/main/java/com/baeldung/finalize/CloseableResource.java new file mode 100644 index 0000000000..d286570fbc --- /dev/null +++ b/core-java/src/main/java/com/baeldung/finalize/CloseableResource.java @@ -0,0 +1,30 @@ +package com.baeldung.finalize; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +public class CloseableResource implements AutoCloseable { + private BufferedReader reader; + + public CloseableResource() { + InputStream input = this.getClass().getClassLoader().getResourceAsStream("file.txt"); + reader = new BufferedReader(new InputStreamReader(input)); + } + + public String readFirstLine() throws IOException { + String firstLine = reader.readLine(); + return firstLine; + } + + @Override + public void close() { + try { + reader.close(); + System.out.println("Closed BufferedReader in the close method"); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/core-java/src/main/java/com/baeldung/finalize/Finalizable.java b/core-java/src/main/java/com/baeldung/finalize/Finalizable.java new file mode 100644 index 0000000000..cfc6616f5c --- /dev/null +++ b/core-java/src/main/java/com/baeldung/finalize/Finalizable.java @@ -0,0 +1,30 @@ +package com.baeldung.finalize; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +public class Finalizable { + private BufferedReader reader; + + public Finalizable() { + InputStream input = this.getClass().getClassLoader().getResourceAsStream("file.txt"); + reader = new BufferedReader(new InputStreamReader(input)); + } + + public String readFirstLine() throws IOException { + String firstLine = reader.readLine(); + return firstLine; + } + + @Override + public void finalize() { + try { + reader.close(); + System.out.println("Closed BufferedReader in the finalizer"); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/core-java/src/test/java/com/baeldung/finalize/FinalizeUnitTest.java b/core-java/src/test/java/com/baeldung/finalize/FinalizeUnitTest.java new file mode 100644 index 0000000000..57d409074b --- /dev/null +++ b/core-java/src/test/java/com/baeldung/finalize/FinalizeUnitTest.java @@ -0,0 +1,23 @@ +package com.baeldung.finalize; + +import java.io.IOException; + +import org.junit.Assert; +import org.junit.Test; + +public class FinalizeUnitTest { + @Test + public void whenGC_thenFinalizerExecuted() throws IOException { + String firstLine = new Finalizable().readFirstLine(); + Assert.assertEquals("baeldung.com", firstLine); + System.gc(); + } + + @Test + public void whenTryWResourcesExits_thenResourceClosed() throws IOException { + try (CloseableResource resource = new CloseableResource()) { + String firstLine = resource.readFirstLine(); + Assert.assertEquals("baeldung.com", firstLine); + } + } +} From 25f449ad38749311959d7c82cc1f89e82a8450e7 Mon Sep 17 00:00:00 2001 From: Ahmad Alsanie Date: Sun, 21 Jan 2018 19:44:22 +0200 Subject: [PATCH 49/65] BAEL-1473 (#3477) * BAEL-1473 Intoduction to Spliterator in Java * BAEL-1473 - Replace .out with logger.info * removed log * BAEL-1473 - added test-cases * modify test-cases --- .../com/baeldung/spliteratorAPI/Executor.java | 44 ++++--------------- .../com/baeldung/spliteratorAPI/Task.java | 9 ++-- .../baeldung/spliteratorAPI/ExecutorTest.java | 44 +++++++++++++++++++ 3 files changed, 58 insertions(+), 39 deletions(-) create mode 100644 core-java-8/src/test/java/com/baeldung/spliteratorAPI/ExecutorTest.java diff --git a/core-java-8/src/main/java/com/baeldung/spliteratorAPI/Executor.java b/core-java-8/src/main/java/com/baeldung/spliteratorAPI/Executor.java index b906acfad9..024d5dabdb 100644 --- a/core-java-8/src/main/java/com/baeldung/spliteratorAPI/Executor.java +++ b/core-java-8/src/main/java/com/baeldung/spliteratorAPI/Executor.java @@ -1,45 +1,19 @@ package com.baeldung.spliteratorAPI; -import java.util.Arrays; import java.util.List; -import java.util.Spliterator; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; import java.util.stream.Collectors; -import java.util.stream.IntStream; import java.util.stream.Stream; -import java.util.stream.StreamSupport; public class Executor { - public void executeCustomSpliterator() { - Article article = new Article(Arrays.asList(new Author("Ahmad", 0), new Author("Eugen", 0), new Author("Alice", 1), new Author("Alice", 1), new Author("Mike", 0), new Author("Alice", 1), new Author("Mike", 0), new Author("Alice", 1), - new Author("Mike", 0), new Author("Alice", 1), new Author("Mike", 0), new Author("Mike", 0), new Author("Alice", 1), new Author("Mike", 0), new Author("Alice", 1), new Author("Mike", 0), new Author("Alice", 1), new Author("Mike", 0), - new Author("Alice", 1), new Author("Mike", 0), new Author("Michał", 0), new Author("Loredana", 1)), 0); - Stream stream = IntStream.range(0, article.getListOfAuthors() - .size()) - .mapToObj(article.getListOfAuthors()::get); - System.out.println("count= " + countAutors(stream.parallel())); - Spliterator spliterator = new RelatedAuthorSpliterator(article.getListOfAuthors()); - Stream stream2 = StreamSupport.stream(spliterator, true); - System.out.println("count= " + countAutors(stream2.parallel())); - } - public void executeSpliterator() { - Spliterator
split1 = generateElements().spliterator(); - Spliterator
split2 = split1.trySplit(); - ExecutorService service = Executors.newCachedThreadPool(); - service.execute(new Task(split1)); - service.execute(new Task(split2)); - } + public static int countAutors(Stream stream) { + RelatedAuthorCounter wordCounter = stream.reduce(new RelatedAuthorCounter(0, true), + RelatedAuthorCounter::accumulate, RelatedAuthorCounter::combine); + return wordCounter.getCounter(); + } - private static int countAutors(Stream stream) { - RelatedAuthorCounter wordCounter = stream.reduce(new RelatedAuthorCounter(0, true), RelatedAuthorCounter::accumulate, RelatedAuthorCounter::combine); - return wordCounter.getCounter(); - } + public static List
generateElements() { + return Stream.generate(() -> new Article("Java")).limit(35000).collect(Collectors.toList()); + } - private List
generateElements() { - return Stream.generate(() -> new Article("Java")) - .limit(35000) - .collect(Collectors.toList()); - } -} +} \ No newline at end of file diff --git a/core-java-8/src/main/java/com/baeldung/spliteratorAPI/Task.java b/core-java-8/src/main/java/com/baeldung/spliteratorAPI/Task.java index 108fdc52aa..70435d1c75 100644 --- a/core-java-8/src/main/java/com/baeldung/spliteratorAPI/Task.java +++ b/core-java-8/src/main/java/com/baeldung/spliteratorAPI/Task.java @@ -1,8 +1,9 @@ package com.baeldung.spliteratorAPI; import java.util.Spliterator; +import java.util.concurrent.Callable; -public class Task implements Runnable { +public class Task implements Callable { private Spliterator
spliterator; private final static String SUFFIX = "- published by Baeldung"; @@ -11,7 +12,7 @@ public class Task implements Runnable { } @Override - public void run() { + public String call() { int current = 0; while (spliterator.tryAdvance(article -> { article.setName(article.getName() @@ -20,7 +21,7 @@ public class Task implements Runnable { current++; } ; - System.out.println(Thread.currentThread() - .getName() + ":" + current); + return Thread.currentThread() + .getName() + ":" + current; } } diff --git a/core-java-8/src/test/java/com/baeldung/spliteratorAPI/ExecutorTest.java b/core-java-8/src/test/java/com/baeldung/spliteratorAPI/ExecutorTest.java new file mode 100644 index 0000000000..64dd65cf5e --- /dev/null +++ b/core-java-8/src/test/java/com/baeldung/spliteratorAPI/ExecutorTest.java @@ -0,0 +1,44 @@ +package com.baeldung.spliteratorAPI; + +import java.util.Arrays; +import java.util.Spliterator; +import java.util.stream.Stream; +import java.util.stream.StreamSupport; + +import static org.assertj.core.api.Assertions.*; +import org.junit.Before; +import org.junit.Test; + +public class ExecutorTest { + Article article; + Stream stream; + Spliterator spliterator; + Spliterator
split1; + Spliterator
split2; + + @Before + public void init() { + article = new Article(Arrays.asList(new Author("Ahmad", 0), new Author("Eugen", 0), new Author("Alice", 1), + new Author("Alice", 1), new Author("Mike", 0), new Author("Alice", 1), new Author("Mike", 0), + new Author("Alice", 1), new Author("Mike", 0), new Author("Alice", 1), new Author("Mike", 0), + new Author("Mike", 0), new Author("Alice", 1), new Author("Mike", 0), new Author("Alice", 1), + new Author("Mike", 0), new Author("Alice", 1), new Author("Mike", 0), new Author("Alice", 1), + new Author("Mike", 0), new Author("Michał", 0), new Author("Loredana", 1)), 0); + stream = article.getListOfAuthors().stream(); + split1 = Executor.generateElements().spliterator(); + split2 = split1.trySplit(); + spliterator = new RelatedAuthorSpliterator(article.getListOfAuthors()); + } + + @Test + public void givenAstreamOfAuthors_whenProcessedInParallelWithCustomSpliterator_coubtProducessRightOutput() { + Stream stream2 = StreamSupport.stream(spliterator, true); + assertThat(Executor.countAutors(stream2.parallel())).isEqualTo(9); + } + + @Test + public void givenSpliterator_whenAppliedToAListOfArticle_thenSplittedInHalf() { + assertThat(new Task(split1).call()).containsSequence(Executor.generateElements().size() / 2 + ""); + assertThat(new Task(split2).call()).containsSequence(Executor.generateElements().size() / 2 + ""); + } +} From 7000fca1971ce2c87f7d5222cd5b3b786033ceec Mon Sep 17 00:00:00 2001 From: Alessio Stalla Date: Mon, 22 Jan 2018 14:30:58 +0100 Subject: [PATCH 50/65] BAEL-1398 Code for the article: HTTP Requests with Kotlin and khttp --- core-kotlin/pom.xml | 5 + .../com/baeldung/kotlin/khttp/KhttpTest.kt | 153 ++++++++++++++++++ 2 files changed, 158 insertions(+) create mode 100644 core-kotlin/src/test/kotlin/com/baeldung/kotlin/khttp/KhttpTest.kt diff --git a/core-kotlin/pom.xml b/core-kotlin/pom.xml index 2cd5275eeb..33bdbf719f 100644 --- a/core-kotlin/pom.xml +++ b/core-kotlin/pom.xml @@ -49,6 +49,11 @@ kotlin-stdlib-jre8 ${kotlin-stdlib.version} + + khttp + khttp + 0.1.0 + org.jetbrains.kotlin kotlin-test-junit diff --git a/core-kotlin/src/test/kotlin/com/baeldung/kotlin/khttp/KhttpTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/kotlin/khttp/KhttpTest.kt new file mode 100644 index 0000000000..e9147c9489 --- /dev/null +++ b/core-kotlin/src/test/kotlin/com/baeldung/kotlin/khttp/KhttpTest.kt @@ -0,0 +1,153 @@ +package com.baeldung.kotlin.khttp + +import khttp.structures.files.FileLike +import org.json.JSONObject +import org.junit.Test +import java.beans.ExceptionListener +import java.beans.XMLEncoder +import java.io.* +import java.lang.Exception +import java.net.ConnectException +import kotlin.test.assertEquals +import kotlin.test.assertTrue +import kotlin.test.fail + +class KhttpTest { + + @Test + fun whenHttpGetRequestIsMade_thenArgsAreReturned() { + val response = khttp.get( + url = "http://httpbin.org/get", + params = mapOf("p1" to "1", "p2" to "2")) + val args = response.jsonObject.getJSONObject("args") + + assertEquals("1", args["p1"]) + assertEquals("2", args["p2"]) + } + + @Test + fun whenAlternateHttpGetRequestIsMade_thenArgsAreReturned() { + val response = khttp.request( + method = "GET", + url = "http://httpbin.org/get", + params = mapOf("p1" to "1", "p2" to "2")) + val args = response.jsonObject.getJSONObject("args") + + assertEquals("1", args["p1"]) + assertEquals("2", args["p2"]) + } + + @Test + fun whenHeadersAreSet_thenHeadersAreSent() { + val response = khttp.get( + url = "http://httpbin.org/get", + headers = mapOf("header1" to "1", "header2" to "2")) + val headers = response.jsonObject.getJSONObject("headers") + + assertEquals("1", headers["Header1"]) + assertEquals("2", headers["Header2"]) + } + + @Test + fun whenHttpPostRequestIsMadeWithJson_thenBodyIsReturned() { + val response = khttp.post( + url = "http://httpbin.org/post", + params = mapOf("p1" to "1", "p2" to "2"), + json = mapOf("pr1" to "1", "pr2" to "2")) + + val args = response.jsonObject.getJSONObject("args") + + assertEquals("1", args["p1"]) + assertEquals("2", args["p2"]) + + val json = response.jsonObject.getJSONObject("json") + + assertEquals("1", json["pr1"]) + assertEquals("2", json["pr2"]) + } + + @Test + fun whenHttpPostRequestIsMadeWithMapData_thenBodyIsReturned() { + val response = khttp.post( + url = "http://httpbin.org/post", + params = mapOf("p1" to "1", "p2" to "2"), + data = mapOf("pr1" to "1", "pr2" to "2")) + + val args = response.jsonObject.getJSONObject("args") + + assertEquals("1", args["p1"]) + assertEquals("2", args["p2"]) + + val form = response.jsonObject.getJSONObject("form") + + assertEquals("1", form["pr1"]) + assertEquals("2", form["pr2"]) + } + + @Test + fun whenHttpPostRequestIsMadeWithFiles_thenBodyIsReturned() { + val response = khttp.post( + url = "http://httpbin.org/post", + params = mapOf("p1" to "1", "p2" to "2"), + files = listOf( + FileLike("file1", "content1"), + FileLike("file2", javaClass.getResource("KhttpTest.class").openStream().readBytes()))) + + val args = response.jsonObject.getJSONObject("args") + + assertEquals("1", args["p1"]) + assertEquals("2", args["p2"]) + + val files = response.jsonObject.getJSONObject("files") + + assertEquals("content1", files["file1"]) + } + + @Test + fun whenHttpPostRequestIsMadeWithInputStream_thenBodyIsReturned() { + val response = khttp.post( + url = "http://httpbin.org/post", + params = mapOf("p1" to "1", "p2" to "2"), + data = ByteArrayInputStream("content!".toByteArray())) + + val args = response.jsonObject.getJSONObject("args") + + assertEquals("1", args["p1"]) + assertEquals("2", args["p2"]) + + assertEquals("content!", response.jsonObject["data"]) + } + + @Test + fun whenHttpPostStreamingRequestIsMade_thenBodyIsReturnedInChunks() { + val response = khttp.post( + url = "http://httpbin.org/post", + stream = true, + json = mapOf("pr1" to "1", "pr2" to "2")) + + val baos = ByteArrayOutputStream() + response.contentIterator(chunkSize = 10).forEach { arr : ByteArray -> baos.write(arr) } + val json = JSONObject(String(baos.toByteArray())).getJSONObject("json") + + assertEquals("1", json["pr1"]) + assertEquals("2", json["pr2"]) + } + + @Test + fun whenHttpRequestFails_thenExceptionIsThrown() { + try { + khttp.get(url = "http://localhost/nothing/to/see/here") + + fail("Should have thrown an exception") + } catch (e : ConnectException) { + //Ok + } + } + + @Test + fun whenHttpNotFound_thenExceptionIsThrown() { + val response = khttp.get(url = "http://httpbin.org/nothing/to/see/here") + + assertEquals(404, response.statusCode) + } +} \ No newline at end of file From b1266c833b4a458bfa0c09cd0604013ba60170d8 Mon Sep 17 00:00:00 2001 From: Juan Moreno Date: Mon, 22 Jan 2018 12:08:33 -0300 Subject: [PATCH 51/65] BAEL-1148 earth001@gmail.com - Merged spring-mvc-push module in spring-mvc-simple (#3459) * Sample code for BAEL-1148 - earth001@gmail.com * Change tabs for spaces in non java files * Change tabs for spaces in non java files * Removed unnecessary argument * BAEL-1148 earth001@gmail.com - Mapped get method in controller / Removed resources * Merged spring-mvc-push module in spring-mvc-simple --- spring-mvc-push/.gitignore | 1 - spring-mvc-push/pom.xml | 91 ----------------- .../baeldung/config/PushConfiguration.java | 48 --------- spring-mvc-push/src/main/webapp/index.jsp | 14 --- .../src/main/webapp/resources/script.js | 1 - .../src/main/webapp/resources/style.css | 9 -- spring-mvc-simple/pom.xml | 93 +++++++++--------- .../ApplicationConfiguration.java | 4 +- .../JadeTemplateConfiguration.java | 22 ++--- .../configuration/PushConfiguration.java | 30 ++++++ .../spring/configuration/WebInitializer.java | 49 +++------ ...AnnotationMethodHandlerAdapterExample.java | 12 +-- .../controller/FileUploadController.java | 18 ++-- .../RequestMappingHandlerAdapterExample.java | 12 +-- ...SimpleControllerHandlerAdapterExample.java | 16 ++- .../controller/push}/PushController.java | 2 +- ...servlet_AnnotationMethodHandlerAdapter.xml | 26 ----- ...g-servlet_RequestMappingHandlerAdapter.xml | 28 ------ ...servlet_SimpleControllerHandlerAdapter.xml | 25 ----- .../src/main/webapp/WEB-INF/views/demo.jsp | 3 +- .../WEB-INF/views/registration-jade.jade | 2 +- .../src/main/webapp/resources/logo.png | Bin .../push}/PushControllerIntegrationTest.java | 6 +- 23 files changed, 138 insertions(+), 374 deletions(-) delete mode 100644 spring-mvc-push/.gitignore delete mode 100644 spring-mvc-push/pom.xml delete mode 100644 spring-mvc-push/src/main/java/com/baeldung/config/PushConfiguration.java delete mode 100644 spring-mvc-push/src/main/webapp/index.jsp delete mode 100644 spring-mvc-push/src/main/webapp/resources/script.js delete mode 100644 spring-mvc-push/src/main/webapp/resources/style.css create mode 100644 spring-mvc-simple/src/main/java/com/baeldung/spring/configuration/PushConfiguration.java rename {spring-mvc-push/src/main/java/com/baeldung/controller => spring-mvc-simple/src/main/java/com/baeldung/spring/controller/push}/PushController.java (93%) delete mode 100644 spring-mvc-simple/src/main/resources/spring-servlet_AnnotationMethodHandlerAdapter.xml delete mode 100644 spring-mvc-simple/src/main/resources/spring-servlet_RequestMappingHandlerAdapter.xml delete mode 100644 spring-mvc-simple/src/main/resources/spring-servlet_SimpleControllerHandlerAdapter.xml rename {spring-mvc-push => spring-mvc-simple}/src/main/webapp/WEB-INF/views/demo.jsp (88%) rename {spring-mvc-push => spring-mvc-simple}/src/main/webapp/resources/logo.png (100%) rename {spring-mvc-push/src/test/java/com/baeldung/controller => spring-mvc-simple/src/test/java/com/baeldung/controller/push}/PushControllerIntegrationTest.java (91%) diff --git a/spring-mvc-push/.gitignore b/spring-mvc-push/.gitignore deleted file mode 100644 index 448298d47f..0000000000 --- a/spring-mvc-push/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/.tern-project diff --git a/spring-mvc-push/pom.xml b/spring-mvc-push/pom.xml deleted file mode 100644 index 2eb10381be..0000000000 --- a/spring-mvc-push/pom.xml +++ /dev/null @@ -1,91 +0,0 @@ - - 4.0.0 - com.baeldung - spring-mvc-push - war - 0.0.1-SNAPSHOT - spring-mvc-push - - 1.8 - 1.8 - 2.20 - 3.7.0 - 3.2.0 - UTF-8 - 5.0.2 - 5.0.2.RELEASE - 4.0.0 - 1.2 - 2.3.2-b02 - 5.0.2 - 1.0.2 - - - - org.springframework - spring-webmvc - ${spring.version} - - - javax.servlet - javax.servlet-api - ${servlet.version} - provided - - - javax.servlet - jstl - ${jstl.version} - - - javax.servlet.jsp - javax.servlet.jsp-api - ${jsp-api.version} - - - - org.springframework - spring-test - ${spring.version} - test - - - org.junit.jupiter - junit-jupiter-engine - ${junit.jupiter.version} - test - - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven.compiler.version} - - - org.apache.maven.plugins - maven-war-plugin - ${maven-war-plugin.version} - - spring-mvc-push - false - ${deploy-path} - - - - maven-surefire-plugin - ${maven-surefire-plugin.version} - - - org.junit.platform - junit-platform-surefire-provider - ${junit.platform.version} - - - - - spring-mvc-push - - diff --git a/spring-mvc-push/src/main/java/com/baeldung/config/PushConfiguration.java b/spring-mvc-push/src/main/java/com/baeldung/config/PushConfiguration.java deleted file mode 100644 index e6188da92d..0000000000 --- a/spring-mvc-push/src/main/java/com/baeldung/config/PushConfiguration.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.baeldung.config; - -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.ServletRegistration; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.WebApplicationInitializer; -import org.springframework.web.context.ContextLoaderListener; -import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; -import org.springframework.web.servlet.DispatcherServlet; -import org.springframework.web.servlet.config.annotation.EnableWebMvc; -import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; -import org.springframework.web.servlet.view.InternalResourceViewResolver; - -@Configuration -@EnableWebMvc -@ComponentScan(basePackages = "com.baeldung.controller") -public class PushConfiguration implements WebApplicationInitializer, WebMvcConfigurer { - - @Override - public void onStartup(ServletContext container) throws ServletException { - AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); - context.register(PushConfiguration.class); - container.addListener(new ContextLoaderListener(context)); - ServletRegistration.Dynamic dispatcher = container.addServlet("DispatcherServlet", new DispatcherServlet(context)); - dispatcher.setLoadOnStartup(1); - dispatcher.addMapping("/"); - } - - @Bean - public InternalResourceViewResolver jspViewResolver() { - InternalResourceViewResolver bean = new InternalResourceViewResolver(); - bean.setPrefix("/WEB-INF/views/"); - bean.setSuffix(".jsp"); - return bean; - } - - @Override - public void addResourceHandlers(ResourceHandlerRegistry registry) { - registry.addResourceHandler("/resources/**") - .addResourceLocations("/resources/"); - } - -} diff --git a/spring-mvc-push/src/main/webapp/index.jsp b/spring-mvc-push/src/main/webapp/index.jsp deleted file mode 100644 index 82ecb68003..0000000000 --- a/spring-mvc-push/src/main/webapp/index.jsp +++ /dev/null @@ -1,14 +0,0 @@ -<%@ page language="java" contentType="text/html; charset=UTF-8" - pageEncoding="UTF-8"%> - - - -PushBuilder demo - - -

- Go to PushBuilder demo
Go to - Simple demo -

- - \ No newline at end of file diff --git a/spring-mvc-push/src/main/webapp/resources/script.js b/spring-mvc-push/src/main/webapp/resources/script.js deleted file mode 100644 index 9bc97c006a..0000000000 --- a/spring-mvc-push/src/main/webapp/resources/script.js +++ /dev/null @@ -1 +0,0 @@ -console.log('Script') \ No newline at end of file diff --git a/spring-mvc-push/src/main/webapp/resources/style.css b/spring-mvc-push/src/main/webapp/resources/style.css deleted file mode 100644 index d5fc158135..0000000000 --- a/spring-mvc-push/src/main/webapp/resources/style.css +++ /dev/null @@ -1,9 +0,0 @@ -.single-title { - font-size: 30px; - color: #535353; - font-weight: 200; - letter-spacing: -1.5px; - line-height: 64px; - max-width: 750px; - font-family: "Helvetica Neue", Helvetica, Arial, sans-serif -} \ No newline at end of file diff --git a/spring-mvc-simple/pom.xml b/spring-mvc-simple/pom.xml index 2cc6aec906..05b2eb49b6 100644 --- a/spring-mvc-simple/pom.xml +++ b/spring-mvc-simple/pom.xml @@ -8,83 +8,62 @@ Spring MVC simple Maven Webapp http://maven.apache.org - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - - - 4.3.10.RELEASE - 3.1.0 + 1.8 + 1.8 + UTF-8 + 5.0.2.RELEASE + 3.2.0 + 3.7.0 + 2.20 1.2 - 2.3.1 - 3.1.0 + 2.3.2-b02 + 4.0.0 5.4.1.Final enter-location-of-server 1.3.2 1.8 3.0.7.RELEASE 2.4.12 - 2.3.23 + 2.3.27-incubating 1.2.5 + 5.0.2 + 5.0.2 + 1.0.2 javax.servlet javax.servlet-api - 3.1.0 - - - org.springframework - spring-webmvc - ${springframework.version} - - - org.springframework - spring-context - ${springframework.version} - - - org.springframework - spring-core - ${springframework.version} - - - commons-logging - commons-logging - - + ${javax.servlet-api.version} javax.servlet.jsp javax.servlet.jsp-api ${javax.servlet.jsp-api.version} - javax.servlet jstl ${jstl.version} - org.hibernate hibernate-validator ${hibernate-validator.version} - - org.springframework - spring-webmvc - ${springframework.version} - commons-fileupload commons-fileupload ${fileupload.version} - + + org.springframework + spring-webmvc + ${springframework.version} + + org.thymeleaf @@ -115,7 +94,7 @@ groovy-templates ${groovy.version} - + de.neuland-bfi @@ -123,6 +102,19 @@ ${jade.version} + + + org.springframework + spring-test + ${springframework.version} + test + + + org.junit.jupiter + junit-jupiter-engine + ${junit.jupiter.version} + test + @@ -141,11 +133,18 @@ org.apache.maven.plugins maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - + ${maven.compiler.version} + + + maven-surefire-plugin + ${maven-surefire-plugin.version} + + + org.junit.platform + junit-platform-surefire-provider + ${junit.platform.version} + + diff --git a/spring-mvc-simple/src/main/java/com/baeldung/spring/configuration/ApplicationConfiguration.java b/spring-mvc-simple/src/main/java/com/baeldung/spring/configuration/ApplicationConfiguration.java index b62ccae465..b9a8336bf2 100644 --- a/spring-mvc-simple/src/main/java/com/baeldung/spring/configuration/ApplicationConfiguration.java +++ b/spring-mvc-simple/src/main/java/com/baeldung/spring/configuration/ApplicationConfiguration.java @@ -7,13 +7,13 @@ import org.springframework.web.multipart.MultipartResolver; import org.springframework.web.multipart.commons.CommonsMultipartResolver; import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer; import org.springframework.web.servlet.config.annotation.EnableWebMvc; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.view.InternalResourceViewResolver; @Configuration @EnableWebMvc @ComponentScan(basePackages = { "com.baeldung.springmvcforms", "com.baeldung.spring.controller", "com.baeldung.spring.validator" }) -class ApplicationConfiguration extends WebMvcConfigurerAdapter { +class ApplicationConfiguration implements WebMvcConfigurer { @Override public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) { diff --git a/spring-mvc-simple/src/main/java/com/baeldung/spring/configuration/JadeTemplateConfiguration.java b/spring-mvc-simple/src/main/java/com/baeldung/spring/configuration/JadeTemplateConfiguration.java index 10345bac58..4c95e5a0bd 100644 --- a/spring-mvc-simple/src/main/java/com/baeldung/spring/configuration/JadeTemplateConfiguration.java +++ b/spring-mvc-simple/src/main/java/com/baeldung/spring/configuration/JadeTemplateConfiguration.java @@ -16,24 +16,24 @@ import de.neuland.jade4j.spring.view.JadeViewResolver; public class JadeTemplateConfiguration { @Bean public SpringTemplateLoader templateLoader() { - SpringTemplateLoader templateLoader = new SpringTemplateLoader(); - templateLoader.setBasePath("/WEB-INF/views/"); - templateLoader.setSuffix(".jade"); - return templateLoader; + SpringTemplateLoader templateLoader = new SpringTemplateLoader(); + templateLoader.setBasePath("/WEB-INF/views/"); + templateLoader.setSuffix(".jade"); + return templateLoader; } @Bean public JadeConfiguration jadeConfiguration() { - JadeConfiguration configuration = new JadeConfiguration(); - configuration.setCaching(false); - configuration.setTemplateLoader(templateLoader()); - return configuration; + JadeConfiguration configuration = new JadeConfiguration(); + configuration.setCaching(false); + configuration.setTemplateLoader(templateLoader()); + return configuration; } @Bean public ViewResolver viewResolver() { - JadeViewResolver viewResolver = new JadeViewResolver(); - viewResolver.setConfiguration(jadeConfiguration()); - return viewResolver; + JadeViewResolver viewResolver = new JadeViewResolver(); + viewResolver.setConfiguration(jadeConfiguration()); + return viewResolver; } } diff --git a/spring-mvc-simple/src/main/java/com/baeldung/spring/configuration/PushConfiguration.java b/spring-mvc-simple/src/main/java/com/baeldung/spring/configuration/PushConfiguration.java new file mode 100644 index 0000000000..3072501cfa --- /dev/null +++ b/spring-mvc-simple/src/main/java/com/baeldung/spring/configuration/PushConfiguration.java @@ -0,0 +1,30 @@ +package com.baeldung.spring.configuration; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import org.springframework.web.servlet.view.InternalResourceViewResolver; + +@Configuration +@EnableWebMvc +@ComponentScan(basePackages = "com.baeldung.spring.controller.push") +public class PushConfiguration implements WebMvcConfigurer { + + @Bean + public InternalResourceViewResolver jspViewResolver() { + InternalResourceViewResolver bean = new InternalResourceViewResolver(); + bean.setPrefix("/WEB-INF/views/"); + bean.setSuffix(".jsp"); + return bean; + } + + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler("/resources/**") + .addResourceLocations("/resources/"); + } + +} diff --git a/spring-mvc-simple/src/main/java/com/baeldung/spring/configuration/WebInitializer.java b/spring-mvc-simple/src/main/java/com/baeldung/spring/configuration/WebInitializer.java index d57d2c621a..09030a8347 100644 --- a/spring-mvc-simple/src/main/java/com/baeldung/spring/configuration/WebInitializer.java +++ b/spring-mvc-simple/src/main/java/com/baeldung/spring/configuration/WebInitializer.java @@ -11,42 +11,23 @@ import javax.servlet.ServletRegistration; public class WebInitializer implements WebApplicationInitializer { - public void onStartup(ServletContext container) throws ServletException { + public void onStartup(ServletContext container) throws ServletException { - AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); - ctx.register(ApplicationConfiguration.class); - //ctx.register(ThymeleafConfiguration.class); - //ctx.register(FreemarkerConfiguration.class); - //ctx.register(GroovyConfiguration.class); - //ctx.register(JadeTemplateConfiguration.class); - ctx.setServletContext(container); + AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); + ctx.register(ApplicationConfiguration.class); + // ctx.register(ThymeleafConfiguration.class); + // ctx.register(FreemarkerConfiguration.class); + // ctx.register(GroovyConfiguration.class); + // ctx.register(JadeTemplateConfiguration.class); + // ctx.register(PushConfiguration.class); + // ctx.setServletContext(container); - // Manage the lifecycle of the root application context - container.addListener(new ContextLoaderListener(ctx)); + // Manage the lifecycle of the root application context + container.addListener(new ContextLoaderListener(ctx)); - ServletRegistration.Dynamic servlet = container.addServlet("dispatcher", new DispatcherServlet(ctx)); + ServletRegistration.Dynamic servlet = container.addServlet("dispatcher", new DispatcherServlet(ctx)); - servlet.setLoadOnStartup(1); - servlet.addMapping("/"); - - } -// @Override -// public void onStartup(ServletContext container) { -// // Create the 'root' Spring application context -// AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); -// rootContext.register(ServiceConfig.class, JPAConfig.class, SecurityConfig.class); -// -// // Manage the lifecycle of the root application context -// container.addListener(new ContextLoaderListener(rootContext)); -// -// // Create the dispatcher servlet's Spring application context -// AnnotationConfigWebApplicationContext dispatcherServlet = new AnnotationConfigWebApplicationContext(); -// dispatcherServlet.register(MvcConfig.class); -// -// // Register and map the dispatcher servlet -// ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(dispatcherServlet)); -// dispatcher.setLoadOnStartup(1); -// dispatcher.addMapping("/"); -// -// } + servlet.setLoadOnStartup(1); + servlet.addMapping("/"); + } } diff --git a/spring-mvc-simple/src/main/java/com/baeldung/spring/controller/AnnotationMethodHandlerAdapterExample.java b/spring-mvc-simple/src/main/java/com/baeldung/spring/controller/AnnotationMethodHandlerAdapterExample.java index 164830cd6a..89f5b2501b 100644 --- a/spring-mvc-simple/src/main/java/com/baeldung/spring/controller/AnnotationMethodHandlerAdapterExample.java +++ b/spring-mvc-simple/src/main/java/com/baeldung/spring/controller/AnnotationMethodHandlerAdapterExample.java @@ -6,10 +6,10 @@ import org.springframework.web.servlet.ModelAndView; @Controller public class AnnotationMethodHandlerAdapterExample { - @RequestMapping("/annotedName") - public ModelAndView getEmployeeName() { - ModelAndView model = new ModelAndView("Greeting"); - model.addObject("message", "Dinesh"); - return model; - } + @RequestMapping("/annotedName") + public ModelAndView getEmployeeName() { + ModelAndView model = new ModelAndView("Greeting"); + model.addObject("message", "Dinesh"); + return model; + } } \ No newline at end of file diff --git a/spring-mvc-simple/src/main/java/com/baeldung/spring/controller/FileUploadController.java b/spring-mvc-simple/src/main/java/com/baeldung/spring/controller/FileUploadController.java index 47af2ab50d..2ca9e2b135 100644 --- a/spring-mvc-simple/src/main/java/com/baeldung/spring/controller/FileUploadController.java +++ b/spring-mvc-simple/src/main/java/com/baeldung/spring/controller/FileUploadController.java @@ -23,13 +23,13 @@ public class FileUploadController implements HandlerExceptionResolver { } @RequestMapping(value = "/uploadFile", method = RequestMethod.POST) - public ModelAndView uploadFile(MultipartFile file) throws IOException{ + public ModelAndView uploadFile(MultipartFile file) throws IOException { ModelAndView modelAndView = new ModelAndView("file"); - - InputStream in = file.getInputStream(); + + InputStream in = file.getInputStream(); File currDir = new File("."); String path = currDir.getAbsolutePath(); - FileOutputStream f = new FileOutputStream(path.substring(0, path.length()-1)+ file.getOriginalFilename()); + FileOutputStream f = new FileOutputStream(path.substring(0, path.length() - 1) + file.getOriginalFilename()); int ch = 0; while ((ch = in.read()) != -1) { f.write(ch); @@ -37,15 +37,17 @@ public class FileUploadController implements HandlerExceptionResolver { f.flush(); f.close(); - modelAndView.getModel().put("message", "File uploaded successfully!"); + modelAndView.getModel() + .put("message", "File uploaded successfully!"); return modelAndView; } - + @Override - public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object object, Exception exc) { + public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object object, Exception exc) { ModelAndView modelAndView = new ModelAndView("file"); if (exc instanceof MaxUploadSizeExceededException) { - modelAndView.getModel().put("message", "File size exceeds limit!"); + modelAndView.getModel() + .put("message", "File size exceeds limit!"); } return modelAndView; } diff --git a/spring-mvc-simple/src/main/java/com/baeldung/spring/controller/RequestMappingHandlerAdapterExample.java b/spring-mvc-simple/src/main/java/com/baeldung/spring/controller/RequestMappingHandlerAdapterExample.java index 76ac3e2806..754bea79f1 100644 --- a/spring-mvc-simple/src/main/java/com/baeldung/spring/controller/RequestMappingHandlerAdapterExample.java +++ b/spring-mvc-simple/src/main/java/com/baeldung/spring/controller/RequestMappingHandlerAdapterExample.java @@ -6,10 +6,10 @@ import org.springframework.web.servlet.ModelAndView; @Controller public class RequestMappingHandlerAdapterExample { - @RequestMapping("/requestName") - public ModelAndView getEmployeeName() { - ModelAndView model = new ModelAndView("Greeting"); - model.addObject("message", "Madhwal"); - return model; - } + @RequestMapping("/requestName") + public ModelAndView getEmployeeName() { + ModelAndView model = new ModelAndView("Greeting"); + model.addObject("message", "Madhwal"); + return model; + } } \ No newline at end of file diff --git a/spring-mvc-simple/src/main/java/com/baeldung/spring/controller/SimpleControllerHandlerAdapterExample.java b/spring-mvc-simple/src/main/java/com/baeldung/spring/controller/SimpleControllerHandlerAdapterExample.java index bac091ffeb..17c4ab689e 100644 --- a/spring-mvc-simple/src/main/java/com/baeldung/spring/controller/SimpleControllerHandlerAdapterExample.java +++ b/spring-mvc-simple/src/main/java/com/baeldung/spring/controller/SimpleControllerHandlerAdapterExample.java @@ -6,13 +6,11 @@ import javax.servlet.http.HttpServletResponse; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.AbstractController; -public class SimpleControllerHandlerAdapterExample extends - AbstractController { - @Override - protected ModelAndView handleRequestInternal(HttpServletRequest request, - HttpServletResponse response) throws Exception { - ModelAndView model = new ModelAndView("Greeting"); - model.addObject("message", "Dinesh Madhwal"); - return model; - } +public class SimpleControllerHandlerAdapterExample extends AbstractController { + @Override + protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { + ModelAndView model = new ModelAndView("Greeting"); + model.addObject("message", "Dinesh Madhwal"); + return model; + } } \ No newline at end of file diff --git a/spring-mvc-push/src/main/java/com/baeldung/controller/PushController.java b/spring-mvc-simple/src/main/java/com/baeldung/spring/controller/push/PushController.java similarity index 93% rename from spring-mvc-push/src/main/java/com/baeldung/controller/PushController.java rename to spring-mvc-simple/src/main/java/com/baeldung/spring/controller/push/PushController.java index c4698fe976..b557c65c93 100644 --- a/spring-mvc-push/src/main/java/com/baeldung/controller/PushController.java +++ b/spring-mvc-simple/src/main/java/com/baeldung/spring/controller/push/PushController.java @@ -1,4 +1,4 @@ -package com.baeldung.controller; +package com.baeldung.spring.controller.push; import javax.servlet.http.PushBuilder; diff --git a/spring-mvc-simple/src/main/resources/spring-servlet_AnnotationMethodHandlerAdapter.xml b/spring-mvc-simple/src/main/resources/spring-servlet_AnnotationMethodHandlerAdapter.xml deleted file mode 100644 index 430b849012..0000000000 --- a/spring-mvc-simple/src/main/resources/spring-servlet_AnnotationMethodHandlerAdapter.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/spring-mvc-simple/src/main/resources/spring-servlet_RequestMappingHandlerAdapter.xml b/spring-mvc-simple/src/main/resources/spring-servlet_RequestMappingHandlerAdapter.xml deleted file mode 100644 index d3783c2e67..0000000000 --- a/spring-mvc-simple/src/main/resources/spring-servlet_RequestMappingHandlerAdapter.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/spring-mvc-simple/src/main/resources/spring-servlet_SimpleControllerHandlerAdapter.xml b/spring-mvc-simple/src/main/resources/spring-servlet_SimpleControllerHandlerAdapter.xml deleted file mode 100644 index 1d6e5628df..0000000000 --- a/spring-mvc-simple/src/main/resources/spring-servlet_SimpleControllerHandlerAdapter.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/spring-mvc-push/src/main/webapp/WEB-INF/views/demo.jsp b/spring-mvc-simple/src/main/webapp/WEB-INF/views/demo.jsp similarity index 88% rename from spring-mvc-push/src/main/webapp/WEB-INF/views/demo.jsp rename to spring-mvc-simple/src/main/webapp/WEB-INF/views/demo.jsp index 28b27322ae..d5579debf7 100644 --- a/spring-mvc-push/src/main/webapp/WEB-INF/views/demo.jsp +++ b/spring-mvc-simple/src/main/webapp/WEB-INF/views/demo.jsp @@ -12,7 +12,6 @@ " alt="Logo" height="126" width="411">
-
Go to - index + \ No newline at end of file diff --git a/spring-mvc-simple/src/main/webapp/WEB-INF/views/registration-jade.jade b/spring-mvc-simple/src/main/webapp/WEB-INF/views/registration-jade.jade index 44b6293ff0..f271ac6852 100644 --- a/spring-mvc-simple/src/main/webapp/WEB-INF/views/registration-jade.jade +++ b/spring-mvc-simple/src/main/webapp/WEB-INF/views/registration-jade.jade @@ -4,7 +4,7 @@ html title User Registration body form(action="register" method="post" ) - label(for="email") Emailaaaaaaaa: + label(for="email") Email: input(type="text" name="email") label(for="password") Password: input(type="password" name="password") diff --git a/spring-mvc-push/src/main/webapp/resources/logo.png b/spring-mvc-simple/src/main/webapp/resources/logo.png similarity index 100% rename from spring-mvc-push/src/main/webapp/resources/logo.png rename to spring-mvc-simple/src/main/webapp/resources/logo.png diff --git a/spring-mvc-push/src/test/java/com/baeldung/controller/PushControllerIntegrationTest.java b/spring-mvc-simple/src/test/java/com/baeldung/controller/push/PushControllerIntegrationTest.java similarity index 91% rename from spring-mvc-push/src/test/java/com/baeldung/controller/PushControllerIntegrationTest.java rename to spring-mvc-simple/src/test/java/com/baeldung/controller/push/PushControllerIntegrationTest.java index 570e05cad6..a03d02895f 100644 --- a/spring-mvc-push/src/test/java/com/baeldung/controller/PushControllerIntegrationTest.java +++ b/spring-mvc-simple/src/test/java/com/baeldung/controller/push/PushControllerIntegrationTest.java @@ -1,10 +1,9 @@ -package com.baeldung.controller; +package com.baeldung.controller.push; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig; @@ -12,9 +11,8 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; -import com.baeldung.config.PushConfiguration; +import com.baeldung.spring.configuration.PushConfiguration; -@Disabled @SpringJUnitWebConfig(PushConfiguration.class) public class PushControllerIntegrationTest { @Autowired From 692f12636f79be0be58fd86b6d527ba28be690f6 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Mon, 22 Jan 2018 18:46:11 +0200 Subject: [PATCH 52/65] add pact provider test (#3475) --- .../PactConsumerDrivenContractUnitTest.java | 12 ++-- spring-rest/pom.xml | 8 +++ .../web/controller/PactController.java | 32 ++++++++++ .../java/org/baeldung/web/dto/PactDto.java | 33 ++++++++++ .../pacts/test_consumer-test_provider.json | 61 +++++++++++++++++++ .../org/baeldung/pact/PactProviderTest.java | 40 ++++++++++++ 6 files changed, 179 insertions(+), 7 deletions(-) create mode 100644 spring-rest/src/main/java/org/baeldung/web/controller/PactController.java create mode 100644 spring-rest/src/main/java/org/baeldung/web/dto/PactDto.java create mode 100644 spring-rest/src/main/resources/pacts/test_consumer-test_provider.json create mode 100644 spring-rest/src/test/java/org/baeldung/pact/PactProviderTest.java diff --git a/libraries/src/test/java/com/baeldung/pact/PactConsumerDrivenContractUnitTest.java b/libraries/src/test/java/com/baeldung/pact/PactConsumerDrivenContractUnitTest.java index b152b22964..cc3b441aa4 100644 --- a/libraries/src/test/java/com/baeldung/pact/PactConsumerDrivenContractUnitTest.java +++ b/libraries/src/test/java/com/baeldung/pact/PactConsumerDrivenContractUnitTest.java @@ -32,9 +32,9 @@ public class PactConsumerDrivenContractUnitTest { headers.put("Content-Type", "application/json"); return builder - .given("test GET ") + .given("test GET") .uponReceiving("GET REQUEST") - .path("/") + .path("/pact") .method("GET") .willRespondWith() .status(200) @@ -45,11 +45,9 @@ public class PactConsumerDrivenContractUnitTest { .method("POST") .headers(headers) .body("{\"name\": \"Michael\"}") - .path("/create") + .path("/pact") .willRespondWith() .status(201) - .headers(headers) - .body("") .toPact(); } @@ -59,7 +57,7 @@ public class PactConsumerDrivenContractUnitTest { public void givenGet_whenSendRequest_shouldReturn200WithProperHeaderAndBody() { //when ResponseEntity response - = new RestTemplate().getForEntity(mockProvider.getUrl(), String.class); + = new RestTemplate().getForEntity(mockProvider.getUrl() + "/pact", String.class); //then assertThat(response.getStatusCode().value()).isEqualTo(200); @@ -73,7 +71,7 @@ public class PactConsumerDrivenContractUnitTest { //when ResponseEntity postResponse = new RestTemplate().exchange( - mockProvider.getUrl() + "/create", + mockProvider.getUrl() + "/pact", HttpMethod.POST, new HttpEntity<>(jsonBody, httpHeaders), String.class diff --git a/spring-rest/pom.xml b/spring-rest/pom.xml index 6da891b054..50ac00e1c3 100644 --- a/spring-rest/pom.xml +++ b/spring-rest/pom.xml @@ -169,6 +169,12 @@ commons-io 2.4
+ + + au.com.dius + pact-jvm-provider-junit_2.11 + ${pact.version} + @@ -324,6 +330,8 @@ 3.4.1 2.2.0 + + 3.5.11 diff --git a/spring-rest/src/main/java/org/baeldung/web/controller/PactController.java b/spring-rest/src/main/java/org/baeldung/web/controller/PactController.java new file mode 100644 index 0000000000..4f586479ef --- /dev/null +++ b/spring-rest/src/main/java/org/baeldung/web/controller/PactController.java @@ -0,0 +1,32 @@ +package org.baeldung.web.controller; + +import java.util.ArrayList; +import java.util.List; + +import org.baeldung.web.dto.PactDto; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class PactController { + + List pacts = new ArrayList<>(); + + @GetMapping(value = "/pact", produces = MediaType.APPLICATION_JSON_VALUE) + @ResponseBody + public PactDto getPact() { + return new PactDto(true, "tom"); + } + + @PostMapping("/pact") + @ResponseStatus(HttpStatus.CREATED) + public void createPact(PactDto pact) { + pacts.add(pact); + } + +} diff --git a/spring-rest/src/main/java/org/baeldung/web/dto/PactDto.java b/spring-rest/src/main/java/org/baeldung/web/dto/PactDto.java new file mode 100644 index 0000000000..e34e2bdf3b --- /dev/null +++ b/spring-rest/src/main/java/org/baeldung/web/dto/PactDto.java @@ -0,0 +1,33 @@ +package org.baeldung.web.dto; + +public class PactDto { + + private boolean condition; + private String name; + + public PactDto() { + } + + public PactDto(boolean condition, String name) { + super(); + this.condition = condition; + this.name = name; + } + + public boolean isCondition() { + return condition; + } + + public void setCondition(boolean condition) { + this.condition = condition; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} diff --git a/spring-rest/src/main/resources/pacts/test_consumer-test_provider.json b/spring-rest/src/main/resources/pacts/test_consumer-test_provider.json new file mode 100644 index 0000000000..c8082798f4 --- /dev/null +++ b/spring-rest/src/main/resources/pacts/test_consumer-test_provider.json @@ -0,0 +1,61 @@ +{ + "provider": { + "name": "test_provider" + }, + "consumer": { + "name": "test_consumer" + }, + "interactions": [ + { + "description": "GET REQUEST", + "request": { + "method": "GET", + "path": "/pact" + }, + "response": { + "status": 200, + "headers": { + "Content-Type": "application/json" + }, + "body": { + "condition": true, + "name": "tom" + } + }, + "providerStates": [ + { + "name": "test GET" + } + ] + }, + { + "description": "POST REQUEST", + "request": { + "method": "POST", + "path": "/pact", + "headers": { + "Content-Type": "application/json" + }, + "body": { + "name": "Michael" + } + }, + "response": { + "status": 201 + }, + "providerStates": [ + { + "name": "test POST" + } + ] + } + ], + "metadata": { + "pact-specification": { + "version": "3.0.0" + }, + "pact-jvm": { + "version": "3.5.0" + } + } +} \ No newline at end of file diff --git a/spring-rest/src/test/java/org/baeldung/pact/PactProviderTest.java b/spring-rest/src/test/java/org/baeldung/pact/PactProviderTest.java new file mode 100644 index 0000000000..0456b0d3e7 --- /dev/null +++ b/spring-rest/src/test/java/org/baeldung/pact/PactProviderTest.java @@ -0,0 +1,40 @@ +package org.baeldung.pact; + +import org.baeldung.config.MainApplication; +import org.junit.BeforeClass; +import org.junit.runner.RunWith; +import org.springframework.boot.SpringApplication; +import org.springframework.web.context.ConfigurableWebApplicationContext; + +import au.com.dius.pact.provider.junit.PactRunner; +import au.com.dius.pact.provider.junit.Provider; +import au.com.dius.pact.provider.junit.State; +import au.com.dius.pact.provider.junit.loader.PactFolder; +import au.com.dius.pact.provider.junit.target.HttpTarget; +import au.com.dius.pact.provider.junit.target.Target; +import au.com.dius.pact.provider.junit.target.TestTarget; + +@RunWith(PactRunner.class) +@Provider("test_provider") +@PactFolder("pacts") +public class PactProviderTest { + + @TestTarget + public final Target target = new HttpTarget("http", "localhost", 8082, "/spring-rest"); + + private static ConfigurableWebApplicationContext application; + + @BeforeClass + public static void start() { + application = (ConfigurableWebApplicationContext) SpringApplication.run(MainApplication.class); + } + + @State("test GET") + public void toGetState() { + } + + @State("test POST") + public void toPostState() { + } + +} From 3e5ac1de94aa9c139ecc433898265bc29dd69abe Mon Sep 17 00:00:00 2001 From: felipeazv Date: Mon, 22 Jan 2018 22:09:57 +0100 Subject: [PATCH 53/65] BAEL-1475: code formatting --- .../ReactiveJavaClientWebSocket.java | 15 ++++---- .../websocket/ReactiveWebSocketHandler.java | 35 +++++-------------- 2 files changed, 18 insertions(+), 32 deletions(-) diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveJavaClientWebSocket.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveJavaClientWebSocket.java index 74e2d7daca..c9a333c044 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveJavaClientWebSocket.java +++ b/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveJavaClientWebSocket.java @@ -2,22 +2,25 @@ package com.baeldung.reactive.websocket; import java.net.URI; import java.time.Duration; -import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.web.reactive.socket.WebSocketMessage; import org.springframework.web.reactive.socket.client.ReactorNettyWebSocketClient; import org.springframework.web.reactive.socket.client.WebSocketClient; import reactor.core.publisher.Mono; -@SpringBootApplication public class ReactiveJavaClientWebSocket { - public static void main(String[] args) throws InterruptedException { + public static void main(String[] args) throws InterruptedException { + WebSocketClient client = new ReactorNettyWebSocketClient(); - client.execute(URI.create("ws://localhost:8080/event-emitter"), session -> session.send(Mono.just(session.textMessage("event-me-from-spring-reactive-client"))) + client.execute( + URI.create("ws://localhost:8080/event-emitter"), + session -> session.send( + Mono.just(session.textMessage("event-spring-reactive-client-websocket"))) .thenMany(session.receive() - .map(WebSocketMessage::getPayloadAsText) - .log()) + .map(WebSocketMessage::getPayloadAsText) + .log()) .then()) .block(Duration.ofSeconds(10L)); } + } diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveWebSocketHandler.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveWebSocketHandler.java index 7f74e714f6..eea0fb9962 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveWebSocketHandler.java +++ b/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveWebSocketHandler.java @@ -12,7 +12,6 @@ import org.springframework.web.reactive.socket.WebSocketMessage; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -import javax.annotation.PostConstruct; import java.time.Duration; import java.time.LocalDateTime; import java.util.UUID; @@ -20,27 +19,14 @@ import java.util.UUID; @Component public class ReactiveWebSocketHandler implements WebSocketHandler { - private Flux eventFlux; - private Flux intervalFlux; + private Flux eventFlux = Flux.generate(e -> { + Event event = new Event(UUID.randomUUID().toString(), LocalDateTime.now().toString()); + e.next(event); + }); - /** - * Here we prepare a Flux that will emit a message every second - */ - @PostConstruct - private void init() throws InterruptedException { + private Flux intervalFlux = Flux.interval(Duration.ofMillis(1000L)).zipWith(eventFlux, (time, event) -> event); - eventFlux = Flux.generate(e -> { - Event event = new Event(UUID.randomUUID() - .toString(), - LocalDateTime.now() - .toString()); - e.next(event); - }); - - intervalFlux = Flux.interval(Duration.ofMillis(1000L)) - .zipWith(eventFlux, (time, event) -> event); - - } + private ObjectMapper json = new ObjectMapper(); /** * On each new client session, send the message flux to the client. @@ -50,7 +36,7 @@ public class ReactiveWebSocketHandler implements WebSocketHandler { */ @Override public Mono handle(WebSocketSession webSocketSession) { - ObjectMapper json = new ObjectMapper(); + return webSocketSession.send(intervalFlux.map(event -> { try { String jsonEvent = json.writeValueAsString(event); @@ -60,12 +46,9 @@ public class ReactiveWebSocketHandler implements WebSocketHandler { e.printStackTrace(); return ""; } - }) - .map(webSocketSession::textMessage)) + }).map(webSocketSession::textMessage)) - .and(webSocketSession.receive() - .map(WebSocketMessage::getPayloadAsText) - .log()); + .and(webSocketSession.receive().map(WebSocketMessage::getPayloadAsText).log()); } } From c38de161c68e0b327b5f27e26ed01d328882a8f3 Mon Sep 17 00:00:00 2001 From: felipeazv Date: Mon, 22 Jan 2018 22:28:02 +0100 Subject: [PATCH 54/65] removing verbose comment --- .../reactive/websocket/ReactiveWebSocketHandler.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveWebSocketHandler.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveWebSocketHandler.java index eea0fb9962..669c212fd3 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveWebSocketHandler.java +++ b/spring-5-reactive/src/main/java/com/baeldung/reactive/websocket/ReactiveWebSocketHandler.java @@ -28,12 +28,6 @@ public class ReactiveWebSocketHandler implements WebSocketHandler { private ObjectMapper json = new ObjectMapper(); - /** - * On each new client session, send the message flux to the client. - * Spring subscribes to the flux and send every new flux event to the WebSocketSession object - * @param session - * @return Mono - */ @Override public Mono handle(WebSocketSession webSocketSession) { From db903618f3f55d93c9d6de07266834e83573524f Mon Sep 17 00:00:00 2001 From: Donato Rimenti Date: Tue, 23 Jan 2018 00:28:45 +0100 Subject: [PATCH 55/65] BAEL-1321 Jetty 9 Server - Create, Configure programmatically (#3482) * Implemented server factory and its tests. Changed Jetty version to latest, removed duplicate entry and added jetty-webapp dependency in pom.xml. * Added missing war file and changed tests port for Travis build. --- libraries/pom.xml | 8 +- .../baeldung/jetty/JettyServerFactory.java | 94 ++++++++++ .../baeldung/jetty/LoggingRequestHandler.java | 168 ++++++++++++++++++ .../jetty/JettyServerFactoryUnitTest.java | 86 +++++++++ .../resources/jetty-embedded-demo-app.war | Bin 0 -> 1021 bytes 5 files changed, 354 insertions(+), 2 deletions(-) create mode 100644 libraries/src/main/java/com/baeldung/jetty/JettyServerFactory.java create mode 100644 libraries/src/main/java/com/baeldung/jetty/LoggingRequestHandler.java create mode 100644 libraries/src/test/java/com/baeldung/jetty/JettyServerFactoryUnitTest.java create mode 100644 libraries/src/test/resources/jetty-embedded-demo-app.war diff --git a/libraries/pom.xml b/libraries/pom.xml index 09c8cb8335..3e802e76c8 100644 --- a/libraries/pom.xml +++ b/libraries/pom.xml @@ -194,6 +194,11 @@ jetty-servlet ${jetty.version} + + org.eclipse.jetty + jetty-webapp + ${jetty.version} + rome rome @@ -741,12 +746,11 @@ 3.6.2 1.5.0 3.1.0 - 9.4.3.v20170317 4.5.3 2.5 1.6 1.4.196 - 9.4.2.v20170220 + 9.4.8.v20171121 4.5.3 2.5 1.2.0 diff --git a/libraries/src/main/java/com/baeldung/jetty/JettyServerFactory.java b/libraries/src/main/java/com/baeldung/jetty/JettyServerFactory.java new file mode 100644 index 0000000000..00ba84368a --- /dev/null +++ b/libraries/src/main/java/com/baeldung/jetty/JettyServerFactory.java @@ -0,0 +1,94 @@ +package com.baeldung.jetty; + +import org.eclipse.jetty.server.Handler; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.ServerConnector; +import org.eclipse.jetty.server.handler.HandlerCollection; +import org.eclipse.jetty.webapp.WebAppContext; + +/** + * Simple factory for creating Jetty basic instances. + * + * @author Donato Rimenti + * + */ +public class JettyServerFactory { + + /** + * Exposed context of the app. + */ + public final static String APP_PATH = "/myApp"; + + /** + * The server port. + */ + public final static int SERVER_PORT = 13133; + + /** + * Private constructor to avoid instantiation. + */ + private JettyServerFactory() { + } + + /** + * Returns a simple server listening on port 80 with a timeout of 30 seconds + * for connections and no handlers. + * + * @return a server + */ + public static Server createBaseServer() { + Server server = new Server(); + + // Adds a connector for port 80 with a timeout of 30 seconds. + ServerConnector connector = new ServerConnector(server); + connector.setPort(SERVER_PORT); + connector.setHost("127.0.0.1"); + connector.setIdleTimeout(30000); + server.addConnector(connector); + + return server; + } + + /** + * Creates a server which delegates the request handling to a web + * application. + * + * @return a server + */ + public static Server createWebAppServer() { + // Adds an handler to a server and returns it. + Server server = createBaseServer(); + String webAppFolderPath = JettyServerFactory.class.getClassLoader().getResource("jetty-embedded-demo-app.war") + .getPath(); + Handler webAppHandler = new WebAppContext(webAppFolderPath, APP_PATH); + server.setHandler(webAppHandler); + + return server; + } + + /** + * Creates a server which delegates the request handling to both a logging + * handler and to a web application, in this order. + * + * @return a server + */ + public static Server createMultiHandlerServer() { + Server server = createBaseServer(); + + // Creates the handlers and adds them to the server. + HandlerCollection handlers = new HandlerCollection(); + + String webAppFolderPath = JettyServerFactory.class.getClassLoader().getResource("jetty-embedded-demo-app.war") + .getPath(); + Handler customRequestHandler = new WebAppContext(webAppFolderPath, APP_PATH); + handlers.addHandler(customRequestHandler); + + Handler loggingRequestHandler = new LoggingRequestHandler(); + handlers.addHandler(loggingRequestHandler); + + server.setHandler(handlers); + + return server; + } + +} \ No newline at end of file diff --git a/libraries/src/main/java/com/baeldung/jetty/LoggingRequestHandler.java b/libraries/src/main/java/com/baeldung/jetty/LoggingRequestHandler.java new file mode 100644 index 0000000000..a38759c903 --- /dev/null +++ b/libraries/src/main/java/com/baeldung/jetty/LoggingRequestHandler.java @@ -0,0 +1,168 @@ +package com.baeldung.jetty; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.eclipse.jetty.server.Handler; +import org.eclipse.jetty.server.Request; +import org.eclipse.jetty.server.Server; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Handler implementation which simply logs that a request has been received. + * + * @author Donato Rimenti + */ +public class LoggingRequestHandler implements Handler { + + /** + * Logger. + */ + private final static Logger LOG = LoggerFactory.getLogger(LoggingRequestHandler.class); + + /* + * (non-Javadoc) + * + * @see org.eclipse.jetty.util.component.LifeCycle#addLifeCycleListener(org. + * eclipse.jetty.util.component.LifeCycle.Listener) + */ + @Override + public void addLifeCycleListener(Listener arg0) { + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jetty.util.component.LifeCycle#isFailed() + */ + @Override + public boolean isFailed() { + return false; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jetty.util.component.LifeCycle#isRunning() + */ + @Override + public boolean isRunning() { + return true; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jetty.util.component.LifeCycle#isStarted() + */ + @Override + public boolean isStarted() { + return true; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jetty.util.component.LifeCycle#isStarting() + */ + @Override + public boolean isStarting() { + return false; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jetty.util.component.LifeCycle#isStopped() + */ + @Override + public boolean isStopped() { + return false; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jetty.util.component.LifeCycle#isStopping() + */ + @Override + public boolean isStopping() { + return false; + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jetty.util.component.LifeCycle#removeLifeCycleListener(org. + * eclipse.jetty.util.component.LifeCycle.Listener) + */ + @Override + public void removeLifeCycleListener(Listener arg0) { + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jetty.util.component.LifeCycle#start() + */ + @Override + public void start() throws Exception { + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jetty.util.component.LifeCycle#stop() + */ + @Override + public void stop() throws Exception { + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jetty.server.Handler#destroy() + */ + @Override + public void destroy() { + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jetty.server.Handler#getServer() + */ + @Override + public Server getServer() { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jetty.server.Handler#handle(java.lang.String, + * org.eclipse.jetty.server.Request, javax.servlet.http.HttpServletRequest, + * javax.servlet.http.HttpServletResponse) + */ + @Override + public void handle(String arg0, Request arg1, HttpServletRequest arg2, HttpServletResponse arg3) + throws IOException, ServletException { + LOG.info("Received a new request"); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jetty.server.Handler#setServer(org.eclipse.jetty.server. + * Server) + */ + @Override + public void setServer(Server server) { + } + +} diff --git a/libraries/src/test/java/com/baeldung/jetty/JettyServerFactoryUnitTest.java b/libraries/src/test/java/com/baeldung/jetty/JettyServerFactoryUnitTest.java new file mode 100644 index 0000000000..849ba24f55 --- /dev/null +++ b/libraries/src/test/java/com/baeldung/jetty/JettyServerFactoryUnitTest.java @@ -0,0 +1,86 @@ +package com.baeldung.jetty; + +import org.apache.http.HttpHost; +import org.apache.http.HttpRequest; +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.HttpClientBuilder; +import org.eclipse.jetty.server.Server; +import org.junit.Assert; +import org.junit.Test; + +/** + * Test for {@link JettyServerFactory}. + * + * @author Donato Rimenti + * + */ +public class JettyServerFactoryUnitTest { + + /** + * Tests that when a base server is provided a request returns a status 404. + * + * @throws Exception + */ + @Test + public void givenBaseServer_whenHttpRequest_thenStatus404() throws Exception { + Server server = JettyServerFactory.createBaseServer(); + server.start(); + + int statusCode = sendGetRequest(); + + Assert.assertEquals(404, statusCode); + server.stop(); + } + + /** + * Tests that when a web app server is provided a request returns a status + * 200. + * + * @throws Exception + */ + @Test + public void givenWebAppServer_whenHttpRequest_thenStatus200() throws Exception { + Server server = JettyServerFactory.createWebAppServer(); + server.start(); + + int statusCode = sendGetRequest(); + + Assert.assertEquals(200, statusCode); + server.stop(); + } + + /** + * Tests that when a multi handler server is provided a request returns a + * status 200. + * + * @throws Exception + */ + @Test + public void givenMultiHandlerServerServer_whenHttpRequest_thenStatus200() throws Exception { + Server server = JettyServerFactory.createMultiHandlerServer(); + server.start(); + + int statusCode = sendGetRequest(); + + Assert.assertEquals(200, statusCode); + server.stop(); + } + + /** + * Sends a default HTTP GET request to the server and returns the response + * status code. + * + * @return the status code of the response + * @throws Exception + */ + private int sendGetRequest() throws Exception { + HttpHost target = new HttpHost("localhost", JettyServerFactory.SERVER_PORT); + HttpRequest request = new HttpGet(JettyServerFactory.APP_PATH); + HttpClient client = HttpClientBuilder.create().build(); + HttpResponse response = client.execute(target, request); + return response.getStatusLine().getStatusCode(); + } + +} diff --git a/libraries/src/test/resources/jetty-embedded-demo-app.war b/libraries/src/test/resources/jetty-embedded-demo-app.war new file mode 100644 index 0000000000000000000000000000000000000000..7f8bc37df0cfd132b96699b37b9f8c12c55cfa4c GIT binary patch literal 1021 zcmWIWW@h1H0D)t(Onkr$D8UJ&eO*Hwbv^yu^aFs(M1TSu3@?Dn4mbN7Xb)7iapDYQR zBBp&nrDEqCFXLjblDS%IMPfdE7V`ci+GJE5{MpN>a_5}xAYt#I-~&Z{teqz%S90y^ zOkG*Yb*$=G)ii;*n!DmOZz`PD`NH$)Y=haSB1Q&~GqL-I1L(|fS0}hH2dg*UFuqD>XG&YI4P`R8^hI)yc}*W%kRV)#2$cgW6vK z&2Z;)FsuSvCC{9mxg2Q4Js{=>Vwm&GQs*^V+=N76OR7#J4(Q7_ngFMb228+z5FWf*$1Is|E+DGcG-)peBJO|IZln$ z{p7KOXO4B<%UKxEqmUNLW`5COQK`D*)}jD`2?B=pmGiT+*WOdKdofwaSo2Vu+|H*v zyk0HfJ2}a=BldXdqOEaE4o8+=l$~4aS}mxqoZUKiYeR|16|R5ldq1S_Kk&i3nmNFm zkx7IZdvJr27z79~ymbVz;3)~DO&*-Muq8Pas5S*4t&Xe>DFJdZfMgjM7#SoOJeNP+ zD?RBl06txy6a)bvU0;Aqm@Y(mf&~cn6a~}2q)~|x kIej5)#hyG6`g(!-V75XNOMo{k8%O~g5VirO6PZ9f0JvWo7ytkO literal 0 HcmV?d00001 From 3459d3ad47d52e41c58431dc4bc0acacc8d73e3b Mon Sep 17 00:00:00 2001 From: chrisoberle Date: Mon, 22 Jan 2018 18:41:03 -0500 Subject: [PATCH 56/65] BAEL-1418 Spring Security with Extra Login Fields (#3476) * BAEL-1418 - spring security with extra login fields * change delimeter for username/domain concatenation * remove unnecessary class * move source to spring-5-security module * finish moving example code to spring-5-security module * fix formatting in pom * adjust spacing * BAEL-1418 Spring Security with Extra Login Fields * added additional custom example * refactored and added tests * remove final keywords and serialVersionUID constants --- .../CustomAuthenticationFilter.java | 50 ++++++++++ .../CustomAuthenticationToken.java | 28 ++++++ ...stomUserDetailsAuthenticationProvider.java | 92 +++++++++++++++++++ .../CustomUserDetailsService.java | 10 ++ .../CustomUserDetailsServiceImpl.java | 30 ++++++ .../CustomUserRepository.java | 2 +- .../ExtraLoginFieldsApplication.java} | 6 +- .../SecurityConfig.java | 62 +++++++++++++ .../User.java | 4 +- .../UserRepository.java | 2 +- .../WebController.java | 2 +- .../ExtraLoginFieldsApplication.java | 13 +++ .../SecurityConfig.java | 6 +- .../SimpleAuthenticationFilter.java} | 4 +- .../SimpleUserDetailsService.java} | 8 +- .../SimpleUserRepository.java | 26 ++++++ .../baeldung/loginextrafieldssimple/User.java | 21 +++++ .../UserRepository.java | 7 ++ .../loginextrafieldssimple/WebController.java | 51 ++++++++++ .../src/main/resources/static/css/main.css | 12 +-- .../resources/templatesextrafields/index.html | 22 +++-- .../resources/templatesextrafields/login.html | 49 ++++++---- .../templatesextrafields/user/index.html | 29 +++--- .../AbstractExtraLoginFieldsTest.java | 46 ++++++++++ .../LoginFieldsFullTest.java} | 45 ++------- .../LoginFieldsSimpleTest.java | 72 +++++++++++++++ 26 files changed, 597 insertions(+), 102 deletions(-) create mode 100644 spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomAuthenticationFilter.java create mode 100644 spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomAuthenticationToken.java create mode 100644 spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomUserDetailsAuthenticationProvider.java create mode 100644 spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomUserDetailsService.java create mode 100644 spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomUserDetailsServiceImpl.java rename spring-5-security/src/main/java/com/baeldung/{securityextrafields => loginextrafieldscustom}/CustomUserRepository.java (91%) rename spring-5-security/src/main/java/com/baeldung/{securityextrafields/SpringExtraLoginFieldsApplication.java => loginextrafieldscustom/ExtraLoginFieldsApplication.java} (54%) create mode 100644 spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/SecurityConfig.java rename spring-5-security/src/main/java/com/baeldung/{securityextrafields => loginextrafieldscustom}/User.java (87%) rename spring-5-security/src/main/java/com/baeldung/{securityextrafields => loginextrafieldscustom}/UserRepository.java (66%) rename spring-5-security/src/main/java/com/baeldung/{securityextrafields => loginextrafieldscustom}/WebController.java (93%) create mode 100644 spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/ExtraLoginFieldsApplication.java rename spring-5-security/src/main/java/com/baeldung/{securityextrafields => loginextrafieldssimple}/SecurityConfig.java (91%) rename spring-5-security/src/main/java/com/baeldung/{securityextrafields/CustomAuthenticationFilter.java => loginextrafieldssimple/SimpleAuthenticationFilter.java} (92%) rename spring-5-security/src/main/java/com/baeldung/{securityextrafields/CustomUserDetailsService.java => loginextrafieldssimple/SimpleUserDetailsService.java} (82%) create mode 100644 spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/SimpleUserRepository.java create mode 100644 spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/User.java create mode 100644 spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/UserRepository.java create mode 100644 spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/WebController.java create mode 100644 spring-5-security/src/test/java/com/baeldung/loginextrafields/AbstractExtraLoginFieldsTest.java rename spring-5-security/src/test/java/com/baeldung/{securityextrafields/SecurityExtraFieldsTest.java => loginextrafields/LoginFieldsFullTest.java} (65%) create mode 100644 spring-5-security/src/test/java/com/baeldung/loginextrafields/LoginFieldsSimpleTest.java diff --git a/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomAuthenticationFilter.java b/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomAuthenticationFilter.java new file mode 100644 index 0000000000..2a5c5f0368 --- /dev/null +++ b/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomAuthenticationFilter.java @@ -0,0 +1,50 @@ +package com.baeldung.loginextrafieldscustom; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.security.authentication.AuthenticationServiceException; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; + +public class CustomAuthenticationFilter extends UsernamePasswordAuthenticationFilter { + + public static final String SPRING_SECURITY_FORM_DOMAIN_KEY = "domain"; + + @Override + public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) + throws AuthenticationException { + + if (!request.getMethod().equals("POST")) { + throw new AuthenticationServiceException("Authentication method not supported: " + + request.getMethod()); + } + + CustomAuthenticationToken authRequest = getAuthRequest(request); + setDetails(request, authRequest); + return this.getAuthenticationManager().authenticate(authRequest); + } + + private CustomAuthenticationToken getAuthRequest(HttpServletRequest request) { + String username = obtainUsername(request); + String password = obtainPassword(request); + String domain = obtainDomain(request); + + if (username == null) { + username = ""; + } + if (password == null) { + password = ""; + } + if (domain == null) { + domain = ""; + } + + return new CustomAuthenticationToken(username, password, domain); + } + + private String obtainDomain(HttpServletRequest request) { + return request.getParameter(SPRING_SECURITY_FORM_DOMAIN_KEY); + } +} diff --git a/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomAuthenticationToken.java b/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomAuthenticationToken.java new file mode 100644 index 0000000000..50995169a1 --- /dev/null +++ b/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomAuthenticationToken.java @@ -0,0 +1,28 @@ +package com.baeldung.loginextrafieldscustom; + +import java.util.Collection; + +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.GrantedAuthority; + +public class CustomAuthenticationToken extends UsernamePasswordAuthenticationToken { + + private String domain; + + public CustomAuthenticationToken(Object principal, Object credentials, String domain) { + super(principal, credentials); + this.domain = domain; + super.setAuthenticated(false); + } + + public CustomAuthenticationToken(Object principal, Object credentials, String domain, + Collection authorities) { + super(principal, credentials, authorities); + this.domain = domain; + super.setAuthenticated(true); // must use super, as we override + } + + public String getDomain() { + return this.domain; + } +} diff --git a/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomUserDetailsAuthenticationProvider.java b/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomUserDetailsAuthenticationProvider.java new file mode 100644 index 0000000000..693900d843 --- /dev/null +++ b/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomUserDetailsAuthenticationProvider.java @@ -0,0 +1,92 @@ +package com.baeldung.loginextrafieldscustom; + +import org.springframework.security.authentication.BadCredentialsException; +import org.springframework.security.authentication.InternalAuthenticationServiceException; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider; +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.util.Assert; + +public class CustomUserDetailsAuthenticationProvider extends AbstractUserDetailsAuthenticationProvider { + + /** + * The plaintext password used to perform + * PasswordEncoder#matches(CharSequence, String)} on when the user is + * not found to avoid SEC-2056. + */ + private static final String USER_NOT_FOUND_PASSWORD = "userNotFoundPassword"; + + private PasswordEncoder passwordEncoder; + private CustomUserDetailsService userDetailsService; + + /** + * The password used to perform + * {@link PasswordEncoder#matches(CharSequence, String)} on when the user is + * not found to avoid SEC-2056. This is necessary, because some + * {@link PasswordEncoder} implementations will short circuit if the password is not + * in a valid format. + */ + private String userNotFoundEncodedPassword; + + public CustomUserDetailsAuthenticationProvider(PasswordEncoder passwordEncoder, CustomUserDetailsService userDetailsService) { + this.passwordEncoder = passwordEncoder; + this.userDetailsService = userDetailsService; + } + + @Override + protected void additionalAuthenticationChecks(UserDetails userDetails, UsernamePasswordAuthenticationToken authentication) + throws AuthenticationException { + + if (authentication.getCredentials() == null) { + logger.debug("Authentication failed: no credentials provided"); + throw new BadCredentialsException( + messages.getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials")); + } + + String presentedPassword = authentication.getCredentials() + .toString(); + + if (!passwordEncoder.matches(presentedPassword, userDetails.getPassword())) { + logger.debug("Authentication failed: password does not match stored value"); + throw new BadCredentialsException( + messages.getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials")); + } + } + + @Override + protected void doAfterPropertiesSet() throws Exception { + Assert.notNull(this.userDetailsService, "A UserDetailsService must be set"); + this.userNotFoundEncodedPassword = this.passwordEncoder.encode(USER_NOT_FOUND_PASSWORD); + } + + @Override + protected UserDetails retrieveUser(String username, UsernamePasswordAuthenticationToken authentication) + throws AuthenticationException { + CustomAuthenticationToken auth = (CustomAuthenticationToken) authentication; + UserDetails loadedUser; + + try { + loadedUser = this.userDetailsService.loadUserByUsernameAndDomain(auth.getPrincipal() + .toString(), auth.getDomain()); + } catch (UsernameNotFoundException notFound) { + if (authentication.getCredentials() != null) { + String presentedPassword = authentication.getCredentials() + .toString(); + passwordEncoder.matches(presentedPassword, userNotFoundEncodedPassword); + } + throw notFound; + } catch (Exception repositoryProblem) { + throw new InternalAuthenticationServiceException(repositoryProblem.getMessage(), repositoryProblem); + } + + if (loadedUser == null) { + throw new InternalAuthenticationServiceException("UserDetailsService returned null, " + + "which is an interface contract violation"); + } + return loadedUser; + } + +} diff --git a/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomUserDetailsService.java b/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomUserDetailsService.java new file mode 100644 index 0000000000..358129173d --- /dev/null +++ b/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomUserDetailsService.java @@ -0,0 +1,10 @@ +package com.baeldung.loginextrafieldscustom; + +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UsernameNotFoundException; + +public interface CustomUserDetailsService { + + UserDetails loadUserByUsernameAndDomain(String username, String domain) throws UsernameNotFoundException; + +} diff --git a/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomUserDetailsServiceImpl.java b/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomUserDetailsServiceImpl.java new file mode 100644 index 0000000000..ea979e2fab --- /dev/null +++ b/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomUserDetailsServiceImpl.java @@ -0,0 +1,30 @@ +package com.baeldung.loginextrafieldscustom; + +import org.apache.commons.lang3.StringUtils; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.stereotype.Service; + +@Service("userDetailsService") +public class CustomUserDetailsServiceImpl implements CustomUserDetailsService { + + private UserRepository userRepository; + + public CustomUserDetailsServiceImpl(UserRepository userRepository) { + this.userRepository = userRepository; + } + + @Override + public UserDetails loadUserByUsernameAndDomain(String username, String domain) throws UsernameNotFoundException { + if (StringUtils.isAnyBlank(username, domain)) { + throw new UsernameNotFoundException("Username and domain must be provided"); + } + User user = userRepository.findUser(username, domain); + if (user == null) { + throw new UsernameNotFoundException( + String.format("Username not found for domain, username=%s, domain=%s", + username, domain)); + } + return user; + } +} diff --git a/spring-5-security/src/main/java/com/baeldung/securityextrafields/CustomUserRepository.java b/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomUserRepository.java similarity index 91% rename from spring-5-security/src/main/java/com/baeldung/securityextrafields/CustomUserRepository.java rename to spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomUserRepository.java index c86769b016..428c8bf532 100644 --- a/spring-5-security/src/main/java/com/baeldung/securityextrafields/CustomUserRepository.java +++ b/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomUserRepository.java @@ -1,4 +1,4 @@ -package com.baeldung.securityextrafields; +package com.baeldung.loginextrafieldscustom; import java.util.ArrayList; import java.util.Collection; diff --git a/spring-5-security/src/main/java/com/baeldung/securityextrafields/SpringExtraLoginFieldsApplication.java b/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/ExtraLoginFieldsApplication.java similarity index 54% rename from spring-5-security/src/main/java/com/baeldung/securityextrafields/SpringExtraLoginFieldsApplication.java rename to spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/ExtraLoginFieldsApplication.java index a779acc75e..0cf934f288 100644 --- a/spring-5-security/src/main/java/com/baeldung/securityextrafields/SpringExtraLoginFieldsApplication.java +++ b/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/ExtraLoginFieldsApplication.java @@ -1,13 +1,13 @@ -package com.baeldung.securityextrafields; +package com.baeldung.loginextrafieldscustom; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication -public class SpringExtraLoginFieldsApplication { +public class ExtraLoginFieldsApplication { public static void main(String[] args) { - SpringApplication.run(SpringExtraLoginFieldsApplication.class, args); + SpringApplication.run(ExtraLoginFieldsApplication.class, args); } } diff --git a/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/SecurityConfig.java b/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/SecurityConfig.java new file mode 100644 index 0000000000..def85ab978 --- /dev/null +++ b/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/SecurityConfig.java @@ -0,0 +1,62 @@ +package com.baeldung.loginextrafieldscustom; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.PropertySource; +import org.springframework.security.authentication.AuthenticationProvider; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +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.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler; +import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; + +@EnableWebSecurity +@PropertySource("classpath:/application-extrafields.properties") +public class SecurityConfig extends WebSecurityConfigurerAdapter { + + @Autowired + private CustomUserDetailsService userDetailsService; + + @Override + protected void configure(HttpSecurity http) throws Exception { + + http + .addFilterBefore(authenticationFilter(), UsernamePasswordAuthenticationFilter.class) + .authorizeRequests() + .antMatchers("/css/**", "/index").permitAll() + .antMatchers("/user/**").authenticated() + .and() + .formLogin().loginPage("/login") + .and() + .logout() + .logoutUrl("/logout"); + } + + public CustomAuthenticationFilter authenticationFilter() throws Exception { + CustomAuthenticationFilter filter = new CustomAuthenticationFilter(); + filter.setAuthenticationManager(authenticationManagerBean()); + filter.setAuthenticationFailureHandler(failureHandler()); + return filter; + } + + @Autowired + public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { + auth.authenticationProvider(authProvider()); + } + + public AuthenticationProvider authProvider() { + CustomUserDetailsAuthenticationProvider provider + = new CustomUserDetailsAuthenticationProvider(passwordEncoder(), userDetailsService); + return provider; + } + + public SimpleUrlAuthenticationFailureHandler failureHandler() { + return new SimpleUrlAuthenticationFailureHandler("/login?error=true"); + } + + public PasswordEncoder passwordEncoder() { + return new BCryptPasswordEncoder(); + } +} diff --git a/spring-5-security/src/main/java/com/baeldung/securityextrafields/User.java b/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/User.java similarity index 87% rename from spring-5-security/src/main/java/com/baeldung/securityextrafields/User.java rename to spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/User.java index a5b3a434ae..aa03f15b6a 100644 --- a/spring-5-security/src/main/java/com/baeldung/securityextrafields/User.java +++ b/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/User.java @@ -1,4 +1,4 @@ -package com.baeldung.securityextrafields; +package com.baeldung.loginextrafieldscustom; import java.util.Collection; @@ -8,7 +8,7 @@ public class User extends org.springframework.security.core.userdetails.User { private static final long serialVersionUID = 1L; - private final String domain; + private String domain; public User(String username, String domain, String password, boolean enabled, boolean accountNonExpired, boolean credentialsNonExpired, diff --git a/spring-5-security/src/main/java/com/baeldung/securityextrafields/UserRepository.java b/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/UserRepository.java similarity index 66% rename from spring-5-security/src/main/java/com/baeldung/securityextrafields/UserRepository.java rename to spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/UserRepository.java index 4ca65b13d5..e2358e055b 100644 --- a/spring-5-security/src/main/java/com/baeldung/securityextrafields/UserRepository.java +++ b/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/UserRepository.java @@ -1,4 +1,4 @@ -package com.baeldung.securityextrafields; +package com.baeldung.loginextrafieldscustom; public interface UserRepository { diff --git a/spring-5-security/src/main/java/com/baeldung/securityextrafields/WebController.java b/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/WebController.java similarity index 93% rename from spring-5-security/src/main/java/com/baeldung/securityextrafields/WebController.java rename to spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/WebController.java index 4a8abb4a83..b5e0b511ac 100644 --- a/spring-5-security/src/main/java/com/baeldung/securityextrafields/WebController.java +++ b/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/WebController.java @@ -1,4 +1,4 @@ -package com.baeldung.securityextrafields; +package com.baeldung.loginextrafieldscustom; import java.util.Optional; diff --git a/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/ExtraLoginFieldsApplication.java b/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/ExtraLoginFieldsApplication.java new file mode 100644 index 0000000000..c82a13de1a --- /dev/null +++ b/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/ExtraLoginFieldsApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.loginextrafieldssimple; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class ExtraLoginFieldsApplication { + + public static void main(String[] args) { + SpringApplication.run(ExtraLoginFieldsApplication.class, args); + } + +} diff --git a/spring-5-security/src/main/java/com/baeldung/securityextrafields/SecurityConfig.java b/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/SecurityConfig.java similarity index 91% rename from spring-5-security/src/main/java/com/baeldung/securityextrafields/SecurityConfig.java rename to spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/SecurityConfig.java index 429f6df972..d8c5ea8147 100644 --- a/spring-5-security/src/main/java/com/baeldung/securityextrafields/SecurityConfig.java +++ b/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/SecurityConfig.java @@ -1,4 +1,4 @@ -package com.baeldung.securityextrafields; +package com.baeldung.loginextrafieldssimple; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.PropertySource; @@ -36,8 +36,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { .logoutUrl("/logout"); } - public CustomAuthenticationFilter authenticationFilter() throws Exception { - CustomAuthenticationFilter filter = new CustomAuthenticationFilter(); + public SimpleAuthenticationFilter authenticationFilter() throws Exception { + SimpleAuthenticationFilter filter = new SimpleAuthenticationFilter(); filter.setAuthenticationManager(authenticationManagerBean()); filter.setAuthenticationFailureHandler(failureHandler()); return filter; diff --git a/spring-5-security/src/main/java/com/baeldung/securityextrafields/CustomAuthenticationFilter.java b/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/SimpleAuthenticationFilter.java similarity index 92% rename from spring-5-security/src/main/java/com/baeldung/securityextrafields/CustomAuthenticationFilter.java rename to spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/SimpleAuthenticationFilter.java index b5d628628d..9dcb524157 100644 --- a/spring-5-security/src/main/java/com/baeldung/securityextrafields/CustomAuthenticationFilter.java +++ b/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/SimpleAuthenticationFilter.java @@ -1,4 +1,4 @@ -package com.baeldung.securityextrafields; +package com.baeldung.loginextrafieldssimple; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -9,7 +9,7 @@ import org.springframework.security.core.Authentication; import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; -public class CustomAuthenticationFilter extends UsernamePasswordAuthenticationFilter { +public class SimpleAuthenticationFilter extends UsernamePasswordAuthenticationFilter { public static final String SPRING_SECURITY_FORM_DOMAIN_KEY = "domain"; diff --git a/spring-5-security/src/main/java/com/baeldung/securityextrafields/CustomUserDetailsService.java b/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/SimpleUserDetailsService.java similarity index 82% rename from spring-5-security/src/main/java/com/baeldung/securityextrafields/CustomUserDetailsService.java rename to spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/SimpleUserDetailsService.java index be02834852..2fad50ad01 100644 --- a/spring-5-security/src/main/java/com/baeldung/securityextrafields/CustomUserDetailsService.java +++ b/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/SimpleUserDetailsService.java @@ -1,4 +1,4 @@ -package com.baeldung.securityextrafields; +package com.baeldung.loginextrafieldssimple; import org.apache.commons.lang3.StringUtils; import org.springframework.security.core.userdetails.UserDetails; @@ -7,11 +7,11 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.stereotype.Service; @Service("userDetailsService") -public class CustomUserDetailsService implements UserDetailsService { +public class SimpleUserDetailsService implements UserDetailsService { - private final UserRepository userRepository; + private UserRepository userRepository; - public CustomUserDetailsService(UserRepository userRepository) { + public SimpleUserDetailsService(UserRepository userRepository) { this.userRepository = userRepository; } diff --git a/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/SimpleUserRepository.java b/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/SimpleUserRepository.java new file mode 100644 index 0000000000..e8aaa774a1 --- /dev/null +++ b/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/SimpleUserRepository.java @@ -0,0 +1,26 @@ +package com.baeldung.loginextrafieldssimple; + +import java.util.ArrayList; +import java.util.Collection; + +import org.apache.commons.lang3.StringUtils; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.stereotype.Repository; + +@Repository("userRepository") +public class SimpleUserRepository implements UserRepository { + + @Override + public User findUser(String username, String domain) { + if (StringUtils.isAnyBlank(username, domain)) { + return null; + } else { + Collection authorities = new ArrayList<>(); + User user = new User(username, domain, + "$2a$10$U3GhSMpsMSOE8Kqsbn58/edxDBKlVuYMh7qk/7ErApYFjJzi2VG5K", true, + true, true, true, authorities); + return user; + } + } + +} diff --git a/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/User.java b/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/User.java new file mode 100644 index 0000000000..b76da65638 --- /dev/null +++ b/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/User.java @@ -0,0 +1,21 @@ +package com.baeldung.loginextrafieldssimple; + +import java.util.Collection; + +import org.springframework.security.core.GrantedAuthority; + +public class User extends org.springframework.security.core.userdetails.User { + + private String domain; + + public User(String username, String domain, String password, boolean enabled, + boolean accountNonExpired, boolean credentialsNonExpired, + boolean accountNonLocked, Collection authorities) { + super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities); + this.domain = domain; + } + + public String getDomain() { + return domain; + } +} diff --git a/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/UserRepository.java b/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/UserRepository.java new file mode 100644 index 0000000000..919e611b9c --- /dev/null +++ b/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/UserRepository.java @@ -0,0 +1,7 @@ +package com.baeldung.loginextrafieldssimple; + +public interface UserRepository { + + public User findUser(String username, String domain); + +} diff --git a/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/WebController.java b/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/WebController.java new file mode 100644 index 0000000000..1b17de7bec --- /dev/null +++ b/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/WebController.java @@ -0,0 +1,51 @@ +package com.baeldung.loginextrafieldssimple; + +import java.util.Optional; + +import org.springframework.security.authentication.AnonymousAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestMapping; + +@Controller +public class WebController { + + @RequestMapping("/") + public String root() { + return "redirect:/index"; + } + + @RequestMapping("/index") + public String index(Model model) { + getDomain().ifPresent(d -> { + model.addAttribute("domain", d); + }); + return "index"; + } + + @RequestMapping("/user/index") + public String userIndex(Model model) { + getDomain().ifPresent(d -> { + model.addAttribute("domain", d); + }); + return "user/index"; + } + + @RequestMapping("/login") + public String login() { + return "login"; + } + + private Optional getDomain() { + Authentication auth = SecurityContextHolder.getContext() + .getAuthentication(); + String domain = null; + if (auth != null && !auth.getClass().equals(AnonymousAuthenticationToken.class)) { + User user = (User) auth.getPrincipal(); + domain = user.getDomain(); + } + return Optional.ofNullable(domain); + } +} diff --git a/spring-5-security/src/main/resources/static/css/main.css b/spring-5-security/src/main/resources/static/css/main.css index 9299ee6158..febc353af7 100644 --- a/spring-5-security/src/main/resources/static/css/main.css +++ b/spring-5-security/src/main/resources/static/css/main.css @@ -1,18 +1,8 @@ -body { - font-family: sans; - font-size: 1em; -} - p.error { font-weight: bold; color: red; } div.logout { - float: right; + margin-right: 2em;; } - -.formfield { - margin: 0.5em; - padding: 0.3em; -} \ No newline at end of file diff --git a/spring-5-security/src/main/resources/templatesextrafields/index.html b/spring-5-security/src/main/resources/templatesextrafields/index.html index 52f6224dfb..37833ff0d2 100644 --- a/spring-5-security/src/main/resources/templatesextrafields/index.html +++ b/spring-5-security/src/main/resources/templatesextrafields/index.html @@ -1,24 +1,32 @@ - + - Spring Security - Login With Extra Fields + Spring Security with Extra Fields + + + + + -
- Logged in user: | - domain: Some Domain +
+
+

Logged in: | Some Domain +

- +
-

Hello Spring Security

+ +

Hello Spring Security

This is an unsecured page, but you can access the secured pages after authenticating.

+
diff --git a/spring-5-security/src/main/resources/templatesextrafields/login.html b/spring-5-security/src/main/resources/templatesextrafields/login.html index cafec89c15..5c51ea3b2c 100644 --- a/spring-5-security/src/main/resources/templatesextrafields/login.html +++ b/spring-5-security/src/main/resources/templatesextrafields/login.html @@ -1,23 +1,36 @@ - - - Login page - - - - -

Login page

+ + + Login page + + + + + + + + + +
+ +

+ + +

+

+ + +

+

+ + +

+

Back to home page

- + +
+ diff --git a/spring-5-security/src/main/resources/templatesextrafields/user/index.html b/spring-5-security/src/main/resources/templatesextrafields/user/index.html index a4c1535100..9c41f0e78c 100644 --- a/spring-5-security/src/main/resources/templatesextrafields/user/index.html +++ b/spring-5-security/src/main/resources/templatesextrafields/user/index.html @@ -1,13 +1,20 @@ - - - Spring Security - Login With Extra Fields - - - - -
-

This is a secured page!

-

Back to home page

- + + + Secured Page + + + + + + + + + +
+
+

This is a secured page!

+

Back to home page

+
+ diff --git a/spring-5-security/src/test/java/com/baeldung/loginextrafields/AbstractExtraLoginFieldsTest.java b/spring-5-security/src/test/java/com/baeldung/loginextrafields/AbstractExtraLoginFieldsTest.java new file mode 100644 index 0000000000..30b869714f --- /dev/null +++ b/spring-5-security/src/test/java/com/baeldung/loginextrafields/AbstractExtraLoginFieldsTest.java @@ -0,0 +1,46 @@ +package com.baeldung.loginextrafields; + +import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrlPattern; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.web.FilterChainProxy; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + +public abstract class AbstractExtraLoginFieldsTest { + + @Autowired + private FilterChainProxy springSecurityFilterChain; + + @Autowired + private WebApplicationContext wac; + + protected MockMvc mockMvc; + + @Before + public void setup() { + this.mockMvc = MockMvcBuilders.webAppContextSetup(wac) + .apply(springSecurity(springSecurityFilterChain)) + .build(); + } + + @Test + public void givenRootPathAccess_thenRedirectToIndex() throws Exception { + this.mockMvc.perform(get("/")) + .andExpect(status().is3xxRedirection()) + .andExpect(redirectedUrlPattern("/index*")); + } + + @Test + public void givenSecuredResource_whenAccessUnauthenticated_thenRequiresAuthentication() throws Exception { + this.mockMvc.perform(get("/user/index")) + .andExpect(status().is3xxRedirection()) + .andExpect(redirectedUrlPattern("**/login")); + } +} diff --git a/spring-5-security/src/test/java/com/baeldung/securityextrafields/SecurityExtraFieldsTest.java b/spring-5-security/src/test/java/com/baeldung/loginextrafields/LoginFieldsFullTest.java similarity index 65% rename from spring-5-security/src/test/java/com/baeldung/securityextrafields/SecurityExtraFieldsTest.java rename to spring-5-security/src/test/java/com/baeldung/loginextrafields/LoginFieldsFullTest.java index cf0701708d..38c219cb5e 100644 --- a/spring-5-security/src/test/java/com/baeldung/securityextrafields/SecurityExtraFieldsTest.java +++ b/spring-5-security/src/test/java/com/baeldung/loginextrafields/LoginFieldsFullTest.java @@ -1,8 +1,7 @@ -package com.baeldung.securityextrafields; +package com.baeldung.loginextrafields; import static org.junit.Assert.assertEquals; import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; -import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrlPattern; @@ -11,57 +10,26 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. import java.util.ArrayList; import java.util.Collection; -import org.junit.Before; 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.mock.web.MockHttpSession; import org.springframework.security.core.Authentication; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.context.SecurityContext; -import org.springframework.security.web.FilterChainProxy; import org.springframework.security.web.context.HttpSessionSecurityContextRepository; import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.web.context.WebApplicationContext; + +import com.baeldung.loginextrafieldscustom.ExtraLoginFieldsApplication; +import com.baeldung.loginextrafieldscustom.User; @RunWith(SpringRunner.class) @SpringJUnitWebConfig -@SpringBootTest(classes = SpringExtraLoginFieldsApplication.class) -public class SecurityExtraFieldsTest { - - @Autowired - private FilterChainProxy springSecurityFilterChain; - - @Autowired - private WebApplicationContext wac; - - private MockMvc mockMvc; - - @Before - public void setup() { - this.mockMvc = MockMvcBuilders.webAppContextSetup(wac) - .apply(springSecurity(springSecurityFilterChain)).build(); - } - - @Test - public void givenRootPathAccess_thenRedirectToIndex() throws Exception { - this.mockMvc.perform(get("/")) - .andExpect(status().is3xxRedirection()) - .andExpect(redirectedUrlPattern("/index*")); - } - - @Test - public void givenSecuredResource_whenAccessUnauthenticated_thenRequiresAuthentication() throws Exception { - this.mockMvc.perform(get("/user/index")) - .andExpect(status().is3xxRedirection()) - .andExpect(redirectedUrlPattern("**/login")); - } +@SpringBootTest(classes = ExtraLoginFieldsApplication.class) +public class LoginFieldsFullTest extends AbstractExtraLoginFieldsTest { @Test public void givenAccessSecuredResource_whenAuthenticated_thenAuthHasExtraFields() throws Exception { @@ -100,4 +68,5 @@ public class SecurityExtraFieldsTest { Collection authorities = new ArrayList<>(); return new User("myusername", "mydomain", "password", true, true, true, true, authorities); } + } diff --git a/spring-5-security/src/test/java/com/baeldung/loginextrafields/LoginFieldsSimpleTest.java b/spring-5-security/src/test/java/com/baeldung/loginextrafields/LoginFieldsSimpleTest.java new file mode 100644 index 0000000000..5c0d462772 --- /dev/null +++ b/spring-5-security/src/test/java/com/baeldung/loginextrafields/LoginFieldsSimpleTest.java @@ -0,0 +1,72 @@ +package com.baeldung.loginextrafields; + +import static org.junit.Assert.assertEquals; +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrlPattern; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import java.util.ArrayList; +import java.util.Collection; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.mock.web.MockHttpSession; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.context.SecurityContext; +import org.springframework.security.web.context.HttpSessionSecurityContextRepository; +import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MvcResult; +import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; + +import com.baeldung.loginextrafieldssimple.ExtraLoginFieldsApplication; +import com.baeldung.loginextrafieldssimple.User; + +@RunWith(SpringRunner.class) +@SpringJUnitWebConfig +@SpringBootTest(classes = ExtraLoginFieldsApplication.class) +public class LoginFieldsSimpleTest extends AbstractExtraLoginFieldsTest { + + @Test + public void givenAccessSecuredResource_whenAuthenticated_thenAuthHasExtraFields() throws Exception { + MockHttpServletRequestBuilder securedResourceAccess = get("/user/index"); + MvcResult unauthenticatedResult = mockMvc.perform(securedResourceAccess) + .andExpect(status().is3xxRedirection()) + .andReturn(); + + MockHttpSession session = (MockHttpSession) unauthenticatedResult.getRequest() + .getSession(); + String loginUrl = unauthenticatedResult.getResponse() + .getRedirectedUrl(); + + User user = getUser(); + + mockMvc.perform(post(loginUrl) + .param("username", user.getUsername()) + .param("password", user.getPassword()) + .param("domain", user.getDomain()) + .session(session) + .with(csrf())) + .andExpect(status().is3xxRedirection()) + .andExpect(redirectedUrlPattern("**/user/index")) + .andReturn(); + + mockMvc.perform(securedResourceAccess.session(session)) + .andExpect(status().isOk()); + + SecurityContext securityContext + = (SecurityContext) session.getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY); + Authentication auth = securityContext.getAuthentication(); + assertEquals(((User)auth.getPrincipal()).getDomain(), user.getDomain()); + } + + private User getUser() { + Collection authorities = new ArrayList<>(); + return new User("myusername", "mydomain", "password", true, true, true, true, authorities); + } + +} From af3edc477d195e444db28cffbdb9c254bfd0e4a3 Mon Sep 17 00:00:00 2001 From: Dassi orleando Date: Tue, 23 Jan 2018 04:43:24 +0100 Subject: [PATCH 57/65] BAEL-1273: Display RSS feed with spring mvc (AbstractRssFeedView) (#3490) * BAEL-1216: improve tests * BAEL-1448: Update Spring 5 articles to use the release version * Setting up the Maven Wrapper on a maven project * Add Maven Wrapper on spring-boot module * simple add * BAEL-976: Update spring version * BAEL-1273: Display RSS feed with spring mvc (AbstractRssFeedView) --- spring-boot/pom.xml | 7 +++ .../com/baeldung/rss/ArticleFeedView.java | 54 +++++++++++++++++++ .../baeldung/rss/ArticleRssController.java | 16 ++++++ .../com/baeldung/rss/CustomContainer.java | 16 ++++++ .../main/java/com/baeldung/rss/RssApp.java | 20 +++++++ 5 files changed, 113 insertions(+) create mode 100644 spring-boot/src/main/java/com/baeldung/rss/ArticleFeedView.java create mode 100644 spring-boot/src/main/java/com/baeldung/rss/ArticleRssController.java create mode 100644 spring-boot/src/main/java/com/baeldung/rss/CustomContainer.java create mode 100644 spring-boot/src/main/java/com/baeldung/rss/RssApp.java diff --git a/spring-boot/pom.xml b/spring-boot/pom.xml index d6ee022522..a557604bf3 100644 --- a/spring-boot/pom.xml +++ b/spring-boot/pom.xml @@ -167,6 +167,12 @@ org.apache.activemq artemis-server + + + com.rometools + rome + ${rome.version} + @@ -276,6 +282,7 @@ 8.5.11 1.4.194 2.4.1.Final + 1.9.0 \ No newline at end of file diff --git a/spring-boot/src/main/java/com/baeldung/rss/ArticleFeedView.java b/spring-boot/src/main/java/com/baeldung/rss/ArticleFeedView.java new file mode 100644 index 0000000000..3efa619409 --- /dev/null +++ b/spring-boot/src/main/java/com/baeldung/rss/ArticleFeedView.java @@ -0,0 +1,54 @@ +package com.baeldung.rss; + +import com.rometools.rome.feed.rss.Channel; +import com.rometools.rome.feed.rss.Description; +import com.rometools.rome.feed.rss.Item; +import org.springframework.stereotype.Service; +import org.springframework.web.servlet.view.feed.AbstractRssFeedView; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Map; + +@Service("articleFeedView") +public class ArticleFeedView extends AbstractRssFeedView { + + protected Channel newFeed() { + Channel channel = new Channel("rss_2.0"); + channel.setLink("http://localhost:8080/rss"); + channel.setTitle("Article Feed"); + channel.setDescription("Article Feed Description"); + channel.setPubDate(new Date()); + return channel; + } + + @Override + protected List buildFeedItems(Map map, HttpServletRequest httpStRequest, HttpServletResponse httpStResponse) throws Exception { + List list = new ArrayList(); + + Item item1 = new Item(); + item1.setLink("http://www.baeldung.com/netty-exception-handling"); + item1.setTitle("Exceptions in Netty"); + Description description1 = new Description(); + description1.setValue("In this quick article, we’ll be looking at exception handling in Netty."); + item1.setDescription(description1); + item1.setPubDate(new Date()); + item1.setAuthor("Carlos"); + + Item item2 = new Item(); + item2.setLink("http://www.baeldung.com/cockroachdb-java"); + item2.setTitle("Guide to CockroachDB in Java"); + Description description2 = new Description(); + description2.setValue("This tutorial is an introductory guide to using CockroachDB with Java."); + item2.setDescription(description2); + item2.setPubDate(new Date()); + item2.setAuthor("Baeldung"); + + list.add(item1); + list.add(item2); + return list; + } +} diff --git a/spring-boot/src/main/java/com/baeldung/rss/ArticleRssController.java b/spring-boot/src/main/java/com/baeldung/rss/ArticleRssController.java new file mode 100644 index 0000000000..a3fbc4a37e --- /dev/null +++ b/spring-boot/src/main/java/com/baeldung/rss/ArticleRssController.java @@ -0,0 +1,16 @@ +package com.baeldung.rss; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +@Controller +@RequestMapping(value = "/rss", produces = "application/*") +public class ArticleRssController { + + @RequestMapping(method = RequestMethod.GET) + public String articleFeed() { + return "articleFeedView"; + } + +} diff --git a/spring-boot/src/main/java/com/baeldung/rss/CustomContainer.java b/spring-boot/src/main/java/com/baeldung/rss/CustomContainer.java new file mode 100644 index 0000000000..ee36ecdc51 --- /dev/null +++ b/spring-boot/src/main/java/com/baeldung/rss/CustomContainer.java @@ -0,0 +1,16 @@ +package com.baeldung.rss; + +import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer; +import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; +import org.springframework.stereotype.Component; + +@Component +public class CustomContainer implements EmbeddedServletContainerCustomizer { + + @Override + public void customize(ConfigurableEmbeddedServletContainer container) { + container.setPort(8080); + container.setContextPath(""); + } + +} \ No newline at end of file diff --git a/spring-boot/src/main/java/com/baeldung/rss/RssApp.java b/spring-boot/src/main/java/com/baeldung/rss/RssApp.java new file mode 100644 index 0000000000..2add7ed421 --- /dev/null +++ b/spring-boot/src/main/java/com/baeldung/rss/RssApp.java @@ -0,0 +1,20 @@ +package com.baeldung.rss; + +import com.baeldung.autoconfiguration.MySQLAutoconfiguration; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; + +import javax.annotation.security.RolesAllowed; + +@SpringBootApplication(exclude = MySQLAutoconfiguration.class) +@ComponentScan(basePackages = "com.baeldung.rss") +public class RssApp { + + @RolesAllowed("*") + public static void main(String[] args) { + System.setProperty("security.basic.enabled", "false"); + SpringApplication.run(RssApp.class, args); + } + +} From 9f1429b067ccbc26204d950e8baa1e653f8f7fdb Mon Sep 17 00:00:00 2001 From: christopherfranklin Date: Tue, 23 Jan 2018 12:29:31 -0500 Subject: [PATCH 58/65] BAEL-1324 A Simple Tagging Implementation with Elasticsearch (#3464) * Christopher Franklin A Simple Tagging Implementation with Elasticsearch Modifying the existing Spring Data Elasticsearch example to use the tags already on the model. Also added a number of tests as examples of how to use the tags. --- .../data/es/repository/ArticleRepository.java | 9 +++++++- .../data/es/service/ArticleService.java | 7 +++++- .../data/es/service/ArticleServiceImpl.java | 15 +++++++++++-- .../data/es/ElasticSearchIntegrationTest.java | 22 +++++++++++++++++-- .../es/ElasticSearchQueryIntegrationTest.java | 12 ++++++++++ 5 files changed, 59 insertions(+), 6 deletions(-) diff --git a/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/repository/ArticleRepository.java b/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/repository/ArticleRepository.java index 8aef865401..93812a3cea 100644 --- a/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/repository/ArticleRepository.java +++ b/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/repository/ArticleRepository.java @@ -1,12 +1,13 @@ package com.baeldung.spring.data.es.repository; -import com.baeldung.spring.data.es.model.Article; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.elasticsearch.annotations.Query; import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; import org.springframework.stereotype.Repository; +import com.baeldung.spring.data.es.model.Article; + @Repository public interface ArticleRepository extends ElasticsearchRepository { @@ -14,4 +15,10 @@ public interface ArticleRepository extends ElasticsearchRepository findByAuthorsNameUsingCustomQuery(String name, Pageable pageable); + + @Query("{\"bool\": {\"must\": {\"match_all\": {}}, \"filter\": {\"term\": {\"tags\": \"?0\" }}}}") + Page
findByFilteredTagQuery(String tag, Pageable pageable); + + @Query("{\"bool\": {\"must\": {\"match\": {\"authors.name\": \"?0\"}}, \"filter\": {\"term\": {\"tags\": \"?1\" }}}}") + Page
findByAuthorsNameAndFilteredTagQuery(String name, String tag, Pageable pageable); } diff --git a/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/service/ArticleService.java b/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/service/ArticleService.java index b5a8fde633..63e2d91fa7 100644 --- a/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/service/ArticleService.java +++ b/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/service/ArticleService.java @@ -1,9 +1,10 @@ package com.baeldung.spring.data.es.service; -import com.baeldung.spring.data.es.model.Article; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; +import com.baeldung.spring.data.es.model.Article; + public interface ArticleService { Article save(Article article); @@ -15,6 +16,10 @@ public interface ArticleService { Page
findByAuthorNameUsingCustomQuery(String name, Pageable pageable); + Page
findByFilteredTagQuery(String tag, Pageable pageable); + + Page
findByAuthorsNameAndFilteredTagQuery(String name, String tag, Pageable pageable); + long count(); void delete(Article article); diff --git a/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/service/ArticleServiceImpl.java b/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/service/ArticleServiceImpl.java index 2a31b52602..0908ffa70e 100644 --- a/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/service/ArticleServiceImpl.java +++ b/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/service/ArticleServiceImpl.java @@ -1,12 +1,13 @@ package com.baeldung.spring.data.es.service; -import com.baeldung.spring.data.es.repository.ArticleRepository; -import com.baeldung.spring.data.es.model.Article; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; +import com.baeldung.spring.data.es.model.Article; +import com.baeldung.spring.data.es.repository.ArticleRepository; + @Service public class ArticleServiceImpl implements ArticleService { @@ -42,6 +43,16 @@ public class ArticleServiceImpl implements ArticleService { return articleRepository.findByAuthorsNameUsingCustomQuery(name, pageable); } + @Override + public Page
findByFilteredTagQuery(String tag, Pageable pageable) { + return articleRepository.findByFilteredTagQuery(tag, pageable); + } + + @Override + public Page
findByAuthorsNameAndFilteredTagQuery(String name, String tag, Pageable pageable) { + return articleRepository.findByAuthorsNameAndFilteredTagQuery(name, tag, pageable); + } + @Override public long count() { return articleRepository.count(); diff --git a/spring-data-elasticsearch/src/test/java/com/baeldung/spring/data/es/ElasticSearchIntegrationTest.java b/spring-data-elasticsearch/src/test/java/com/baeldung/spring/data/es/ElasticSearchIntegrationTest.java index be31de724d..41965fbb83 100644 --- a/spring-data-elasticsearch/src/test/java/com/baeldung/spring/data/es/ElasticSearchIntegrationTest.java +++ b/spring-data-elasticsearch/src/test/java/com/baeldung/spring/data/es/ElasticSearchIntegrationTest.java @@ -46,14 +46,22 @@ public class ElasticSearchIntegrationTest { Article article = new Article("Spring Data Elasticsearch"); article.setAuthors(asList(johnSmith, johnDoe)); + article.setTags("elasticsearch", "spring data"); articleService.save(article); article = new Article("Search engines"); article.setAuthors(asList(johnDoe)); + article.setTags("search engines", "tutorial"); articleService.save(article); article = new Article("Second Article About Elasticsearch"); article.setAuthors(asList(johnSmith)); + article.setTags("elasticsearch", "spring data"); + articleService.save(article); + + article = new Article("Elasticsearch Tutorial"); + article.setAuthors(asList(johnDoe)); + article.setTags("elasticsearch"); articleService.save(article); } @@ -78,12 +86,22 @@ public class ElasticSearchIntegrationTest { @Test public void givenCustomQuery_whenSearchByAuthorsName_thenArticleIsFound() { + final Page
articleByAuthorName = articleService.findByAuthorNameUsingCustomQuery("Smith", new PageRequest(0, 10)); + assertEquals(2L, articleByAuthorName.getTotalElements()); + } - final Page
articleByAuthorName = articleService - .findByAuthorNameUsingCustomQuery("John Smith", new PageRequest(0, 10)); + @Test + public void givenTagFilterQuery_whenSearchByTag_thenArticleIsFound() { + final Page
articleByAuthorName = articleService.findByFilteredTagQuery("elasticsearch", new PageRequest(0, 10)); assertEquals(3L, articleByAuthorName.getTotalElements()); } + @Test + public void givenTagFilterQuery_whenSearchByAuthorsName_thenArticleIsFound() { + final Page
articleByAuthorName = articleService.findByAuthorsNameAndFilteredTagQuery("Doe", "elasticsearch", new PageRequest(0, 10)); + assertEquals(2L, articleByAuthorName.getTotalElements()); + } + @Test public void givenPersistedArticles_whenUseRegexQuery_thenRightArticlesFound() { diff --git a/spring-data-elasticsearch/src/test/java/com/baeldung/spring/data/es/ElasticSearchQueryIntegrationTest.java b/spring-data-elasticsearch/src/test/java/com/baeldung/spring/data/es/ElasticSearchQueryIntegrationTest.java index 7a9ac2de06..c6af93bb62 100644 --- a/spring-data-elasticsearch/src/test/java/com/baeldung/spring/data/es/ElasticSearchQueryIntegrationTest.java +++ b/spring-data-elasticsearch/src/test/java/com/baeldung/spring/data/es/ElasticSearchQueryIntegrationTest.java @@ -191,4 +191,16 @@ public class ElasticSearchQueryIntegrationTest { final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); assertEquals(2, articles.size()); } + + @Test + public void givenBoolQuery_whenQueryByAuthorsName_thenFoundArticlesByThatAuthorAndFilteredTag() { + final QueryBuilder builder = boolQuery().must(nestedQuery("authors", boolQuery().must(termQuery("authors.name", "doe")))) + .filter(termQuery("tags", "elasticsearch")); + + final SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(builder) + .build(); + final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); + + assertEquals(2, articles.size()); + } } From 689083a090caf9095d886b21e42f6f1e803614cf Mon Sep 17 00:00:00 2001 From: KevinGilmore Date: Wed, 24 Jan 2018 08:12:03 -0600 Subject: [PATCH 59/65] BAEL-1148 README (#3505) * BAEL-973: updated README * BAEL-1069: Updated README * BAEL-817: add README file * BAEL-1084: README update * BAEL-960: Update README * BAEL-1155: updated README * BAEL-1041: updated README * BAEL-973: Updated README * BAEL-1187: updated README * BAEL-1183: Update README * BAEL-1133: Updated README * BAEL-1098: README update * BAEL-719: add README.md * BAEL-1272: README update * BAEL-1272: README update * BAEL-1196: Update README * BAEL-1328: Updated README * BAEL-1371: Update README.md * BAEL-1371: Update README.md * BAEL-1278: Update README * BAEL-1326: Update README * BAEL-399: Update README * BAEL-1297: Update README * BAEL-1218: README * BAEL-1148 README update --- spring-mvc-simple/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-mvc-simple/README.md b/spring-mvc-simple/README.md index 197a22cbac..69a9027280 100644 --- a/spring-mvc-simple/README.md +++ b/spring-mvc-simple/README.md @@ -2,3 +2,4 @@ - [HandlerAdapters in Spring MVC](http://www.baeldung.com/spring-mvc-handler-adapters) - [Template Engines for Spring](http://www.baeldung.com/spring-template-engines) +- [Spring 5 and Servlet 4 – The PushBuilder](http://www.baeldung.com/spring-5-push) From 0585764866cc01bba4adb07a0c91d16d6038116b Mon Sep 17 00:00:00 2001 From: Ahmad Alsanie Date: Wed, 24 Jan 2018 19:29:14 +0200 Subject: [PATCH 60/65] BAEL-1473 replaced int with AtomicInteger for safe usage in multi-threaded env (#3497) * BAEL-1473 Intoduction to Spliterator in Java * BAEL-1473 - Replace .out with logger.info * removed log * BAEL-1473 - added test-cases * modify test-cases * AtomicInteger instead of int * SIZED removed --- .../RelatedAuthorSpliterator.java | 70 ++++++++++--------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/core-java-8/src/main/java/com/baeldung/spliteratorAPI/RelatedAuthorSpliterator.java b/core-java-8/src/main/java/com/baeldung/spliteratorAPI/RelatedAuthorSpliterator.java index ae91c6fe6c..0a7190964e 100644 --- a/core-java-8/src/main/java/com/baeldung/spliteratorAPI/RelatedAuthorSpliterator.java +++ b/core-java-8/src/main/java/com/baeldung/spliteratorAPI/RelatedAuthorSpliterator.java @@ -2,46 +2,48 @@ package com.baeldung.spliteratorAPI; import java.util.List; import java.util.Spliterator; +import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; public class RelatedAuthorSpliterator implements Spliterator { - private final List list; - private int current = 0; + private final List list; + AtomicInteger current = new AtomicInteger(); - public RelatedAuthorSpliterator(List list) { - this.list = list; - } + public RelatedAuthorSpliterator(List list) { + this.list = list; + } - @Override - public boolean tryAdvance(Consumer action) { - action.accept(list.get(current++)); - return current < list.size(); - } + @Override + public boolean tryAdvance(Consumer action) { - @Override - public Spliterator trySplit() { - int currentSize = list.size() - current; - if (currentSize < 10) { - return null; - } - for (int splitPos = currentSize / 2 + current; splitPos < list.size(); splitPos++) { - if (list.get(splitPos) - .getRelatedArticleId() == 0) { - Spliterator spliterator = new RelatedAuthorSpliterator(list.subList(current, splitPos)); - current = splitPos; - return spliterator; - } - } - return null; - } + action.accept(list.get(current.getAndIncrement())); + return current.get() < list.size(); + } - @Override - public long estimateSize() { - return list.size() - current; - } + @Override + public Spliterator trySplit() { + int currentSize = list.size() - current.get(); + if (currentSize < 10) { + return null; + } + for (int splitPos = currentSize / 2 + current.intValue(); splitPos < list.size(); splitPos++) { + if (list.get(splitPos).getRelatedArticleId() == 0) { + Spliterator spliterator = new RelatedAuthorSpliterator(list.subList(current.get(), splitPos)); + current.set(splitPos); + return spliterator; + } + } + return null; + } + + @Override + public long estimateSize() { + return list.size() - current.get(); + } + + @Override + public int characteristics() { + return CONCURRENT; + } - @Override - public int characteristics() { - return SIZED + CONCURRENT; - } } From 70e4a552568f1041667cc1c2276ef07ee26ad9c2 Mon Sep 17 00:00:00 2001 From: Eugen Paraschiv Date: Thu, 25 Jan 2018 11:33:50 +0200 Subject: [PATCH 61/65] minor import cleanup --- .../java/com/baeldung/utils/controller/UtilsController.java | 1 - .../main/java/com/baeldung/webjar/WebjarsdemoApplication.java | 1 - .../org/baeldung/boot/converter/GenericBigDecimalConverter.java | 1 - .../controller/StringToEmployeeConverterController.java | 1 - .../src/main/java/org/baeldung/main/SpringBootApplication.java | 1 - .../test/java/org/baeldung/SpringBootMailIntegrationTest.java | 2 -- 6 files changed, 7 deletions(-) diff --git a/spring-boot/src/main/java/com/baeldung/utils/controller/UtilsController.java b/spring-boot/src/main/java/com/baeldung/utils/controller/UtilsController.java index 7c66391bd2..8c7f2f932a 100644 --- a/spring-boot/src/main/java/com/baeldung/utils/controller/UtilsController.java +++ b/spring-boot/src/main/java/com/baeldung/utils/controller/UtilsController.java @@ -4,7 +4,6 @@ import javax.servlet.http.HttpServletRequest; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; -import org.springframework.web.bind.ServletRequestBindingException; import org.springframework.web.bind.ServletRequestUtils; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; diff --git a/spring-boot/src/main/java/com/baeldung/webjar/WebjarsdemoApplication.java b/spring-boot/src/main/java/com/baeldung/webjar/WebjarsdemoApplication.java index 8704b42166..5038c7e5f7 100644 --- a/spring-boot/src/main/java/com/baeldung/webjar/WebjarsdemoApplication.java +++ b/spring-boot/src/main/java/com/baeldung/webjar/WebjarsdemoApplication.java @@ -2,7 +2,6 @@ package com.baeldung.webjar; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.ComponentScan; import com.baeldung.autoconfiguration.MySQLAutoconfiguration; diff --git a/spring-boot/src/main/java/org/baeldung/boot/converter/GenericBigDecimalConverter.java b/spring-boot/src/main/java/org/baeldung/boot/converter/GenericBigDecimalConverter.java index decd8ac5db..7bcbfee45b 100644 --- a/spring-boot/src/main/java/org/baeldung/boot/converter/GenericBigDecimalConverter.java +++ b/spring-boot/src/main/java/org/baeldung/boot/converter/GenericBigDecimalConverter.java @@ -5,7 +5,6 @@ import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.converter.GenericConverter; import java.math.BigDecimal; -import java.math.MathContext; import java.util.Set; public class GenericBigDecimalConverter implements GenericConverter { diff --git a/spring-boot/src/main/java/org/baeldung/boot/converter/controller/StringToEmployeeConverterController.java b/spring-boot/src/main/java/org/baeldung/boot/converter/controller/StringToEmployeeConverterController.java index ad921c2c43..a6e0400845 100644 --- a/spring-boot/src/main/java/org/baeldung/boot/converter/controller/StringToEmployeeConverterController.java +++ b/spring-boot/src/main/java/org/baeldung/boot/converter/controller/StringToEmployeeConverterController.java @@ -1,7 +1,6 @@ package org.baeldung.boot.converter.controller; import com.baeldung.toggle.Employee; -import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; diff --git a/spring-boot/src/main/java/org/baeldung/main/SpringBootApplication.java b/spring-boot/src/main/java/org/baeldung/main/SpringBootApplication.java index 0ab4ecb128..f9bdb67a10 100644 --- a/spring-boot/src/main/java/org/baeldung/main/SpringBootApplication.java +++ b/spring-boot/src/main/java/org/baeldung/main/SpringBootApplication.java @@ -11,7 +11,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; -import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; diff --git a/spring-boot/src/test/java/org/baeldung/SpringBootMailIntegrationTest.java b/spring-boot/src/test/java/org/baeldung/SpringBootMailIntegrationTest.java index 17e7d2d9e0..5dd6ab8e17 100644 --- a/spring-boot/src/test/java/org/baeldung/SpringBootMailIntegrationTest.java +++ b/spring-boot/src/test/java/org/baeldung/SpringBootMailIntegrationTest.java @@ -10,8 +10,6 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.mail.SimpleMailMessage; import org.springframework.mail.javamail.JavaMailSender; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; -import org.springframework.web.context.WebApplicationContext; import org.subethamail.wiser.Wiser; import org.subethamail.wiser.WiserMessage; From 19e8849361c52cb57793df924d7c419b56eb123e Mon Sep 17 00:00:00 2001 From: gautamshetty Date: Thu, 25 Jan 2018 04:16:39 -0600 Subject: [PATCH 62/65] [BAEL 1209] - Java RMI Files. (#3374) * [BAEL 1209] - Java RMI Files. * Added parent tag and deleted dependency tag for junit. * Added java-rmi module. * Removed duplicate java-lite module entry. * Deleting this file as it is covered in test class. * Spell check. --- java-rmi/pom.xml | 20 +++++++++ .../main/java/com/baeldung/rmi/Message.java | 36 +++++++++++++++ .../com/baeldung/rmi/MessengerService.java | 11 +++++ .../baeldung/rmi/MessengerServiceImpl.java | 37 ++++++++++++++++ .../baeldung/rmi/JavaRMIIntegrationTest.java | 44 +++++++++++++++++++ pom.xml | 5 ++- 6 files changed, 151 insertions(+), 2 deletions(-) create mode 100644 java-rmi/pom.xml create mode 100644 java-rmi/src/main/java/com/baeldung/rmi/Message.java create mode 100644 java-rmi/src/main/java/com/baeldung/rmi/MessengerService.java create mode 100644 java-rmi/src/main/java/com/baeldung/rmi/MessengerServiceImpl.java create mode 100644 java-rmi/src/test/java/com/baeldung/rmi/JavaRMIIntegrationTest.java diff --git a/java-rmi/pom.xml b/java-rmi/pom.xml new file mode 100644 index 0000000000..7c08968cbf --- /dev/null +++ b/java-rmi/pom.xml @@ -0,0 +1,20 @@ + + 4.0.0 + + com.baeldung.rmi + java-rmi + 1.0-SNAPSHOT + jar + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + + UTF-8 + + + diff --git a/java-rmi/src/main/java/com/baeldung/rmi/Message.java b/java-rmi/src/main/java/com/baeldung/rmi/Message.java new file mode 100644 index 0000000000..6d21a45fe3 --- /dev/null +++ b/java-rmi/src/main/java/com/baeldung/rmi/Message.java @@ -0,0 +1,36 @@ +package com.baeldung.rmi; + +import java.io.Serializable; + +public class Message implements Serializable { + + private String messageText; + + private String contentType; + + public Message() { + } + + public Message(String messageText, String contentType) { + + this.messageText = messageText; + this.contentType = contentType; + } + + public String getMessageText() { + return messageText; + } + + public void setMessageText(String messageText) { + this.messageText = messageText; + } + + public String getContentType() { + return contentType; + } + + public void setContentType(String contentType) { + this.contentType = contentType; + } + +} diff --git a/java-rmi/src/main/java/com/baeldung/rmi/MessengerService.java b/java-rmi/src/main/java/com/baeldung/rmi/MessengerService.java new file mode 100644 index 0000000000..f962e4ad07 --- /dev/null +++ b/java-rmi/src/main/java/com/baeldung/rmi/MessengerService.java @@ -0,0 +1,11 @@ +package com.baeldung.rmi; + +import java.rmi.Remote; +import java.rmi.RemoteException; + +public interface MessengerService extends Remote { + + public String sendMessage(String clientMessage) throws RemoteException; + + public Message sendMessage(Message clientMessage) throws RemoteException; +} \ No newline at end of file diff --git a/java-rmi/src/main/java/com/baeldung/rmi/MessengerServiceImpl.java b/java-rmi/src/main/java/com/baeldung/rmi/MessengerServiceImpl.java new file mode 100644 index 0000000000..ebf03d4b67 --- /dev/null +++ b/java-rmi/src/main/java/com/baeldung/rmi/MessengerServiceImpl.java @@ -0,0 +1,37 @@ +package com.baeldung.rmi; + +import java.rmi.RemoteException; +import java.rmi.registry.LocateRegistry; +import java.rmi.registry.Registry; +import java.rmi.server.UnicastRemoteObject; + +public class MessengerServiceImpl implements MessengerService { + + public String sendMessage(String clientMessage) { + + String serverMessage = null; + if (clientMessage.equals("Client Message")) { + serverMessage = "Server Message"; + } + + return serverMessage; + } + + public void createStubAndBind() throws RemoteException { + + MessengerService stub = (MessengerService) UnicastRemoteObject.exportObject((MessengerService) this, 0); + Registry registry = LocateRegistry.createRegistry(1099); + registry.rebind("MessengerService", stub); + } + + public Message sendMessage(Message clientMessage) throws RemoteException { + + Message serverMessage = null; + if (clientMessage.getMessageText().equals("Client Message")) { + serverMessage = new Message("Server Message", "text/plain"); + } + + return serverMessage; + } + +} \ No newline at end of file diff --git a/java-rmi/src/test/java/com/baeldung/rmi/JavaRMIIntegrationTest.java b/java-rmi/src/test/java/com/baeldung/rmi/JavaRMIIntegrationTest.java new file mode 100644 index 0000000000..66bfbe49eb --- /dev/null +++ b/java-rmi/src/test/java/com/baeldung/rmi/JavaRMIIntegrationTest.java @@ -0,0 +1,44 @@ +package com.baeldung.rmi; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import java.rmi.NotBoundException; +import java.rmi.RemoteException; +import java.rmi.registry.LocateRegistry; +import java.rmi.registry.Registry; + +import org.junit.BeforeClass; +import org.junit.Test; + +public class JavaRMIIntegrationTest { + + @BeforeClass + public static void whenRunServer_thenServerStarts() { + + try { + MessengerServiceImpl server = new MessengerServiceImpl(); + server.createStubAndBind(); + } catch (RemoteException e) { + fail("Exception Occurred"); + } + } + + @Test + public void whenClientSendsMessageToServer_thenServerSendsResponseMessage() { + + try { + Registry registry = LocateRegistry.getRegistry(); + MessengerService server = (MessengerService) registry.lookup("MessengerService"); + String responseMessage = server.sendMessage("Client Message"); + + String expectedMessage = "Server Message"; + assertEquals(responseMessage, expectedMessage); + } catch (RemoteException e) { + fail("Exception Occurred"); + } catch (NotBoundException nb) { + fail("Exception Occurred"); + } + } + +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 6321b0333e..4a25459fcb 100644 --- a/pom.xml +++ b/pom.xml @@ -87,8 +87,9 @@ jackson vavr - java-lite - java-vavr-stream + java-lite + java-rmi + java-vavr-stream javax-servlets javaxval jaxb From 211c8a0c30b88c7f5411cae976e3762eb135eaea Mon Sep 17 00:00:00 2001 From: Tom Hombergs Date: Thu, 25 Jan 2018 22:06:00 +0100 Subject: [PATCH 63/65] added link to finalize article --- core-java/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java/README.md b/core-java/README.md index 6a4a87de0c..ed60db855c 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -126,3 +126,4 @@ - [A Guide to Inner Interfaces in Java](http://www.baeldung.com/java-inner-interfaces) - [Polymorphism in Java](http://www.baeldung.com/java-polymorphism) - [Recursion In Java](http://www.baeldung.com/java-recursion) +- [A Guide to the finalize Method in Java](http://www.baeldung.com/java-finalize) From 5d6c47789e359f63cf5c5faddea77ce0e9ce9273 Mon Sep 17 00:00:00 2001 From: ramansahasi Date: Fri, 26 Jan 2018 23:34:38 +0530 Subject: [PATCH 64/65] Logged InterruptedException instead of ignoring it (#3517) --- .../concurrent/waitandnotify/Data.java | 10 ++- .../concurrent/waitandnotify/Receiver.java | 4 +- .../concurrent/waitandnotify/Sender.java | 14 ++-- .../waitandnotify/NetworkIntegrationTest.java | 78 +++++++++---------- 4 files changed, 58 insertions(+), 48 deletions(-) diff --git a/core-java-concurrency/src/main/java/com/baeldung/concurrent/waitandnotify/Data.java b/core-java-concurrency/src/main/java/com/baeldung/concurrent/waitandnotify/Data.java index 9b850c4153..d9e7434e0c 100644 --- a/core-java-concurrency/src/main/java/com/baeldung/concurrent/waitandnotify/Data.java +++ b/core-java-concurrency/src/main/java/com/baeldung/concurrent/waitandnotify/Data.java @@ -1,5 +1,7 @@ package com.baeldung.concurrent.waitandnotify; +import org.slf4j.Logger; + public class Data { private String packet; @@ -11,7 +13,9 @@ public class Data { while (transfer) { try { wait(); - } catch (InterruptedException e) {} + } catch (InterruptedException e) { + System.out.println("Thread Interrupted"); + } } transfer = true; @@ -23,7 +27,9 @@ public class Data { while (!transfer) { try { wait(); - } catch (InterruptedException e) {} + } catch (InterruptedException e) { + System.out.println("Thread Interrupted"); + } } transfer = false; diff --git a/core-java-concurrency/src/main/java/com/baeldung/concurrent/waitandnotify/Receiver.java b/core-java-concurrency/src/main/java/com/baeldung/concurrent/waitandnotify/Receiver.java index 63f48b8031..724e908a99 100644 --- a/core-java-concurrency/src/main/java/com/baeldung/concurrent/waitandnotify/Receiver.java +++ b/core-java-concurrency/src/main/java/com/baeldung/concurrent/waitandnotify/Receiver.java @@ -19,7 +19,9 @@ public class Receiver implements Runnable { //Thread.sleep() to mimic heavy server-side processing try { Thread.sleep(ThreadLocalRandom.current().nextInt(1000, 5000)); - } catch (InterruptedException e) {} + } catch (InterruptedException e) { + System.out.println("Thread Interrupted"); + } } } } \ No newline at end of file diff --git a/core-java-concurrency/src/main/java/com/baeldung/concurrent/waitandnotify/Sender.java b/core-java-concurrency/src/main/java/com/baeldung/concurrent/waitandnotify/Sender.java index b7d782c3f5..b4945b7b73 100644 --- a/core-java-concurrency/src/main/java/com/baeldung/concurrent/waitandnotify/Sender.java +++ b/core-java-concurrency/src/main/java/com/baeldung/concurrent/waitandnotify/Sender.java @@ -11,11 +11,11 @@ public class Sender implements Runnable { public void run() { String packets[] = { - "First packet", - "Second packet", - "Third packet", - "Fourth packet", - "End" + "First packet", + "Second packet", + "Third packet", + "Fourth packet", + "End" }; for (String packet : packets) { @@ -24,7 +24,9 @@ public class Sender implements Runnable { //Thread.sleep() to mimic heavy server-side processing try { Thread.sleep(ThreadLocalRandom.current().nextInt(1000, 5000)); - } catch (InterruptedException e) {} + } catch (InterruptedException e) { + System.out.println("Thread Interrupted"); + } } } } \ No newline at end of file diff --git a/core-java-concurrency/src/test/java/com/baeldung/concurrent/waitandnotify/NetworkIntegrationTest.java b/core-java-concurrency/src/test/java/com/baeldung/concurrent/waitandnotify/NetworkIntegrationTest.java index 49f4313e9d..8ecc92236e 100644 --- a/core-java-concurrency/src/test/java/com/baeldung/concurrent/waitandnotify/NetworkIntegrationTest.java +++ b/core-java-concurrency/src/test/java/com/baeldung/concurrent/waitandnotify/NetworkIntegrationTest.java @@ -13,38 +13,38 @@ import org.junit.Test; public class NetworkIntegrationTest { - private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); - private final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); - private String expected; - - @Before - public void setUpStreams() { - System.setOut(new PrintStream(outContent)); - System.setErr(new PrintStream(errContent)); - } - - @Before - public void setUpExpectedOutput() { - StringWriter expectedStringWriter = new StringWriter(); - - PrintWriter printWriter = new PrintWriter(expectedStringWriter); - printWriter.println("First packet"); - printWriter.println("Second packet"); - printWriter.println("Third packet"); - printWriter.println("Fourth packet"); - printWriter.close(); - - expected = expectedStringWriter.toString(); - } + private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); + private final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); + private String expected; + + @Before + public void setUpStreams() { + System.setOut(new PrintStream(outContent)); + System.setErr(new PrintStream(errContent)); + } + + @Before + public void setUpExpectedOutput() { + StringWriter expectedStringWriter = new StringWriter(); + + PrintWriter printWriter = new PrintWriter(expectedStringWriter); + printWriter.println("First packet"); + printWriter.println("Second packet"); + printWriter.println("Third packet"); + printWriter.println("Fourth packet"); + printWriter.close(); + + expected = expectedStringWriter.toString(); + } - @After - public void cleanUpStreams() { - System.setOut(null); - System.setErr(null); - } - - @Test - public void givenSenderAndReceiver_whenSendingPackets_thenNetworkSynchronized() { + @After + public void cleanUpStreams() { + System.setOut(null); + System.setErr(null); + } + + @Test + public void givenSenderAndReceiver_whenSendingPackets_thenNetworkSynchronized() { Data data = new Data(); Thread sender = new Thread(new Sender(data)); Thread receiver = new Thread(new Receiver(data)); @@ -54,12 +54,12 @@ public class NetworkIntegrationTest { //wait for sender and receiver to finish before we test against expected try { - sender.join(); - receiver.join(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - - assertEquals(expected, outContent.toString()); - } + sender.join(); + receiver.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + assertEquals(expected, outContent.toString()); + } } From fab4aec7a1dbad52dee577ecb83e76594e38bcf4 Mon Sep 17 00:00:00 2001 From: Satish Pandey Date: Sat, 27 Jan 2018 10:54:22 +0530 Subject: [PATCH 65/65] Instance profile credentials example. (#3401) * Instance profile credentials example. * InstanceProfile CloudFormation template included to provision AWS environment. * Included java package installation under Yaml script. * Using SpringApplication reference to prepare application context. * Introducing SpringCloudS3Service to handle all S3 operations. --- spring-cloud/spring-cloud-aws/README.md | 5 ++ spring-cloud/spring-cloud-aws/pom.xml | 1 + .../aws/InstanceProfileAwsApplication.java | 60 ++++++++++++++ .../cloud/aws/s3/SpringCloudS3Service.java | 64 +++++++++++++++ .../resources/InstanceProfileFormation.yaml | 78 +++++++++++++++++++ .../application-instance-profile.properties | 14 ++++ 6 files changed, 222 insertions(+) create mode 100644 spring-cloud/spring-cloud-aws/src/main/java/com/baeldung/spring/cloud/aws/InstanceProfileAwsApplication.java create mode 100644 spring-cloud/spring-cloud-aws/src/main/java/com/baeldung/spring/cloud/aws/s3/SpringCloudS3Service.java create mode 100644 spring-cloud/spring-cloud-aws/src/main/resources/InstanceProfileFormation.yaml create mode 100644 spring-cloud/spring-cloud-aws/src/main/resources/application-instance-profile.properties diff --git a/spring-cloud/spring-cloud-aws/README.md b/spring-cloud/spring-cloud-aws/README.md index c5f58159c8..1340712c7a 100644 --- a/spring-cloud/spring-cloud-aws/README.md +++ b/spring-cloud/spring-cloud-aws/README.md @@ -19,3 +19,8 @@ to write the following in `application.properties`: cloud.aws.rds.spring-cloud-test-db cloud.aws.rds.spring-cloud-test-db.password=se3retpass ``` +Multiple application classes are available under this project. To launch InstanceProfileAwsApplication application, replace `start-class` under `pom.xml`: + +``` +com.baeldung.spring.cloud.aws.InstanceProfileAwsApplication +``` \ No newline at end of file diff --git a/spring-cloud/spring-cloud-aws/pom.xml b/spring-cloud/spring-cloud-aws/pom.xml index 632e050d92..b27b6c0d18 100644 --- a/spring-cloud/spring-cloud-aws/pom.xml +++ b/spring-cloud/spring-cloud-aws/pom.xml @@ -19,6 +19,7 @@ + com.baeldung.spring.cloud.aws.SpringCloudAwsApplication UTF-8 UTF-8 1.8 diff --git a/spring-cloud/spring-cloud-aws/src/main/java/com/baeldung/spring/cloud/aws/InstanceProfileAwsApplication.java b/spring-cloud/spring-cloud-aws/src/main/java/com/baeldung/spring/cloud/aws/InstanceProfileAwsApplication.java new file mode 100644 index 0000000000..80c0851a6f --- /dev/null +++ b/spring-cloud/spring-cloud-aws/src/main/java/com/baeldung/spring/cloud/aws/InstanceProfileAwsApplication.java @@ -0,0 +1,60 @@ +package com.baeldung.spring.cloud.aws; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.UUID; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import com.baeldung.spring.cloud.aws.s3.SpringCloudS3Service; + +@Configuration +@EnableAutoConfiguration +@ComponentScan("com.baeldung.spring.cloud.aws.s3") +public class InstanceProfileAwsApplication { + + private static final Logger logger = LoggerFactory.getLogger(InstanceProfileAwsApplication.class); + private static final String applicationConfig = "spring.config.name:application-instance-profile"; + + private static String bucketName; + private static String fileName = "sample-file.txt"; + + private static void setupResources() { + bucketName = "baeldung-test-" + UUID.randomUUID() + .toString(); + try { + Files.write(Paths.get(fileName), "Hello World!".getBytes()); + } catch (IOException e) { + logger.error(e.getMessage(), e); + } + } + + public static void main(String[] args) { + setupResources(); + if (!new File(fileName).exists()) { + logger.warn("Not able to create {} file. Check your folder permissions.", fileName); + System.exit(1); + } + + SpringApplication application = new SpringApplicationBuilder(InstanceProfileAwsApplication.class).properties(applicationConfig) + .build(); + ConfigurableApplicationContext context = application.run(args); + SpringCloudS3Service service = context.getBean(SpringCloudS3Service.class); + + // S3 bucket operations + service.createBucket(bucketName); + service.uploadObject(bucketName, fileName); + service.downloadObject(bucketName, fileName); + service.deleteBucket(bucketName); + } + +} diff --git a/spring-cloud/spring-cloud-aws/src/main/java/com/baeldung/spring/cloud/aws/s3/SpringCloudS3Service.java b/spring-cloud/spring-cloud-aws/src/main/java/com/baeldung/spring/cloud/aws/s3/SpringCloudS3Service.java new file mode 100644 index 0000000000..a0fdce2143 --- /dev/null +++ b/spring-cloud/spring-cloud-aws/src/main/java/com/baeldung/spring/cloud/aws/s3/SpringCloudS3Service.java @@ -0,0 +1,64 @@ +package com.baeldung.spring.cloud.aws.s3; + +import java.io.File; +import java.io.IOException; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.amazonaws.services.s3.AmazonS3; +import com.amazonaws.services.s3.model.ListObjectsV2Result; +import com.amazonaws.services.s3.model.S3ObjectSummary; + +@Component +public class SpringCloudS3Service { + + private static final Logger logger = LoggerFactory.getLogger(SpringCloudS3Service.class); + + @Autowired + AmazonS3 amazonS3; + + @Autowired + SpringCloudS3 springCloudS3; + + public void createBucket(String bucketName) { + logger.debug("Creating S3 bucket: {}", bucketName); + amazonS3.createBucket(bucketName); + logger.info("{} bucket created successfully", bucketName); + } + + public void downloadObject(String bucketName, String objectName) { + String s3Url = "s3://" + bucketName + "/" + objectName; + try { + springCloudS3.downloadS3Object(s3Url); + logger.info("{} file download result: {}", objectName, new File(objectName).exists()); + } catch (IOException e) { + logger.error(e.getMessage(), e); + } + } + + public void uploadObject(String bucketName, String objectName) { + String s3Url = "s3://" + bucketName + "/" + objectName; + File file = new File(objectName); + try { + springCloudS3.uploadFileToS3(file, s3Url); + logger.info("{} file uploaded to S3", objectName); + } catch (IOException e) { + logger.error(e.getMessage(), e); + } + } + + public void deleteBucket(String bucketName) { + logger.trace("Deleting S3 objects under {} bucket...", bucketName); + ListObjectsV2Result listObjectsV2Result = amazonS3.listObjectsV2(bucketName); + for (S3ObjectSummary objectSummary : listObjectsV2Result.getObjectSummaries()) { + logger.info("Deleting S3 object: {}", objectSummary.getKey()); + amazonS3.deleteObject(bucketName, objectSummary.getKey()); + } + logger.info("Deleting S3 bucket: {}", bucketName); + amazonS3.deleteBucket(bucketName); + } + +} diff --git a/spring-cloud/spring-cloud-aws/src/main/resources/InstanceProfileFormation.yaml b/spring-cloud/spring-cloud-aws/src/main/resources/InstanceProfileFormation.yaml new file mode 100644 index 0000000000..f8c3d3c915 --- /dev/null +++ b/spring-cloud/spring-cloud-aws/src/main/resources/InstanceProfileFormation.yaml @@ -0,0 +1,78 @@ +AWSTemplateFormatVersion: 2010-09-09 +Metadata: + 'AWS::CloudFormation::Designer': + 157e7d5f-5cb3-4a23-a50c-97e7f6c57173: + size: + width: 60 + height: 60 + position: + x: 450 + 'y': 90 + z: 0 + embeds: [] + 9bbaaa55-9cba-4555-a7c6-fb6ac248fd3a: + size: + width: 60 + height: 60 + position: + x: 260 + 'y': 90 + z: 0 + embeds: [] + isassociatedwith: + - 157e7d5f-5cb3-4a23-a50c-97e7f6c57173 + a7348729-a594-4dca-9b0a-e1c8d777dc3b: + size: + width: 60 + height: 60 + position: + x: 70 + 'y': 90 + z: 0 + embeds: [] +Resources: + IAMRoleBaeldung: + Type: 'AWS::IAM::Role' + Properties: + AssumeRolePolicyDocument: + Version: 2012-10-17 + Statement: + - Effect: Allow + Principal: + Service: + - ec2.amazonaws.com + Action: + - 'sts:AssumeRole' + ManagedPolicyArns: + - 'arn:aws:iam::aws:policy/AmazonS3FullAccess' + Metadata: + 'AWS::CloudFormation::Designer': + id: 157e7d5f-5cb3-4a23-a50c-97e7f6c57173 + InstanceProfileBaeldung: + Type: 'AWS::IAM::InstanceProfile' + Properties: + Roles: + - !Ref IAMRoleBaeldung + Metadata: + 'AWS::CloudFormation::Designer': + id: 9bbaaa55-9cba-4555-a7c6-fb6ac248fd3a + EC2Instance: + Type: 'AWS::EC2::Instance' + Properties: + ImageId: ami-2581aa40 + InstanceType: t2.micro + IamInstanceProfile: !Ref InstanceProfileBaeldung + KeyName: Satish-Ohio + UserData: !Base64 + 'Fn::Join': + - '' + - - | + #!/bin/bash + - | + apt -y install openjdk-8-jre-headless + Metadata: + 'AWS::CloudFormation::Designer': + id: a7348729-a594-4dca-9b0a-e1c8d777dc3b + DependsOn: + - InstanceProfileBaeldung + diff --git a/spring-cloud/spring-cloud-aws/src/main/resources/application-instance-profile.properties b/spring-cloud/spring-cloud-aws/src/main/resources/application-instance-profile.properties new file mode 100644 index 0000000000..23ca09c85c --- /dev/null +++ b/spring-cloud/spring-cloud-aws/src/main/resources/application-instance-profile.properties @@ -0,0 +1,14 @@ +# Don't try to create DataSouce when running tests which don't need a DataSource +spring.autoconfigure.exclude=\ + org.springframework.cloud.aws.autoconfigure.jdbc.AmazonRdsDatabaseAutoConfiguration,\ + org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration +cloud.aws.region.auto=true + +# Load instance profile credentials +cloud.aws.credentials.instanceProfile=true + +# Disable auto cloud formation +cloud.aws.stack.auto=false + +# Disable web environment +spring.main.web-environment=false \ No newline at end of file