-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
2,402 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.idea/ | ||
target/ | ||
*.iml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
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.teapot</groupId> | ||
<artifactId>teapot-backend</artifactId> | ||
<version>1.0</version> | ||
<packaging>jar</packaging> | ||
|
||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>1.4.7.RELEASE</version> | ||
</parent> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<java.version>1.8</java.version> | ||
|
||
<!-- JPA --> | ||
<javax.persistence.version>2.1.1</javax.persistence.version> | ||
|
||
<!-- Spring --> | ||
<spring.version>4.3.8.RELEASE</spring.version> | ||
|
||
<!-- JUnit --> | ||
<junit.version>4.12</junit.version> | ||
|
||
<!-- H2 Database --> | ||
<h2.version>1.4.195</h2.version> | ||
|
||
<!-- Hibernate --> | ||
<hibernate.version>5.2.10.Final</hibernate.version> | ||
|
||
<!--Google Guava--> | ||
<guava.version>22.0</guava.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-autoconfigure</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-jdbc</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-jpa</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-security</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-mail</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<!-- https://mvnrepository.com/artifact/org.eclipse.persistence/javax.persistence --> | ||
<dependency> | ||
<groupId>org.eclipse.persistence</groupId> | ||
<artifactId>javax.persistence</artifactId> | ||
<version>${javax.persistence.version}</version> | ||
</dependency> | ||
|
||
<!-- https://mvnrepository.com/artifact/org.springframework/spring-core --> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-core</artifactId> | ||
<version>${spring.version}</version> | ||
</dependency> | ||
|
||
<!-- https://mvnrepository.com/artifact/org.springframework/spring-tx --> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-tx</artifactId> | ||
<version>${spring.version}</version> | ||
</dependency> | ||
|
||
<!-- https://mvnrepository.com/artifact/org.springframework/spring-orm --> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-orm</artifactId> | ||
<version>${spring.version}</version> | ||
</dependency> | ||
|
||
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core --> | ||
<dependency> | ||
<groupId>org.hibernate</groupId> | ||
<artifactId>hibernate-core</artifactId> | ||
<version>${hibernate.version}</version> | ||
</dependency> | ||
|
||
<!-- https://mvnrepository.com/artifact/org.springframework.security.oauth/spring-security-oauth2 --> | ||
<dependency> | ||
<groupId>org.springframework.security.oauth</groupId> | ||
<artifactId>spring-security-oauth2</artifactId> | ||
</dependency> | ||
|
||
<!-- https://mvnrepository.com/artifact/com.h2database/h2 --> | ||
<dependency> | ||
<groupId>com.h2database</groupId> | ||
<artifactId>h2</artifactId> | ||
<version>${h2.version}</version> | ||
</dependency> | ||
|
||
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.datatype/jackson-datatype-jsr310 --> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.datatype</groupId> | ||
<artifactId>jackson-datatype-jsr310</artifactId> | ||
</dependency> | ||
|
||
<!-- https://mvnrepository.com/artifact/com.google.guava/guava --> | ||
<dependency> | ||
<groupId>com.google.guava</groupId> | ||
<artifactId>guava</artifactId> | ||
<version>${guava.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.security</groupId> | ||
<artifactId>spring-security-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<finalName>${project.artifactId}-${project.version}</finalName> | ||
|
||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.teapot.backend; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class Application { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(Application.class, args); | ||
} | ||
} |
199 changes: 199 additions & 0 deletions
199
src/main/java/org/teapot/backend/config/DevelopmentProfileConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
package org.teapot.backend.config; | ||
|
||
import org.h2.server.web.WebServlet; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.CommandLineRunner; | ||
import org.springframework.boot.web.servlet.ServletRegistrationBean; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | ||
import org.springframework.security.crypto.password.PasswordEncoder; | ||
import org.teapot.backend.model.meta.TeapotAction; | ||
import org.teapot.backend.model.meta.TeapotProperty; | ||
import org.teapot.backend.model.User; | ||
import org.teapot.backend.model.UserAuthority; | ||
import org.teapot.backend.model.meta.TeapotResource; | ||
import org.teapot.backend.repository.TeapotActionRepository; | ||
import org.teapot.backend.repository.TeapotPropertyRepository; | ||
import org.teapot.backend.repository.TeapotResourceRepository; | ||
import org.teapot.backend.repository.UserRepository; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.util.Arrays; | ||
|
||
|
||
@Configuration | ||
@Profile("development") | ||
public class DevelopmentProfileConfig { | ||
|
||
@Autowired | ||
private UserRepository userRepository; | ||
|
||
@Autowired | ||
private TeapotPropertyRepository propertyRepository; | ||
|
||
@Autowired | ||
private TeapotActionRepository actionRepository; | ||
|
||
@Autowired | ||
private TeapotResourceRepository resourceRepository; | ||
|
||
@Autowired | ||
private PasswordEncoder passwordEncoder; | ||
|
||
@Bean | ||
public PasswordEncoder passwordEncoder() { | ||
return new BCryptPasswordEncoder(); | ||
} | ||
|
||
@Bean | ||
ServletRegistrationBean h2ServletRegistrationBean() { | ||
ServletRegistrationBean registrationBean = | ||
new ServletRegistrationBean(new WebServlet()); | ||
|
||
registrationBean.addUrlMappings("/h2/*"); | ||
|
||
return registrationBean; | ||
} | ||
|
||
@Bean | ||
public CommandLineRunner loadData() { | ||
return args -> { | ||
registerAdmin(); | ||
registerDaleCooper(); | ||
registerLoraPalmer(); | ||
registerSherlockHolmes(); | ||
registerDoctorWatson(); | ||
|
||
addProperties(); | ||
addResources(); | ||
addActions(); | ||
}; | ||
} | ||
|
||
private void registerAdmin() { | ||
User admin = new User(); | ||
|
||
admin.setUsername("admin"); | ||
admin.setEmail("admin@teapot.org"); | ||
admin.setPassword(passwordEncoder.encode("1234")); | ||
admin.setActivated(true); | ||
admin.setFirstName("Cake"); | ||
admin.setLastName("Lover"); | ||
admin.setRegistrationDate(LocalDateTime.now()); | ||
admin.setBirthday(LocalDate.now()); | ||
admin.setDescription("i manage everything"); | ||
admin.setAuthority(UserAuthority.ADMIN); | ||
|
||
userRepository.save(admin); | ||
} | ||
|
||
private void registerDaleCooper() { | ||
User user = new User(); | ||
|
||
user.setUsername("dale_cooper"); | ||
user.setEmail("dale_cooper@twin.peaks"); | ||
user.setPassword(passwordEncoder.encode("1234")); | ||
user.setActivated(true); | ||
user.setFirstName("Dale"); | ||
user.setLastName("Cooper"); | ||
user.setRegistrationDate(LocalDateTime.now()); | ||
user.setBirthday(LocalDate.now()); | ||
user.setDescription("a special FBI agent"); | ||
user.setAuthority(UserAuthority.USER); | ||
|
||
userRepository.save(user); | ||
} | ||
|
||
private void registerLoraPalmer() { | ||
User user = new User(); | ||
|
||
user.setUsername("lora_palmer"); | ||
user.setEmail("lora_palmer@twin.peaks"); | ||
user.setPassword(passwordEncoder.encode("1234")); | ||
user.setActivated(true); | ||
user.setFirstName("Lora"); | ||
user.setLastName("Palmer"); | ||
user.setRegistrationDate(LocalDateTime.now()); | ||
user.setBirthday(LocalDate.now()); | ||
user.setDescription("a dead girl"); | ||
user.setAuthority(UserAuthority.USER); | ||
|
||
userRepository.save(user); | ||
} | ||
|
||
private void registerSherlockHolmes() { | ||
User user = new User(); | ||
|
||
user.setUsername("sherlock_holmes"); | ||
user.setEmail("sherlock_holmes@baker.st"); | ||
user.setPassword(passwordEncoder.encode("1234")); | ||
user.setActivated(true); | ||
user.setFirstName("Sherlock"); | ||
user.setLastName("Holmes"); | ||
user.setRegistrationDate(LocalDateTime.now()); | ||
user.setBirthday(LocalDate.now()); | ||
user.setDescription("private detective"); | ||
user.setAuthority(UserAuthority.USER); | ||
|
||
userRepository.save(user); | ||
} | ||
|
||
private void registerDoctorWatson() { | ||
User user = new User(); | ||
|
||
user.setUsername("dr_watson"); | ||
user.setEmail("dr_watson@baker.st"); | ||
user.setPassword(passwordEncoder.encode("1234")); | ||
user.setActivated(true); | ||
user.setFirstName("John"); | ||
user.setLastName("Watson"); | ||
user.setRegistrationDate(LocalDateTime.now()); | ||
user.setBirthday(LocalDate.now()); | ||
user.setDescription("Sherlock Holmes' mate"); | ||
user.setAuthority(UserAuthority.USER); | ||
|
||
userRepository.save(user); | ||
} | ||
|
||
private void addProperties() { | ||
TeapotProperty property1 = new TeapotProperty(); | ||
TeapotProperty property2 = new TeapotProperty(); | ||
|
||
property1.setName("verification-token-expire-days"); | ||
property1.setValue("1"); | ||
|
||
property2.setName("site-uri"); | ||
property2.setValue("localhost:8080"); | ||
|
||
propertyRepository.save(property1); | ||
propertyRepository.save(property2); | ||
} | ||
|
||
private void addResources() { | ||
TeapotResource resource1 = new TeapotResource(); | ||
|
||
resource1.setName("user"); | ||
resource1.setUri("/users"); | ||
resource1.setDescription( | ||
"Available methods:\n\nGET /users/{id|username}\n" + | ||
"POST /users\nPUT /users\nDELETE /users/{id}\n\n"); | ||
|
||
resourceRepository.save(resource1); | ||
} | ||
|
||
private void addActions() { | ||
TeapotAction action1 = new TeapotAction(); | ||
TeapotAction action2 = new TeapotAction(); | ||
|
||
action1.setName("help"); | ||
action1.setUsage("/actions/help?resource={name|id}|action={name|id}"); | ||
|
||
action2.setName("activate"); | ||
action2.setUsage("/actions/activate?user={username|id}&token={token}"); | ||
|
||
actionRepository.save(Arrays.asList(action1, action2)); | ||
} | ||
} |
Oops, something went wrong.