Skip to content

Commit

Permalink
Merge pull request #736 from catenax-ng/fix/auth-config-properties
Browse files Browse the repository at this point in the history
fix(BPDM): auth configuration in code not matching properties
  • Loading branch information
nicoprow authored Feb 6, 2024
2 parents 81c84e5 + daa6849 commit 57d994c
Show file tree
Hide file tree
Showing 62 changed files with 781 additions and 1,123 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*******************************************************************************
* Copyright (c) 2021,2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/

package com.catenax.bpdm.bridge.dummy.config

import org.eclipse.tractusx.bpdm.common.util.BpdmWebClientProvider
import org.eclipse.tractusx.bpdm.common.util.ClientConfigurationProperties
import org.eclipse.tractusx.bpdm.common.util.ConditionalOnBoundProperty
import org.eclipse.tractusx.bpdm.gate.api.client.GateClient
import org.eclipse.tractusx.bpdm.gate.api.client.GateClientImpl
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientService
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository

@ConfigurationProperties(prefix = GateConfigProperties.PREFIX)
data class GateConfigProperties(
override val baseUrl: String = "http://localhost:8081",
override val securityEnabled: Boolean = false,
override val oauth2ClientRegistration: String = "gate-client"
) : ClientConfigurationProperties {
companion object {
const val PREFIX = "${ClientConfigurationProperties.PREFIX}.gate"
}
}

@Configuration
class GateClientConfiguration(
clientProperties: GateConfigProperties,
) : BpdmWebClientProvider(
clientProperties
) {
@Bean
@ConditionalOnBoundProperty(GateConfigProperties.PREFIX, GateConfigProperties::class, true)
fun authorizedGateClient(
clientRegistrationRepository: ClientRegistrationRepository,
oAuth2AuthorizedClientService: OAuth2AuthorizedClientService
): GateClient =
GateClientImpl { provideAuthorizedClient(clientRegistrationRepository, oAuth2AuthorizedClientService) }

@Bean
@ConditionalOnBoundProperty(GateConfigProperties.PREFIX, GateConfigProperties::class, false)
fun unauthorizedGateClient(): GateClient =
GateClientImpl { provideUnauthorizedClient() }
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@

package com.catenax.bpdm.bridge.dummy.config

import com.catenax.bpdm.bridge.dummy.config.PermissionConfigProperties.Companion.PREFIX
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.context.annotation.Configuration

@Configuration
@ConfigurationProperties(prefix = "bpdm.bridge.permissions")
class BridgeAuthProperties {
var syncAuthorities: List<String> = listOf()

val syncAuthority: String
get() = syncAuthorities.joinToString(", ") { "ROLE_$it" }
}
@ConfigurationProperties(prefix = PREFIX)
class PermissionConfigProperties(
@Suppress("unused") val sync: String = "sync_company_data"
) {
companion object {
const val PREFIX = "bpdm.security.permissions"
private const val QUALIFIED_NAME = "com.catenax.bpdm.bridge.dummy.config.PermissionConfigProperties"
private const val BEAN_QUALIFIER = "'$PREFIX-$QUALIFIED_NAME'"

const val SYNC = "@$BEAN_QUALIFIER.getSync()"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*******************************************************************************
* Copyright (c) 2021,2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/

package com.catenax.bpdm.bridge.dummy.config

import org.eclipse.tractusx.bpdm.common.util.BpdmWebClientProvider
import org.eclipse.tractusx.bpdm.common.util.ClientConfigurationProperties
import org.eclipse.tractusx.bpdm.common.util.ConditionalOnBoundProperty
import org.eclipse.tractusx.bpdm.pool.api.client.PoolApiClient
import org.eclipse.tractusx.bpdm.pool.api.client.PoolClientImpl
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientService
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository


@ConfigurationProperties(prefix = PoolConfigProperties.PREFIX)
data class PoolConfigProperties(
override val baseUrl: String = "http://localhost:8080",
override val securityEnabled: Boolean = false,
override val oauth2ClientRegistration: String = "pool-client"
) : ClientConfigurationProperties {
companion object {
const val PREFIX = "${ClientConfigurationProperties.PREFIX}.pool"
}
}

@Configuration
class PoolClientConfiguration(
poolConfigProperties: PoolConfigProperties,
) : BpdmWebClientProvider(
poolConfigProperties
) {
@Bean
@ConditionalOnBoundProperty(PoolConfigProperties.PREFIX, PoolConfigProperties::class, true)
fun authorizedPoolClient(
clientRegistrationRepository: ClientRegistrationRepository,
oAuth2AuthorizedClientService: OAuth2AuthorizedClientService
): PoolApiClient = PoolClientImpl { provideAuthorizedClient(clientRegistrationRepository, oAuth2AuthorizedClientService) }

@Bean
@ConditionalOnBoundProperty(PoolConfigProperties.PREFIX, PoolConfigProperties::class, false)
fun unauthorizedPoolClient(): PoolApiClient =
PoolClientImpl { provideUnauthorizedClient() }
}
Loading

0 comments on commit 57d994c

Please sign in to comment.