-
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.
Merge pull request #7 from Z-100/feature/#4_Init-spring-boot
Feature/#4 init spring boot
- Loading branch information
Showing
43 changed files
with
1,321 additions
and
3 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,16 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="DmzAppApplication" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot" nameIsGenerated="true"> | ||
<option name="ACTIVE_PROFILES" value="dev" /> | ||
<module name="dmz-app" /> | ||
<option name="SPRING_BOOT_MAIN_CLASS" value="ch.zindustries.dmz.app.DmzAppApplication" /> | ||
<extension name="coverage"> | ||
<pattern> | ||
<option name="PATTERN" value="ch.zindustries.dmz.app.*" /> | ||
<option name="ENABLED" value="true" /> | ||
</pattern> | ||
</extension> | ||
<method v="2"> | ||
<option name="Make" enabled="true" /> | ||
</method> | ||
</configuration> | ||
</component> |
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,11 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="Docker - pgsql full" type="docker-deploy" factoryName="docker-compose.yml" server-name="Docker"> | ||
<deployment type="docker-compose.yml"> | ||
<settings> | ||
<option name="envFilePath" value="" /> | ||
<option name="sourceFilePath" value="docker/pgsql-compose.yml" /> | ||
</settings> | ||
</deployment> | ||
<method v="2" /> | ||
</configuration> | ||
</component> |
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,55 @@ | ||
<?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> | ||
|
||
<parent> | ||
<groupId>ch.zindustries.dmz</groupId> | ||
<artifactId>dmz-root</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>dmz-api</artifactId> | ||
|
||
<dependencies> | ||
|
||
<!-- Modules --> | ||
<dependency> | ||
<groupId>ch.zindustries.dmz</groupId> | ||
<artifactId>dmz-auth</artifactId> | ||
</dependency> | ||
|
||
<!-- Kotlin --> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-stdlib</artifactId> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-maven-plugin</artifactId> | ||
</plugin> | ||
|
||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.22.2</version> | ||
</plugin> | ||
|
||
<plugin> | ||
<artifactId>maven-failsafe-plugin</artifactId> | ||
<version>2.22.2</version> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
10 changes: 10 additions & 0 deletions
10
dmz-api/src/main/kotlin/ch/zindustries/dmz/api/TestService.kt
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,10 @@ | ||
package ch.zindustries.dmz.api | ||
|
||
import ch.zindustries.dmz.auth.dtos.AccountDTO | ||
|
||
interface TestService { | ||
|
||
fun test(): String | ||
|
||
fun createTestUsers(): List<AccountDTO> | ||
} |
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,73 @@ | ||
<?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> | ||
|
||
<parent> | ||
<groupId>ch.zindustries.dmz</groupId> | ||
<artifactId>dmz-root</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>dmz-app</artifactId> | ||
|
||
<dependencies> | ||
|
||
<!-- Modules --> | ||
<dependency> | ||
<groupId>ch.zindustries.dmz</groupId> | ||
<artifactId>dmz-rs-server</artifactId> | ||
</dependency> | ||
|
||
<!-- Others --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-jpa</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.postgresql</groupId> | ||
<artifactId>postgresql</artifactId> | ||
</dependency> | ||
|
||
<!-- Kotlin --> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-stdlib</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-reflect</artifactId> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<testSourceDirectory>src/test/kotlin</testSourceDirectory> | ||
|
||
<plugins> | ||
<plugin> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-maven-plugin</artifactId> | ||
</plugin> | ||
|
||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.22.2</version> | ||
</plugin> | ||
|
||
<plugin> | ||
<artifactId>maven-failsafe-plugin</artifactId> | ||
<version>2.22.2</version> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
23 changes: 23 additions & 0 deletions
23
dmz-app/src/main/kotlin/ch/zindustries/dmz/app/DmzApplication.kt
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,23 @@ | ||
package ch.zindustries.dmz.app | ||
|
||
import org.springframework.boot.autoconfigure.SpringBootApplication | ||
import org.springframework.boot.autoconfigure.domain.EntityScan | ||
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration | ||
import org.springframework.boot.runApplication | ||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories | ||
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity | ||
|
||
@SpringBootApplication( | ||
scanBasePackages = ["ch.zindustries.dmz"], | ||
exclude = [ | ||
SecurityAutoConfiguration::class, | ||
] | ||
) | ||
@EntityScan("ch.zindustries.dmz") | ||
@EnableJpaRepositories("ch.zindustries.dmz") | ||
@EnableMethodSecurity(securedEnabled = true) | ||
open class DmzAppApplication | ||
|
||
fun main(args: Array<String>) { | ||
runApplication<DmzAppApplication>(*args) | ||
} |
58 changes: 58 additions & 0 deletions
58
dmz-app/src/main/kotlin/ch/zindustries/dmz/app/configs/SecurityConfig.kt
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,58 @@ | ||
package ch.zindustries.dmz.app.configs | ||
|
||
import ch.zindustries.dmz.auth.filters.AuthenticationFilter | ||
import ch.zindustries.dmz.auth.filters.AuthorizationFilter | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.security.authentication.AuthenticationManager | ||
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity | ||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity | ||
import org.springframework.security.core.userdetails.UserDetailsService | ||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder | ||
import org.springframework.security.crypto.password.PasswordEncoder | ||
import org.springframework.security.web.SecurityFilterChain | ||
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter | ||
|
||
@Configuration | ||
@EnableWebSecurity | ||
open class SecurityConfig { | ||
|
||
private val AUTH_WHITELIST = arrayOf( | ||
"/anonymous/**", | ||
"/test/**" | ||
) | ||
|
||
@Bean | ||
open fun filterChain( | ||
httpSecurity: HttpSecurity, | ||
userDetailsService: UserDetailsService, | ||
authenticationFilter: AuthenticationFilter, | ||
authorizationFilter: AuthorizationFilter | ||
): SecurityFilterChain { | ||
|
||
// Custom login url | ||
authenticationFilter.setFilterProcessesUrl("/auth/login") | ||
|
||
httpSecurity | ||
.csrf { it.disable() } | ||
.httpBasic { it.disable() } | ||
.formLogin { it.disable() } | ||
.authorizeHttpRequests { | ||
it.requestMatchers(*AUTH_WHITELIST).permitAll() | ||
.anyRequest().authenticated() | ||
} | ||
.addFilterBefore(authenticationFilter, BasicAuthenticationFilter::class.java) | ||
.addFilterAfter(authorizationFilter, AuthenticationFilter::class.java) | ||
|
||
return httpSecurity.build() | ||
} | ||
|
||
@Bean | ||
open fun authenticationManager( | ||
authConfig: AuthenticationConfiguration | ||
): AuthenticationManager = authConfig.authenticationManager | ||
|
||
@Bean | ||
open fun passwordEncoder(): PasswordEncoder = BCryptPasswordEncoder() | ||
} |
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,15 @@ | ||
server: | ||
port: 8001 | ||
spring: | ||
application: | ||
name: dmz | ||
datasource: | ||
url: jdbc:postgresql://localhost:5432/dmz-pgsql | ||
username: postgres | ||
password: postgres | ||
jpa: | ||
properties: | ||
hibernate: | ||
dialect: org.hibernate.dialect.PostgreSQLDialect | ||
hibernate: | ||
ddl-auto: update |
14 changes: 14 additions & 0 deletions
14
dmz-app/src/test/kotlin/ch/zindustries/dmz/app/DmzAppApplicationKtTest.kt
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,14 @@ | ||
package ch.zindustries.dmz.app | ||
|
||
import org.junit.jupiter.api.Assertions.* | ||
import org.junit.jupiter.api.Test | ||
import org.springframework.boot.test.context.SpringBootTest | ||
|
||
@SpringBootTest | ||
class DmzAppApplicationKtTest { | ||
|
||
@Test | ||
fun `Test server startup`() { | ||
assertTrue(true) | ||
} | ||
} |
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,84 @@ | ||
<?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> | ||
|
||
<parent> | ||
<groupId>ch.zindustries.dmz</groupId> | ||
<artifactId>dmz-root</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>dmz-auth</artifactId> | ||
|
||
<dependencies> | ||
|
||
<!-- Spring Boot --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-security</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-test</artifactId> | ||
</dependency> | ||
|
||
<!-- Additional necessary libraries--> | ||
<dependency> | ||
<groupId>jakarta.servlet</groupId> | ||
<artifactId>jakarta.servlet-api</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.auth0</groupId> | ||
<artifactId>java-jwt</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.google.code.gson</groupId> | ||
<artifactId>gson</artifactId> | ||
</dependency> | ||
|
||
|
||
<!-- Kotlin --> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-stdlib</artifactId> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<testSourceDirectory>src/test/kotlin</testSourceDirectory> | ||
|
||
<plugins> | ||
<plugin> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-maven-plugin</artifactId> | ||
</plugin> | ||
|
||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.22.2</version> | ||
</plugin> | ||
|
||
<plugin> | ||
<artifactId>maven-failsafe-plugin</artifactId> | ||
<version>2.22.2</version> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-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,9 @@ | ||
package ch.zindustries.dmz.auth | ||
|
||
class Roles { | ||
companion object { | ||
const val ADMIN = "ROLE_ADMIN" | ||
const val USER = "ROLE_USER" | ||
const val ANONYMOUS = "ROLE_ANONYMOUS" | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
dmz-auth/src/main/kotlin/ch/zindustries/dmz/auth/annotations/AccessibleByAdmin.kt
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,7 @@ | ||
package ch.zindustries.dmz.auth.annotations | ||
|
||
import ch.zindustries.dmz.auth.Roles | ||
import org.springframework.security.access.annotation.Secured | ||
|
||
@Secured(value = [Roles.ADMIN]) | ||
annotation class AccessibleByAdmin |
7 changes: 7 additions & 0 deletions
7
dmz-auth/src/main/kotlin/ch/zindustries/dmz/auth/annotations/AccessibleByAnonymous.kt
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,7 @@ | ||
package ch.zindustries.dmz.auth.annotations | ||
|
||
import ch.zindustries.dmz.auth.Roles | ||
import org.springframework.security.access.annotation.Secured | ||
|
||
@Secured(value = [Roles.ANONYMOUS]) | ||
annotation class AccessibleByAnonymous |
Oops, something went wrong.