Created holder for ldap project (based on trimmed down basic auth project)

This commit is contained in:
corsoft 2014-06-11 07:16:07 +01:00
parent 2102bcc0b0
commit 82d51cb08d
23 changed files with 40 additions and 356 deletions

View File

@ -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;
}
}

View File

@ -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();
}
}

View File

@ -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);
}
}

View File

@ -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 + "\"";
}
}

View File

@ -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;
}
}

View File

@ -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<ResourceCreated> {
@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());
}
}

View File

@ -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;
}
}

View File

@ -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<SingleResourceRetrieved> {
@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);
}
}

View File

@ -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";
}
}

View File

@ -1,11 +0,0 @@
package org.baeldung.web.dto;
import java.io.Serializable;
public class Foo implements Serializable {
public Foo() {
super();
}
}

View File

@ -1,42 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>Spring Security Basic Auth Application</display-name>
<context-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>org.baeldung.spring</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>mvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>

View File

@ -2,10 +2,10 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.baeldung</groupId>
<artifactId>spring-security-ldap</artifactId>
<artifactId>spring-security-mvc-ldap</artifactId>
<version>0.1-SNAPSHOT</version>
<name>spring-security-ldap</name>
<name>spring-security-mvc-ldap</name>
<packaging>war</packaging>
<dependencies>
@ -159,7 +159,7 @@
</dependencies>
<build>
<finalName>spring-security-mvc-basic-auth</finalName>
<finalName>spring-security-mvc-ldap</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>

View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>Spring Security Basic Auth Application</display-name>
<context-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>org.baeldung.spring</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>mvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>