-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from smartSenseSolutions/main
Fix: local deployment issues
- Loading branch information
Showing
14 changed files
with
2,743 additions
and
172 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,60 @@ | ||
# ******************************************************************************* | ||
# Copyright (c) 2024 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 | ||
# ******************************************************************************** | ||
|
||
services: | ||
database: | ||
image: 'postgres:16.2' | ||
ports: | ||
- '5432:5432' | ||
environment: | ||
- 'POSTGRES_USER=dcm' | ||
- 'POSTGRES_DB=dcm' | ||
- 'POSTGRES_PASSWORD=dcm' | ||
volumes: | ||
- mydb:/var/lib/postgresql/data | ||
- ./dev/create_keycloak_db.sh:/docker-entrypoint-initdb.d/create_second_db.sh | ||
|
||
keycloak: | ||
healthcheck: | ||
test: ["CMD", "curl", "-f", "http://0.0.0.0:8888/auth/"] | ||
interval: 5s | ||
timeout: 2s | ||
retries: 15 | ||
pid: "host" | ||
depends_on: | ||
- database | ||
volumes: | ||
- keycloak-data:/opt/keycloak/data/ | ||
- ./dev/dcm_realm.json:/opt/keycloak/data/import/dcm_realm_local.json | ||
environment: | ||
KEYCLOAK_ADMIN: admin | ||
KEYCLOAK_ADMIN_PASSWORD: admin | ||
DB_VENDOR: postgres | ||
DB_ADDR: database | ||
DB_DATABASE: auth | ||
DB_USER: root | ||
DB_PASSWORD: password | ||
image: quay.io/keycloak/keycloak:24.0.2 | ||
entrypoint: ["/opt/keycloak/bin/kc.sh", "start-dev", "--import-realm"] | ||
ports: | ||
- "28080:8080" | ||
|
||
volumes: | ||
mydb: | ||
keycloak-data: |
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
27 changes: 27 additions & 0 deletions
27
...ipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/appinfo/InfoConfiguration.java
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,27 @@ | ||
/* | ||
* ****************************************************************************** | ||
* Copyright (c) 2024 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 org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.appinfo; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
@ConfigurationProperties(prefix = "app.openapi") | ||
public record InfoConfiguration(String name, String description, String version) {} |
106 changes: 106 additions & 0 deletions
106
...e/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/config/openapi/OpenApiConfig.java
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,106 @@ | ||
/* | ||
* ****************************************************************************** | ||
* Copyright (c) 2024 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 org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.config.openapi; | ||
|
||
import io.swagger.v3.oas.models.Components; | ||
import io.swagger.v3.oas.models.OpenAPI; | ||
import io.swagger.v3.oas.models.info.Info; | ||
import io.swagger.v3.oas.models.security.OAuthFlow; | ||
import io.swagger.v3.oas.models.security.OAuthFlows; | ||
import io.swagger.v3.oas.models.security.SecurityRequirement; | ||
import io.swagger.v3.oas.models.security.SecurityScheme; | ||
import java.util.Collections; | ||
import lombok.AllArgsConstructor; | ||
import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.appinfo.InfoConfiguration; | ||
import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.security.AppSecurityConfigProperties; | ||
import org.springdoc.core.models.GroupedOpenApi; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@AllArgsConstructor | ||
public class OpenApiConfig { | ||
|
||
private final AppSecurityConfigProperties properties; | ||
private final InfoConfiguration appInfoConfiguration; | ||
|
||
@Bean | ||
public OpenAPI customOpenAPI() { | ||
Info info = new Info(); | ||
info.setTitle(appInfoConfiguration.name()); | ||
info.setDescription(appInfoConfiguration.description()); | ||
info.setVersion(appInfoConfiguration.version()); | ||
OpenAPI openAPI = new OpenAPI(); | ||
if (properties.enabled()) { | ||
openAPI = enableSecurity(openAPI); | ||
} | ||
return openAPI.info(info); | ||
} | ||
|
||
@Bean | ||
public GroupedOpenApi openApiDefinition() { | ||
return GroupedOpenApi.builder().group("docs").pathsToMatch("/**").displayName("Docs").build(); | ||
} | ||
|
||
private OpenAPI enableSecurity(OpenAPI openAPI) { | ||
Components components = new Components(); | ||
|
||
//Auth using access_token | ||
String accessTokenAuth = "Authenticate using access_token"; | ||
components.addSecuritySchemes( | ||
accessTokenAuth, | ||
new SecurityScheme() | ||
.name(accessTokenAuth) | ||
.description("Authenticate using token") | ||
.type(SecurityScheme.Type.HTTP) | ||
.scheme("Bearer") | ||
); | ||
|
||
//Auth using Resource Owner Password Flow | ||
String passwordFlow = "Authenticate using Resource Owner Password Flow"; | ||
components.addSecuritySchemes( | ||
passwordFlow, | ||
new SecurityScheme() | ||
.name(passwordFlow) | ||
.description( | ||
"Authenticate using Resource Owner Password Flow. provide username and password to authenticate" | ||
) | ||
.type(SecurityScheme.Type.OAUTH2) | ||
.flows( | ||
new OAuthFlows() | ||
.password( | ||
new OAuthFlow() | ||
.tokenUrl(properties.tokenUrl()) | ||
.refreshUrl(properties.refreshTokenUrl()) | ||
) | ||
) | ||
); | ||
|
||
return openAPI | ||
.components(components) | ||
.addSecurityItem( | ||
new SecurityRequirement() | ||
.addList(accessTokenAuth, Collections.emptyList()) | ||
.addList(passwordFlow, Collections.emptyList()) | ||
); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...sx/demandcapacitymgmt/demandcapacitymgmtbackend/security/AppSecurityConfigProperties.java
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,32 @@ | ||
/* | ||
* ****************************************************************************** | ||
* Copyright (c) 2024 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 org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.security; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
@ConfigurationProperties("app.openapi.security") | ||
public record AppSecurityConfigProperties( | ||
Boolean enabled, | ||
String authUrl, | ||
String tokenUrl, | ||
String refreshTokenUrl | ||
) {} |
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
Oops, something went wrong.