Skip to content

Commit 6820ff4

Browse files
committed
Merge branch 'release-3.0.0' of https://github.com/RADAR-base/ManagementPortal into release-3.0.0-keycloak-fix
2 parents 3eeb5d2 + b26324f commit 6820ff4

File tree

3 files changed

+67
-38
lines changed

3 files changed

+67
-38
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ jobs:
3535
id: yarn-cache-dir-path
3636
run: echo "dir=.yarn/cache" >> $GITHUB_OUTPUT
3737

38-
- uses: actions/setup-java@v3
38+
- uses: actions/setup-java@v4
3939
with:
4040
distribution: temurin
41-
java-version: 17
41+
java-version: '17.0.15'
4242

4343
- name: Setup Gradle
4444
uses: gradle/gradle-build-action@v2
@@ -76,7 +76,7 @@ jobs:
7676
run: |
7777
cp src/test/resources/config/keystore.p12 src/main/resources/config/keystore.p12
7878
./gradlew bootRun &>mp.log </dev/null &
79-
yarn run wait-for-managementportal
79+
yarn wait-for-managementportal
8080
yarn e2e
8181
./gradlew --stop
8282

src/main/java/org/radarbase/management/config/SecurityConfiguration.kt

Lines changed: 64 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package org.radarbase.management.config
33
import org.radarbase.auth.authentication.TokenValidator
44
import org.radarbase.auth.jwks.JwkAlgorithmParser
55
import org.radarbase.auth.jwks.JwksTokenVerifierLoader
6+
import org.radarbase.management.config.annotations.AuthServerDisabled
7+
import org.radarbase.management.config.annotations.AuthServerEnabled
68
import org.radarbase.management.repository.UserRepository
79
import org.radarbase.management.security.Http401UnauthorizedEntryPoint
810
import org.radarbase.management.security.JwtAuthenticationFilter
@@ -41,34 +43,9 @@ class SecurityConfiguration
4143
private val applicationEventPublisher: ApplicationEventPublisher,
4244
private val passwordEncoder: PasswordEncoder,
4345
private val managementPortalProperties: ManagementPortalProperties,
44-
private val userRepository: UserRepository
46+
private val userRepository: UserRepository,
47+
private val tokenValidator: TokenValidator,
4548
) : WebSecurityConfigurerAdapter() {
46-
/**
47-
* Create the token validator instance.
48-
* This is a private method to avoid creating multiple instances.
49-
*/
50-
private fun createTokenValidator(): TokenValidator {
51-
val loaderList = mutableListOf(
52-
JwksTokenVerifierLoader(
53-
managementPortalProperties.authServer.jwksUrl,
54-
RES_MANAGEMENT_PORTAL,
55-
JwkAlgorithmParser(),
56-
)
57-
)
58-
59-
// Only load ManagementPortal's own token_key endpoint if the internal auth server is enabled.
60-
if (managementPortalProperties.authServer.internal) {
61-
loaderList.add(
62-
JwksTokenVerifierLoader(
63-
managementPortalProperties.common.managementPortalBaseUrl + "/oauth/token_key",
64-
RES_MANAGEMENT_PORTAL,
65-
JwkAlgorithmParser()
66-
)
67-
)
68-
}
69-
return TokenValidator(loaderList)
70-
}
71-
7249
@PostConstruct
7350
fun init() {
7451
try {
@@ -90,10 +67,7 @@ class SecurityConfiguration
9067
fun http401UnauthorizedEntryPoint(): Http401UnauthorizedEntryPoint = Http401UnauthorizedEntryPoint()
9168

9269
@Bean
93-
fun tokenValidatorBean(): TokenValidator = createTokenValidator()
94-
95-
@Bean
96-
fun jwtAuthenticationFilter(tokenValidator: TokenValidator): JwtAuthenticationFilter {
70+
fun jwtAuthenticationFilter(): JwtAuthenticationFilter {
9771
val useInternalAuth = managementPortalProperties.authServer.internal
9872

9973
return JwtAuthenticationFilter(
@@ -165,7 +139,7 @@ class SecurityConfiguration
165139
.authenticationEntryPoint(http401UnauthorizedEntryPoint())
166140
.and()
167141
.addFilterBefore(
168-
jwtAuthenticationFilter(tokenValidatorBean()),
142+
jwtAuthenticationFilter(),
169143
UsernamePasswordAuthenticationFilter::class.java,
170144
)
171145
.authorizeRequests()
@@ -190,3 +164,61 @@ class SecurityConfiguration
190164
const val RES_MANAGEMENT_PORTAL = "res_ManagementPortal"
191165
}
192166
}
167+
168+
/**
169+
* TokenValidator configuration for internal auth server.
170+
* Active when managementportal.authServer.internal=true (or missing).
171+
*/
172+
@AuthServerEnabled
173+
@Configuration
174+
class InternalTokenValidatorConfiguration(
175+
private val managementPortalProperties: ManagementPortalProperties,
176+
) {
177+
178+
@Bean
179+
fun internalTokenValidator(): TokenValidator {
180+
val loaderList = mutableListOf(
181+
JwksTokenVerifierLoader(
182+
managementPortalProperties.authServer.jwksUrl,
183+
SecurityConfiguration.RES_MANAGEMENT_PORTAL,
184+
JwkAlgorithmParser(),
185+
)
186+
)
187+
188+
// Also load ManagementPortal's own token_key endpoint for internal auth.
189+
loaderList.add(
190+
JwksTokenVerifierLoader(
191+
managementPortalProperties.common.managementPortalBaseUrl + "/oauth/token_key",
192+
SecurityConfiguration.RES_MANAGEMENT_PORTAL,
193+
JwkAlgorithmParser()
194+
)
195+
)
196+
197+
return TokenValidator(loaderList)
198+
}
199+
}
200+
201+
/**
202+
* TokenValidator configuration for external auth server (e.g. Hydra).
203+
* Active when managementportal.authServer.internal=false.
204+
*/
205+
@AuthServerDisabled
206+
@Configuration
207+
class ExternalTokenValidatorConfiguration(
208+
private val managementPortalProperties: ManagementPortalProperties,
209+
) {
210+
211+
@Bean
212+
fun externalTokenValidator(): TokenValidator {
213+
val loaderList = listOf(
214+
JwksTokenVerifierLoader(
215+
managementPortalProperties.authServer.jwksUrl,
216+
SecurityConfiguration.RES_MANAGEMENT_PORTAL,
217+
JwkAlgorithmParser(),
218+
)
219+
)
220+
221+
return TokenValidator(loaderList)
222+
}
223+
}
224+

src/main/java/org/radarbase/management/service/DefaultOAuthClientService.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,12 @@ import org.springframework.security.oauth2.provider.NoSuchClientException
1818
import org.springframework.security.oauth2.provider.OAuth2Authentication
1919
import org.springframework.security.oauth2.provider.OAuth2Request
2020
import org.springframework.security.oauth2.provider.client.JdbcClientDetailsService
21-
import org.springframework.stereotype.Service
2221
import java.util.*
2322

2423
/**
2524
* Default implementation of OAuthClientService using Spring OAuth2 and JDBC.
2625
* This service handles OAuth client and token related functions using the internal OAuth server.
2726
*/
28-
@AuthServerEnabled
29-
@Service
3027
class DefaultOAuthClientService(
3128
@Autowired private val clientDetailsService: JdbcClientDetailsService,
3229
@Autowired private val clientDetailsMapper: ClientDetailsMapper,

0 commit comments

Comments
 (0)