Skip to content

Commit ecf713f

Browse files
committed
Turned application into a Spring Boot application
1 parent 6793df8 commit ecf713f

File tree

13 files changed

+271
-207
lines changed

13 files changed

+271
-207
lines changed

direct-object-references/pom.xml

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,29 @@
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111
<artifactId>direct-object-references</artifactId>
12-
<packaging>war</packaging>
12+
<packaging>jar</packaging>
1313
<name>Direct Object References</name>
1414

15-
<description>Direct Object References (Indirect Object References) sample project. Requires a server like Apache Tomcat or the Maven Tomcat7
16-
plugin. After launching, open the web application in your browser at http://localhost:8080/direct-object-references
15+
<description>Direct Object References (Indirect Object References) sample project. Start via the main method in the
16+
Application class. After launching, open the web application in your browser at http://localhost:8080.
1717
</description>
1818

19+
<properties>
20+
<start-class>de.dominikschadow.javasecurity.Application</start-class>
21+
</properties>
22+
1923
<dependencies>
2024
<dependency>
21-
<groupId>javax.servlet</groupId>
22-
<artifactId>javax.servlet-api</artifactId>
23-
</dependency>
24-
<dependency>
25-
<groupId>org.slf4j</groupId>
26-
<artifactId>slf4j-api</artifactId>
25+
<groupId>org.springframework.boot</groupId>
26+
<artifactId>spring-boot-starter-thymeleaf</artifactId>
2727
</dependency>
2828
<dependency>
29-
<groupId>org.slf4j</groupId>
30-
<artifactId>slf4j-log4j12</artifactId>
29+
<groupId>org.webjars</groupId>
30+
<artifactId>bootstrap</artifactId>
3131
</dependency>
3232
<dependency>
33-
<groupId>commons-io</groupId>
34-
<artifactId>commons-io</artifactId>
33+
<groupId>org.webjars</groupId>
34+
<artifactId>webjars-locator</artifactId>
3535
</dependency>
3636
<dependency>
3737
<groupId>org.owasp.esapi</groupId>
@@ -47,11 +47,38 @@
4747

4848
<build>
4949
<finalName>${project.artifactId}</finalName>
50-
<defaultGoal>tomcat7:run-war</defaultGoal>
50+
<defaultGoal>spring-boot:run</defaultGoal>
5151
<plugins>
5252
<plugin>
53-
<groupId>org.apache.tomcat.maven</groupId>
54-
<artifactId>tomcat7-maven-plugin</artifactId>
53+
<groupId>org.springframework.boot</groupId>
54+
<artifactId>spring-boot-maven-plugin</artifactId>
55+
<executions>
56+
<execution>
57+
<goals>
58+
<goal>build-info</goal>
59+
</goals>
60+
<configuration>
61+
<additionalProperties>
62+
<versions.spring-boot>${project.parent.parent.version}</versions.spring-boot>
63+
</additionalProperties>
64+
</configuration>
65+
</execution>
66+
</executions>
67+
</plugin>
68+
<plugin>
69+
<groupId>com.spotify</groupId>
70+
<artifactId>docker-maven-plugin</artifactId>
71+
<configuration>
72+
<imageName>${docker.image.prefix}/${project.artifactId}</imageName>
73+
<dockerDirectory>src/main/docker</dockerDirectory>
74+
<resources>
75+
<resource>
76+
<targetPath>/</targetPath>
77+
<directory>${project.build.directory}</directory>
78+
<include>${project.build.finalName}.jar</include>
79+
</resource>
80+
</resources>
81+
</configuration>
5582
</plugin>
5683
</plugins>
5784
</build>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM openjdk:8-jre-alpine
2+
MAINTAINER Dominik Schadow <dominikschadow@gmail.com>
3+
4+
VOLUME /tmp
5+
6+
ADD direct-object-references.jar app.jar
7+
8+
RUN sh -c 'touch /app.jar'
9+
10+
ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "app.jar"]
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (C) 2017 Dominik Schadow, dominikschadow@gmail.com
3+
*
4+
* This file is part of the Java Security project.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package de.dominikschadow.javasecurity;
19+
20+
import org.springframework.boot.SpringApplication;
21+
import org.springframework.boot.autoconfigure.SpringBootApplication;
22+
23+
/**
24+
* Starter class for the Spring Boot application.
25+
*
26+
* @author Dominik Schadow
27+
*/
28+
@SpringBootApplication
29+
public class Application {
30+
public static void main(String[] args) {
31+
SpringApplication.run(Application.class, args);
32+
}
33+
}

direct-object-references/src/main/java/de/dominikschadow/javasecurity/DownloadServlet.java

Lines changed: 0 additions & 62 deletions
This file was deleted.

direct-object-references/src/main/java/de/dominikschadow/javasecurity/ReferenceUtil.java

Lines changed: 0 additions & 81 deletions
This file was deleted.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package de.dominikschadow.javasecurity;
2+
3+
import org.owasp.esapi.errors.AccessControlException;
4+
import org.owasp.esapi.reference.RandomAccessReferenceMap;
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
7+
import org.springframework.core.io.Resource;
8+
import org.springframework.core.io.UrlResource;
9+
import org.springframework.stereotype.Service;
10+
11+
import javax.annotation.PostConstruct;
12+
import java.io.File;
13+
import java.net.MalformedURLException;
14+
import java.util.HashSet;
15+
import java.util.Set;
16+
17+
@Service
18+
public class ResourceService {
19+
private static final Logger log = LoggerFactory.getLogger(ResourceService.class);
20+
private final Set<Object> resources = new HashSet<>();
21+
private final RandomAccessReferenceMap referenceMap = new RandomAccessReferenceMap(resources);
22+
private final String rootLocation;
23+
24+
public ResourceService() {
25+
this.rootLocation = "http://localhost:8080/files/";
26+
}
27+
28+
@PostConstruct
29+
protected void init() {
30+
File coverImage = new File("cover.pdf");
31+
referenceMap.addDirectReference(coverImage);
32+
resources.add(coverImage);
33+
34+
File coverPdf = new File("cover.jpg");
35+
referenceMap.addDirectReference(coverPdf);
36+
resources.add(coverPdf);
37+
}
38+
39+
public Set<String> getAllIndirectReferences() {
40+
Set<String> indirectReferences = new HashSet<>();
41+
42+
for (Object file : resources) {
43+
String indirectReference = referenceMap.getIndirectReference(file);
44+
indirectReferences.add(indirectReference);
45+
}
46+
47+
return indirectReferences;
48+
}
49+
50+
public File getFileByIndirectReference(String indirectReference) throws AccessControlException {
51+
File file = referenceMap.getDirectReference(indirectReference);
52+
53+
log.info("File name {}", file.getName());
54+
55+
return file;
56+
}
57+
58+
public Resource loadAsResource(String filename) throws MalformedURLException {
59+
Resource resource = new UrlResource(rootLocation + filename);
60+
if (resource.exists() || resource.isReadable()) {
61+
return resource;
62+
}
63+
64+
return null;
65+
}
66+
}

0 commit comments

Comments
 (0)