diff --git a/spring-mvc-push/.gitignore b/spring-mvc-push/.gitignore
new file mode 100644
index 0000000000..448298d47f
--- /dev/null
+++ b/spring-mvc-push/.gitignore
@@ -0,0 +1 @@
+/.tern-project
diff --git a/spring-mvc-push/pom.xml b/spring-mvc-push/pom.xml
new file mode 100644
index 0000000000..2eb10381be
--- /dev/null
+++ b/spring-mvc-push/pom.xml
@@ -0,0 +1,91 @@
+
+ 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
new file mode 100644
index 0000000000..e6188da92d
--- /dev/null
+++ b/spring-mvc-push/src/main/java/com/baeldung/config/PushConfiguration.java
@@ -0,0 +1,48 @@
+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/java/com/baeldung/controller/PushController.java b/spring-mvc-push/src/main/java/com/baeldung/controller/PushController.java
new file mode 100644
index 0000000000..c4698fe976
--- /dev/null
+++ b/spring-mvc-push/src/main/java/com/baeldung/controller/PushController.java
@@ -0,0 +1,25 @@
+package com.baeldung.controller;
+
+import javax.servlet.http.PushBuilder;
+
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+
+@Controller
+public class PushController {
+
+ @GetMapping(path = "/demoWithPush")
+ public String demoWithPush(PushBuilder pushBuilder) {
+ if (null != pushBuilder) {
+ pushBuilder.path("resources/logo.png")
+ .addHeader("Content-Type", "image/png")
+ .push();
+ }
+ return "demo";
+ }
+
+ @GetMapping(path = "/demoWithoutPush")
+ public String demoWithoutPush() {
+ return "demo";
+ }
+}
\ No newline at end of file
diff --git a/spring-mvc-push/src/main/webapp/WEB-INF/views/demo.jsp b/spring-mvc-push/src/main/webapp/WEB-INF/views/demo.jsp
new file mode 100644
index 0000000000..28b27322ae
--- /dev/null
+++ b/spring-mvc-push/src/main/webapp/WEB-INF/views/demo.jsp
@@ -0,0 +1,18 @@
+<%@ page language="java" contentType="text/html; charset=UTF-8"
+ pageEncoding="UTF-8"%>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
+
+
+
+PushBuilder demo
+
+
+ PushBuilder demo
+
+ " alt="Logo"
+ height="126" width="411">
+
+
Go to
+ index
+
+
\ No newline at end of file
diff --git a/spring-mvc-push/src/main/webapp/index.jsp b/spring-mvc-push/src/main/webapp/index.jsp
new file mode 100644
index 0000000000..82ecb68003
--- /dev/null
+++ b/spring-mvc-push/src/main/webapp/index.jsp
@@ -0,0 +1,14 @@
+<%@ page language="java" contentType="text/html; charset=UTF-8"
+ pageEncoding="UTF-8"%>
+
+
+
+PushBuilder demo
+
+
+
+
+
\ No newline at end of file
diff --git a/spring-mvc-push/src/main/webapp/resources/logo.png b/spring-mvc-push/src/main/webapp/resources/logo.png
new file mode 100644
index 0000000000..edb83efbe3
Binary files /dev/null and b/spring-mvc-push/src/main/webapp/resources/logo.png differ
diff --git a/spring-mvc-push/src/main/webapp/resources/script.js b/spring-mvc-push/src/main/webapp/resources/script.js
new file mode 100644
index 0000000000..9bc97c006a
--- /dev/null
+++ b/spring-mvc-push/src/main/webapp/resources/script.js
@@ -0,0 +1 @@
+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
new file mode 100644
index 0000000000..d5fc158135
--- /dev/null
+++ b/spring-mvc-push/src/main/webapp/resources/style.css
@@ -0,0 +1,9 @@
+.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-push/src/test/java/com/baeldung/controller/PushControllerIntegrationTest.java b/spring-mvc-push/src/test/java/com/baeldung/controller/PushControllerIntegrationTest.java
new file mode 100644
index 0000000000..570e05cad6
--- /dev/null
+++ b/spring-mvc-push/src/test/java/com/baeldung/controller/PushControllerIntegrationTest.java
@@ -0,0 +1,41 @@
+package com.baeldung.controller;
+
+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;
+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;
+
+@Disabled
+@SpringJUnitWebConfig(PushConfiguration.class)
+public class PushControllerIntegrationTest {
+ @Autowired
+ private WebApplicationContext webAppContext;
+ private MockMvc mockMvc;
+
+ @BeforeEach
+ public void setup() {
+ mockMvc = MockMvcBuilders.webAppContextSetup(webAppContext)
+ .build();
+ }
+
+ @Test
+ public void whenDemoWithPushGETisPerformed_thenRetrievedStatusOk() throws Exception {
+ mockMvc.perform(get("/demoWithPush"))
+ .andExpect(status().isOk());
+ }
+
+ @Test
+ public void whenDemoWithoutPushGETisPerformed_thenRetrievedStatusOk() throws Exception {
+ mockMvc.perform(get("/demoWithoutPush"))
+ .andExpect(status().isOk());
+ }
+}
\ No newline at end of file
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
+
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/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
+
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();
-
+
}
-
+
}
diff --git a/spring-protobuf/pom.xml b/spring-protobuf/pom.xml
index 36310e08f1..1771c3e1f2 100644
--- a/spring-protobuf/pom.xml
+++ b/spring-protobuf/pom.xml
@@ -7,10 +7,10 @@
spring-protobuf
- parent-boot-4
+ parent-boot-5
com.baeldung
0.0.1-SNAPSHOT
- ../parent-boot-4
+ ../parent-boot-5
diff --git a/spring-protobuf/src/test/java/com/baeldung/protobuf/ApplicationIntegrationTest.java b/spring-protobuf/src/test/java/com/baeldung/protobuf/ApplicationIntegrationTest.java
index 914cf18627..4b9f41ace3 100644
--- a/spring-protobuf/src/test/java/com/baeldung/protobuf/ApplicationIntegrationTest.java
+++ b/spring-protobuf/src/test/java/com/baeldung/protobuf/ApplicationIntegrationTest.java
@@ -1,7 +1,11 @@
package com.baeldung.protobuf;
-import com.baeldung.protobuf.BaeldungTraining.Course;
-import com.googlecode.protobuf.format.JsonFormat;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.junit.Assert.assertThat;
+
+import java.io.IOException;
+import java.io.InputStream;
+
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
@@ -9,21 +13,17 @@ import org.apache.http.impl.client.HttpClients;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.test.SpringApplicationConfiguration;
-import org.springframework.boot.test.WebIntegrationTest;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.web.client.RestTemplate;
-import java.io.IOException;
-import java.io.InputStream;
-
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.junit.Assert.assertThat;
+import com.baeldung.protobuf.BaeldungTraining.Course;
+import com.googlecode.protobuf.format.JsonFormat;
@RunWith(SpringJUnit4ClassRunner.class)
-@SpringApplicationConfiguration(classes = Application.class)
-@WebIntegrationTest
+@SpringBootTest(classes = Application.class, webEnvironment = WebEnvironment.DEFINED_PORT)
public class ApplicationIntegrationTest {
private static final String COURSE1_URL = "http://localhost:8080/courses/1";
diff --git a/spring-quartz/pom.xml b/spring-quartz/pom.xml
index eb00911543..78beab6e38 100644
--- a/spring-quartz/pom.xml
+++ b/spring-quartz/pom.xml
@@ -11,10 +11,10 @@
Demo project for Scheduling in Spring with Quartz
- parent-boot-4
+ parent-boot-5
com.baeldung
0.0.1-SNAPSHOT
- ../parent-boot-4
+ ../parent-boot-5
diff --git a/spring-reactive-websocket/pom.xml b/spring-reactive-websocket/pom.xml
new file mode 100644
index 0000000000..846cece177
--- /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
+ 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
diff --git a/spring-reactor/pom.xml b/spring-reactor/pom.xml
index 759e9f2b58..1a19d9c6d9 100644
--- a/spring-reactor/pom.xml
+++ b/spring-reactor/pom.xml
@@ -9,10 +9,10 @@
http://maven.apache.org
- parent-boot-4
+ parent-boot-5
com.baeldung
0.0.1-SNAPSHOT
- ../parent-boot-4
+ ../parent-boot-5
diff --git a/spring-remoting/pom.xml b/spring-remoting/pom.xml
index b40f77eb50..aac8357c10 100644
--- a/spring-remoting/pom.xml
+++ b/spring-remoting/pom.xml
@@ -11,10 +11,10 @@
Parent for all projects related to Spring Remoting.
- parent-boot-4
+ parent-boot-5
com.baeldung
0.0.1-SNAPSHOT
- ../parent-boot-4
+ ../parent-boot-5
diff --git a/spring-remoting/remoting-hessian-burlap/client/src/test/java/com/baeldung/client/CabBookingServiceTest.java b/spring-remoting/remoting-hessian-burlap/client/src/test/java/com/baeldung/client/CabBookingServiceIntegrationTest.java
similarity index 97%
rename from spring-remoting/remoting-hessian-burlap/client/src/test/java/com/baeldung/client/CabBookingServiceTest.java
rename to spring-remoting/remoting-hessian-burlap/client/src/test/java/com/baeldung/client/CabBookingServiceIntegrationTest.java
index 373701f714..a1fed9637f 100644
--- a/spring-remoting/remoting-hessian-burlap/client/src/test/java/com/baeldung/client/CabBookingServiceTest.java
+++ b/spring-remoting/remoting-hessian-burlap/client/src/test/java/com/baeldung/client/CabBookingServiceIntegrationTest.java
@@ -18,9 +18,9 @@ import static java.lang.Thread.sleep;
@SpringBootTest(classes = {BurlapClient.class, HessianClient.class})
@RunWith(SpringRunner.class)
-public class CabBookingServiceTest {
+public class CabBookingServiceIntegrationTest {
- static Logger log = LoggerFactory.getLogger(CabBookingServiceTest.class);
+ static Logger log = LoggerFactory.getLogger(CabBookingServiceIntegrationTest.class);
@Autowired @Qualifier("burlapInvoker") CabBookingService burlapClient;
@Autowired @Qualifier("hessianInvoker") CabBookingService hessianClient;
static Thread serverThread;
diff --git a/spring-rest-docs/README.MD b/spring-rest-docs/README.MD
deleted file mode 100644
index f5d001d126..0000000000
--- a/spring-rest-docs/README.MD
+++ /dev/null
@@ -1,5 +0,0 @@
-###The Course
-The "REST With Spring" Classes: http://bit.ly/restwithspring
-
-###Relevant Articles:
-- [Introduction to Spring REST Docs](http://www.baeldung.com/spring-rest-docs)
diff --git a/spring-rest-docs/pom.xml b/spring-rest-docs/pom.xml
deleted file mode 100644
index 4647577629..0000000000
--- a/spring-rest-docs/pom.xml
+++ /dev/null
@@ -1,112 +0,0 @@
-
-
- 4.0.0
-
- com.example
- spring-rest-docs
- 0.0.1-SNAPSHOT
- jar
-
- spring-rest-docs
- Demo project for Spring Boot
-
-
- parent-boot-4
- com.baeldung
- 0.0.1-SNAPSHOT
- ../parent-boot-4
-
-
-
- ${project.build.directory}/generated-snippets
- 1.1.2.RELEASE
- 2.2.0
- 1.5.3
-
-
-
-
- org.springframework.boot
- spring-boot-starter-hateoas
-
-
- org.springframework.boot
- spring-boot-starter-web
-
-
-
- org.springframework.restdocs
- spring-restdocs-mockmvc
- test
-
-
- com.jayway.jsonpath
- json-path
-
-
-
-
-
-
- org.asciidoctor
- asciidoctor-maven-plugin
- ${asciidoctor-plugin.version}
-
-
- generate-docs
- package
-
- process-asciidoc
-
-
- html
- book
-
- ${snippetsDirectory}
-
- src/docs/asciidocs
- target/generated-docs
-
-
-
-
-
-
-
-
-
- integration
-
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
-
-
- integration-test
-
- test
-
-
-
- **/*LiveTest.java
-
-
- **/*IntegrationTest.java
-
-
-
-
-
-
- json
-
-
-
-
-
-
-
-
-
diff --git a/spring-rest-docs/src/main/java/com/example/CrudInput.java b/spring-rest-docs/src/main/java/com/example/CrudInput.java
deleted file mode 100644
index 36ad67eb21..0000000000
--- a/spring-rest-docs/src/main/java/com/example/CrudInput.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package com.example;
-
-import java.net.URI;
-import java.util.Collections;
-import java.util.List;
-
-import org.hibernate.validator.constraints.NotBlank;
-
-import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-public class CrudInput {
-
- // @NotBlank
- private final String title;
-
- private final String body;
-
- private final List tagUris;
-
- @JsonCreator
- public CrudInput(@JsonProperty("title") String title, @JsonProperty("body") String body, @JsonProperty("tags") List tagUris) {
- this.title = title;
- this.body = body;
- this.tagUris = tagUris == null ? Collections. emptyList() : tagUris;
- }
-
- public String getTitle() {
- return title;
- }
-
- public String getBody() {
- return body;
- }
-
- @JsonProperty("tags")
- public List getTagUris() {
- return this.tagUris;
- }
-
-}
\ No newline at end of file
diff --git a/spring-rest-docs/src/test/java/com/example/ApiDocumentationIntegrationTest.java b/spring-rest-docs/src/test/java/com/example/ApiDocumentationIntegrationTest.java
deleted file mode 100644
index f2ac9d0f82..0000000000
--- a/spring-rest-docs/src/test/java/com/example/ApiDocumentationIntegrationTest.java
+++ /dev/null
@@ -1,180 +0,0 @@
-package com.example;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.test.SpringApplicationConfiguration;
-import org.springframework.hateoas.MediaTypes;
-import org.springframework.restdocs.RestDocumentation;
-import org.springframework.restdocs.constraints.ConstraintDescriptions;
-import org.springframework.restdocs.mockmvc.RestDocumentationResultHandler;
-import org.springframework.restdocs.payload.FieldDescriptor;
-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;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import static java.util.Collections.singletonList;
-import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName;
-import static org.springframework.restdocs.headers.HeaderDocumentation.responseHeaders;
-import static org.springframework.restdocs.hypermedia.HypermediaDocumentation.linkWithRel;
-import static org.springframework.restdocs.hypermedia.HypermediaDocumentation.links;
-import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
-import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration;
-import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.delete;
-import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
-import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.patch;
-import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post;
-import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.put;
-import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest;
-import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse;
-import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint;
-import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
-import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields;
-import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
-import static org.springframework.restdocs.snippet.Attributes.key;
-import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
-import static org.springframework.util.StringUtils.collectionToDelimitedString;
-
-@RunWith(SpringJUnit4ClassRunner.class)
-@SpringApplicationConfiguration(classes = SpringRestDocsApplication.class)
-@WebAppConfiguration
-public class ApiDocumentationIntegrationTest {
-
- @Rule
- public final RestDocumentation restDocumentation = new RestDocumentation("target/generated-snippets");
-
- @Autowired
- private WebApplicationContext context;
-
- @Autowired
- private ObjectMapper objectMapper;
-
- private RestDocumentationResultHandler document;
-
- private MockMvc mockMvc;
-
- @Before
- public void setUp() {
- this.document = document("{method-name}", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()));
- this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context).apply(documentationConfiguration(this.restDocumentation)).alwaysDo(this.document).build();
- }
-
- @Test
- public void headersExample() throws Exception {
- this.document.snippets(responseHeaders(headerWithName("Content-Type").description("The Content-Type of the payload, e.g. `application/hal+json`")));
- this.mockMvc.perform(get("/")).andExpect(status().isOk());
- }
-
- @Test
- public void indexExample() throws Exception {
- this.document.snippets(links(linkWithRel("crud").description("The <>")), responseFields(fieldWithPath("_links").description("<> to other resources")));
- this.mockMvc.perform(get("/")).andExpect(status().isOk());
- }
-
- @Test
- public void crudGetExample() throws Exception {
-
- Map tag = new HashMap<>();
- tag.put("name", "GET");
-
- String tagLocation = this.mockMvc.perform(get("/crud").contentType(MediaTypes.HAL_JSON).content(this.objectMapper.writeValueAsString(tag))).andExpect(status().isOk()).andReturn().getResponse().getHeader("Location");
-
- Map crud = new HashMap<>();
- crud.put("title", "Sample Model");
- crud.put("body", "http://www.baeldung.com/");
- crud.put("tags", singletonList(tagLocation));
-
- this.mockMvc.perform(get("/crud").contentType(MediaTypes.HAL_JSON).content(this.objectMapper.writeValueAsString(crud))).andExpect(status().isOk());
- }
-
- @Test
- public void crudCreateExample() throws Exception {
- Map tag = new HashMap<>();
- tag.put("name", "CREATE");
-
- String tagLocation = this.mockMvc.perform(post("/crud").contentType(MediaTypes.HAL_JSON).content(this.objectMapper.writeValueAsString(tag))).andExpect(status().isCreated()).andReturn().getResponse().getHeader("Location");
-
- Map crud = new HashMap<>();
- crud.put("title", "Sample Model");
- crud.put("body", "http://www.baeldung.com/");
- crud.put("tags", singletonList(tagLocation));
-
- ConstrainedFields fields = new ConstrainedFields(CrudInput.class);
- this.document.snippets(requestFields(fields.withPath("title").description("The title of the note"), fields.withPath("body").description("The body of the note"), fields.withPath("tags").description("An array of tag resource URIs")));
- this.mockMvc.perform(post("/crud").contentType(MediaTypes.HAL_JSON).content(this.objectMapper.writeValueAsString(crud))).andExpect(status().isCreated());
-
- }
-
- @Test
- public void crudDeleteExample() throws Exception {
-
- Map tag = new HashMap<>();
- tag.put("name", "DELETE");
-
- String tagLocation = this.mockMvc.perform(delete("/crud/10").contentType(MediaTypes.HAL_JSON).content(this.objectMapper.writeValueAsString(tag))).andExpect(status().isOk()).andReturn().getResponse().getHeader("Location");
-
- Map crud = new HashMap<>();
- crud.put("title", "Sample Model");
- crud.put("body", "http://www.baeldung.com/");
- crud.put("tags", singletonList(tagLocation));
-
- this.mockMvc.perform(delete("/crud/10").contentType(MediaTypes.HAL_JSON).content(this.objectMapper.writeValueAsString(crud))).andExpect(status().isOk());
- }
-
- @Test
- public void crudPatchExample() throws Exception {
-
- Map tag = new HashMap<>();
- tag.put("name", "PATCH");
-
- String tagLocation = this.mockMvc.perform(patch("/crud/10").contentType(MediaTypes.HAL_JSON).content(this.objectMapper.writeValueAsString(tag))).andExpect(status().isNoContent()).andReturn().getResponse().getHeader("Location");
-
- Map crud = new HashMap<>();
- crud.put("title", "Sample Model");
- crud.put("body", "http://www.baeldung.com/");
- crud.put("tags", singletonList(tagLocation));
-
- this.mockMvc.perform(patch("/crud/10").contentType(MediaTypes.HAL_JSON).content(this.objectMapper.writeValueAsString(crud))).andExpect(status().isNoContent());
- }
-
- @Test
- public void crudPutExample() throws Exception {
- Map tag = new HashMap<>();
- tag.put("name", "PUT");
-
- String tagLocation = this.mockMvc.perform(put("/crud/10").contentType(MediaTypes.HAL_JSON).content(this.objectMapper.writeValueAsString(tag))).andExpect(status().isAccepted()).andReturn().getResponse().getHeader("Location");
-
- Map crud = new HashMap<>();
- crud.put("title", "Sample Model");
- crud.put("body", "http://www.baeldung.com/");
- crud.put("tags", singletonList(tagLocation));
-
- this.mockMvc.perform(put("/crud/10").contentType(MediaTypes.HAL_JSON).content(this.objectMapper.writeValueAsString(crud))).andExpect(status().isAccepted());
- }
-
- @Test
- public void contextLoads() {
- }
-
- private static class ConstrainedFields {
-
- private final ConstraintDescriptions constraintDescriptions;
-
- ConstrainedFields(Class> input) {
- this.constraintDescriptions = new ConstraintDescriptions(input);
- }
-
- private FieldDescriptor withPath(String path) {
- return fieldWithPath(path).attributes(key("constraints").value(collectionToDelimitedString(this.constraintDescriptions.descriptionsForProperty(path), ". ")));
- }
- }
-
-}
diff --git a/spring-rest-docs/src/test/java/com/example/GettingStartedDocumentationIntegrationTest.java b/spring-rest-docs/src/test/java/com/example/GettingStartedDocumentationIntegrationTest.java
deleted file mode 100644
index c02c0c27f8..0000000000
--- a/spring-rest-docs/src/test/java/com/example/GettingStartedDocumentationIntegrationTest.java
+++ /dev/null
@@ -1,146 +0,0 @@
-package com.example;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.test.SpringApplicationConfiguration;
-import org.springframework.hateoas.MediaTypes;
-import org.springframework.restdocs.RestDocumentation;
-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;
-
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
-import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration;
-import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
-import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest;
-import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse;
-import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint;
-import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
-import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
-
-@RunWith(SpringJUnit4ClassRunner.class)
-@SpringApplicationConfiguration(classes = SpringRestDocsApplication.class)
-@WebAppConfiguration
-public class GettingStartedDocumentationIntegrationTest {
-
- @Rule
- public final RestDocumentation restDocumentation = new RestDocumentation("target/generated-snippets");
-
- @Autowired
- private ObjectMapper objectMapper;
-
- @Autowired
- private WebApplicationContext context;
-
- private MockMvc mockMvc;
-
- @Before
- public void setUp() {
- this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context).apply(documentationConfiguration(this.restDocumentation)).alwaysDo(document("{method-name}/{step}/", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()))).build();
- }
-
- @Test
- public void index() throws Exception {
- this.mockMvc.perform(get("/").accept(MediaTypes.HAL_JSON)).andExpect(status().isOk()).andExpect(jsonPath("_links.crud", is(notNullValue()))).andExpect(jsonPath("_links.crud", is(notNullValue())));
- }
-
- // String createNote() throws Exception {
- // Map note = new HashMap();
- // note.put("title", "Note creation with cURL");
- // note.put("body", "An example of how to create a note using curl");
- // String noteLocation = this.mockMvc.perform(post("/crud")
- // .contentType(MediaTypes.HAL_JSON)
- // .content(objectMapper.writeValueAsString(note)))
- // .andExpect(status().isCreated())
- // .andExpect(header().string("Location", notNullValue()))
- // .andReturn()
- // .getResponse()
- // .getHeader("Location");
- // return noteLocation;
- // }
- //
- // MvcResult getNote(String noteLocation) throws Exception {
- // return this.mockMvc.perform(get(noteLocation))
- // .andExpect(status().isOk())
- // .andExpect(jsonPath("title", is(notNullValue())))
- // .andExpect(jsonPath("body", is(notNullValue())))
- // .andExpect(jsonPath("_links.crud", is(notNullValue())))
- // .andReturn();
- // }
- //
- //
- // String createTag() throws Exception, JsonProcessingException {
- // Map tag = new HashMap();
- // tag.put("name", "getting-started");
- // String tagLocation = this.mockMvc.perform(post("/crud")
- // .contentType(MediaTypes.HAL_JSON)
- // .content(objectMapper.writeValueAsString(tag)))
- // .andExpect(status().isCreated())
- // .andExpect(header().string("Location", notNullValue()))
- // .andReturn()
- // .getResponse()
- // .getHeader("Location");
- // return tagLocation;
- // }
- //
- // void getTag(String tagLocation) throws Exception {
- // this.mockMvc.perform(get(tagLocation)).andExpect(status().isOk())
- // .andExpect(jsonPath("name", is(notNullValue())))
- // .andExpect(jsonPath("_links.tagged-notes", is(notNullValue())));
- // }
- //
- // String createTaggedNote(String tag) throws Exception {
- // Map note = new HashMap();
- // note.put("title", "Tagged note creation with cURL");
- // note.put("body", "An example of how to create a tagged note using cURL");
- // note.put("tags", Arrays.asList(tag));
- //
- // String noteLocation = this.mockMvc.perform(post("/notes")
- // .contentType(MediaTypes.HAL_JSON)
- // .content(objectMapper.writeValueAsString(note)))
- // .andExpect(status().isCreated())
- // .andExpect(header().string("Location", notNullValue()))
- // .andReturn()
- // .getResponse()
- // .getHeader("Location");
- // return noteLocation;
- // }
- //
- // void getTags(String noteTagsLocation) throws Exception {
- // this.mockMvc.perform(get(noteTagsLocation))
- // .andExpect(status().isOk())
- // .andExpect(jsonPath("_embedded.tags", hasSize(1)));
- // }
- //
- // void tagExistingNote(String noteLocation, String tagLocation) throws Exception {
- // Map update = new HashMap();
- // update.put("tags", Arrays.asList(tagLocation));
- // this.mockMvc.perform(patch(noteLocation)
- // .contentType(MediaTypes.HAL_JSON)
- // .content(objectMapper.writeValueAsString(update)))
- // .andExpect(status().isNoContent());
- // }
- //
- // MvcResult getTaggedExistingNote(String noteLocation) throws Exception {
- // return this.mockMvc.perform(get(noteLocation)).andExpect(status().isOk()).andReturn();
- // }
- //
- // void getTagsForExistingNote(String noteTagsLocation) throws Exception {
- // this.mockMvc.perform(get(noteTagsLocation))
- // .andExpect(status().isOk()).andExpect(jsonPath("_embedded.tags", hasSize(1)));
- // }
- //
- // private String getLink(MvcResult result, String rel)
- // throws UnsupportedEncodingException {
- // return JsonPath.parse(result.getResponse().getContentAsString()).read("_links." + rel + ".href");
- // }
-
-}
diff --git a/spring-rest-full/pom.xml b/spring-rest-full/pom.xml
index c596e79b31..c00387e7de 100644
--- a/spring-rest-full/pom.xml
+++ b/spring-rest-full/pom.xml
@@ -9,10 +9,10 @@
war
- parent-boot-4
+ parent-boot-5
com.baeldung
0.0.1-SNAPSHOT
- ../parent-boot-4
+ ../parent-boot-5
diff --git a/spring-rest-query-language/pom.xml b/spring-rest-query-language/pom.xml
index bf3eb8cb78..6826634bc9 100644
--- a/spring-rest-query-language/pom.xml
+++ b/spring-rest-query-language/pom.xml
@@ -9,10 +9,10 @@
war
- parent-boot-4
+ parent-boot-5
com.baeldung
0.0.1-SNAPSHOT
- ../parent-boot-4
+ ../parent-boot-5
diff --git a/spring-rest/pom.xml b/spring-rest/pom.xml
index 06747ffd41..6da891b054 100644
--- a/spring-rest/pom.xml
+++ b/spring-rest/pom.xml
@@ -8,10 +8,10 @@
war
- parent-boot-4
+ parent-boot-5
com.baeldung
0.0.1-SNAPSHOT
- ../parent-boot-4
+ ../parent-boot-5
diff --git a/spring-security-cache-control/pom.xml b/spring-security-cache-control/pom.xml
index e525cd4e8e..4ccb83c29b 100644
--- a/spring-security-cache-control/pom.xml
+++ b/spring-security-cache-control/pom.xml
@@ -8,10 +8,10 @@
1.0-SNAPSHOT
- parent-boot-4
+ parent-boot-5
com.baeldung
0.0.1-SNAPSHOT
- ../parent-boot-4
+ ../parent-boot-5
diff --git a/spring-security-client/spring-security-jsp-authentication/pom.xml b/spring-security-client/spring-security-jsp-authentication/pom.xml
index 6f4095c2d5..b29ce90aa4 100644
--- a/spring-security-client/spring-security-jsp-authentication/pom.xml
+++ b/spring-security-client/spring-security-jsp-authentication/pom.xml
@@ -12,10 +12,10 @@
Spring Security JSP Authentication tag sample
- parent-boot-4
+ parent-boot-5
com.baeldung
0.0.1-SNAPSHOT
- ../../parent-boot-4
+ ../../parent-boot-5
diff --git a/spring-security-client/spring-security-jsp-authorize/pom.xml b/spring-security-client/spring-security-jsp-authorize/pom.xml
index 2e1a57a468..6fd89933bb 100644
--- a/spring-security-client/spring-security-jsp-authorize/pom.xml
+++ b/spring-security-client/spring-security-jsp-authorize/pom.xml
@@ -12,10 +12,10 @@
Spring Security JSP Authorize tag sample
- parent-boot-4
+ parent-boot-5
com.baeldung
0.0.1-SNAPSHOT
- ../../parent-boot-4
+ ../../parent-boot-5
diff --git a/spring-security-client/spring-security-jsp-config/pom.xml b/spring-security-client/spring-security-jsp-config/pom.xml
index 4f92e24563..f533410acc 100644
--- a/spring-security-client/spring-security-jsp-config/pom.xml
+++ b/spring-security-client/spring-security-jsp-config/pom.xml
@@ -12,10 +12,10 @@
Spring Security JSP configuration
- parent-boot-4
+ parent-boot-5
com.baeldung
0.0.1-SNAPSHOT
- ../../parent-boot-4
+ ../../parent-boot-5
diff --git a/spring-security-client/spring-security-mvc/pom.xml b/spring-security-client/spring-security-mvc/pom.xml
index a642e8719d..c67bc336f6 100644
--- a/spring-security-client/spring-security-mvc/pom.xml
+++ b/spring-security-client/spring-security-mvc/pom.xml
@@ -12,10 +12,10 @@
Spring Security MVC
- parent-boot-4
+ parent-boot-5
com.baeldung
0.0.1-SNAPSHOT
- ../../parent-boot-4
+ ../../parent-boot-5
diff --git a/spring-security-client/spring-security-mvc/src/main/java/org/baeldung/config/Application.java b/spring-security-client/spring-security-mvc/src/main/java/org/baeldung/config/Application.java
index 4057a85f13..34c43fbe5a 100644
--- a/spring-security-client/spring-security-mvc/src/main/java/org/baeldung/config/Application.java
+++ b/spring-security-client/spring-security-mvc/src/main/java/org/baeldung/config/Application.java
@@ -3,7 +3,7 @@ package org.baeldung.config;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
-import org.springframework.boot.context.web.SpringBootServletInitializer;
+import org.springframework.boot.web.support.SpringBootServletInitializer;
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
diff --git a/spring-security-client/spring-security-thymeleaf-authentication/pom.xml b/spring-security-client/spring-security-thymeleaf-authentication/pom.xml
index 7573d430d3..941cbb8a76 100644
--- a/spring-security-client/spring-security-thymeleaf-authentication/pom.xml
+++ b/spring-security-client/spring-security-thymeleaf-authentication/pom.xml
@@ -12,10 +12,10 @@
Spring Security thymeleaf authentication tag sample
- parent-boot-4
+ parent-boot-5
com.baeldung
0.0.1-SNAPSHOT
- ../../parent-boot-4
+ ../../parent-boot-5
diff --git a/spring-security-client/spring-security-thymeleaf-authorize/pom.xml b/spring-security-client/spring-security-thymeleaf-authorize/pom.xml
index 20d141e70c..c70a099e68 100644
--- a/spring-security-client/spring-security-thymeleaf-authorize/pom.xml
+++ b/spring-security-client/spring-security-thymeleaf-authorize/pom.xml
@@ -12,10 +12,10 @@
Spring Security thymeleaf authorize tag sample
- parent-boot-4
+ parent-boot-5
com.baeldung
0.0.1-SNAPSHOT
- ../../parent-boot-4
+ ../../parent-boot-5
diff --git a/spring-security-client/spring-security-thymeleaf-config/pom.xml b/spring-security-client/spring-security-thymeleaf-config/pom.xml
index ad856c7e20..9ef2444d6c 100644
--- a/spring-security-client/spring-security-thymeleaf-config/pom.xml
+++ b/spring-security-client/spring-security-thymeleaf-config/pom.xml
@@ -12,10 +12,10 @@
Spring Security thymeleaf configuration sample project
- parent-boot-4
+ parent-boot-5
com.baeldung
0.0.1-SNAPSHOT
- ../../parent-boot-4
+ ../../parent-boot-5
diff --git a/spring-security-core/pom.xml b/spring-security-core/pom.xml
index 7deea5deb0..db8837df46 100644
--- a/spring-security-core/pom.xml
+++ b/spring-security-core/pom.xml
@@ -9,10 +9,10 @@
war
- parent-boot-4
+ parent-boot-5
com.baeldung
0.0.1-SNAPSHOT
- ../parent-boot-4
+ ../parent-boot-5
diff --git a/spring-security-core/src/main/java/org/baeldung/methodsecurity/annotation/IsViewer.java b/spring-security-core/src/main/java/org/baeldung/methodsecurity/annotation/IsViewer.java
new file mode 100644
index 0000000000..711784adbb
--- /dev/null
+++ b/spring-security-core/src/main/java/org/baeldung/methodsecurity/annotation/IsViewer.java
@@ -0,0 +1,14 @@
+package org.baeldung.methodsecurity.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.springframework.security.access.prepost.PreAuthorize;
+
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+@PreAuthorize("hasRole('VIEWER')")
+public @interface IsViewer {
+}
\ No newline at end of file
diff --git a/spring-security-core/src/main/java/org/baeldung/testmethodsecurity/config/MethodSecurityConfig.java b/spring-security-core/src/main/java/org/baeldung/methodsecurity/config/MethodSecurityConfig.java
similarity index 85%
rename from spring-security-core/src/main/java/org/baeldung/testmethodsecurity/config/MethodSecurityConfig.java
rename to spring-security-core/src/main/java/org/baeldung/methodsecurity/config/MethodSecurityConfig.java
index 1b2227f9be..4749c730dc 100644
--- a/spring-security-core/src/main/java/org/baeldung/testmethodsecurity/config/MethodSecurityConfig.java
+++ b/spring-security-core/src/main/java/org/baeldung/methodsecurity/config/MethodSecurityConfig.java
@@ -1,11 +1,11 @@
-package org.baeldung.testmethodsecurity.config;
+package org.baeldung.methodsecurity.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration;
@Configuration
-@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
+@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true, jsr250Enabled = true)
public class MethodSecurityConfig extends GlobalMethodSecurityConfiguration {
}
diff --git a/spring-security-core/src/main/java/org/baeldung/testmethodsecurity/entity/CustomUser.java b/spring-security-core/src/main/java/org/baeldung/methodsecurity/entity/CustomUser.java
similarity index 78%
rename from spring-security-core/src/main/java/org/baeldung/testmethodsecurity/entity/CustomUser.java
rename to spring-security-core/src/main/java/org/baeldung/methodsecurity/entity/CustomUser.java
index b145a82c80..fb9174befa 100644
--- a/spring-security-core/src/main/java/org/baeldung/testmethodsecurity/entity/CustomUser.java
+++ b/spring-security-core/src/main/java/org/baeldung/methodsecurity/entity/CustomUser.java
@@ -1,4 +1,4 @@
-package org.baeldung.testmethodsecurity.entity;
+package org.baeldung.methodsecurity.entity;
import java.util.Collection;
@@ -6,15 +6,15 @@ import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;
@SuppressWarnings("serial")
-public class CustomUser extends User{
-
+public class CustomUser extends User {
+
private String nickName;
public CustomUser(String username, String password, Collection extends GrantedAuthority> authorities) {
super(username, password, authorities);
}
-
- public CustomUser(String username, String password, Collection extends GrantedAuthority> authorities,String nickName) {
+
+ public CustomUser(String username, String password, Collection extends GrantedAuthority> authorities, String nickName) {
super(username, password, authorities);
this.nickName = nickName;
}
diff --git a/spring-security-core/src/main/java/org/baeldung/methodsecurity/repository/UserRoleRepository.java b/spring-security-core/src/main/java/org/baeldung/methodsecurity/repository/UserRoleRepository.java
new file mode 100644
index 0000000000..fc1a32289d
--- /dev/null
+++ b/spring-security-core/src/main/java/org/baeldung/methodsecurity/repository/UserRoleRepository.java
@@ -0,0 +1,57 @@
+package org.baeldung.methodsecurity.repository;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.baeldung.methodsecurity.entity.CustomUser;
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.authority.SimpleGrantedAuthority;
+import org.springframework.security.core.userdetails.UsernameNotFoundException;
+import org.springframework.stereotype.Service;
+
+@Service
+public class UserRoleRepository {
+
+ static Map DB_BASED_USER_MAPPING;
+
+ static {
+ DB_BASED_USER_MAPPING = new LinkedHashMap<>();
+ DB_BASED_USER_MAPPING.put("jane", new CustomUser("jane", "1234", getGrantedAuthorities("ROLE_USER", "ROLE_VIEWER"), "jane"));
+ DB_BASED_USER_MAPPING.put("john", new CustomUser("john", "1234", getGrantedAuthorities("ROLE_EDITOR", "ROLE_ADMIN"), "jane"));
+ DB_BASED_USER_MAPPING.put("jack", new CustomUser("jack", "1234", getGrantedAuthorities("ROLE_USER", "ROLE_REVIEWER"), "jane"));
+ }
+
+ private static List getGrantedAuthorities(String... roles) {
+ ArrayList authorities = new ArrayList<>();
+ for (String role : roles) {
+ authorities.add(new SimpleGrantedAuthority(role));
+ }
+ return authorities;
+ }
+
+ public CustomUser loadUserByUserName(String username) {
+ if (DB_BASED_USER_MAPPING.containsKey(username)) {
+ return DB_BASED_USER_MAPPING.get(username);
+ }
+ throw new UsernameNotFoundException("User " + username + " cannot be found");
+ }
+
+ public boolean isValidUsername(String username) {
+ return DB_BASED_USER_MAPPING.containsKey(username);
+ }
+
+ public boolean isValidRole(String roleName) {
+ return roleName.startsWith("ROLE_");
+ }
+
+ public List getAllUsernames() {
+ List usernames = new ArrayList<>();
+ usernames.add("jane");
+ usernames.add("john");
+ usernames.add("jack");
+ return usernames;
+ }
+
+}
diff --git a/spring-security-core/src/main/java/org/baeldung/testmethodsecurity/service/CustomUserDetailsService.java b/spring-security-core/src/main/java/org/baeldung/methodsecurity/service/CustomUserDetailsService.java
similarity index 80%
rename from spring-security-core/src/main/java/org/baeldung/testmethodsecurity/service/CustomUserDetailsService.java
rename to spring-security-core/src/main/java/org/baeldung/methodsecurity/service/CustomUserDetailsService.java
index a5adcd3408..91171468bb 100644
--- a/spring-security-core/src/main/java/org/baeldung/testmethodsecurity/service/CustomUserDetailsService.java
+++ b/spring-security-core/src/main/java/org/baeldung/methodsecurity/service/CustomUserDetailsService.java
@@ -1,6 +1,6 @@
-package org.baeldung.testmethodsecurity.service;
+package org.baeldung.methodsecurity.service;
-import org.baeldung.testmethodsecurity.repository.UserRoleRepository;
+import org.baeldung.methodsecurity.repository.UserRoleRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
diff --git a/spring-security-core/src/main/java/org/baeldung/methodsecurity/service/SystemService.java b/spring-security-core/src/main/java/org/baeldung/methodsecurity/service/SystemService.java
new file mode 100644
index 0000000000..5f29d7dee6
--- /dev/null
+++ b/spring-security-core/src/main/java/org/baeldung/methodsecurity/service/SystemService.java
@@ -0,0 +1,18 @@
+package org.baeldung.methodsecurity.service;
+
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.stereotype.Service;
+
+@Service
+@PreAuthorize("hasRole('ROLE_ADMIN')")
+public class SystemService {
+
+ public String getSystemYear(){
+ return "2017";
+ }
+
+ public String getSystemDate(){
+ return "31-12-2017";
+ }
+
+}
diff --git a/spring-security-core/src/main/java/org/baeldung/methodsecurity/service/UserRoleService.java b/spring-security-core/src/main/java/org/baeldung/methodsecurity/service/UserRoleService.java
new file mode 100644
index 0000000000..30bbdbc10f
--- /dev/null
+++ b/spring-security-core/src/main/java/org/baeldung/methodsecurity/service/UserRoleService.java
@@ -0,0 +1,108 @@
+package org.baeldung.methodsecurity.service;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import javax.annotation.security.RolesAllowed;
+
+import org.baeldung.methodsecurity.annotation.IsViewer;
+import org.baeldung.methodsecurity.entity.CustomUser;
+import org.baeldung.methodsecurity.repository.UserRoleRepository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.annotation.Secured;
+import org.springframework.security.access.prepost.PostAuthorize;
+import org.springframework.security.access.prepost.PostFilter;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.security.access.prepost.PreFilter;
+import org.springframework.security.core.context.SecurityContext;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.stereotype.Service;
+
+@Service
+public class UserRoleService {
+
+ @Autowired
+ UserRoleRepository userRoleRepository;
+
+ @Secured("ROLE_VIEWER")
+ public String getUsername() {
+ SecurityContext securityContext = SecurityContextHolder.getContext();
+ return securityContext.getAuthentication().getName();
+ }
+
+ @Secured({ "ROLE_VIEWER", "ROLE_EDITOR" })
+ public boolean isValidUsername(String username) {
+ return userRoleRepository.isValidUsername(username);
+ }
+
+ @RolesAllowed("ROLE_VIEWER")
+ public String getUsername2() {
+ SecurityContext securityContext = SecurityContextHolder.getContext();
+ return securityContext.getAuthentication().getName();
+ }
+
+ @RolesAllowed({ "ROLE_VIEWER", "ROLE_EDITOR" })
+ public boolean isValidUsername2(String username) {
+ return userRoleRepository.isValidUsername(username);
+ }
+
+ @PreAuthorize("hasRole('ROLE_VIEWER')")
+ public String getUsernameInUpperCase() {
+ return getUsername().toUpperCase();
+ }
+
+ @PreAuthorize("hasAuthority('SYS_ADMIN')")
+ public String getUsernameLC() {
+ return getUsername().toLowerCase();
+ }
+
+ @PreAuthorize("hasRole('ROLE_VIEWER') or hasRole('ROLE_EDITOR')")
+ public boolean isValidUsername3(String username) {
+ return userRoleRepository.isValidUsername(username);
+ }
+
+ @PreAuthorize("#username == authentication.principal.username")
+ public String getMyRoles(String username) {
+ SecurityContext securityContext = SecurityContextHolder.getContext();
+ return securityContext.getAuthentication().getAuthorities().stream().map(auth -> auth.getAuthority()).collect(Collectors.joining(","));
+ }
+
+ @PostAuthorize("#username == authentication.principal.username")
+ public String getMyRoles2(String username) {
+ SecurityContext securityContext = SecurityContextHolder.getContext();
+ return securityContext.getAuthentication().getAuthorities().stream().map(auth -> auth.getAuthority()).collect(Collectors.joining(","));
+ }
+
+ @PostAuthorize("returnObject.username == authentication.principal.nickName")
+ public CustomUser loadUserDetail(String username) {
+ return userRoleRepository.loadUserByUserName(username);
+ }
+
+ @PreFilter("filterObject != authentication.principal.username")
+ public String joinUsernames(List usernames) {
+ return usernames.stream().collect(Collectors.joining(";"));
+ }
+
+ @PreFilter(value = "filterObject != authentication.principal.username", filterTarget = "usernames")
+ public String joinUsernamesAndRoles(List usernames, List roles) {
+ return usernames.stream().collect(Collectors.joining(";")) + ":" + roles.stream().collect(Collectors.joining(";"));
+ }
+
+ @PostFilter("filterObject != authentication.principal.username")
+ public List getAllUsernamesExceptCurrent() {
+ return userRoleRepository.getAllUsernames();
+ }
+
+ @IsViewer
+ public String getUsername4() {
+ SecurityContext securityContext = SecurityContextHolder.getContext();
+ return securityContext.getAuthentication().getName();
+ }
+
+ @PreAuthorize("#username == authentication.principal.username")
+ @PostAuthorize("returnObject.username == authentication.principal.nickName")
+ public CustomUser securedLoadUserDetail(String username) {
+ return userRoleRepository.loadUserByUserName(username);
+ }
+
+}
diff --git a/spring-security-core/src/main/java/org/baeldung/testmethodsecurity/repository/UserRoleRepository.java b/spring-security-core/src/main/java/org/baeldung/testmethodsecurity/repository/UserRoleRepository.java
deleted file mode 100644
index 565b46262d..0000000000
--- a/spring-security-core/src/main/java/org/baeldung/testmethodsecurity/repository/UserRoleRepository.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package org.baeldung.testmethodsecurity.repository;
-
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.baeldung.testmethodsecurity.entity.CustomUser;
-import org.springframework.security.core.GrantedAuthority;
-import org.springframework.security.core.authority.SimpleGrantedAuthority;
-import org.springframework.security.core.userdetails.UsernameNotFoundException;
-import org.springframework.stereotype.Service;
-
-@Service
-public class UserRoleRepository {
-
- static Map DB_BASED_USER_MAPPING;
-
- static{
- DB_BASED_USER_MAPPING = new LinkedHashMap<>();
- DB_BASED_USER_MAPPING.put("jane", new CustomUser("jane","1234", getGrantedAuthorities("ROLE_USER","ROLE_VIEWER"),"jane"));
- DB_BASED_USER_MAPPING.put("john", new CustomUser("john","1234", getGrantedAuthorities("ROLE_EDITOR","ROLE_ADMIN"),"jane"));
- DB_BASED_USER_MAPPING.put("jack", new CustomUser("jack","1234", getGrantedAuthorities("ROLE_USER","ROLE_REVIEWER"),"jane"));
- }
-
- private static List getGrantedAuthorities(String...roles){
- ArrayList authorities = new ArrayList<>();
- for (String role : roles){
- authorities.add(new SimpleGrantedAuthority(role));
- }
- return authorities;
- }
-
- public CustomUser loadUserByUserName(String username){
- if (DB_BASED_USER_MAPPING.containsKey(username)){
- return DB_BASED_USER_MAPPING.get(username);
- }
- throw new UsernameNotFoundException("User "+username+" cannot be found");
- }
-
-}
diff --git a/spring-security-core/src/main/java/org/baeldung/testmethodsecurity/service/UserRoleService.java b/spring-security-core/src/main/java/org/baeldung/testmethodsecurity/service/UserRoleService.java
deleted file mode 100644
index f4dc6cf335..0000000000
--- a/spring-security-core/src/main/java/org/baeldung/testmethodsecurity/service/UserRoleService.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package org.baeldung.testmethodsecurity.service;
-
-import org.baeldung.testmethodsecurity.entity.CustomUser;
-import org.baeldung.testmethodsecurity.repository.UserRoleRepository;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.access.prepost.PostAuthorize;
-import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.security.core.context.SecurityContext;
-import org.springframework.security.core.context.SecurityContextHolder;
-import org.springframework.stereotype.Service;
-
-@Service
-public class UserRoleService {
-
- @Autowired
- UserRoleRepository userRoleRepository;
-
- @PreAuthorize("hasRole('ROLE_VIEWER') or hasAuthority('SYS_ADMIN')")
- public String getUsername(){
- SecurityContext securityContext = SecurityContextHolder.getContext();
- return securityContext.getAuthentication().getName();
- }
-
- @PostAuthorize("returnObject.username == authentication.principal.nickName")
- public CustomUser loadUserDetail(String username){
- return userRoleRepository.loadUserByUserName(username);
- }
-
-}
diff --git a/spring-security-core/src/test/java/org/baeldung/methodsecurity/TestClassLevelSecurity.java b/spring-security-core/src/test/java/org/baeldung/methodsecurity/TestClassLevelSecurity.java
new file mode 100644
index 0000000000..502fd50c46
--- /dev/null
+++ b/spring-security-core/src/test/java/org/baeldung/methodsecurity/TestClassLevelSecurity.java
@@ -0,0 +1,49 @@
+package org.baeldung.methodsecurity;
+
+import static org.junit.Assert.*;
+
+import org.baeldung.methodsecurity.service.SystemService;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.security.access.AccessDeniedException;
+import org.springframework.security.test.context.support.WithMockUser;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@ContextConfiguration
+public class TestClassLevelSecurity {
+
+ @Autowired
+ SystemService systemService;
+
+ @Configuration
+ @ComponentScan("org.baeldung.methodsecurity.*")
+ public static class SpringConfig {
+
+ }
+
+ @Test
+ @WithMockUser(username="john",roles={"ADMIN"})
+ public void givenRoleAdmin_whenCallGetSystemYear_return2017(){
+ String systemYear = systemService.getSystemYear();
+ assertEquals("2017",systemYear);
+ }
+
+ @Test(expected=AccessDeniedException.class)
+ @WithMockUser(username="john",roles={"VIEWER"})
+ public void givenRoleViewer_whenCallGetSystemYear_returnAccessDenied(){
+ String systemYear = systemService.getSystemYear();
+ assertEquals("2017",systemYear);
+ }
+
+ @Test
+ @WithMockUser(username="john",roles={"ADMIN"})
+ public void givenRoleAdmin_whenCallGetSystemDate_returnDate(){
+ String systemYear = systemService.getSystemDate();
+ assertEquals("31-12-2017",systemYear);
+ }
+}
diff --git a/spring-security-core/src/test/java/org/baeldung/methodsecurity/TestMethodSecurity.java b/spring-security-core/src/test/java/org/baeldung/methodsecurity/TestMethodSecurity.java
new file mode 100644
index 0000000000..309ee3076d
--- /dev/null
+++ b/spring-security-core/src/test/java/org/baeldung/methodsecurity/TestMethodSecurity.java
@@ -0,0 +1,176 @@
+package org.baeldung.methodsecurity;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.baeldung.methodsecurity.service.UserRoleService;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.security.access.AccessDeniedException;
+import org.springframework.security.authentication.AuthenticationCredentialsNotFoundException;
+import org.springframework.security.test.context.support.WithAnonymousUser;
+import org.springframework.security.test.context.support.WithMockUser;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@ContextConfiguration
+public class TestMethodSecurity {
+
+ @Autowired
+ UserRoleService userRoleService;
+
+ @Configuration
+ @ComponentScan("org.baeldung.methodsecurity.*")
+ public static class SpringConfig {
+
+ }
+
+ @Test(expected = AuthenticationCredentialsNotFoundException.class)
+ public void givenNoSecurity_whenCallGetUsername_thenReturnException() {
+ String userName = userRoleService.getUsername();
+ assertEquals("john", userName);
+ }
+
+ @Test
+ @WithMockUser(username = "john", roles = { "VIEWER" })
+ public void givenRoleViewer_whenCallGetUsername_thenReturnUsername() {
+ String userName = userRoleService.getUsername();
+ assertEquals("john", userName);
+ }
+
+ @Test
+ @WithMockUser(username = "john", roles = { "EDITOR" })
+ public void givenUsernameJohn_whenCallIsValidUsername_thenReturnTrue() {
+ boolean isValid = userRoleService.isValidUsername("john");
+ assertEquals(true, isValid);
+ }
+
+ @Test(expected = AccessDeniedException.class)
+ @WithMockUser(username = "john", roles = { "ADMIN" })
+ public void givenRoleAdmin_whenCallGetUsername_thenReturnAccessDenied() {
+ userRoleService.getUsername();
+ }
+
+ @Test(expected = AccessDeniedException.class)
+ @WithMockUser(username = "john", roles = { "USER" })
+ public void givenRoleUser_whenCallGetUsername2_thenReturnAccessDenied() {
+ userRoleService.getUsername2();
+ }
+
+ @Test
+ @WithMockUser(username = "john", roles = { "VIEWER", "EDITOR" })
+ public void givenRoleViewer_whenCallGetUsername2_thenReturnUsername() {
+ String userName = userRoleService.getUsername2();
+ assertEquals("john", userName);
+ }
+
+ @Test
+ @WithMockUser(username = "john", roles = { "VIEWER" })
+ public void givenUsernameJerry_whenCallIsValidUsername2_thenReturnFalse() {
+ boolean isValid = userRoleService.isValidUsername2("jerry");
+ assertEquals(false, isValid);
+ }
+
+ @Test
+ @WithMockUser(username = "JOHN", authorities = { "SYS_ADMIN" })
+ public void givenAuthoritySysAdmin_whenCallGetUsernameInLowerCase_thenReturnUsername() {
+ String username = userRoleService.getUsernameLC();
+ assertEquals("john", username);
+ }
+
+ @Test
+ @WithMockUser(username = "john", roles = { "ADMIN", "USER", "VIEWER" })
+ public void givenUserJohn_whenCallGetMyRolesWithJohn_thenReturnRoles() {
+ String roles = userRoleService.getMyRoles("john");
+ assertEquals("ROLE_ADMIN,ROLE_USER,ROLE_VIEWER", roles);
+ }
+
+ @Test(expected = AccessDeniedException.class)
+ @WithMockUser(username = "john", roles = { "ADMIN", "USER", "VIEWER" })
+ public void givenUserJane_whenCallGetMyRolesWithJane_thenAccessDenied() {
+ userRoleService.getMyRoles("jane");
+ }
+
+ @Test
+ @WithMockUser(username = "john", roles = { "ADMIN", "USER", "VIEWER" })
+ public void givenUserJohn_whenCallGetMyRoles2WithJohn_thenReturnRoles() {
+ String roles = userRoleService.getMyRoles2("john");
+ assertEquals("ROLE_ADMIN,ROLE_USER,ROLE_VIEWER", roles);
+ }
+
+ @Test(expected = AccessDeniedException.class)
+ @WithMockUser(username = "john", roles = { "ADMIN", "USER", "VIEWER" })
+ public void givenUserJane_whenCallGetMyRoles2WithJane_thenAccessDenied() {
+ userRoleService.getMyRoles2("jane");
+ }
+
+ @Test(expected = AccessDeniedException.class)
+ @WithAnonymousUser
+ public void givenAnomynousUser_whenCallGetUsername_thenAccessDenied() {
+ userRoleService.getUsername();
+ }
+
+ @Test
+ @WithMockJohnViewer
+ public void givenMockedJohnViewer_whenCallGetUsername_thenReturnUsername() {
+ String userName = userRoleService.getUsername();
+ assertEquals("john", userName);
+ }
+
+ @Test
+ @WithMockUser(username = "jane")
+ public void givenListContainCurrentUsername_whenJoinUsernames_thenReturnUsernames() {
+ List usernames = new ArrayList<>();
+ usernames.add("jane");
+ usernames.add("john");
+ usernames.add("jack");
+ String containCurrentUser = userRoleService.joinUsernames(usernames);
+ assertEquals("john;jack", containCurrentUser);
+ }
+
+ @Test
+ @WithMockUser(username = "john")
+ public void givenListContainCurrentUsername_whenCallJoinUsernamesAndRoles_thenReturnUsernameAndRoles() {
+ List usernames = new ArrayList<>();
+ usernames.add("jane");
+ usernames.add("john");
+ usernames.add("jack");
+
+ List roles = new ArrayList<>();
+ roles.add("ROLE_ADMIN");
+ roles.add("ROLE_TEST");
+
+ String containCurrentUser = userRoleService.joinUsernamesAndRoles(usernames, roles);
+ assertEquals("jane;jack:ROLE_ADMIN;ROLE_TEST", containCurrentUser);
+ }
+
+ @Test
+ @WithMockUser(username = "john")
+ public void givenUserJohn_whenCallGetAllUsernamesExceptCurrent_thenReturnOtherusernames() {
+ List others = userRoleService.getAllUsernamesExceptCurrent();
+ assertEquals(2, others.size());
+ assertTrue(others.contains("jane"));
+ assertTrue(others.contains("jack"));
+ }
+
+ @Test
+ @WithMockUser(username = "john", roles = { "VIEWER" })
+ public void givenRoleViewer_whenCallGetUsername4_thenReturnUsername() {
+ String userName = userRoleService.getUsername4();
+ assertEquals("john", userName);
+ }
+
+ @Test(expected = AccessDeniedException.class)
+ @WithMockUser(username = "john")
+ public void givenDefaultRole_whenCallGetUsername4_thenAccessDenied() {
+ userRoleService.getUsername4();
+ }
+
+}
\ No newline at end of file
diff --git a/spring-security-core/src/test/java/org/baeldung/testmethodsecurity/TestWithMockUserAtClassLevel.java b/spring-security-core/src/test/java/org/baeldung/methodsecurity/TestWithMockUserAtClassLevel.java
similarity index 72%
rename from spring-security-core/src/test/java/org/baeldung/testmethodsecurity/TestWithMockUserAtClassLevel.java
rename to spring-security-core/src/test/java/org/baeldung/methodsecurity/TestWithMockUserAtClassLevel.java
index a348a7799d..4df1af8ca9 100644
--- a/spring-security-core/src/test/java/org/baeldung/testmethodsecurity/TestWithMockUserAtClassLevel.java
+++ b/spring-security-core/src/test/java/org/baeldung/methodsecurity/TestWithMockUserAtClassLevel.java
@@ -1,8 +1,8 @@
-package org.baeldung.testmethodsecurity;
+package org.baeldung.methodsecurity;
import static org.junit.Assert.assertEquals;
-import org.baeldung.testmethodsecurity.service.UserRoleService;
+import org.baeldung.methodsecurity.service.UserRoleService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -14,20 +14,20 @@ import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@ContextConfiguration
-@WithMockUser(username="john",roles={"VIEWER"})
+@WithMockUser(username = "john", roles = { "VIEWER" })
public class TestWithMockUserAtClassLevel {
-
+
@Test
- public void givenRoleViewer_whenCallGetUsername_thenReturnUsername(){
+ public void givenRoleViewer_whenCallGetUsername_thenReturnUsername() {
String currentUserName = userService.getUsername();
- assertEquals("john",currentUserName);
+ assertEquals("john", currentUserName);
}
-
+
@Autowired
UserRoleService userService;
-
+
@Configuration
- @ComponentScan("org.baeldung.testmethodsecurity.*")
+ @ComponentScan("org.baeldung.methodsecurity.*")
public static class SpringConfig {
}
diff --git a/spring-security-core/src/test/java/org/baeldung/methodsecurity/TestWithUserDetails.java b/spring-security-core/src/test/java/org/baeldung/methodsecurity/TestWithUserDetails.java
new file mode 100644
index 0000000000..3ef5996554
--- /dev/null
+++ b/spring-security-core/src/test/java/org/baeldung/methodsecurity/TestWithUserDetails.java
@@ -0,0 +1,56 @@
+package org.baeldung.methodsecurity;
+
+import static org.junit.Assert.assertEquals;
+
+import org.baeldung.methodsecurity.entity.CustomUser;
+import org.baeldung.methodsecurity.service.UserRoleService;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.security.access.AccessDeniedException;
+import org.springframework.security.test.context.support.WithUserDetails;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@ContextConfiguration
+public class TestWithUserDetails {
+
+ @Autowired
+ UserRoleService userService;
+
+ @Configuration
+ @ComponentScan("org.baeldung.methodsecurity.*")
+ public static class SpringConfig {
+
+ }
+
+ @Test
+ @WithUserDetails(value = "john", userDetailsServiceBeanName = "userDetailService")
+ public void whenJohn_callLoadUserDetail_thenOK() {
+ CustomUser user = userService.loadUserDetail("jane");
+ assertEquals("jane", user.getNickName());
+ }
+
+ @Test
+ @WithUserDetails(value = "jane", userDetailsServiceBeanName = "userDetailService")
+ public void givenJane_callSecuredLoadUserDetailWithJane_thenOK() {
+ CustomUser user = userService.securedLoadUserDetail("jane");
+ assertEquals("jane", user.getNickName());
+ assertEquals("jane", user.getUsername());
+ }
+
+ @Test(expected = AccessDeniedException.class)
+ @WithUserDetails(value = "john", userDetailsServiceBeanName = "userDetailService")
+ public void givenJohn_callSecuredLoadUserDetailWithJane_thenAccessDenied() {
+ userService.securedLoadUserDetail("jane");
+ }
+
+ @Test(expected = AccessDeniedException.class)
+ @WithUserDetails(value = "john", userDetailsServiceBeanName = "userDetailService")
+ public void givenJohn_callSecuredLoadUserDetailWithJohn_thenAccessDenied() {
+ userService.securedLoadUserDetail("john");
+ }
+}
diff --git a/spring-security-core/src/test/java/org/baeldung/testmethodsecurity/WithMockJohnViewer.java b/spring-security-core/src/test/java/org/baeldung/methodsecurity/WithMockJohnViewer.java
similarity index 84%
rename from spring-security-core/src/test/java/org/baeldung/testmethodsecurity/WithMockJohnViewer.java
rename to spring-security-core/src/test/java/org/baeldung/methodsecurity/WithMockJohnViewer.java
index 994fe2e69b..5e1e882f3d 100644
--- a/spring-security-core/src/test/java/org/baeldung/testmethodsecurity/WithMockJohnViewer.java
+++ b/spring-security-core/src/test/java/org/baeldung/methodsecurity/WithMockJohnViewer.java
@@ -1,4 +1,4 @@
-package org.baeldung.testmethodsecurity;
+package org.baeldung.methodsecurity;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
diff --git a/spring-security-core/src/test/java/org/baeldung/testmethodsecurity/TestMethodSecurity.java b/spring-security-core/src/test/java/org/baeldung/testmethodsecurity/TestMethodSecurity.java
deleted file mode 100644
index 671229c726..0000000000
--- a/spring-security-core/src/test/java/org/baeldung/testmethodsecurity/TestMethodSecurity.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package org.baeldung.testmethodsecurity;
-
-import static org.junit.Assert.assertEquals;
-
-import org.baeldung.testmethodsecurity.service.UserRoleService;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.ComponentScan;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.security.access.AccessDeniedException;
-import org.springframework.security.test.context.support.WithAnonymousUser;
-import org.springframework.security.test.context.support.WithMockUser;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringRunner;
-
-@RunWith(SpringRunner.class)
-@ContextConfiguration
-public class TestMethodSecurity{
-
- @Autowired
- UserRoleService userRoleService;
-
- @Configuration
- @ComponentScan("org.baeldung.testmethodsecurity.*")
- public static class SpringConfig {
-
- }
-
- @Test
- @WithMockUser(username="john",roles={"VIEWER"})
- public void givenRoleViewer_whenCallGetUsername_thenReturnUsername(){
- String userName = userRoleService.getUsername();
- assertEquals("john", userName);
- }
-
- @Test
- @WithMockUser(username="john",authorities={"SYS_ADMIN"})
- public void givenAuthoritySysAdmin_whenCallGetUsername_thenReturnUsername(){
- String userName = userRoleService.getUsername();
- assertEquals("john", userName);
- }
-
- @Test(expected=AccessDeniedException.class)
- @WithAnonymousUser
- public void givenAnomynousUser_whenCallGetUsername_thenAccessDenied(){
- userRoleService.getUsername();
- }
-
- @Test
- @WithMockJohnViewer
- public void givenMockedJohnViewer_whenCallGetUsername_thenReturnUsername(){
- String userName = userRoleService.getUsername();
- assertEquals("john", userName);
- }
-
-}
\ No newline at end of file
diff --git a/spring-security-core/src/test/java/org/baeldung/testmethodsecurity/TestWithUserDetails.java b/spring-security-core/src/test/java/org/baeldung/testmethodsecurity/TestWithUserDetails.java
deleted file mode 100644
index ed8ed8cc85..0000000000
--- a/spring-security-core/src/test/java/org/baeldung/testmethodsecurity/TestWithUserDetails.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package org.baeldung.testmethodsecurity;
-
-import static org.junit.Assert.assertEquals;
-
-import org.baeldung.testmethodsecurity.entity.CustomUser;
-import org.baeldung.testmethodsecurity.service.UserRoleService;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.ComponentScan;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.security.test.context.support.WithUserDetails;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringRunner;
-
-@RunWith(SpringRunner.class)
-@ContextConfiguration
-public class TestWithUserDetails {
-
- @Autowired
- UserRoleService userService;
-
- @Configuration
- @ComponentScan("org.baeldung.testmethodsecurity.*")
- public static class SpringConfig {
-
- }
-
- @Test
- @WithUserDetails(value="john",userDetailsServiceBeanName="userDetailService")
- public void whenJohn_callLoadUserDetail_thenOK(){
- CustomUser user = userService.loadUserDetail("jane");
- assertEquals("jane",user.getNickName());
- }
-}
diff --git a/spring-security-mvc-ldap/pom.xml b/spring-security-mvc-ldap/pom.xml
index e6452ea70b..4b0b9525e4 100644
--- a/spring-security-mvc-ldap/pom.xml
+++ b/spring-security-mvc-ldap/pom.xml
@@ -9,10 +9,10 @@
war
- parent-boot-4
+ parent-boot-5
com.baeldung
0.0.1-SNAPSHOT
- ../parent-boot-4
+ ../parent-boot-5
diff --git a/spring-security-rest-custom/pom.xml b/spring-security-rest-custom/pom.xml
index 77a58a56d8..746ddb6615 100644
--- a/spring-security-rest-custom/pom.xml
+++ b/spring-security-rest-custom/pom.xml
@@ -9,10 +9,10 @@
war
- parent-boot-4
+ parent-boot-5
com.baeldung
0.0.1-SNAPSHOT
- ../parent-boot-4
+ ../parent-boot-5
diff --git a/spring-security-stormpath/pom.xml b/spring-security-stormpath/pom.xml
index 982c677bf5..060f8a553d 100644
--- a/spring-security-stormpath/pom.xml
+++ b/spring-security-stormpath/pom.xml
@@ -24,10 +24,10 @@
- parent-boot-4
+ parent-boot-5
com.baeldung
0.0.1-SNAPSHOT
- ../parent-boot-4
+ ../parent-boot-5
diff --git a/spring-security-x509/pom.xml b/spring-security-x509/pom.xml
index 77830ebe5a..6225f73ebc 100644
--- a/spring-security-x509/pom.xml
+++ b/spring-security-x509/pom.xml
@@ -15,10 +15,10 @@
- parent-boot-4
+ parent-boot-5
com.baeldung
0.0.1-SNAPSHOT
- ../parent-boot-4
+ ../parent-boot-5
diff --git a/spring-session/pom.xml b/spring-session/pom.xml
index bb644c8b2e..b62d814665 100644
--- a/spring-session/pom.xml
+++ b/spring-session/pom.xml
@@ -8,10 +8,10 @@
jar
- parent-boot-4
+ parent-boot-5
com.baeldung
0.0.1-SNAPSHOT
- ../parent-boot-4
+ ../parent-boot-5
diff --git a/spring-sleuth/pom.xml b/spring-sleuth/pom.xml
index dda5e09a26..aac0084720 100644
--- a/spring-sleuth/pom.xml
+++ b/spring-sleuth/pom.xml
@@ -9,10 +9,10 @@
jar
- parent-boot-4
+ parent-boot-5
com.baeldung
0.0.1-SNAPSHOT
- ../parent-boot-4
+ ../parent-boot-5
diff --git a/spring-social-login/pom.xml b/spring-social-login/pom.xml
index 0ca04ac298..50e2abfbfc 100644
--- a/spring-social-login/pom.xml
+++ b/spring-social-login/pom.xml
@@ -7,10 +7,10 @@
war
- parent-boot-4
+ parent-boot-5
com.baeldung
0.0.1-SNAPSHOT
- ../parent-boot-4
+ ../parent-boot-5
diff --git a/spring-zuul/pom.xml b/spring-zuul/pom.xml
index e1a551bc84..ca9cbc765d 100644
--- a/spring-zuul/pom.xml
+++ b/spring-zuul/pom.xml
@@ -9,10 +9,10 @@
pom
- parent-boot-4
+ parent-boot-5
com.baeldung
0.0.1-SNAPSHOT
- ../parent-boot-4
+ ../parent-boot-5
diff --git a/spring-zuul/spring-zuul-foos-resource/src/main/java/org/baeldung/config/ResourceServerApplication.java b/spring-zuul/spring-zuul-foos-resource/src/main/java/org/baeldung/config/ResourceServerApplication.java
index 1e35eff551..9f1d2e162b 100644
--- a/spring-zuul/spring-zuul-foos-resource/src/main/java/org/baeldung/config/ResourceServerApplication.java
+++ b/spring-zuul/spring-zuul-foos-resource/src/main/java/org/baeldung/config/ResourceServerApplication.java
@@ -2,7 +2,7 @@ package org.baeldung.config;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.boot.context.web.SpringBootServletInitializer;
+import org.springframework.boot.web.support.SpringBootServletInitializer;
@SpringBootApplication
public class ResourceServerApplication extends SpringBootServletInitializer {
diff --git a/vavr/README.md b/vavr/README.md
index 4361363fbd..d39c9f36a1 100644
--- a/vavr/README.md
+++ b/vavr/README.md
@@ -8,3 +8,5 @@
- [Introduction to Vavr’s Validation API](http://www.baeldung.com/vavr-validation-api)
- [Guide to Collections API in Vavr](http://www.baeldung.com/vavr-collections)
- [Collection Factory Methods for Vavr](http://www.baeldung.com/vavr-collection-factory-methods)
+- [Introduction to Future in Vavr](http://www.baeldung.com/vavr-future)
+
diff --git a/vavr/src/test/java/com/baeldung/vavr/future/FutureTest.java b/vavr/src/test/java/com/baeldung/vavr/future/FutureTest.java
index 002919a937..d5345cad55 100644
--- a/vavr/src/test/java/com/baeldung/vavr/future/FutureTest.java
+++ b/vavr/src/test/java/com/baeldung/vavr/future/FutureTest.java
@@ -58,6 +58,14 @@ public class FutureTest {
assertThat(result)
.isEqualTo(HELLO);
}
+
+ @Test
+ public void whenTransform_thenCorrect() {
+ Future