-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bridge): Add authorization config and properties
- Loading branch information
1 parent
9097895
commit 4751aa8
Showing
5 changed files
with
180 additions
and
3 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
...src/main/kotlin/com/catenax/bpdm/bridge/dummy/config/BpdmSecurityConfigurerAdapterImpl.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,51 @@ | ||
/******************************************************************************* | ||
* 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.config.BpdmSecurityConfigurerAdapter | ||
import org.eclipse.tractusx.bpdm.common.config.CustomJwtAuthenticationConverter | ||
import org.eclipse.tractusx.bpdm.common.config.SecurityConfigProperties | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.http.HttpMethod | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity | ||
import org.springframework.security.config.http.SessionCreationPolicy | ||
import org.springframework.security.web.util.matcher.AntPathRequestMatcher | ||
|
||
@Configuration | ||
class BpdmSecurityConfigurerAdapterImpl( | ||
val securityConfigProperties: SecurityConfigProperties | ||
) : BpdmSecurityConfigurerAdapter { | ||
override fun configure(http: HttpSecurity) { | ||
http.csrf().disable() | ||
http.cors() | ||
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) | ||
http.authorizeHttpRequests() | ||
.requestMatchers(AntPathRequestMatcher("/api/**", HttpMethod.OPTIONS.name())).permitAll() | ||
.requestMatchers(AntPathRequestMatcher("/")).permitAll() // forwards to swagger | ||
.requestMatchers(AntPathRequestMatcher("/docs/api-docs/**")).permitAll() | ||
.requestMatchers(AntPathRequestMatcher("/ui/swagger-ui/**")).permitAll() | ||
.requestMatchers(AntPathRequestMatcher("/actuator/health/**")).permitAll() | ||
.requestMatchers(AntPathRequestMatcher("/error")).permitAll() | ||
.requestMatchers(AntPathRequestMatcher("/api/**")).authenticated() | ||
http.oauth2ResourceServer() | ||
.jwt() | ||
.jwtAuthenticationConverter(CustomJwtAuthenticationConverter(securityConfigProperties.clientId)) | ||
} | ||
} |
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
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
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
45 changes: 45 additions & 0 deletions
45
bpdm-bridge-dummy/src/main/resources/application-auth.properties
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,45 @@ | ||
################################################################################ | ||
# 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 | ||
################################################################################ | ||
## | ||
# Security config (defined in common) for restricting access to the bridge dummy resource server | ||
bpdm.security.enabled=true | ||
bpdm.security.cors-origins=* | ||
# OAuth configuration | ||
bpdm.security.client-id=BPDM_BRIDGE_DUMMY | ||
bpdm.security.realm=master | ||
bpdm.security.auth-server-url=http://localhost:8180 | ||
bpdm.security.auth-url=${bpdm.security.auth-server-url}/realms/${bpdm.security.realm}/protocol/openid-connect/auth | ||
bpdm.security.token-url=${bpdm.security.auth-server-url}/realms/${bpdm.security.realm}/protocol/openid-connect/token | ||
bpdm.security.refresh-url=${bpdm.security.token-url} | ||
# Spring security | ||
spring.security.oauth2.resourceserver.jwt.issuer-uri=${bpdm.security.auth-server-url}/realms/${bpdm.security.realm} | ||
spring.security.oauth2.resourceserver.jwt.jwk-set-uri=${bpdm.security.auth-server-url}/realms/${bpdm.security.realm}/protocol/openid-connect/certs | ||
## | ||
# OAuth2 authorized connection to Pool and Gate client | ||
bpdm.pool.security-enabled=true | ||
bpdm.pool.oauth2-client-registration=bridge-client | ||
bpdm.gate.security-enabled=true | ||
bpdm.gate.oauth2-client-registration=bridge-client | ||
## Note that the oauth2-client-registration properties is NOT the client id in Keycloak but references spring.security.oauth2.client.registration | ||
# registration "bridge-client" - can be used for both pool and gate client | ||
spring.security.oauth2.client.registration.bridge-client.client-id=${bpdm.security.client-id} | ||
spring.security.oauth2.client.registration.bridge-client.client-secret=${bpdm.security.credentials.secret} | ||
spring.security.oauth2.client.registration.bridge-client.authorization-grant-type=client_credentials | ||
spring.security.oauth2.client.registration.bridge-client.provider=catena-keycloak-provider | ||
spring.security.oauth2.client.provider.catena-keycloak-provider.issuer-uri=${bpdm.security.auth-server-url:http://localhost:8180}/realms/${bpdm.security.realm:master} |