Skip to content

Commit

Permalink
- enable spring boot Java 21 virtual threads
Browse files Browse the repository at this point in the history
- Added sticky footer to website
  • Loading branch information
MichiBaum committed Jul 19, 2024
1 parent 5747894 commit 63ba15b
Show file tree
Hide file tree
Showing 13 changed files with 96 additions and 31 deletions.
4 changes: 4 additions & 0 deletions admin-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ server:
undertow:
url-charset: UTF-8


spring:
threads:
virtual:
enabled: true
lifecycle:
timeout-per-shutdown-phase: 20s
boot:
Expand Down
3 changes: 3 additions & 0 deletions authentication-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ server:
url-charset: UTF-8

spring:
threads:
virtual:
enabled: true
lifecycle:
timeout-per-shutdown-phase: 20s
application:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,34 @@ import org.springframework.web.server.ServerWebExchange
import reactor.core.publisher.Mono

@Component
class AuthenticationFilter(private val authenticationValidator: AuthenticationValidator): GatewayFilter {
class AuthenticationFilter(
private val authenticationValidator: AuthenticationValidator
) : GatewayFilter {

override fun filter(exchange: ServerWebExchange?, chain: GatewayFilterChain?): Mono<Void> {
override fun filter(
exchange: ServerWebExchange?,
chain: GatewayFilterChain?
): Mono<Void> {
exchange?.let {
val authHeaders = it.request.headers["Authorization"]
val headerExists = (authHeaders?.size ?: 0) == 1
if(headerExists){
val authHeader = authHeaders!![0]
val valid = authenticationValidator.valid(authHeader)
if(valid) {
return chain!!.filter(exchange); // Forward to route
val headerExists = authHeaders?.size == 1

return if (headerExists) {
val authHeader = authHeaders?.get(0)
if (authenticationValidator.valid(authHeader ?: "")) {
chain?.filter(exchange) ?: Mono.empty() // Continue the filter chain if it isn't null. If it is null, return an empty Mono.
} else {
handleAuthenticationFailure(it)
}
} else {
handleAuthenticationFailure(it)
}
}
return exchange!!.let { this.onError(it) }

return Mono.error(Exception("ServerWebExchange or GatewayFilterChain is null"))
}

private fun onError(exchange: ServerWebExchange): Mono<Void> {
private fun handleAuthenticationFailure(exchange: ServerWebExchange): Mono<Void> {
val response: ServerHttpResponse = exchange.response
response.setStatusCode(HttpStatus.FORBIDDEN)
return response.setComplete()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,56 +9,71 @@ import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

@Configuration
class RoutesConfiguration (private val authenticationFilter: AuthenticationFilter) {
class RoutesConfiguration(private val authenticationFilter: AuthenticationFilter) {

companion object {
const val ADMIN_SERVICE_HOST = "admin.michibaum.ch"
const val ADMIN_SERVICE_URI = "lb://admin-service"
const val AUTHENTICATION_SERVICE_HOST = "authentication.michibaum.ch"
const val AUTHENTICATION_SERVICE_URI = "lb://authentication-service"
const val JAVADOC_SERVICE_HOST = "javadoc.michibaum.ch"
const val JAVADOC_SERVICE_URI = "lb://javadoc-service"
const val REGISTRY_SERVICE_HOST = "registry.michibaum.ch"
const val REGISTRY_SERVICE_URI = "lb://registry-service"
const val USERMANAGEMENT_SERVICE_HOST = "usermanagement.michibaum.ch"
const val USERMANAGEMENT_SERVICE_URI = "lb://usermanagement-service"
const val WEBSITE_SERVICE_HOST = "michibaum.ch"
const val WEBSITE_SERVICE_URI = "lb://website-service"
}

@Bean
fun routes(builder: RouteLocatorBuilder): RouteLocator {
return builder.routes {
route {
host("admin.michibaum.ch")
host(ADMIN_SERVICE_HOST)
filters {
authenticationFilter
AuthorizationPreFilter(Permissions.Admin_Service.CAN_SEND_REQUEST)
}
uri("lb://admin-service")
uri(ADMIN_SERVICE_URI)
}
route {
host("authentication.michibaum.ch")
host(AUTHENTICATION_SERVICE_HOST)
filters {

}
uri("lb://authentication-service")
uri(AUTHENTICATION_SERVICE_URI)
}
route {
host("javadoc.michibaum.ch")
host(JAVADOC_SERVICE_HOST)
filters {
authenticationFilter
AuthorizationPreFilter(Permissions.JavaDoc_Service.CAN_READ)
}
uri("lb://javadoc-service")
uri(JAVADOC_SERVICE_URI)
}
route {
host("registry.michibaum.ch")
host(REGISTRY_SERVICE_HOST)
filters {
authenticationFilter
AuthorizationPreFilter()
}
uri("lb://registry-service")
uri(REGISTRY_SERVICE_URI)
}
route {
host("usermanagement.michibaum.ch")
host(USERMANAGEMENT_SERVICE_HOST)
filters {
authenticationFilter
AuthorizationPreFilter()
}
uri("lb://usermanagement-service")
uri(USERMANAGEMENT_SERVICE_URI)
}
route {
host("michibaum.ch")
host(WEBSITE_SERVICE_HOST)
filters {

}
uri("lb://website-service")
uri(WEBSITE_SERVICE_URI)
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions gateway-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ server:


spring:
threads:
virtual:
enabled: true
lifecycle:
timeout-per-shutdown-phase: 20s
application:
Expand Down
3 changes: 3 additions & 0 deletions javadoc-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ server:
url-charset: UTF-8

spring:
threads:
virtual:
enabled: true
lifecycle:
timeout-per-shutdown-phase: 20s
application:
Expand Down
3 changes: 3 additions & 0 deletions registry-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ server:
port: 8761

spring:
threads:
virtual:
enabled: true
lifecycle:
timeout-per-shutdown-phase: 20s
application:
Expand Down
3 changes: 3 additions & 0 deletions usermanagement-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ server:
url-charset: UTF-8

spring:
threads:
virtual:
enabled: true
lifecycle:
timeout-per-shutdown-phase: 20s
application:
Expand Down
3 changes: 3 additions & 0 deletions website-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ server:
url-charset: UTF-8

spring:
threads:
virtual:
enabled: true
lifecycle:
timeout-per-shutdown-phase: 20s
application:
Expand Down
6 changes: 5 additions & 1 deletion website/src/app/footer/footer.component.html
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
<p>footer works!</p>
<div class="p-fluid p-justify-between p-mb-4">
<p-footer class="p-d-flex p-jc-center p-ai-center" style="height: 60px;">
<span class="p-text-center">Your app ©2024</span>
</p-footer>
</div>
9 changes: 9 additions & 0 deletions website/src/app/footer/footer.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
p-footer {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
background-color: #333;
color: white;
text-align: center;
}
5 changes: 4 additions & 1 deletion website/src/app/footer/footer.component.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { Component } from '@angular/core';
import {Footer} from "primeng/api";

@Component({
selector: 'app-footer',
standalone: true,
imports: [],
imports: [
Footer
],
templateUrl: './footer.component.html',
styleUrl: './footer.component.scss'
})
Expand Down
14 changes: 8 additions & 6 deletions website/src/app/light-dark-mode/light-dark-mode.component.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<div class=" border-round">
<p-toggleButton
[(ngModel)]="isDarkMode"
(onChange)="toggleLightDark()"
onLabel="Light"
offLabel="Dark" />
<div class="border-round">
<p-toggleButton
[(ngModel)]="isDarkMode"
(onChange)="toggleLightDark()"
onLabel="Light"
offLabel="Dark"
onIcon="pi pi-sun"
offIcon="pi pi-moon"/>
</div>

0 comments on commit 63ba15b

Please sign in to comment.