Skip to content

Commit 5e3b5b8

Browse files
Rodrigo Dos SantosRodrigo Dos Santos
authored andcommitted
Fixed kotlin and react services - build react-webapp, build kotlin-service
1 parent f71c7e9 commit 5e3b5b8

File tree

3 files changed

+18
-23
lines changed

3 files changed

+18
-23
lines changed

.github/workflows/docker-build-push-image-react-webapp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
build-args: |
5050
GITHUB_SHA=$GITHUB_SHA
5151
GITHUB_REF=$GITHUB_REF
52-
PORT=3003Ï
52+
PORT=3003
5353
5454
- name: Image digest
5555
run: echo ${{ steps.docker_build.outputs.digest }}

.github/workflows/kubernetes/edge-server-configmap.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,15 @@ spring:
2828
uri: lb://authentication-service
2929
predicates:
3030
- Path=/oauth/**,/api/account,/api/authenticatedUser,/api/authenticate,/api/logout,/api/refreshToken,/login/oauth2/**,/oauth2/**,/.well-known/jwks.json
31+
filters:
32+
- SaveSession
3133
- id: authentication-service-swagger
3234
uri: lb://authentication-service
3335
predicates:
3436
- Path=/swagger/authentication-service/**
3537
filters:
36-
- RewritePath=/authentication-service/(?<segment>.*), /$\{segment}
38+
- StripPrefix=2
39+
#- RewritePath=/authentication-service/(?<segment>.*), /$\{segment}
3740
- id: user-service
3841
uri: lb://user-service
3942
predicates:

kotlin-service/src/main/kotlin/com/microservice/kotlin/config/SpringSecurityConfiguration.kt

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ package com.microservice.kotlin.config
22

33
import com.fasterxml.jackson.databind.ObjectMapper
44
import com.microservice.authentication.autoconfigure.AuthenticationProperties
5-
import com.microservice.authentication.common.service.Base64DecodeUtil
65
import com.microservice.web.common.util.CustomDefaultErrorAttributes
76
import org.springframework.beans.factory.annotation.Autowired
87
import org.springframework.boot.web.error.ErrorAttributeOptions
8+
import org.springframework.context.annotation.Bean
99
import org.springframework.context.annotation.Configuration
10-
import org.springframework.core.env.Profiles
11-
import org.springframework.core.io.FileSystemResource
1210
import org.springframework.http.HttpHeaders
1311
import org.springframework.http.MediaType
1412
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity
@@ -20,7 +18,6 @@ import org.springframework.security.oauth2.jwt.JwtDecoder
2018
import org.springframework.security.oauth2.jwt.NimbusJwtDecoder
2119
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationConverter
2220
import org.springframework.security.oauth2.server.resource.authentication.JwtGrantedAuthoritiesConverter
23-
import org.springframework.security.rsa.crypto.KeyStoreKeyFactory
2421
import org.springframework.web.context.request.ServletWebRequest
2522
import java.io.IOException
2623
import java.nio.charset.StandardCharsets
@@ -35,7 +32,7 @@ import javax.servlet.http.HttpServletResponse
3532
class SpringSecurityConfiguration(@Autowired val customDefaultErrorAttributes: CustomDefaultErrorAttributes,
3633
@Autowired val objectMapper: ObjectMapper,
3734
@Autowired val properties: AuthenticationProperties) : WebSecurityConfigurerAdapter() {
38-
private val WHITELIST = arrayOf(
35+
private val WHITE_LIST = arrayOf(
3936
// -- swagger ui
4037
// -- swagger ui
4138
"/v3/api-docs/**", "/swagger-resources", "/swagger-resources/**", "/configuration/ui", "/configuration/security", "/swagger-ui.html", "/webjars/**", "/**/*.js", "/**/*.css", "/**/*.html", "/favicon.ico",
@@ -57,33 +54,28 @@ class SpringSecurityConfiguration(@Autowired val customDefaultErrorAttributes: C
5754
.httpBasic().disable()
5855
.logout().disable()
5956
.authorizeRequests()
60-
.antMatchers(*WHITELIST).permitAll()
57+
.antMatchers(*WHITE_LIST).permitAll()
6158
.anyRequest().authenticated()
6259
.and()
6360
.oauth2ResourceServer()
6461
.accessDeniedHandler(this::handleErrorResponse)
6562
.authenticationEntryPoint(this::handleErrorResponse)
6663
.jwt {
67-
val environment = applicationContext.environment
68-
val jwtDecoder = if (environment.acceptsProfiles(Profiles.of("prod"))) jwtDecoderProd(keyPair(properties)) else jwtDecoder(properties)
64+
val jwtDecoder = jwtDecoder(properties)
6965
it.decoder(jwtDecoder).jwtAuthenticationConverter(jwtAuthenticationConverter())
7066
}
7167
}
7268

73-
fun keyPair(properties: AuthenticationProperties): RSAPublicKey? {
74-
val jwt = properties.jwt
75-
val password = Base64DecodeUtil.decodePassword(jwt.keyStorePassword)
76-
val keyStoreKeyFactory = KeyStoreKeyFactory(FileSystemResource(jwt.keyStore.replaceFirst("file:".toRegex(), "")), password)
77-
return keyStoreKeyFactory.getKeyPair(jwt.keyAlias).public as RSAPublicKey
78-
}
79-
80-
fun jwtDecoderProd(publicKey: RSAPublicKey?): JwtDecoder? {
81-
return NimbusJwtDecoder.withPublicKey(publicKey).build()
82-
}
83-
69+
@Bean
8470
fun jwtDecoder(properties: AuthenticationProperties): JwtDecoder? {
85-
val secretKeySpec = SecretKeySpec(properties.jwt.keyValue.toByteArray(StandardCharsets.UTF_8), "HS256")
86-
return NimbusJwtDecoder.withSecretKey(secretKeySpec).build()
71+
val jwt = properties.jwt
72+
return if (jwt != null && jwt.keyValue != null) {
73+
val secretKeySpec = SecretKeySpec(jwt.keyValue.toByteArray(StandardCharsets.UTF_8), "HS256")
74+
NimbusJwtDecoder.withSecretKey(secretKeySpec).build()
75+
} else {
76+
val publicKey = applicationContext.getBean(RSAPublicKey::class.java)
77+
NimbusJwtDecoder.withPublicKey(publicKey).build()
78+
}
8779
}
8880

8981
@Throws(IOException::class)

0 commit comments

Comments
 (0)