Skip to content

Commit

Permalink
Merge pull request #2 from bci-oss/feature/update-selfdescription-to-…
Browse files Browse the repository at this point in the history
…v.3.0.1

getDescription request updated to new API version 3.0.1.
  • Loading branch information
bs-sili authored Sep 27, 2023
2 parents d4b6736 + 67dfae8 commit 5321ee2
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.util.*;

import org.eclipse.tractusx.semantics.RegistryProperties;
import org.eclipse.tractusx.semantics.aas.registry.api.DescriptionApiDelegate;
import org.eclipse.tractusx.semantics.aas.registry.api.LookupApiDelegate;
import org.eclipse.tractusx.semantics.aas.registry.api.ShellDescriptorsApiDelegate;
Expand Down Expand Up @@ -48,7 +49,7 @@ public class AssetAdministrationShellApiDelegate implements DescriptionApiDelega

public AssetAdministrationShellApiDelegate(final ShellService shellService,
final ShellMapper shellMapper,
final SubmodelMapper submodelMapper) {
final SubmodelMapper submodelMapper ) {
this.shellService = shellService;
this.shellMapper = shellMapper;
this.submodelMapper = submodelMapper;
Expand All @@ -61,9 +62,9 @@ public Optional<NativeWebRequest> getRequest() {

@Override
public ResponseEntity<ServiceDescription> getDescription() {

ServiceDescription serviceDescription = new ServiceDescription();
serviceDescription.setProfiles( List.of( ServiceDescription.ProfilesEnum.ASSETADMINISTRATIONSHELLREPOSITORYSERVICESPECIFICATION_V3_0_MINIMALPROFILE,
ServiceDescription.ProfilesEnum.REGISTRYSERVICESPECIFICATION_V3_0) );
serviceDescription.setProfiles( List.of( ServiceDescription.ProfilesEnum.ASSETADMINISTRATIONSHELLREGISTRYSERVICESPECIFICATION_SSP_001, ServiceDescription.ProfilesEnum.DISCOVERYSERVICESPECIFICATION_SSP_001) );
return new ResponseEntity<>( serviceDescription, HttpStatus.OK );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ protected SecurityFilterChain configure(HttpSecurity http) throws Exception {
.requestMatchers( HttpMethod.POST, "/**/lookup/**" ).access( "@authorizationEvaluator.hasRoleAddDigitalTwin()" )
.requestMatchers( HttpMethod.PUT, "/**/lookup/**" ).access( "@authorizationEvaluator.hasRoleUpdateDigitalTwin()" )
.requestMatchers( HttpMethod.DELETE, "/**/lookup/**" ).access( "@authorizationEvaluator.hasRoleDeleteDigitalTwin()" )

//getDescription allowed for reader
.requestMatchers( HttpMethod.GET, "/**/description" ).access( "@authorizationEvaluator.hasRoleViewDigitalTwin()" )
)
.csrf().disable()
.sessionManagement().sessionCreationPolicy( SessionCreationPolicy.STATELESS )
Expand Down
37 changes: 19 additions & 18 deletions backend/src/main/resources/static/aas-registry-openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1502,29 +1502,30 @@ components:
properties:
profiles:
minItems: 1
maxItems: 10000
type: array
items:
type: string
enum:
- AssetAdministrationShellServiceSpecification/V3.0
- AssetAdministrationShellServiceSpecification/V3.0-MinimalProfile
- SubmodelServiceSpecification/V3.0
- SubmodelServiceSpecification/V3.0-ValueProfile
- SubmodelServiceSpecification/V3.0-MinimalProfile
- AasxFileServerServiceSpecification/V3.0
- RegistryServiceSpecification/V3.0
- RegistryServiceSpecification/V3.0- AssetAdministrationShellRegistry
- RegistryServiceSpecification/V3.0-SubmodelRegistry
- RepositoryServiceSpecification/V3.0
- RepositoryServiceSpecification/V3.0-MinimalProfile
- AssetAdministrationShellRepositoryServiceSpecification/V3.0
- AssetAdministrationShellRepositoryServiceSpecification/V3.0-MinimalProfile
- SubmodelRepositoryServiceSpecification/V3.0
- SubmodelRepositoryServiceSpecification/V3.0-MinimalProfile
- RegistryAndDiscoveryServiceSpecification/V3.0
- https://admin-shell.io/aas/API/3/0/AssetAdministrationShellServiceSpecification/SSP-001
- https://admin-shell.io/aas/API/3/0/AssetAdministrationShellServiceSpecification/SSP-002
- https://admin-shell.io/aas/API/3/0/SubmodelServiceSpecification/SSP-001
- https://admin-shell.io/aas/API/3/0/SubmodelServiceSpecification/SSP-002
- https://admin-shell.io/aas/API/3/0/SubmodelServiceSpecification/SSP-003
- https://admin-shell.io/aas/API/3/0/AasxFileServerServiceSpecification/SSP-001
- https://admin-shell.io/aas/API/3/0/AssetAdministrationShellRegistryServiceSpecification/SSP-001
- https://admin-shell.io/aas/API/3/0/AssetAdministrationShellRegistryServiceSpecification/SSP-002
- https://admin-shell.io/aas/API/3/0/SubmodelRegistryServiceSpecification/SSP-001
- https://admin-shell.io/aas/API/3/0/SubmodelRegistryServiceSpecification/SSP-002
- https://admin-shell.io/aas/API/3/0/DiscoveryServiceSpecification/SSP-001
- https://admin-shell.io/aas/API/3/0/AssetAdministrationShellRepositoryServiceSpecification/SSP-001
- https://admin-shell.io/aas/API/3/0/AssetAdministrationShellRepositoryServiceSpecification/SSP-002
- https://admin-shell.io/aas/API/3/0/SubmodelRepositoryServiceSpecification/SSP-001
- https://admin-shell.io/aas/API/3/0/SubmodelRepositoryServiceSpecification/SSP-002
- https://admin-shell.io/aas/API/3/0/SubmodelRepositoryServiceSpecification/SSP-003
- https://admin-shell.io/aas/API/3/0/SubmodelRepositoryServiceSpecification/SSP-004
- https://admin-shell.io/aas/API/3/0/ConceptDescriptionServiceSpecification/SSP-001
description: "The Description object enables servers to present their capabilities to the clients, in particular which profiles they implement. At least one defined profile is required. Additional, proprietary attributes might be included. Nevertheless, the server must not expect that a regular client understands them."
example: { "profiles": [ "RepositoryServiceSpecification/V3.0-MinimalProfile", "RegistryServiceSpecification/V3.0" ] }
example: { "profiles": ["https://admin-shell.io/aas/API/3/0/AssetAdministrationShellRegistryServiceSpecification/SSP-002", "https://admin-shell.io/aas/API/3/0/SubmodelRegistryServiceSpecification/SSP-002"] }
PagedResult_paging_metadata:
type: object
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1243,4 +1243,55 @@ public void testGetAllShellByExternalIdWithPublicAccessByTenantId() throws Excep
.andExpect(jsonPath("$.specificAssetIds[*]").exists());
}
}
@Nested
@DisplayName( "Description Authentication Tests" )
class DescriptionApiTest {

@Test
public void testGetDescriptionOnlyDeleteRoleExpectForbidden() throws Exception {
mvc.perform(
MockMvcRequestBuilders
.get( "/api/v3.0/description" )
.accept( MediaType.APPLICATION_JSON )
.with( jwtTokenFactory.deleteTwin() )
)
.andDo( MockMvcResultHandlers.print() )
.andExpect(status().isForbidden());
}

@Test
public void testGetDescriptionNoRoleExpectForbidden() throws Exception {
mvc.perform(
MockMvcRequestBuilders
.get( "/api/v3.0/description" )
.accept( MediaType.APPLICATION_JSON )
.with( jwtTokenFactory.withoutRoles() )
)
.andDo( MockMvcResultHandlers.print() )
.andExpect(status().isForbidden());
}

@Test
public void testGetDescriptionReadRoleExpectSuccess() throws Exception {
mvc.perform(
MockMvcRequestBuilders
.get( "/api/v3.0/description" )
.accept( MediaType.APPLICATION_JSON )
.with( jwtTokenFactory.readTwin() )
)
.andDo( MockMvcResultHandlers.print() )
.andExpect(status().isOk());
}

@Test
public void testGetDescriptionReadRoleExpectUnauthorized() throws Exception {
mvc.perform(
MockMvcRequestBuilders
.get( "/api/v3.0/description" )
.accept( MediaType.APPLICATION_JSON )
)
.andDo( MockMvcResultHandlers.print() )
.andExpect(status().isUnauthorized());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -992,4 +992,20 @@ public void testFetchShellsByMultipleIdentificationsExpectSuccessExpectSuccess()
}
}

@Nested
@DisplayName( "Description Tests" )
class DescriptionApiTest {
@Test
public void testGetDescriptionExpectSuccess() throws Exception {
mvc.perform(
MockMvcRequestBuilders
.get( "/api/v3.0/description" )
.accept( MediaType.APPLICATION_JSON )
.with( jwtTokenFactory.allRoles() )
)
.andDo( MockMvcResultHandlers.print() )
.andExpect( status().isOk() )
.andExpect( jsonPath( "$.profiles[0]", is( "https://admin-shell.io/aas/API/3/0/AssetAdministrationShellRegistryServiceSpecification/SSP-001" ) ) );
}
}
}

0 comments on commit 5321ee2

Please sign in to comment.