Skip to content

Commit

Permalink
Changes done for Base64 encryption for parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
agg3fe committed Jul 17, 2023
1 parent fe9d84f commit 0b9ffc1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public ResponseEntity<ServiceDescription> getDescription() {
}

@Override
public ResponseEntity<Void> deleteAssetAdministrationShellDescriptorById( String aasIdentifier ) {
shellService.deleteShell( aasIdentifier );
public ResponseEntity<Void> deleteAssetAdministrationShellDescriptorById( byte[] aasIdentifier ) {
shellService.deleteShell( getDecodedId(aasIdentifier) );
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@Override
Expand All @@ -80,8 +80,8 @@ public ResponseEntity<Void> deleteAllAssetLinksById(byte[] aasIdentifier) {
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@Override
public ResponseEntity<Void> deleteSubmodelDescriptorByIdThroughSuperpath( byte[] aasIdentifier, String submodelIdentifier ) {
shellService.deleteSubmodel(getDecodedId( aasIdentifier ), submodelIdentifier,getExternalSubjectIdOrEmpty( null ));
public ResponseEntity<Void> deleteSubmodelDescriptorByIdThroughSuperpath( byte[] aasIdentifier, byte[] submodelIdentifier ) {
shellService.deleteSubmodel(getDecodedId( aasIdentifier ), getDecodedId( submodelIdentifier ),getExternalSubjectIdOrEmpty( null ));
return new ResponseEntity<>(HttpStatus.NO_CONTENT);

}
Expand Down Expand Up @@ -110,14 +110,8 @@ public ResponseEntity<AssetAdministrationShellDescriptor> getAssetAdministration
return new ResponseEntity<>(shellMapper.toApiDto(saved), HttpStatus.OK);
}

private static String getDecodedId( byte[] aasIdentifier ) {
byte[] decodedBytes = Base64.getUrlDecoder().decode( aasIdentifier );
String decodedAasIdentifier = new String(decodedBytes);
return decodedAasIdentifier;
}

@Override
public ResponseEntity<SubmodelDescriptor> getSubmodelDescriptorByIdThroughSuperpath( byte[] aasIdentifier, String submodelIdentifier ) {
public ResponseEntity<SubmodelDescriptor> getSubmodelDescriptorByIdThroughSuperpath( byte[] aasIdentifier, byte[] submodelIdentifier ) {
Submodel submodel = shellService.findSubmodelByExternalId(getDecodedId( aasIdentifier ), getDecodedId( submodelIdentifier ),getExternalSubjectIdOrEmpty( null ));
return new ResponseEntity<>(submodelMapper.toApiDto(submodel), HttpStatus.OK);
}
Expand All @@ -139,10 +133,10 @@ public ResponseEntity<SubmodelDescriptor> postSubmodelDescriptorThroughSuperpath
}

@Override
public ResponseEntity<Void> putAssetAdministrationShellDescriptorById( String aasIdentifier, AssetAdministrationShellDescriptor assetAdministrationShellDescriptor ) {
public ResponseEntity<Void> putAssetAdministrationShellDescriptorById( byte[] aasIdentifier, AssetAdministrationShellDescriptor assetAdministrationShellDescriptor ) {
Shell shell = shellMapper.fromApiDto( assetAdministrationShellDescriptor );
Shell shellFromDb = shellService.findShellByExternalId( aasIdentifier,getExternalSubjectIdOrEmpty(null) );
shellService.update( shell.withId( shellFromDb.getId() ).withIdExternal(aasIdentifier ),aasIdentifier);
Shell shellFromDb = shellService.findShellByExternalId( getDecodedId( aasIdentifier),getExternalSubjectIdOrEmpty(null) );
shellService.update( shell.withId( shellFromDb.getId() ).withIdExternal(getDecodedId(aasIdentifier) ),getDecodedId(aasIdentifier));
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}

Expand All @@ -151,7 +145,7 @@ public ResponseEntity<Void> putSubmodelDescriptorByIdThroughSuperpath( byte[] aa
Submodel submodel = submodelMapper.fromApiDto( submodelDescriptor );
Submodel fromDB = shellService.findSubmodelByExternalId( getDecodedId( aasIdentifier ),getDecodedId( submodelIdentifier ),getExternalSubjectIdOrEmpty( null ) );
shellService.deleteSubmodel(getDecodedId( aasIdentifier ), getDecodedId( submodelIdentifier ),getExternalSubjectIdOrEmpty( null ));
shellService.update( aasIdentifier, submodel.withIdExternal( submodelIdentifier ).withId( fromDB.getId() ) ,getExternalSubjectIdOrEmpty( "" ));
shellService.update( getDecodedId( aasIdentifier ), submodel.withIdExternal( getDecodedId( submodelIdentifier ) ).withId( fromDB.getId() ) ,getExternalSubjectIdOrEmpty( "" ));
return new ResponseEntity<>( HttpStatus.NO_CONTENT );
}

Expand Down Expand Up @@ -189,5 +183,15 @@ public ResponseEntity<List<String>> postQueryAllAssetAdministrationShellIds(Shel
private String getExternalSubjectIdOrEmpty(String externalSubjectId) {
return (null ==externalSubjectId) ? "" : externalSubjectId;
}

private String getDecodedId( byte[] aasIdentifier ) {
try {
byte[] decodedBytes = Base64.getUrlDecoder().decode( aasIdentifier );
return new String( decodedBytes );
}catch ( Exception e ){
throw new IllegalArgumentException("Incorrect Base64 encoded value provided as parameter");
}
}

}

4 changes: 2 additions & 2 deletions backend/src/main/resources/static/aas-registry-openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ paths:
explode: false
schema:
type: string
# format: byte
format: byte
requestBody:
description: Asset Administration Shell Descriptor object
content:
Expand Down Expand Up @@ -306,7 +306,7 @@ paths:
explode: false
schema:
type: string
# format: byte
format: byte
responses:
"204":
description: Asset Administration Shell Descriptor deleted successfully
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public void testRbacForUpdate() throws Exception {
String shellPayloadForUpdate = mapper.writeValueAsString(testAas);
mvc.perform(
MockMvcRequestBuilders
.put(SINGLE_SHELL_BASE_PATH, shellId)
.put(SINGLE_SHELL_BASE_PATH, getEncodedValue(shellId))
.contentType(MediaType.APPLICATION_JSON)
.content(shellPayloadForUpdate)
// test with wrong role
Expand All @@ -203,7 +203,7 @@ public void testRbacForUpdate() throws Exception {

mvc.perform(
MockMvcRequestBuilders
.put(SINGLE_SHELL_BASE_PATH, shellId )
.put(SINGLE_SHELL_BASE_PATH, getEncodedValue(shellId) )
.contentType(MediaType.APPLICATION_JSON)
.content(shellPayloadForUpdate)
.with(jwtTokenFactory.updateTwin())
Expand All @@ -217,7 +217,7 @@ public void testRbacForUpdate() throws Exception {
public void testRbacForDelete() throws Exception {
mvc.perform(
MockMvcRequestBuilders
.delete(SINGLE_SHELL_BASE_PATH, shellId )
.delete(SINGLE_SHELL_BASE_PATH, getEncodedValue(shellId) )
// test with wrong role
.with(jwtTokenFactory.readTwin())
)
Expand All @@ -226,7 +226,7 @@ public void testRbacForDelete() throws Exception {

mvc.perform(
MockMvcRequestBuilders
.delete(SINGLE_SHELL_BASE_PATH, shellId )
.delete(SINGLE_SHELL_BASE_PATH, getEncodedValue(shellId) )
// test with wrong role
.with(jwtTokenFactory.deleteTwin())
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

import java.util.UUID;

import static org.assertj.core.api.AssertionsForClassTypes.notIn;
import static org.eclipse.tractusx.semantics.registry.TestUtil.getEncodedValue;
import static org.hamcrest.Matchers.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
Expand Down Expand Up @@ -140,7 +139,7 @@ public void testUpdateShellExpectSuccess() throws Exception {

mvc.perform(
MockMvcRequestBuilders
.put( SINGLE_SHELL_BASE_PATH, shellId )
.put( SINGLE_SHELL_BASE_PATH, getEncodedValue(shellId) )
.header( EXTERNAL_SUBJECT_ID_HEADER, jwtTokenFactory.tenantOne().getTenantId() )
.accept( MediaType.APPLICATION_JSON )
.contentType( MediaType.APPLICATION_JSON )
Expand Down Expand Up @@ -169,7 +168,7 @@ public void testUpdateShellExpectNotFound() throws Exception {

mvc.perform(
MockMvcRequestBuilders
.put( SINGLE_SHELL_BASE_PATH, "shellIdthatdoesnotexists" )
.put( SINGLE_SHELL_BASE_PATH, getEncodedValue("shellIdthatdoesnotexists") )
.accept( MediaType.APPLICATION_JSON )
.contentType( MediaType.APPLICATION_JSON )
.content( mapper.writeValueAsString( shellPayload ) )
Expand All @@ -194,7 +193,7 @@ public void testUpdateShellWithDifferentIdInPayloadExpectPathIdIsTaken() throws

mvc.perform(
MockMvcRequestBuilders
.put( SINGLE_SHELL_BASE_PATH, shellId )
.put( SINGLE_SHELL_BASE_PATH, getEncodedValue(shellId) )
.accept( MediaType.APPLICATION_JSON )
.header( EXTERNAL_SUBJECT_ID_HEADER, jwtTokenFactory.tenantOne().getTenantId() )
.contentType( MediaType.APPLICATION_JSON )
Expand Down Expand Up @@ -228,7 +227,7 @@ public void testDeleteShellExpectSuccess() throws Exception {
String shellId = shellPayload.getId();
mvc.perform(
MockMvcRequestBuilders
.delete( SINGLE_SHELL_BASE_PATH, shellId )
.delete( SINGLE_SHELL_BASE_PATH, getEncodedValue(shellId) )
.accept( MediaType.APPLICATION_JSON )
.with( jwtTokenFactory.allRoles() )
)
Expand All @@ -246,7 +245,7 @@ public void testDeleteShellExpectNotFound() throws Exception {
String shellId = shellPayload.getId();
mvc.perform(
MockMvcRequestBuilders
.delete( SINGLE_SHELL_BASE_PATH, shellId )
.delete( SINGLE_SHELL_BASE_PATH, getEncodedValue(shellId) )
.accept( MediaType.APPLICATION_JSON )
.with( jwtTokenFactory.allRoles() )
)
Expand Down

0 comments on commit 0b9ffc1

Please sign in to comment.