From 1cb252d05232eb866ccac4915d62e49da41b5a13 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Wed, 17 Jan 2018 22:57:20 +0200 Subject: [PATCH] refactor cloud security ex --- .../spring-cloud-security/authserver/pom.xml | 2 +- .../auth => baeldung}/AuthServer.java | 7 +--- .../config/AuthServerConfigurer.java | 2 +- .../config/ResourceServerConfigurer.java | 5 +-- .../config/WebMvcConfigurer.java | 5 +-- .../config/WebSecurityConfigurer.java | 4 +- .../controller/ResourceController.java | 2 +- .../pom.xml | 8 ++-- .../main/java/com/baeldung}/CloudSite.java | 8 ++-- .../config/SiteSecurityConfigurer.java | 2 +- .../controller/CloudSiteController.java | 29 +++++--------- .../com/baeldung/filters/SimpleFilter.java | 39 +++++++++++++++++++ .../src/main/resources/application.properties | 0 .../src/main/resources/application.yml | 0 .../main/resources/templates/personinfo.html | 13 +++++++ .../Springoath2ApplicationTests.java | 0 .../{personservice => personresource}/pom.xml | 8 ++-- .../main/java/com/baeldung/Application.java} | 6 +-- .../baeldung}/config/ResourceConfigurer.java | 4 +- .../controller/PersonInfoController.java | 21 ++++++++++ .../main/java/com/baeldung}/model/Person.java | 22 +++++++---- .../src/main/resources/application.yml | 3 -- .../PersonserviceApplicationTests.java | 6 +-- .../controller/PersonInfoController.java | 31 --------------- .../cloudsite/filters/pre/SimpleFilter.java | 39 ------------------- .../src/main/resources/application.properties | 0 .../main/resources/templates/personinfo.html | 32 --------------- 27 files changed, 127 insertions(+), 171 deletions(-) rename spring-cloud/spring-cloud-security/authserver/src/main/java/com/{cloudsecurity/auth => baeldung}/AuthServer.java (58%) rename spring-cloud/spring-cloud-security/authserver/src/main/java/com/{cloudsecurity/auth => baeldung}/config/AuthServerConfigurer.java (98%) rename spring-cloud/spring-cloud-security/authserver/src/main/java/com/{cloudsecurity/auth => baeldung}/config/ResourceServerConfigurer.java (94%) rename spring-cloud/spring-cloud-security/authserver/src/main/java/com/{cloudsecurity/auth => baeldung}/config/WebMvcConfigurer.java (91%) rename spring-cloud/spring-cloud-security/authserver/src/main/java/com/{cloudsecurity/auth => baeldung}/config/WebSecurityConfigurer.java (90%) rename spring-cloud/spring-cloud-security/authserver/src/main/java/com/{cloudsecurity/auth => baeldung}/controller/ResourceController.java (91%) rename spring-cloud/spring-cloud-security/{springoath2client => oauth2client}/pom.xml (95%) rename spring-cloud/spring-cloud-security/{springoath2client/src/main/java/com/cloud/springwebsite => oauth2client/src/main/java/com/baeldung}/CloudSite.java (73%) rename spring-cloud/spring-cloud-security/{springoath2client/src/main/java/com/cloud/springwebsite => oauth2client/src/main/java/com/baeldung}/config/SiteSecurityConfigurer.java (97%) rename spring-cloud/spring-cloud-security/{springoath2client/src/main/java/com/cloud/springwebsite => oauth2client/src/main/java/com/baeldung}/controller/CloudSiteController.java (51%) create mode 100644 spring-cloud/spring-cloud-security/oauth2client/src/main/java/com/baeldung/filters/SimpleFilter.java rename spring-cloud/spring-cloud-security/{personservice => oauth2client}/src/main/resources/application.properties (100%) rename spring-cloud/spring-cloud-security/{springoath2client => oauth2client}/src/main/resources/application.yml (100%) create mode 100644 spring-cloud/spring-cloud-security/oauth2client/src/main/resources/templates/personinfo.html rename spring-cloud/spring-cloud-security/{springoath2client => oauth2client}/src/test/java/com/example/springoath2/Springoath2ApplicationTests.java (100%) rename spring-cloud/spring-cloud-security/{personservice => personresource}/pom.xml (93%) rename spring-cloud/spring-cloud-security/{personservice/src/main/java/com/baeldung/service/personservice/PersonserviceApplication.java => personresource/src/main/java/com/baeldung/Application.java} (56%) rename spring-cloud/spring-cloud-security/{personservice/src/main/java/com/baeldung/service/personservice => personresource/src/main/java/com/baeldung}/config/ResourceConfigurer.java (94%) create mode 100644 spring-cloud/spring-cloud-security/personresource/src/main/java/com/baeldung/controller/PersonInfoController.java rename spring-cloud/spring-cloud-security/{personservice/src/main/java/com/baeldung/service => personresource/src/main/java/com/baeldung}/model/Person.java (92%) rename spring-cloud/spring-cloud-security/{personservice => personresource}/src/main/resources/application.yml (95%) rename spring-cloud/spring-cloud-security/{personservice => personresource}/src/test/java/com/baeldung/service/personservice/PersonserviceApplicationTests.java (86%) delete mode 100644 spring-cloud/spring-cloud-security/personservice/src/main/java/com/baeldung/service/personservice/controller/PersonInfoController.java delete mode 100644 spring-cloud/spring-cloud-security/springoath2client/src/main/java/com/cloudsite/filters/pre/SimpleFilter.java delete mode 100644 spring-cloud/spring-cloud-security/springoath2client/src/main/resources/application.properties delete mode 100644 spring-cloud/spring-cloud-security/springoath2client/src/main/resources/templates/personinfo.html diff --git a/spring-cloud/spring-cloud-security/authserver/pom.xml b/spring-cloud/spring-cloud-security/authserver/pom.xml index ab30f3f2ec..ed88ac046b 100644 --- a/spring-cloud/spring-cloud-security/authserver/pom.xml +++ b/spring-cloud/spring-cloud-security/authserver/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.baeldung - auth-server + authserver 0.0.1-SNAPSHOT diff --git a/spring-cloud/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/AuthServer.java b/spring-cloud/spring-cloud-security/authserver/src/main/java/com/baeldung/AuthServer.java similarity index 58% rename from spring-cloud/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/AuthServer.java rename to spring-cloud/spring-cloud-security/authserver/src/main/java/com/baeldung/AuthServer.java index 33b2391437..c5b330b0e3 100644 --- a/spring-cloud/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/AuthServer.java +++ b/spring-cloud/spring-cloud-security/authserver/src/main/java/com/baeldung/AuthServer.java @@ -1,15 +1,12 @@ -package com.cloudsecurity.auth; +package com.baeldung; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.*; - @SpringBootApplication public class AuthServer { public static void main(String[] args) { - // TODO Auto-generated method stub - SpringApplication.run( - AuthServer.class, args); + SpringApplication.run(AuthServer.class, args); } } \ No newline at end of file diff --git a/spring-cloud/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/AuthServerConfigurer.java b/spring-cloud/spring-cloud-security/authserver/src/main/java/com/baeldung/config/AuthServerConfigurer.java similarity index 98% rename from spring-cloud/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/AuthServerConfigurer.java rename to spring-cloud/spring-cloud-security/authserver/src/main/java/com/baeldung/config/AuthServerConfigurer.java index 78bae59b7d..32e445f998 100644 --- a/spring-cloud/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/AuthServerConfigurer.java +++ b/spring-cloud/spring-cloud-security/authserver/src/main/java/com/baeldung/config/AuthServerConfigurer.java @@ -1,4 +1,4 @@ -package com.cloudsecurity.auth.config; +package com.baeldung.config; import java.security.KeyPair; diff --git a/spring-cloud/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/ResourceServerConfigurer.java b/spring-cloud/spring-cloud-security/authserver/src/main/java/com/baeldung/config/ResourceServerConfigurer.java similarity index 94% rename from spring-cloud/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/ResourceServerConfigurer.java rename to spring-cloud/spring-cloud-security/authserver/src/main/java/com/baeldung/config/ResourceServerConfigurer.java index 06a4679f8b..f97544dc59 100644 --- a/spring-cloud/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/ResourceServerConfigurer.java +++ b/spring-cloud/spring-cloud-security/authserver/src/main/java/com/baeldung/config/ResourceServerConfigurer.java @@ -1,4 +1,4 @@ -package com.cloudsecurity.auth.config; +package com.baeldung.config; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; @@ -11,9 +11,6 @@ import org.springframework.security.oauth2.config.annotation.web.configuration.R @Configuration @EnableResourceServer public class ResourceServerConfigurer extends ResourceServerConfigurerAdapter { - - - @Override public void configure(HttpSecurity http) throws Exception { http.antMatcher("/user") diff --git a/spring-cloud/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/WebMvcConfigurer.java b/spring-cloud/spring-cloud-security/authserver/src/main/java/com/baeldung/config/WebMvcConfigurer.java similarity index 91% rename from spring-cloud/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/WebMvcConfigurer.java rename to spring-cloud/spring-cloud-security/authserver/src/main/java/com/baeldung/config/WebMvcConfigurer.java index 839908fcc2..23b56151e7 100644 --- a/spring-cloud/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/WebMvcConfigurer.java +++ b/spring-cloud/spring-cloud-security/authserver/src/main/java/com/baeldung/config/WebMvcConfigurer.java @@ -1,10 +1,9 @@ -package com.cloudsecurity.auth.config; +package com.baeldung.config; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; - @Configuration public class WebMvcConfigurer extends WebMvcConfigurerAdapter { @@ -12,4 +11,4 @@ public class WebMvcConfigurer extends WebMvcConfigurerAdapter { public void addViewControllers(ViewControllerRegistry registry) { registry.addViewController("login").setViewName("login"); } -} +} \ No newline at end of file diff --git a/spring-cloud/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/WebSecurityConfigurer.java b/spring-cloud/spring-cloud-security/authserver/src/main/java/com/baeldung/config/WebSecurityConfigurer.java similarity index 90% rename from spring-cloud/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/WebSecurityConfigurer.java rename to spring-cloud/spring-cloud-security/authserver/src/main/java/com/baeldung/config/WebSecurityConfigurer.java index 8934333d5a..44406b8fa0 100644 --- a/spring-cloud/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/config/WebSecurityConfigurer.java +++ b/spring-cloud/spring-cloud-security/authserver/src/main/java/com/baeldung/config/WebSecurityConfigurer.java @@ -1,6 +1,5 @@ -package com.cloudsecurity.auth.config; +package com.baeldung.config; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; @@ -9,7 +8,6 @@ import org.springframework.security.config.annotation.web.configuration.EnableWe import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.core.userdetails.UserDetailsService; -import org.springframework.security.oauth2.client.OAuth2ClientContext; import org.springframework.security.oauth2.config.annotation.web.configuration.EnableOAuth2Client; @Configuration diff --git a/spring-cloud/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/controller/ResourceController.java b/spring-cloud/spring-cloud-security/authserver/src/main/java/com/baeldung/controller/ResourceController.java similarity index 91% rename from spring-cloud/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/controller/ResourceController.java rename to spring-cloud/spring-cloud-security/authserver/src/main/java/com/baeldung/controller/ResourceController.java index 684181fcbb..739a6f6240 100644 --- a/spring-cloud/spring-cloud-security/authserver/src/main/java/com/cloudsecurity/auth/controller/ResourceController.java +++ b/spring-cloud/spring-cloud-security/authserver/src/main/java/com/baeldung/controller/ResourceController.java @@ -1,4 +1,4 @@ -package com.cloudsecurity.auth.controller; +package com.baeldung.controller; import java.security.Principal; import org.springframework.web.bind.annotation.RequestMapping; diff --git a/spring-cloud/spring-cloud-security/springoath2client/pom.xml b/spring-cloud/spring-cloud-security/oauth2client/pom.xml similarity index 95% rename from spring-cloud/spring-cloud-security/springoath2client/pom.xml rename to spring-cloud/spring-cloud-security/oauth2client/pom.xml index 833a377410..fd1c6964e1 100644 --- a/spring-cloud/spring-cloud-security/springoath2client/pom.xml +++ b/spring-cloud/spring-cloud-security/oauth2client/pom.xml @@ -2,18 +2,18 @@ 4.0.0 - com.example - springoath2 + com.baeldung + oauth2client 0.0.1-SNAPSHOT jar - springoath2 + oauth2client Demo project for Spring Boot org.springframework.boot spring-boot-starter-parent - 1.5.8.RELEASE + 1.5.9.RELEASE diff --git a/spring-cloud/spring-cloud-security/springoath2client/src/main/java/com/cloud/springwebsite/CloudSite.java b/spring-cloud/spring-cloud-security/oauth2client/src/main/java/com/baeldung/CloudSite.java similarity index 73% rename from spring-cloud/spring-cloud-security/springoath2client/src/main/java/com/cloud/springwebsite/CloudSite.java rename to spring-cloud/spring-cloud-security/oauth2client/src/main/java/com/baeldung/CloudSite.java index 9cfea2faea..a072605ec0 100644 --- a/spring-cloud/spring-cloud-security/springoath2client/src/main/java/com/cloud/springwebsite/CloudSite.java +++ b/spring-cloud/spring-cloud-security/oauth2client/src/main/java/com/baeldung/CloudSite.java @@ -1,20 +1,18 @@ -package com.cloud.springwebsite; +package com.baeldung; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.cloud.netflix.zuul.EnableZuulProxy; import org.springframework.context.annotation.Bean; -import com.cloudsite.filters.pre.SimpleFilter; +import com.baeldung.filters.SimpleFilter; @SpringBootApplication public class CloudSite { public static void main(String[] args) { SpringApplication.run(CloudSite.class, args); - } - + } @Bean public SimpleFilter simpleFilter() { diff --git a/spring-cloud/spring-cloud-security/springoath2client/src/main/java/com/cloud/springwebsite/config/SiteSecurityConfigurer.java b/spring-cloud/spring-cloud-security/oauth2client/src/main/java/com/baeldung/config/SiteSecurityConfigurer.java similarity index 97% rename from spring-cloud/spring-cloud-security/springoath2client/src/main/java/com/cloud/springwebsite/config/SiteSecurityConfigurer.java rename to spring-cloud/spring-cloud-security/oauth2client/src/main/java/com/baeldung/config/SiteSecurityConfigurer.java index af002080be..217edb22fb 100644 --- a/spring-cloud/spring-cloud-security/springoath2client/src/main/java/com/cloud/springwebsite/config/SiteSecurityConfigurer.java +++ b/spring-cloud/spring-cloud-security/oauth2client/src/main/java/com/baeldung/config/SiteSecurityConfigurer.java @@ -1,4 +1,4 @@ -package com.cloud.springwebsite.config; +package com.baeldung.config; import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso; import org.springframework.cloud.netflix.zuul.EnableZuulProxy; diff --git a/spring-cloud/spring-cloud-security/springoath2client/src/main/java/com/cloud/springwebsite/controller/CloudSiteController.java b/spring-cloud/spring-cloud-security/oauth2client/src/main/java/com/baeldung/controller/CloudSiteController.java similarity index 51% rename from spring-cloud/spring-cloud-security/springoath2client/src/main/java/com/cloud/springwebsite/controller/CloudSiteController.java rename to spring-cloud/spring-cloud-security/oauth2client/src/main/java/com/baeldung/controller/CloudSiteController.java index 829648b43f..b6bfd0bcf6 100644 --- a/spring-cloud/spring-cloud-security/springoath2client/src/main/java/com/cloud/springwebsite/controller/CloudSiteController.java +++ b/spring-cloud/spring-cloud-security/oauth2client/src/main/java/com/baeldung/controller/CloudSiteController.java @@ -1,11 +1,7 @@ -package com.cloud.springwebsite.controller; - -import java.net.URI; +package com.baeldung.controller; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestOperations; @@ -13,27 +9,22 @@ import org.springframework.web.servlet.ModelAndView; @RestController public class CloudSiteController { - + @Autowired private RestOperations restOperations; - - @Value("${person.url}") - private String personUrl; - - - @RequestMapping("/") + @GetMapping("/") @ResponseBody public String helloFromBaeldung() { return "Hello From Baeldung!"; } - - @RequestMapping("/person") - public ModelAndView person(){ + @GetMapping("/person") + public ModelAndView person() { ModelAndView mav = new ModelAndView("personinfo"); - mav.addObject("person",restOperations.getForObject(personUrl, String.class)); - return mav; + String personResourceUrl = "http://localhost:9000/personResource"; + mav.addObject("person", restOperations.getForObject(personResourceUrl, String.class)); + return mav; } - + } \ No newline at end of file diff --git a/spring-cloud/spring-cloud-security/oauth2client/src/main/java/com/baeldung/filters/SimpleFilter.java b/spring-cloud/spring-cloud-security/oauth2client/src/main/java/com/baeldung/filters/SimpleFilter.java new file mode 100644 index 0000000000..98e25ac9c4 --- /dev/null +++ b/spring-cloud/spring-cloud-security/oauth2client/src/main/java/com/baeldung/filters/SimpleFilter.java @@ -0,0 +1,39 @@ +package com.baeldung.filters; + +import javax.servlet.http.HttpServletRequest; +import com.netflix.zuul.context.RequestContext; +import com.netflix.zuul.ZuulFilter; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SimpleFilter extends ZuulFilter { + + private static Logger log = LoggerFactory.getLogger(SimpleFilter.class); + + @Override + public String filterType() { + return "pre"; + } + + @Override + public int filterOrder() { + return 1; + } + + @Override + public boolean shouldFilter() { + return true; + } + + @Override + public Object run() { + RequestContext ctx = RequestContext.getCurrentContext(); + HttpServletRequest request = ctx.getRequest(); + + log.info(String.format("%s request to %s", request.getMethod(), request.getRequestURL().toString())); + + return null; + } + +} \ No newline at end of file diff --git a/spring-cloud/spring-cloud-security/personservice/src/main/resources/application.properties b/spring-cloud/spring-cloud-security/oauth2client/src/main/resources/application.properties similarity index 100% rename from spring-cloud/spring-cloud-security/personservice/src/main/resources/application.properties rename to spring-cloud/spring-cloud-security/oauth2client/src/main/resources/application.properties diff --git a/spring-cloud/spring-cloud-security/springoath2client/src/main/resources/application.yml b/spring-cloud/spring-cloud-security/oauth2client/src/main/resources/application.yml similarity index 100% rename from spring-cloud/spring-cloud-security/springoath2client/src/main/resources/application.yml rename to spring-cloud/spring-cloud-security/oauth2client/src/main/resources/application.yml diff --git a/spring-cloud/spring-cloud-security/oauth2client/src/main/resources/templates/personinfo.html b/spring-cloud/spring-cloud-security/oauth2client/src/main/resources/templates/personinfo.html new file mode 100644 index 0000000000..bc3197e93a --- /dev/null +++ b/spring-cloud/spring-cloud-security/oauth2client/src/main/resources/templates/personinfo.html @@ -0,0 +1,13 @@ + + + + +Getting Personal Information + + +

Providing Person Information

+

+ Person's information: +

+ + \ No newline at end of file diff --git a/spring-cloud/spring-cloud-security/springoath2client/src/test/java/com/example/springoath2/Springoath2ApplicationTests.java b/spring-cloud/spring-cloud-security/oauth2client/src/test/java/com/example/springoath2/Springoath2ApplicationTests.java similarity index 100% rename from spring-cloud/spring-cloud-security/springoath2client/src/test/java/com/example/springoath2/Springoath2ApplicationTests.java rename to spring-cloud/spring-cloud-security/oauth2client/src/test/java/com/example/springoath2/Springoath2ApplicationTests.java diff --git a/spring-cloud/spring-cloud-security/personservice/pom.xml b/spring-cloud/spring-cloud-security/personresource/pom.xml similarity index 93% rename from spring-cloud/spring-cloud-security/personservice/pom.xml rename to spring-cloud/spring-cloud-security/personresource/pom.xml index 74bd67d031..783fd41e66 100644 --- a/spring-cloud/spring-cloud-security/personservice/pom.xml +++ b/spring-cloud/spring-cloud-security/personresource/pom.xml @@ -3,18 +3,18 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.baeldung.service - personservice + com.baeldung + personresource 0.0.1-SNAPSHOT jar - personservice + personresource Demo project for Spring Boot org.springframework.boot spring-boot-starter-parent - 1.5.8.RELEASE + 1.5.9.RELEASE diff --git a/spring-cloud/spring-cloud-security/personservice/src/main/java/com/baeldung/service/personservice/PersonserviceApplication.java b/spring-cloud/spring-cloud-security/personresource/src/main/java/com/baeldung/Application.java similarity index 56% rename from spring-cloud/spring-cloud-security/personservice/src/main/java/com/baeldung/service/personservice/PersonserviceApplication.java rename to spring-cloud/spring-cloud-security/personresource/src/main/java/com/baeldung/Application.java index 0fc14db64f..8c087476bf 100644 --- a/spring-cloud/spring-cloud-security/personservice/src/main/java/com/baeldung/service/personservice/PersonserviceApplication.java +++ b/spring-cloud/spring-cloud-security/personresource/src/main/java/com/baeldung/Application.java @@ -1,12 +1,12 @@ -package com.baeldung.service.personservice; +package com.baeldung; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication -public class PersonserviceApplication { +public class Application { public static void main(String[] args) { - SpringApplication.run(PersonserviceApplication.class, args); + SpringApplication.run(Application.class, args); } } \ No newline at end of file diff --git a/spring-cloud/spring-cloud-security/personservice/src/main/java/com/baeldung/service/personservice/config/ResourceConfigurer.java b/spring-cloud/spring-cloud-security/personresource/src/main/java/com/baeldung/config/ResourceConfigurer.java similarity index 94% rename from spring-cloud/spring-cloud-security/personservice/src/main/java/com/baeldung/service/personservice/config/ResourceConfigurer.java rename to spring-cloud/spring-cloud-security/personresource/src/main/java/com/baeldung/config/ResourceConfigurer.java index 807aa95736..977d74093a 100644 --- a/spring-cloud/spring-cloud-security/personservice/src/main/java/com/baeldung/service/personservice/config/ResourceConfigurer.java +++ b/spring-cloud/spring-cloud-security/personresource/src/main/java/com/baeldung/config/ResourceConfigurer.java @@ -1,4 +1,4 @@ -package com.baeldung.service.personservice.config; +package com.baeldung.config; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; @@ -21,5 +21,5 @@ public class ResourceConfigurer extends ResourceServerConfigurerAdapter { http.httpBasic().disable(); http.authorizeRequests().anyRequest().authenticated(); } - + } diff --git a/spring-cloud/spring-cloud-security/personresource/src/main/java/com/baeldung/controller/PersonInfoController.java b/spring-cloud/spring-cloud-security/personresource/src/main/java/com/baeldung/controller/PersonInfoController.java new file mode 100644 index 0000000000..15ffc557fc --- /dev/null +++ b/spring-cloud/spring-cloud-security/personresource/src/main/java/com/baeldung/controller/PersonInfoController.java @@ -0,0 +1,21 @@ +package com.baeldung.controller; + +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +import com.baeldung.model.Person; +import com.google.gson.Gson; + +@RestController +public class PersonInfoController { + + @GetMapping("/personResource") + @PreAuthorize("hasAnyRole('ADMIN', 'USER')") + public @ResponseBody String personInfo() { + Gson gson = new Gson(); + String person = gson.toJson(new Person("abir", "Dhaka", "Bangladesh", 29, "Male")); + return person; + } +} \ No newline at end of file diff --git a/spring-cloud/spring-cloud-security/personservice/src/main/java/com/baeldung/service/model/Person.java b/spring-cloud/spring-cloud-security/personresource/src/main/java/com/baeldung/model/Person.java similarity index 92% rename from spring-cloud/spring-cloud-security/personservice/src/main/java/com/baeldung/service/model/Person.java rename to spring-cloud/spring-cloud-security/personresource/src/main/java/com/baeldung/model/Person.java index 58e36faaa7..b568291da3 100644 --- a/spring-cloud/spring-cloud-security/personservice/src/main/java/com/baeldung/service/model/Person.java +++ b/spring-cloud/spring-cloud-security/personresource/src/main/java/com/baeldung/model/Person.java @@ -1,51 +1,59 @@ -package com.baeldung.service.model; +package com.baeldung.model; public class Person { - + private String name; private String city; private String country; private Integer age; private String sex; - - public Person(String name, String city, String country, Integer age, String sex){ + + public Person(String name, String city, String country, Integer age, String sex) { this.name = name; this.city = city; this.country = country; this.age = age; this.sex = sex; } - - + public String getName() { return name; } + public void setName(String name) { this.name = name; } + public String getCity() { return city; } + public void setCity(String city) { this.city = city; } + public String getCountry() { return country; } + public void setCountry(String country) { this.country = country; } + public Integer getAge() { return age; } + public void setAge(Integer age) { this.age = age; } + public String getSex() { return sex; } + public void setSex(String sex) { this.sex = sex; } - + } \ No newline at end of file diff --git a/spring-cloud/spring-cloud-security/personservice/src/main/resources/application.yml b/spring-cloud/spring-cloud-security/personresource/src/main/resources/application.yml similarity index 95% rename from spring-cloud/spring-cloud-security/personservice/src/main/resources/application.yml rename to spring-cloud/spring-cloud-security/personresource/src/main/resources/application.yml index 38dc22c2cd..20a3313a60 100644 --- a/spring-cloud/spring-cloud-security/personservice/src/main/resources/application.yml +++ b/spring-cloud/spring-cloud-security/personresource/src/main/resources/application.yml @@ -1,7 +1,4 @@ # Make the application available at http://localhost:9000 -#spring: -# session: -# store-type: redis server: port: 9000 diff --git a/spring-cloud/spring-cloud-security/personservice/src/test/java/com/baeldung/service/personservice/PersonserviceApplicationTests.java b/spring-cloud/spring-cloud-security/personresource/src/test/java/com/baeldung/service/personservice/PersonserviceApplicationTests.java similarity index 86% rename from spring-cloud/spring-cloud-security/personservice/src/test/java/com/baeldung/service/personservice/PersonserviceApplicationTests.java rename to spring-cloud/spring-cloud-security/personresource/src/test/java/com/baeldung/service/personservice/PersonserviceApplicationTests.java index 6e246bc363..e0fe7006d9 100644 --- a/spring-cloud/spring-cloud-security/personservice/src/test/java/com/baeldung/service/personservice/PersonserviceApplicationTests.java +++ b/spring-cloud/spring-cloud-security/personresource/src/test/java/com/baeldung/service/personservice/PersonserviceApplicationTests.java @@ -9,8 +9,8 @@ import org.springframework.test.context.junit4.SpringRunner; @SpringBootTest public class PersonserviceApplicationTests { - @Test - public void contextLoads() { - } + @Test + public void contextLoads() { + } } diff --git a/spring-cloud/spring-cloud-security/personservice/src/main/java/com/baeldung/service/personservice/controller/PersonInfoController.java b/spring-cloud/spring-cloud-security/personservice/src/main/java/com/baeldung/service/personservice/controller/PersonInfoController.java deleted file mode 100644 index 59351ed621..0000000000 --- a/spring-cloud/spring-cloud-security/personservice/src/main/java/com/baeldung/service/personservice/controller/PersonInfoController.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.baeldung.service.personservice.controller; - -import java.time.LocalTime; -import java.time.format.DateTimeFormatter; - -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.bind.annotation.RestController; - -import com.baeldung.service.model.Person; -import com.google.gson.Gson; - -@RestController -public class PersonInfoController { - - @RequestMapping(value = "/currenttime") - @PreAuthorize("hasAnyRole('ADMIN', 'USER')") - public String currentTime(){ - return LocalTime.now().format(DateTimeFormatter.ISO_LOCAL_TIME); - } - - - @RequestMapping(value = "/person") - @PreAuthorize("hasAnyRole('ADMIN', 'USER')") - public @ResponseBody String personInfo(){ - Gson gson = new Gson(); - String person = gson.toJson(new Person("abir","Dhaka", "Bangladesh",29,"Male")); - return person; - } -} \ No newline at end of file diff --git a/spring-cloud/spring-cloud-security/springoath2client/src/main/java/com/cloudsite/filters/pre/SimpleFilter.java b/spring-cloud/spring-cloud-security/springoath2client/src/main/java/com/cloudsite/filters/pre/SimpleFilter.java deleted file mode 100644 index e9412b5ab6..0000000000 --- a/spring-cloud/spring-cloud-security/springoath2client/src/main/java/com/cloudsite/filters/pre/SimpleFilter.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.cloudsite.filters.pre; - -import javax.servlet.http.HttpServletRequest; -import com.netflix.zuul.context.RequestContext; -import com.netflix.zuul.ZuulFilter; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class SimpleFilter extends ZuulFilter { - - private static Logger log = LoggerFactory.getLogger(SimpleFilter.class); - - @Override - public String filterType() { - return "pre"; - } - - @Override - public int filterOrder() { - return 1; - } - - @Override - public boolean shouldFilter() { - return true; - } - - @Override - public Object run() { - RequestContext ctx = RequestContext.getCurrentContext(); - HttpServletRequest request = ctx.getRequest(); - - log.info(String.format("%s request to %s", request.getMethod(), request.getRequestURL().toString())); - - return null; - } - -} \ No newline at end of file diff --git a/spring-cloud/spring-cloud-security/springoath2client/src/main/resources/application.properties b/spring-cloud/spring-cloud-security/springoath2client/src/main/resources/application.properties deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/spring-cloud/spring-cloud-security/springoath2client/src/main/resources/templates/personinfo.html b/spring-cloud/spring-cloud-security/springoath2client/src/main/resources/templates/personinfo.html deleted file mode 100644 index 4f8eedfb6a..0000000000 --- a/spring-cloud/spring-cloud-security/springoath2client/src/main/resources/templates/personinfo.html +++ /dev/null @@ -1,32 +0,0 @@ - - - - -My Website - Getting Personal Information - - - -

Providing Person Information

-

- Person's information: -

-

- The current time is: -

- - - - \ No newline at end of file