From 05593115393981650ba08e2c1f773be0089c94e3 Mon Sep 17 00:00:00 2001 From: corsoft Date: Wed, 11 Jun 2014 07:16:07 +0100 Subject: [PATCH] Created holder for ldap project (based on trimmed down basic auth project) --- .../persistence/service/FooService.java | 23 ------ .../baeldung/spring/PersistenceConfig.java | 14 ---- .../web/controller/FooController.java | 74 ------------------- .../org/baeldung/web/controller/LinkUtil.java | 30 -------- .../web/controller/ResourceCreated.java | 35 --------- ...esourceCreatedDiscoverabilityListener.java | 35 --------- .../controller/SingleResourceRetrieved.java | 29 -------- ...ourceRetrievedDiscoverabilityListener.java | 32 -------- .../web/controller/TestController.java | 28 ------- .../main/java/org/baeldung/web/dto/Foo.java | 11 --- .../src/main/webapp/WEB-INF/web.xml | 42 ----------- .../README.md | 0 .../pom.xml | 6 +- .../MyBasicAuthenticationEntryPoint.java | 0 .../java/org/baeldung/spring/MvcConfig.java | 0 .../baeldung/spring/SecSecurityConfig.java | 1 + .../java/org/baeldung/spring/WebConfig.java | 0 .../src/main/resources/logback.xml | 0 .../src/main/resources/webSecurityConfig.xml | 0 .../src/main/webapp/WEB-INF/mvc-servlet.xml | 0 .../src/main/webapp/WEB-INF/view/homepage.jsp | 0 .../src/main/webapp/WEB-INF/web.xml | 36 +++++++++ .../src/test/resources/.gitignore | 0 23 files changed, 40 insertions(+), 356 deletions(-) delete mode 100644 spring-security-ldap/src/main/java/org/baeldung/persistence/service/FooService.java delete mode 100644 spring-security-ldap/src/main/java/org/baeldung/spring/PersistenceConfig.java delete mode 100644 spring-security-ldap/src/main/java/org/baeldung/web/controller/FooController.java delete mode 100644 spring-security-ldap/src/main/java/org/baeldung/web/controller/LinkUtil.java delete mode 100644 spring-security-ldap/src/main/java/org/baeldung/web/controller/ResourceCreated.java delete mode 100644 spring-security-ldap/src/main/java/org/baeldung/web/controller/ResourceCreatedDiscoverabilityListener.java delete mode 100644 spring-security-ldap/src/main/java/org/baeldung/web/controller/SingleResourceRetrieved.java delete mode 100644 spring-security-ldap/src/main/java/org/baeldung/web/controller/SingleResourceRetrievedDiscoverabilityListener.java delete mode 100644 spring-security-ldap/src/main/java/org/baeldung/web/controller/TestController.java delete mode 100644 spring-security-ldap/src/main/java/org/baeldung/web/dto/Foo.java delete mode 100644 spring-security-ldap/src/main/webapp/WEB-INF/web.xml rename {spring-security-ldap => spring-security-mvc-ldap}/README.md (100%) rename {spring-security-ldap => spring-security-mvc-ldap}/pom.xml (98%) rename {spring-security-ldap => spring-security-mvc-ldap}/src/main/java/org/baeldung/security/basic/MyBasicAuthenticationEntryPoint.java (100%) rename {spring-security-ldap => spring-security-mvc-ldap}/src/main/java/org/baeldung/spring/MvcConfig.java (100%) rename {spring-security-ldap => spring-security-mvc-ldap}/src/main/java/org/baeldung/spring/SecSecurityConfig.java (98%) rename {spring-security-ldap => spring-security-mvc-ldap}/src/main/java/org/baeldung/spring/WebConfig.java (100%) rename {spring-security-ldap => spring-security-mvc-ldap}/src/main/resources/logback.xml (100%) rename {spring-security-ldap => spring-security-mvc-ldap}/src/main/resources/webSecurityConfig.xml (100%) rename {spring-security-ldap => spring-security-mvc-ldap}/src/main/webapp/WEB-INF/mvc-servlet.xml (100%) rename {spring-security-ldap => spring-security-mvc-ldap}/src/main/webapp/WEB-INF/view/homepage.jsp (100%) create mode 100644 spring-security-mvc-ldap/src/main/webapp/WEB-INF/web.xml rename {spring-security-ldap => spring-security-mvc-ldap}/src/test/resources/.gitignore (100%) diff --git a/spring-security-ldap/src/main/java/org/baeldung/persistence/service/FooService.java b/spring-security-ldap/src/main/java/org/baeldung/persistence/service/FooService.java deleted file mode 100644 index 02db7a733a..0000000000 --- a/spring-security-ldap/src/main/java/org/baeldung/persistence/service/FooService.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.baeldung.persistence.service; - -import org.baeldung.web.dto.Foo; -import org.springframework.stereotype.Service; - -@Service -public class FooService { - - public FooService() { - super(); - } - - // API - - public Foo getById(final Long id) { - return null; - } - - public Long create(final Foo resource) { - return null; - } - -} diff --git a/spring-security-ldap/src/main/java/org/baeldung/spring/PersistenceConfig.java b/spring-security-ldap/src/main/java/org/baeldung/spring/PersistenceConfig.java deleted file mode 100644 index 4ea0053f48..0000000000 --- a/spring-security-ldap/src/main/java/org/baeldung/spring/PersistenceConfig.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.baeldung.spring; - -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; - -@Configuration -@ComponentScan("org.baeldung.persistence") -public class PersistenceConfig { - - public PersistenceConfig() { - super(); - } - -} diff --git a/spring-security-ldap/src/main/java/org/baeldung/web/controller/FooController.java b/spring-security-ldap/src/main/java/org/baeldung/web/controller/FooController.java deleted file mode 100644 index daa797ee36..0000000000 --- a/spring-security-ldap/src/main/java/org/baeldung/web/controller/FooController.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.baeldung.web.controller; - -import java.net.URI; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.baeldung.persistence.service.FooService; -import org.baeldung.web.dto.Foo; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationEventPublisher; -import org.springframework.http.HttpStatus; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.bind.annotation.ResponseStatus; -import org.springframework.web.util.UriComponentsBuilder; -import org.springframework.web.util.UriTemplate; - -import com.google.common.base.Preconditions; - -@Controller -@RequestMapping(value = "/foo") -public class FooController { - - @Autowired - private ApplicationEventPublisher eventPublisher; - - @Autowired - private FooService service; - - public FooController() { - super(); - } - - // API - - @RequestMapping(value = "/{id}", method = RequestMethod.GET) - @ResponseBody - public Foo findOne(@PathVariable("id") final Long id, final UriComponentsBuilder uriBuilder, final HttpServletResponse response) { - return new Foo(); - } - - @RequestMapping(value = "admin/foo/{id}", method = RequestMethod.GET) - @ResponseBody - public Foo get(@PathVariable("id") final Long id, final HttpServletRequest request, final HttpServletResponse response) { - final Foo resourceById = Preconditions.checkNotNull(service.getById(id)); - - eventPublisher.publishEvent(new SingleResourceRetrieved(this, request, response)); - return resourceById; - } - - @RequestMapping(value = "admin/foo", method = RequestMethod.POST) - @ResponseStatus(HttpStatus.CREATED) - public void create(@RequestBody final Foo resource, final HttpServletRequest request, final HttpServletResponse response) { - Preconditions.checkNotNull(resource); - final Long idOfCreatedResource = service.create(resource); - - eventPublisher.publishEvent(new ResourceCreated(this, request, response, idOfCreatedResource)); - } - - @RequestMapping(value = "admin", method = RequestMethod.GET) - @ResponseStatus(value = HttpStatus.NO_CONTENT) - public void adminRoot(final HttpServletRequest request, final HttpServletResponse response) { - final String rootUri = request.getRequestURL().toString(); - - final URI fooUri = new UriTemplate("{rootUri}/{resource}").expand(rootUri, "foo"); - final String linkToFoo = LinkUtil.createLinkHeader(fooUri.toASCIIString(), "collection"); - response.addHeader("Link", linkToFoo); - } -} diff --git a/spring-security-ldap/src/main/java/org/baeldung/web/controller/LinkUtil.java b/spring-security-ldap/src/main/java/org/baeldung/web/controller/LinkUtil.java deleted file mode 100644 index a41ebb5a5c..0000000000 --- a/spring-security-ldap/src/main/java/org/baeldung/web/controller/LinkUtil.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.baeldung.web.controller; - -import javax.servlet.http.HttpServletResponse; - -/** - * Provides some constants and utility methods to build a Link Header to be stored in the {@link HttpServletResponse} object - */ -public final class LinkUtil { - - private LinkUtil() { - throw new AssertionError(); - } - - // - - /** - * Creates a Link Header to be stored in the {@link HttpServletResponse} to provide Discoverability features to the user - * - * @param uri - * the base uri - * @param rel - * the relative path - * - * @return the complete url - */ - public static String createLinkHeader(final String uri, final String rel) { - return "<" + uri + ">; rel=\"" + rel + "\""; - } - -} diff --git a/spring-security-ldap/src/main/java/org/baeldung/web/controller/ResourceCreated.java b/spring-security-ldap/src/main/java/org/baeldung/web/controller/ResourceCreated.java deleted file mode 100644 index a677888101..0000000000 --- a/spring-security-ldap/src/main/java/org/baeldung/web/controller/ResourceCreated.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.baeldung.web.controller; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.springframework.context.ApplicationEvent; - -public class ResourceCreated extends ApplicationEvent { - private final HttpServletResponse response; - private final HttpServletRequest request; - private final long idOfNewResource; - - public ResourceCreated(final Object source, final HttpServletRequest request, final HttpServletResponse response, final long idOfNewResource) { - super(source); - - this.request = request; - this.response = response; - this.idOfNewResource = idOfNewResource; - } - - // API - - public HttpServletResponse getResponse() { - return response; - } - - public HttpServletRequest getRequest() { - return request; - } - - public long getIdOfNewResource() { - return idOfNewResource; - } - -} diff --git a/spring-security-ldap/src/main/java/org/baeldung/web/controller/ResourceCreatedDiscoverabilityListener.java b/spring-security-ldap/src/main/java/org/baeldung/web/controller/ResourceCreatedDiscoverabilityListener.java deleted file mode 100644 index 8d19ef82fc..0000000000 --- a/spring-security-ldap/src/main/java/org/baeldung/web/controller/ResourceCreatedDiscoverabilityListener.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.baeldung.web.controller; - -import java.net.URI; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.springframework.context.ApplicationListener; -import org.springframework.stereotype.Component; -import org.springframework.web.util.UriTemplate; - -import com.google.common.base.Preconditions; -import com.google.common.net.HttpHeaders; - -@Component -class ResourceCreatedDiscoverabilityListener implements ApplicationListener { - - @Override - public void onApplicationEvent(final ResourceCreated resourceCreatedEvent) { - Preconditions.checkNotNull(resourceCreatedEvent); - - final HttpServletRequest request = resourceCreatedEvent.getRequest(); - final HttpServletResponse response = resourceCreatedEvent.getResponse(); - final long idOfNewResource = resourceCreatedEvent.getIdOfNewResource(); - - addLinkHeaderOnResourceCreation(request, response, idOfNewResource); - } - - void addLinkHeaderOnResourceCreation(final HttpServletRequest request, final HttpServletResponse response, final long idOfNewResource) { - final String requestUrl = request.getRequestURL().toString(); - final URI uri = new UriTemplate("{requestUrl}/{idOfNewResource}").expand(requestUrl, idOfNewResource); - response.setHeader(HttpHeaders.LOCATION, uri.toASCIIString()); - } - -} \ No newline at end of file diff --git a/spring-security-ldap/src/main/java/org/baeldung/web/controller/SingleResourceRetrieved.java b/spring-security-ldap/src/main/java/org/baeldung/web/controller/SingleResourceRetrieved.java deleted file mode 100644 index 3de7918105..0000000000 --- a/spring-security-ldap/src/main/java/org/baeldung/web/controller/SingleResourceRetrieved.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.baeldung.web.controller; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.springframework.context.ApplicationEvent; - -public class SingleResourceRetrieved extends ApplicationEvent { - private final HttpServletResponse response; - private final HttpServletRequest request; - - public SingleResourceRetrieved(final Object source, final HttpServletRequest request, final HttpServletResponse response) { - super(source); - - this.request = request; - this.response = response; - } - - // API - - public HttpServletResponse getResponse() { - return response; - } - - public HttpServletRequest getRequest() { - return request; - } - -} diff --git a/spring-security-ldap/src/main/java/org/baeldung/web/controller/SingleResourceRetrievedDiscoverabilityListener.java b/spring-security-ldap/src/main/java/org/baeldung/web/controller/SingleResourceRetrievedDiscoverabilityListener.java deleted file mode 100644 index 45cd7c4d13..0000000000 --- a/spring-security-ldap/src/main/java/org/baeldung/web/controller/SingleResourceRetrievedDiscoverabilityListener.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.baeldung.web.controller; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.springframework.context.ApplicationListener; -import org.springframework.stereotype.Component; - -import com.google.common.base.Preconditions; - -@Component -class SingleResourceRetrievedDiscoverabilityListener implements ApplicationListener { - - @Override - public void onApplicationEvent(final SingleResourceRetrieved resourceRetrievedEvent) { - Preconditions.checkNotNull(resourceRetrievedEvent); - - final HttpServletRequest request = resourceRetrievedEvent.getRequest(); - final HttpServletResponse response = resourceRetrievedEvent.getResponse(); - addLinkHeaderOnSingleResourceRetrieval(request, response); - } - - void addLinkHeaderOnSingleResourceRetrieval(final HttpServletRequest request, final HttpServletResponse response) { - final StringBuffer requestURL = request.getRequestURL(); - final int positionOfLastSlash = requestURL.lastIndexOf("/"); - final String uriForResourceCreation = requestURL.substring(0, positionOfLastSlash); - - final String linkHeaderValue = LinkUtil.createLinkHeader(uriForResourceCreation, "collection"); - response.addHeader("Link", linkHeaderValue); - } - -} \ No newline at end of file diff --git a/spring-security-ldap/src/main/java/org/baeldung/web/controller/TestController.java b/spring-security-ldap/src/main/java/org/baeldung/web/controller/TestController.java deleted file mode 100644 index f68cfb2eb7..0000000000 --- a/spring-security-ldap/src/main/java/org/baeldung/web/controller/TestController.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.baeldung.web.controller; - -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; - -@Controller -public class TestController { - - public TestController() { - super(); - } - - // API - - @RequestMapping("/permitAll") - @ResponseBody - public String permitAll() { - return "Permit All"; - } - - @RequestMapping("/securityNone") - @ResponseBody - public String securityNone() { - return "Security None"; - } - -} diff --git a/spring-security-ldap/src/main/java/org/baeldung/web/dto/Foo.java b/spring-security-ldap/src/main/java/org/baeldung/web/dto/Foo.java deleted file mode 100644 index 352045989d..0000000000 --- a/spring-security-ldap/src/main/java/org/baeldung/web/dto/Foo.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.baeldung.web.dto; - -import java.io.Serializable; - -public class Foo implements Serializable { - - public Foo() { - super(); - } - -} diff --git a/spring-security-ldap/src/main/webapp/WEB-INF/web.xml b/spring-security-ldap/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 08183daa24..0000000000 --- a/spring-security-ldap/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - Spring Security Basic Auth Application - - - contextClass - org.springframework.web.context.support.AnnotationConfigWebApplicationContext - - - contextConfigLocation - org.baeldung.spring - - - - org.springframework.web.context.ContextLoaderListener - - - - mvc - org.springframework.web.servlet.DispatcherServlet - 1 - - - mvc - / - - - - springSecurityFilterChain - org.springframework.web.filter.DelegatingFilterProxy - - - springSecurityFilterChain - /* - - - - index.html - - - \ No newline at end of file diff --git a/spring-security-ldap/README.md b/spring-security-mvc-ldap/README.md similarity index 100% rename from spring-security-ldap/README.md rename to spring-security-mvc-ldap/README.md diff --git a/spring-security-ldap/pom.xml b/spring-security-mvc-ldap/pom.xml similarity index 98% rename from spring-security-ldap/pom.xml rename to spring-security-mvc-ldap/pom.xml index 607ddf50d1..11e875a071 100644 --- a/spring-security-ldap/pom.xml +++ b/spring-security-mvc-ldap/pom.xml @@ -2,10 +2,10 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 org.baeldung - spring-security-ldap + spring-security-mvc-ldap 0.1-SNAPSHOT - spring-security-ldap + spring-security-mvc-ldap war @@ -159,7 +159,7 @@ - spring-security-mvc-basic-auth + spring-security-mvc-ldap src/main/resources diff --git a/spring-security-ldap/src/main/java/org/baeldung/security/basic/MyBasicAuthenticationEntryPoint.java b/spring-security-mvc-ldap/src/main/java/org/baeldung/security/basic/MyBasicAuthenticationEntryPoint.java similarity index 100% rename from spring-security-ldap/src/main/java/org/baeldung/security/basic/MyBasicAuthenticationEntryPoint.java rename to spring-security-mvc-ldap/src/main/java/org/baeldung/security/basic/MyBasicAuthenticationEntryPoint.java diff --git a/spring-security-ldap/src/main/java/org/baeldung/spring/MvcConfig.java b/spring-security-mvc-ldap/src/main/java/org/baeldung/spring/MvcConfig.java similarity index 100% rename from spring-security-ldap/src/main/java/org/baeldung/spring/MvcConfig.java rename to spring-security-mvc-ldap/src/main/java/org/baeldung/spring/MvcConfig.java diff --git a/spring-security-ldap/src/main/java/org/baeldung/spring/SecSecurityConfig.java b/spring-security-mvc-ldap/src/main/java/org/baeldung/spring/SecSecurityConfig.java similarity index 98% rename from spring-security-ldap/src/main/java/org/baeldung/spring/SecSecurityConfig.java rename to spring-security-mvc-ldap/src/main/java/org/baeldung/spring/SecSecurityConfig.java index 4ce80dab9f..9f0591d7db 100644 --- a/spring-security-ldap/src/main/java/org/baeldung/spring/SecSecurityConfig.java +++ b/spring-security-mvc-ldap/src/main/java/org/baeldung/spring/SecSecurityConfig.java @@ -13,4 +13,5 @@ public class SecSecurityConfig { super(); } + } diff --git a/spring-security-ldap/src/main/java/org/baeldung/spring/WebConfig.java b/spring-security-mvc-ldap/src/main/java/org/baeldung/spring/WebConfig.java similarity index 100% rename from spring-security-ldap/src/main/java/org/baeldung/spring/WebConfig.java rename to spring-security-mvc-ldap/src/main/java/org/baeldung/spring/WebConfig.java diff --git a/spring-security-ldap/src/main/resources/logback.xml b/spring-security-mvc-ldap/src/main/resources/logback.xml similarity index 100% rename from spring-security-ldap/src/main/resources/logback.xml rename to spring-security-mvc-ldap/src/main/resources/logback.xml diff --git a/spring-security-ldap/src/main/resources/webSecurityConfig.xml b/spring-security-mvc-ldap/src/main/resources/webSecurityConfig.xml similarity index 100% rename from spring-security-ldap/src/main/resources/webSecurityConfig.xml rename to spring-security-mvc-ldap/src/main/resources/webSecurityConfig.xml diff --git a/spring-security-ldap/src/main/webapp/WEB-INF/mvc-servlet.xml b/spring-security-mvc-ldap/src/main/webapp/WEB-INF/mvc-servlet.xml similarity index 100% rename from spring-security-ldap/src/main/webapp/WEB-INF/mvc-servlet.xml rename to spring-security-mvc-ldap/src/main/webapp/WEB-INF/mvc-servlet.xml diff --git a/spring-security-ldap/src/main/webapp/WEB-INF/view/homepage.jsp b/spring-security-mvc-ldap/src/main/webapp/WEB-INF/view/homepage.jsp similarity index 100% rename from spring-security-ldap/src/main/webapp/WEB-INF/view/homepage.jsp rename to spring-security-mvc-ldap/src/main/webapp/WEB-INF/view/homepage.jsp diff --git a/spring-security-mvc-ldap/src/main/webapp/WEB-INF/web.xml b/spring-security-mvc-ldap/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..fe4d560262 --- /dev/null +++ b/spring-security-mvc-ldap/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,36 @@ + + + Spring Security Basic Auth Application + + contextClass + org.springframework.web.context.support.AnnotationConfigWebApplicationContext + + + contextConfigLocation + org.baeldung.spring + + + org.springframework.web.context.ContextLoaderListener + + + mvc + org.springframework.web.servlet.DispatcherServlet + 1 + + + mvc + / + + + springSecurityFilterChain + org.springframework.web.filter.DelegatingFilterProxy + + + springSecurityFilterChain + /* + + + index.html + + \ No newline at end of file diff --git a/spring-security-ldap/src/test/resources/.gitignore b/spring-security-mvc-ldap/src/test/resources/.gitignore similarity index 100% rename from spring-security-ldap/src/test/resources/.gitignore rename to spring-security-mvc-ldap/src/test/resources/.gitignore