-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split open api config to DDI and MGMT resources (#1954)
Signed-off-by: Avgustin Marinov <[email protected]>
- Loading branch information
1 parent
7a0735c
commit 57e6d35
Showing
3 changed files
with
121 additions
and
71 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
...resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiOpenApiConfiguration.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,53 @@ | ||
/** | ||
* Copyright (c) 2023 Bosch.IO GmbH and others | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.hawkbit.ddi.rest.resource; | ||
|
||
import io.swagger.v3.oas.models.security.SecurityRequirement; | ||
import io.swagger.v3.oas.models.security.SecurityScheme; | ||
import org.eclipse.hawkbit.rest.OpenApiConfiguration; | ||
import org.springdoc.core.models.GroupedOpenApi; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@ConditionalOnProperty( | ||
value = OpenApiConfiguration.HAWKBIT_SERVER_SWAGGER_ENABLED, | ||
havingValue = "true", | ||
matchIfMissing = true) | ||
public class DdiOpenApiConfiguration { | ||
|
||
private static final String DDI_TOKEN_SEC_SCHEME_NAME = "DDI Target/GatewayToken Authentication"; | ||
|
||
@Bean | ||
@ConditionalOnProperty( | ||
value = "hawkbit.server.swagger.ddi.api.group.enabled", | ||
havingValue = "true", | ||
matchIfMissing = true) | ||
public GroupedOpenApi ddiApi() { | ||
return GroupedOpenApi | ||
.builder() | ||
.group("Direct Device Integration API") | ||
.pathsToMatch("/{tenant}/controller/**") | ||
.addOpenApiCustomizer(openApi -> | ||
openApi | ||
.addSecurityItem(new SecurityRequirement().addList(DDI_TOKEN_SEC_SCHEME_NAME)) | ||
.components( | ||
openApi | ||
.getComponents() | ||
.addSecuritySchemes(DDI_TOKEN_SEC_SCHEME_NAME, | ||
new SecurityScheme() | ||
.name("Authorization") | ||
.type(SecurityScheme.Type.APIKEY) | ||
.in(SecurityScheme.In.HEADER) | ||
.description("Format: (Target|Gateway)Token <token>")))) | ||
.build(); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...source/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtOpenApiConfiguration.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,63 @@ | ||
/** | ||
* Copyright (c) 2023 Bosch.IO GmbH and others | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.hawkbit.mgmt.rest.resource; | ||
|
||
import io.swagger.v3.oas.models.security.SecurityRequirement; | ||
import io.swagger.v3.oas.models.security.SecurityScheme; | ||
import org.eclipse.hawkbit.rest.OpenApiConfiguration; | ||
import org.springdoc.core.models.GroupedOpenApi; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@ConditionalOnProperty( | ||
value = "hawkbit.server.swagger.enabled", | ||
havingValue = "true", | ||
matchIfMissing = true) | ||
public class MgmtOpenApiConfiguration { | ||
|
||
private static final String BASIC_AUTH_SEC_SCHEME_NAME = "Basic Authentication"; | ||
private static final String BEARER_AUTH_SEC_SCHEME_NAME = "Bearer Authentication"; | ||
|
||
@Bean | ||
@ConditionalOnProperty( | ||
value = OpenApiConfiguration.HAWKBIT_SERVER_SWAGGER_ENABLED, | ||
havingValue = "true", | ||
matchIfMissing = true) | ||
public GroupedOpenApi mgmtApi() { | ||
return GroupedOpenApi | ||
.builder() | ||
.group("Management API") | ||
.pathsToMatch("/rest/v1/**") | ||
.addOpenApiCustomizer(openApi -> | ||
openApi | ||
.addSecurityItem(new SecurityRequirement() | ||
.addList(BASIC_AUTH_SEC_SCHEME_NAME) | ||
.addList(BEARER_AUTH_SEC_SCHEME_NAME)) | ||
.components( | ||
openApi | ||
.getComponents() | ||
.addSecuritySchemes(BASIC_AUTH_SEC_SCHEME_NAME, | ||
new SecurityScheme() | ||
.name(BASIC_AUTH_SEC_SCHEME_NAME) | ||
.type(SecurityScheme.Type.HTTP) | ||
.in(SecurityScheme.In.HEADER) | ||
.scheme("basic")) | ||
.addSecuritySchemes(BEARER_AUTH_SEC_SCHEME_NAME, | ||
new SecurityScheme() | ||
.name(BEARER_AUTH_SEC_SCHEME_NAME) | ||
.type(SecurityScheme.Type.HTTP) | ||
.in(SecurityScheme.In.HEADER) | ||
.bearerFormat("JWT") | ||
.scheme("bearer")))) | ||
.build(); | ||
} | ||
} |
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