From 540e719c11bdd91c8e686785d495140778bef83e Mon Sep 17 00:00:00 2001 From: Amit Pandey Date: Mon, 14 Sep 2020 21:51:24 +0530 Subject: [PATCH] moved spring-security-web-jsonview module to spring-security-core (#10015) * moved spring-security-web-jsonview module to spring-security-core * removed deleted module from project build --- spring-security-modules/pom.xml | 1 - .../spring-security-core/README.md | 1 + .../java/com/baeldung/filterresponse/App.java | 13 ++ .../filterresponse/config}/AppConfig.java | 6 +- .../SecurityJsonViewControllerAdvice.java | 11 +- .../controller/ItemsController.java | 12 +- .../filterresponse}/controller/View.java | 5 +- .../baeldung/filterresponse}/model/Item.java | 4 +- ...SpringSecurityJsonViewIntegrationTest.java | 4 +- .../spring-security-web-jsonview/.gitignore | 13 -- .../spring-security-web-jsonview/README.md | 7 - .../spring-security-web-jsonview/pom.xml | 206 ------------------ .../java/com/baeldung/AppInitializer.java | 33 --- .../src/main/resources/logback.xml | 19 -- .../java/com/baeldung/SpringContextTest.java | 17 -- 15 files changed, 34 insertions(+), 318 deletions(-) create mode 100644 spring-security-modules/spring-security-core/src/main/java/com/baeldung/filterresponse/App.java rename spring-security-modules/{spring-security-web-jsonview/src/main/java/com/baeldung/spring => spring-security-core/src/main/java/com/baeldung/filterresponse/config}/AppConfig.java (95%) rename spring-security-modules/{spring-security-web-jsonview/src/main/java/com/baeldung/spring => spring-security-core/src/main/java/com/baeldung/filterresponse/config}/SecurityJsonViewControllerAdvice.java (95%) rename spring-security-modules/{spring-security-web-jsonview/src/main/java/com/baeldung => spring-security-core/src/main/java/com/baeldung/filterresponse}/controller/ItemsController.java (68%) rename spring-security-modules/{spring-security-web-jsonview/src/main/java/com/baeldung => spring-security-core/src/main/java/com/baeldung/filterresponse}/controller/View.java (76%) rename spring-security-modules/{spring-security-web-jsonview/src/main/java/com/baeldung => spring-security-core/src/main/java/com/baeldung/filterresponse}/model/Item.java (85%) rename spring-security-modules/{spring-security-web-jsonview/src/test/java/com/baeldung/security => spring-security-core/src/test/java/com/baeldung/filterresponse}/SpringSecurityJsonViewIntegrationTest.java (97%) delete mode 100644 spring-security-modules/spring-security-web-jsonview/.gitignore delete mode 100644 spring-security-modules/spring-security-web-jsonview/README.md delete mode 100644 spring-security-modules/spring-security-web-jsonview/pom.xml delete mode 100644 spring-security-modules/spring-security-web-jsonview/src/main/java/com/baeldung/AppInitializer.java delete mode 100644 spring-security-modules/spring-security-web-jsonview/src/main/resources/logback.xml delete mode 100644 spring-security-modules/spring-security-web-jsonview/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-security-modules/pom.xml b/spring-security-modules/pom.xml index b68138964b..d5c0c0dd6e 100644 --- a/spring-security-modules/pom.xml +++ b/spring-security-modules/pom.xml @@ -24,7 +24,6 @@ spring-security-web-boot-2 spring-security-web-mvc-custom spring-security-web-digest-auth - spring-security-web-jsonview spring-security-ldap spring-security-web-login spring-security-web-persisted-remember-me diff --git a/spring-security-modules/spring-security-core/README.md b/spring-security-modules/spring-security-core/README.md index f28b3abb2b..9f8e4dda53 100644 --- a/spring-security-modules/spring-security-core/README.md +++ b/spring-security-modules/spring-security-core/README.md @@ -9,6 +9,7 @@ This module contains articles about core Spring Security - [Overview and Need for DelegatingFilterProxy in Spring](https://www.baeldung.com/spring-delegating-filter-proxy) - [Deny Access on Missing @PreAuthorize to Spring Controller Methods](https://www.baeldung.com/spring-deny-access) - [Spring Security: Check If a User Has a Role in Java](https://www.baeldung.com/spring-security-check-user-role) +- [Filtering Jackson JSON Output Based on Spring Security Role](https://www.baeldung.com/spring-security-role-filter-json) ### Build the Project diff --git a/spring-security-modules/spring-security-core/src/main/java/com/baeldung/filterresponse/App.java b/spring-security-modules/spring-security-core/src/main/java/com/baeldung/filterresponse/App.java new file mode 100644 index 0000000000..a5389e93d3 --- /dev/null +++ b/spring-security-modules/spring-security-core/src/main/java/com/baeldung/filterresponse/App.java @@ -0,0 +1,13 @@ +package com.baeldung.filterresponse; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class App { + + public static void main(String[] args) { + SpringApplication.run(App.class, args); + } + +} diff --git a/spring-security-modules/spring-security-web-jsonview/src/main/java/com/baeldung/spring/AppConfig.java b/spring-security-modules/spring-security-core/src/main/java/com/baeldung/filterresponse/config/AppConfig.java similarity index 95% rename from spring-security-modules/spring-security-web-jsonview/src/main/java/com/baeldung/spring/AppConfig.java rename to spring-security-modules/spring-security-core/src/main/java/com/baeldung/filterresponse/config/AppConfig.java index 10b2d2447e..8ff6000129 100644 --- a/spring-security-modules/spring-security-web-jsonview/src/main/java/com/baeldung/spring/AppConfig.java +++ b/spring-security-modules/spring-security-core/src/main/java/com/baeldung/filterresponse/config/AppConfig.java @@ -1,4 +1,4 @@ -package com.baeldung.spring; +package com.baeldung.filterresponse.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -12,12 +12,10 @@ import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; -import java.util.Arrays; - @Configuration @EnableWebMvc @EnableWebSecurity -@ComponentScan("com.baeldung") +@ComponentScan("com.baeldung.filterresponse") public class AppConfig extends WebSecurityConfigurerAdapter implements WebMvcConfigurer { @Override diff --git a/spring-security-modules/spring-security-web-jsonview/src/main/java/com/baeldung/spring/SecurityJsonViewControllerAdvice.java b/spring-security-modules/spring-security-core/src/main/java/com/baeldung/filterresponse/config/SecurityJsonViewControllerAdvice.java similarity index 95% rename from spring-security-modules/spring-security-web-jsonview/src/main/java/com/baeldung/spring/SecurityJsonViewControllerAdvice.java rename to spring-security-modules/spring-security-core/src/main/java/com/baeldung/filterresponse/config/SecurityJsonViewControllerAdvice.java index d6d022a110..d0ba0adcf5 100644 --- a/spring-security-modules/spring-security-web-jsonview/src/main/java/com/baeldung/spring/SecurityJsonViewControllerAdvice.java +++ b/spring-security-modules/spring-security-core/src/main/java/com/baeldung/filterresponse/config/SecurityJsonViewControllerAdvice.java @@ -1,6 +1,9 @@ -package com.baeldung.spring; +package com.baeldung.filterresponse.config; + +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; -import com.baeldung.controller.View; import org.springframework.core.MethodParameter; import org.springframework.http.MediaType; import org.springframework.http.converter.json.MappingJacksonValue; @@ -11,9 +14,7 @@ import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.servlet.mvc.method.annotation.AbstractMappingJacksonResponseBodyAdvice; -import java.util.Collection; -import java.util.List; -import java.util.stream.Collectors; +import com.baeldung.filterresponse.controller.View; @RestControllerAdvice public class SecurityJsonViewControllerAdvice extends AbstractMappingJacksonResponseBodyAdvice { diff --git a/spring-security-modules/spring-security-web-jsonview/src/main/java/com/baeldung/controller/ItemsController.java b/spring-security-modules/spring-security-core/src/main/java/com/baeldung/filterresponse/controller/ItemsController.java similarity index 68% rename from spring-security-modules/spring-security-web-jsonview/src/main/java/com/baeldung/controller/ItemsController.java rename to spring-security-modules/spring-security-core/src/main/java/com/baeldung/filterresponse/controller/ItemsController.java index 16268a239b..f5fd4ee7f1 100644 --- a/spring-security-modules/spring-security-web-jsonview/src/main/java/com/baeldung/controller/ItemsController.java +++ b/spring-security-modules/spring-security-core/src/main/java/com/baeldung/filterresponse/controller/ItemsController.java @@ -1,14 +1,12 @@ -package com.baeldung.controller; +package com.baeldung.filterresponse.controller; + +import java.util.Arrays; +import java.util.Collection; -import com.baeldung.model.Item; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; +import com.baeldung.filterresponse.model.Item; @RestController public class ItemsController { diff --git a/spring-security-modules/spring-security-web-jsonview/src/main/java/com/baeldung/controller/View.java b/spring-security-modules/spring-security-core/src/main/java/com/baeldung/filterresponse/controller/View.java similarity index 76% rename from spring-security-modules/spring-security-web-jsonview/src/main/java/com/baeldung/controller/View.java rename to spring-security-modules/spring-security-core/src/main/java/com/baeldung/filterresponse/controller/View.java index 10ae50adef..3099807578 100644 --- a/spring-security-modules/spring-security-web-jsonview/src/main/java/com/baeldung/controller/View.java +++ b/spring-security-modules/spring-security-core/src/main/java/com/baeldung/filterresponse/controller/View.java @@ -1,10 +1,11 @@ -package com.baeldung.controller; +package com.baeldung.filterresponse.controller; -import com.baeldung.spring.AppConfig.Role; import java.util.HashMap; import java.util.Map; +import com.baeldung.filterresponse.config.AppConfig.Role; + public class View { public static final Map MAPPING = new HashMap<>(); diff --git a/spring-security-modules/spring-security-web-jsonview/src/main/java/com/baeldung/model/Item.java b/spring-security-modules/spring-security-core/src/main/java/com/baeldung/filterresponse/model/Item.java similarity index 85% rename from spring-security-modules/spring-security-web-jsonview/src/main/java/com/baeldung/model/Item.java rename to spring-security-modules/spring-security-core/src/main/java/com/baeldung/filterresponse/model/Item.java index 002ee73e4f..9ebdc6bad0 100644 --- a/spring-security-modules/spring-security-web-jsonview/src/main/java/com/baeldung/model/Item.java +++ b/spring-security-modules/spring-security-core/src/main/java/com/baeldung/filterresponse/model/Item.java @@ -1,6 +1,6 @@ -package com.baeldung.model; +package com.baeldung.filterresponse.model; -import com.baeldung.controller.View; +import com.baeldung.filterresponse.controller.View; import com.fasterxml.jackson.annotation.JsonView; public class Item { diff --git a/spring-security-modules/spring-security-web-jsonview/src/test/java/com/baeldung/security/SpringSecurityJsonViewIntegrationTest.java b/spring-security-modules/spring-security-core/src/test/java/com/baeldung/filterresponse/SpringSecurityJsonViewIntegrationTest.java similarity index 97% rename from spring-security-modules/spring-security-web-jsonview/src/test/java/com/baeldung/security/SpringSecurityJsonViewIntegrationTest.java rename to spring-security-modules/spring-security-core/src/test/java/com/baeldung/filterresponse/SpringSecurityJsonViewIntegrationTest.java index 626c8cb497..fc821b5175 100644 --- a/spring-security-modules/spring-security-web-jsonview/src/test/java/com/baeldung/security/SpringSecurityJsonViewIntegrationTest.java +++ b/spring-security-modules/spring-security-core/src/test/java/com/baeldung/filterresponse/SpringSecurityJsonViewIntegrationTest.java @@ -1,6 +1,6 @@ -package com.baeldung.security; +package com.baeldung.filterresponse; -import com.baeldung.spring.AppConfig; +import com.baeldung.filterresponse.config.AppConfig; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.junit.Before; diff --git a/spring-security-modules/spring-security-web-jsonview/.gitignore b/spring-security-modules/spring-security-web-jsonview/.gitignore deleted file mode 100644 index 83c05e60c8..0000000000 --- a/spring-security-modules/spring-security-web-jsonview/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -*.class - -#folders# -/target -/neoDb* -/data -/src/main/webapp/WEB-INF/classes -*/META-INF/* - -# Packaged files # -*.jar -*.war -*.ear \ No newline at end of file diff --git a/spring-security-modules/spring-security-web-jsonview/README.md b/spring-security-modules/spring-security-web-jsonview/README.md deleted file mode 100644 index 83f8106df9..0000000000 --- a/spring-security-modules/spring-security-web-jsonview/README.md +++ /dev/null @@ -1,7 +0,0 @@ -## Spring Security Web Json View - -This module contains articles about Spring Security with JSON - -### Relevant Articles: - -- [Filtering Jackson JSON Output Based on Spring Security Role](https://www.baeldung.com/spring-security-role-filter-json) diff --git a/spring-security-modules/spring-security-web-jsonview/pom.xml b/spring-security-modules/spring-security-web-jsonview/pom.xml deleted file mode 100644 index 0d1b0b09db..0000000000 --- a/spring-security-modules/spring-security-web-jsonview/pom.xml +++ /dev/null @@ -1,206 +0,0 @@ - - - 4.0.0 - spring-security-web-jsonview - 0.1-SNAPSHOT - spring-security-web-jsonview - war - - - com.baeldung - parent-spring-5 - 0.0.1-SNAPSHOT - ../../parent-spring-5 - - - - - com.fasterxml.jackson.core - jackson-core - ${jackson.version} - - - com.fasterxml.jackson.core - jackson-annotations - ${jackson.version} - - - com.fasterxml.jackson.core - jackson-databind - ${jackson.version} - - - - - - org.springframework.security - spring-security-web - ${spring-security.version} - - - org.springframework.security - spring-security-config - ${spring-security.version} - - - org.springframework.security - spring-security-taglibs - ${spring-security.version} - - - - - - org.springframework - spring-core - ${spring.version} - - - commons-logging - commons-logging - - - - - org.springframework - spring-context - ${spring.version} - - - org.springframework - spring-jdbc - ${spring.version} - - - org.springframework - spring-beans - ${spring.version} - - - org.springframework - spring-aop - ${spring.version} - - - org.springframework - spring-tx - ${spring.version} - - - org.springframework - spring-expression - ${spring.version} - - - - org.springframework - spring-web - ${spring.version} - - - org.springframework - spring-webmvc - ${spring.version} - - - - - - javax.servlet - javax.servlet-api - ${javax.servlet-api.version} - provided - - - - javax.servlet - jstl - ${jstl.version} - runtime - - - - - - org.springframework - spring-test - ${spring.version} - test - - - org.springframework.security - spring-security-test - ${spring-security.version} - test - - - com.jayway.jsonpath - json-path - ${json-path.version} - test - - - - - spring-security-mvc-jsonview - - - src/main/resources - true - - - - - org.apache.maven.plugins - maven-war-plugin - ${maven-war-plugin.version} - - - default-war - prepare-package - - false - - - - - - - org.codehaus.cargo - cargo-maven2-plugin - ${cargo-maven2-plugin.version} - - - - ${project.build.directory}/${project.name}.war - war - - / - - - - - 2400000 - tomcat8x - embedded - - - - - - - 8084 - - - - - - - - - 1.6.1 - 2.4.0 - - - \ No newline at end of file diff --git a/spring-security-modules/spring-security-web-jsonview/src/main/java/com/baeldung/AppInitializer.java b/spring-security-modules/spring-security-web-jsonview/src/main/java/com/baeldung/AppInitializer.java deleted file mode 100644 index 4f38d190eb..0000000000 --- a/spring-security-modules/spring-security-web-jsonview/src/main/java/com/baeldung/AppInitializer.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.baeldung; - -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.ServletRegistration; - -import org.springframework.web.WebApplicationInitializer; -import org.springframework.web.context.ContextLoaderListener; -import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; -import org.springframework.web.context.support.GenericWebApplicationContext; -import org.springframework.web.filter.DelegatingFilterProxy; -import org.springframework.web.servlet.DispatcherServlet; - -public class AppInitializer implements WebApplicationInitializer { - - @Override - public void onStartup(final ServletContext sc) throws ServletException { - - AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext(); - - root.scan("com.baeldung"); - sc.addListener(new ContextLoaderListener(root)); - - ServletRegistration.Dynamic appServlet = sc.addServlet("mvc", new DispatcherServlet(new GenericWebApplicationContext())); - appServlet.setLoadOnStartup(1); - appServlet.addMapping("/"); - - sc.addFilter("securityFilter", new DelegatingFilterProxy("springSecurityFilterChain")) - .addMappingForUrlPatterns(null, false, "/*"); - - } - -} diff --git a/spring-security-modules/spring-security-web-jsonview/src/main/resources/logback.xml b/spring-security-modules/spring-security-web-jsonview/src/main/resources/logback.xml deleted file mode 100644 index 56af2d397e..0000000000 --- a/spring-security-modules/spring-security-web-jsonview/src/main/resources/logback.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - - - - - - - - \ No newline at end of file diff --git a/spring-security-modules/spring-security-web-jsonview/src/test/java/com/baeldung/SpringContextTest.java b/spring-security-modules/spring-security-web-jsonview/src/test/java/com/baeldung/SpringContextTest.java deleted file mode 100644 index b1a3de714e..0000000000 --- a/spring-security-modules/spring-security-web-jsonview/src/test/java/com/baeldung/SpringContextTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung; - -import com.baeldung.spring.AppConfig; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = AppConfig.class) -@WebAppConfiguration -public class SpringContextTest { - @Test - public void whenSpringContextIsBootstrapped_thenNoExceptions() { - } -}