From 818884246f6380224b544e39c493d1a359fd4ad9 Mon Sep 17 00:00:00 2001 From: Mohammad Ghazanfar Ali Danish Date: Mon, 23 Dec 2024 17:52:12 +0100 Subject: [PATCH] Filter models as per RBAC rules Signed-off-by: Mohammad Ghazanfar Ali Danish --- .github/workflows/basyx_test.yml | 2 - .github/workflows/docker_test.yml | 2 - .../pom.xml | 4 - ...AuthorizedAasEnvironmentConfiguration.java | 10 - ...asEnvironmentTargetInformationAdapter.java | 134 ------------- ...vironmentTargetInformationAdapterTest.java | 184 ----------------- .../src/main/resources/application.properties | 17 +- .../AasRegistryTargetInformationAdapter.java | 44 +---- ...sRegistryTargetInformationAdapterTest.java | 27 +-- .../submodel/AasTargetInformationAdapter.java | 41 +--- .../AasTargetInformationAdapterTest.java | 25 +-- .../CommonSecurityConfiguration.java | 4 - .../pom.xml | 4 - ...eptDescriptionRepositoryConfiguration.java | 8 - .../submodel/CDTargetInformationAdapter.java | 114 ----------- .../CDTargetInformationAdapterTest.java | 161 --------------- .../pom.xml | 4 - ...thorizedSubmodelRegistryConfiguration.java | 8 - ...modelRegistryTargetInformationAdapter.java | 114 ----------- ...lRegistryTargetInformationAdapterTest.java | 163 --------------- .../pom.xml | 24 +-- ...orizedSubmodelRepositoryConfiguration.java | 8 - .../SubmodelTargetInformationAdapter.java | 130 ------------ .../SubmodelTargetInformationAdapterTest.java | 185 ------------------ ci/docker-compose.yml | 20 +- ci/rules/sm-repo-rbac_rules.json | 155 --------------- ci/rules/sm-repo.properties | 10 - 27 files changed, 42 insertions(+), 1560 deletions(-) delete mode 100644 basyx.aasenvironment/basyx.aasenvironment-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/aasenvironment/feature/authorization/rbac/backend/submodel/AasEnvironmentTargetInformationAdapter.java delete mode 100644 basyx.aasenvironment/basyx.aasenvironment-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/aasenvironment/feature/authorization/AasEnvironmentTargetInformationAdapterTest.java delete mode 100644 basyx.conceptdescriptionrepository/basyx.conceptdescriptionrepository-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/conceptdescriptionrepository/feature/authorization/rbac/backend/submodel/CDTargetInformationAdapter.java delete mode 100644 basyx.conceptdescriptionrepository/basyx.conceptdescriptionrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/conceptdescriptionrepository/feature/authorization/CDTargetInformationAdapterTest.java delete mode 100644 basyx.submodelregistry/basyx.submodelregistry-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/submodelregistry/feature/authorization/rbac/backend/submodel/SubmodelRegistryTargetInformationAdapter.java delete mode 100644 basyx.submodelregistry/basyx.submodelregistry-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/submodelregistry/regression/feature/authorization/SubmodelRegistryTargetInformationAdapterTest.java delete mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/authorization/rbac/backend/submodel/SubmodelTargetInformationAdapter.java delete mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/authorization/SubmodelTargetInformationAdapterTest.java delete mode 100644 ci/rules/sm-repo-rbac_rules.json delete mode 100644 ci/rules/sm-repo.properties diff --git a/.github/workflows/basyx_test.yml b/.github/workflows/basyx_test.yml index 90143950c..1187244a2 100644 --- a/.github/workflows/basyx_test.yml +++ b/.github/workflows/basyx_test.yml @@ -1,8 +1,6 @@ name: Build and Test BaSyx on: - push: - branches: [ temp-feature/filter-dyn-rbac ] pull_request: branches: [ main ] paths-ignore: diff --git a/.github/workflows/docker_test.yml b/.github/workflows/docker_test.yml index dcd288655..d10df98fa 100644 --- a/.github/workflows/docker_test.yml +++ b/.github/workflows/docker_test.yml @@ -4,8 +4,6 @@ name: Build and Start Docker Images on: - push: - branches: [ temp-feature/filter-dyn-rbac ] pull_request: branches: [ main ] paths-ignore: diff --git a/basyx.aasenvironment/basyx.aasenvironment-feature-authorization/pom.xml b/basyx.aasenvironment/basyx.aasenvironment-feature-authorization/pom.xml index 532051b99..637abee7e 100644 --- a/basyx.aasenvironment/basyx.aasenvironment-feature-authorization/pom.xml +++ b/basyx.aasenvironment/basyx.aasenvironment-feature-authorization/pom.xml @@ -81,10 +81,6 @@ org.eclipse.digitaltwin.basyx basyx.authorization.rules.rbac.backend.inmemory - - - org.eclipse.digitaltwin.basyx - basyx.authorization.rules.rbac.backend.submodel diff --git a/basyx.aasenvironment/basyx.aasenvironment-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/aasenvironment/feature/authorization/AuthorizedAasEnvironmentConfiguration.java b/basyx.aasenvironment/basyx.aasenvironment-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/aasenvironment/feature/authorization/AuthorizedAasEnvironmentConfiguration.java index 6dab7228b..79475434a 100644 --- a/basyx.aasenvironment/basyx.aasenvironment-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/aasenvironment/feature/authorization/AuthorizedAasEnvironmentConfiguration.java +++ b/basyx.aasenvironment/basyx.aasenvironment-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/aasenvironment/feature/authorization/AuthorizedAasEnvironmentConfiguration.java @@ -27,7 +27,6 @@ import org.eclipse.digitaltwin.basyx.aasenvironment.AasEnvironment; import org.eclipse.digitaltwin.basyx.aasenvironment.feature.authorization.rbac.AasEnvironmentTargetPermissionVerifier; -import org.eclipse.digitaltwin.basyx.aasenvironment.feature.authorization.rbac.backend.submodel.AasEnvironmentTargetInformationAdapter; import org.eclipse.digitaltwin.basyx.aasenvironment.preconfiguration.AasEnvironmentPreconfigurationLoader; import org.eclipse.digitaltwin.basyx.authorization.CommonAuthorizationProperties; import org.eclipse.digitaltwin.basyx.authorization.rbac.RbacPermissionResolver; @@ -35,8 +34,6 @@ import org.eclipse.digitaltwin.basyx.authorization.rbac.SimpleRbacPermissionResolver; import org.eclipse.digitaltwin.basyx.authorization.rbac.RoleProvider; import org.eclipse.digitaltwin.basyx.authorization.rbac.TargetPermissionVerifier; -import org.eclipse.digitaltwin.basyx.authorization.rules.rbac.backend.submodel.TargetInformationAdapter; -import org.eclipse.digitaltwin.basyx.conceptdescriptionrepository.feature.authorization.rbac.backend.submodel.CDTargetInformationAdapter; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -70,12 +67,5 @@ public RbacPermissionResolver getAasEnvironment public static AasEnvironmentPreconfigurationLoader getAuthorizedAasEnvironmentPreconfigurationLoader(ResourceLoader resourceLoader, List pathsToLoad) { return new AuthorizedAASEnvironmentPreconfigurationLoader(resourceLoader, pathsToLoad); } - - @Bean - @Primary - public TargetInformationAdapter getAasEnvInformationAdapter() { - - return new AasEnvironmentTargetInformationAdapter(); - } } diff --git a/basyx.aasenvironment/basyx.aasenvironment-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/aasenvironment/feature/authorization/rbac/backend/submodel/AasEnvironmentTargetInformationAdapter.java b/basyx.aasenvironment/basyx.aasenvironment-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/aasenvironment/feature/authorization/rbac/backend/submodel/AasEnvironmentTargetInformationAdapter.java deleted file mode 100644 index 7465ff28e..000000000 --- a/basyx.aasenvironment/basyx.aasenvironment-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/aasenvironment/feature/authorization/rbac/backend/submodel/AasEnvironmentTargetInformationAdapter.java +++ /dev/null @@ -1,134 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2024 the Eclipse BaSyx Authors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * SPDX-License-Identifier: MIT - ******************************************************************************/ - -package org.eclipse.digitaltwin.basyx.aasenvironment.feature.authorization.rbac.backend.submodel; - -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import org.eclipse.digitaltwin.aas4j.v3.model.Property; -import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElement; -import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElementCollection; -import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElementList; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultProperty; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSubmodelElementCollection; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSubmodelElementList; -import org.eclipse.digitaltwin.basyx.aasenvironment.feature.authorization.AasEnvironmentTargetInformation; -import org.eclipse.digitaltwin.basyx.aasrepository.feature.authorization.AasTargetInformation; -import org.eclipse.digitaltwin.basyx.aasrepository.feature.authorization.rbac.backend.submodel.AasTargetInformationAdapter; -import org.eclipse.digitaltwin.basyx.authorization.rbac.TargetInformation; -import org.eclipse.digitaltwin.basyx.authorization.rules.rbac.backend.submodel.TargetInformationAdapter; -import org.eclipse.digitaltwin.basyx.conceptdescriptionrepository.feature.authorization.ConceptDescriptionTargetInformation; -import org.eclipse.digitaltwin.basyx.conceptdescriptionrepository.feature.authorization.rbac.backend.submodel.CDTargetInformationAdapter; -import org.eclipse.digitaltwin.basyx.core.exceptions.InvalidTargetInformationException; -import org.eclipse.digitaltwin.basyx.submodelrepository.feature.authorization.SubmodelTargetInformation; -import org.eclipse.digitaltwin.basyx.submodelrepository.feature.authorization.rbac.backend.submodel.SubmodelTargetInformationAdapter; - -/** - * An implementation of the {@link TargetInformationAdapter} to adapt with Aas - * {@link TargetInformation} - * - * @author danish - */ -public class AasEnvironmentTargetInformationAdapter implements TargetInformationAdapter { - - @Override - public SubmodelElementCollection adapt(TargetInformation targetInformation) { - - if (targetInformation instanceof AasTargetInformation) - return new AasTargetInformationAdapter().adapt(targetInformation); - - if (targetInformation instanceof SubmodelTargetInformation) - return new SubmodelTargetInformationAdapter().adapt(targetInformation); - - if (targetInformation instanceof ConceptDescriptionTargetInformation) - return new CDTargetInformationAdapter().adapt(targetInformation); - - SubmodelElementCollection targetInformationSMC = new DefaultSubmodelElementCollection.Builder().idShort("targetInformation").build(); - - SubmodelElementList aasId = new DefaultSubmodelElementList.Builder().idShort("aasIds").build(); - SubmodelElementList submodelId = new DefaultSubmodelElementList.Builder().idShort("submodelIds").build(); - Property typeProperty = new DefaultProperty.Builder().idShort("@type").value("aas-environment").build(); - - List aasIds = ((AasEnvironmentTargetInformation) targetInformation).getAasIds().stream().map(this::transform).collect(Collectors.toList()); - List submodelIds = ((AasEnvironmentTargetInformation) targetInformation).getSubmodelIds().stream().map(this::transform).collect(Collectors.toList()); - aasId.setValue(aasIds); - submodelId.setValue(submodelIds); - - targetInformationSMC.setValue(Arrays.asList(aasId, submodelId, typeProperty)); - - return targetInformationSMC; - } - - @Override - public TargetInformation adapt(SubmodelElementCollection targetInformation) { - - String targetInformationType = getTargetInformationType(targetInformation); - - if (targetInformationType.equals("aas")) - return new AasTargetInformationAdapter().adapt(targetInformation); - - if (targetInformationType.equals("submodel")) - return new SubmodelTargetInformationAdapter().adapt(targetInformation); - - if (targetInformationType.equals("concept-description")) - return new CDTargetInformationAdapter().adapt(targetInformation); - - if (!targetInformationType.equals("aas-environment")) - throw new InvalidTargetInformationException( - "The TargetInformation @type: " + targetInformationType + " is not compatible with " - + getClass().getName() + "."); - - SubmodelElement aasIdSubmodelElement = targetInformation.getValue().stream().filter(sme -> sme.getIdShort().equals("aasIds")).findAny().orElseThrow( - () -> new InvalidTargetInformationException("The TargetInformation defined in the SubmodelElementCollection Rule with id: " + targetInformation.getIdShort() + " is not compatible with the " + getClass().getName())); - - SubmodelElement submodelIdSubmodelElement = targetInformation.getValue().stream().filter(sme -> sme.getIdShort().equals("submodelIds")).findAny().orElseThrow( - () -> new InvalidTargetInformationException("The TargetInformation defined in the SubmodelElementCollection Rule with id: " + targetInformation.getIdShort() + " is not compatible with the " + getClass().getName())); - - if (!(aasIdSubmodelElement instanceof SubmodelElementList) || !(submodelIdSubmodelElement instanceof SubmodelElementList)) - throw new InvalidTargetInformationException("The TargetInformation defined in the SubmodelElementCollection Rule with id: " + targetInformation.getIdShort() + " is not compatible with the " + getClass().getName()); - - SubmodelElementList aasIdList = (SubmodelElementList) aasIdSubmodelElement; - SubmodelElementList submodelIdList = (SubmodelElementList) submodelIdSubmodelElement; - - List aasIds = aasIdList.getValue().stream().map(Property.class::cast).map(Property::getValue).collect(Collectors.toList()); - List submodelIds = submodelIdList.getValue().stream().map(Property.class::cast).map(Property::getValue).collect(Collectors.toList()); - - return new AasEnvironmentTargetInformation(aasIds, submodelIds); - } - - private String getTargetInformationType(SubmodelElementCollection targetInformation) { - - Property typeProperty = (Property) targetInformation.getValue().stream().filter(sme -> sme.getIdShort().equals("@type")).findAny().orElseThrow(() -> new InvalidTargetInformationException("The TargetInformation defined in the SubmodelElementCollection Rule with id: " + targetInformation.getIdShort() + " does not have @type definition")); - - return typeProperty.getValue(); - } - - private Property transform(String aasId) { - return new DefaultProperty.Builder().value(aasId).build(); - } - -} diff --git a/basyx.aasenvironment/basyx.aasenvironment-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/aasenvironment/feature/authorization/AasEnvironmentTargetInformationAdapterTest.java b/basyx.aasenvironment/basyx.aasenvironment-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/aasenvironment/feature/authorization/AasEnvironmentTargetInformationAdapterTest.java deleted file mode 100644 index 298e3381e..000000000 --- a/basyx.aasenvironment/basyx.aasenvironment-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/aasenvironment/feature/authorization/AasEnvironmentTargetInformationAdapterTest.java +++ /dev/null @@ -1,184 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2024 the Eclipse BaSyx Authors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * SPDX-License-Identifier: MIT - ******************************************************************************/ - -package org.eclipse.digitaltwin.basyx.aasenvironment.feature.authorization; - -import static org.junit.Assert.*; -import org.eclipse.digitaltwin.aas4j.v3.model.Property; -import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElement; -import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElementCollection; -import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElementList; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultProperty; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSubmodelElementCollection; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSubmodelElementList; -import org.junit.Before; -import org.junit.Test; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - -import org.eclipse.digitaltwin.basyx.aasenvironment.feature.authorization.rbac.backend.submodel.AasEnvironmentTargetInformationAdapter; -import org.eclipse.digitaltwin.basyx.authorization.rbac.TargetInformation; -import org.eclipse.digitaltwin.basyx.core.exceptions.InvalidTargetInformationException; - -/** - * Tests {@link AasRegistryTargetInformationAdapter} - * - * @author danish - */ -public class AasEnvironmentTargetInformationAdapterTest { - - private AasEnvironmentTargetInformationAdapter aasEnvironmentTargetInformationAdapter; - - @Before - public void setUp() { - aasEnvironmentTargetInformationAdapter = new AasEnvironmentTargetInformationAdapter(); - } - - @Test - public void testAdaptTargetInformationToSubmodelElementCollection() { - - List aasIds = Arrays.asList("aasId1", "aasId2"); - List submodelIds = Arrays.asList("smId1", "smId2"); - TargetInformation targetInformation = new AasEnvironmentTargetInformation(aasIds, submodelIds); - - SubmodelElementCollection result = aasEnvironmentTargetInformationAdapter.adapt(targetInformation); - - assertEquals("targetInformation", result.getIdShort()); - - List elements = result.getValue(); - assertEquals(3, elements.size()); - - SubmodelElementList aasIdList = (SubmodelElementList) elements.get(0); - assertEquals("aasIds", aasIdList.getIdShort()); - - SubmodelElementList submodelIdList = (SubmodelElementList) elements.get(1); - assertEquals("submodelIds", submodelIdList.getIdShort()); - - Property typeProperty = (Property) elements.get(2); - assertEquals("@type", typeProperty.getIdShort()); - - List actualAasIds = aasIdList.getValue().stream().map(Property.class::cast).map(Property::getValue).map(String::valueOf).collect(Collectors.toList()); - assertEquals(aasIds, actualAasIds); - - List actualSubmodelIds = submodelIdList.getValue().stream().map(Property.class::cast).map(Property::getValue).map(String::valueOf).collect(Collectors.toList()); - assertEquals(submodelIds, actualSubmodelIds); - - String actualType = typeProperty.getValue(); - assertTrue(actualType.equals("aas-environment")); - } - - @Test - public void testAdaptSubmodelElementCollectionToTargetInformation() { - - List expectedAasIds = Arrays.asList("aasId1", "aasId2"); - List expectedSubmodelIds = Arrays.asList("smId1", "smId2"); - String type = "aas-environment"; - - List aasIdProperties = expectedAasIds.stream().map(aasId -> new DefaultProperty.Builder().value(aasId).build()).collect(Collectors.toList()); - List submodelIdProperties = expectedSubmodelIds.stream().map(submodelId -> new DefaultProperty.Builder().value(submodelId).build()).collect(Collectors.toList()); - - SubmodelElementList aasIdList = new DefaultSubmodelElementList.Builder().idShort("aasIds").value(aasIdProperties).build(); - SubmodelElementList submodelIdList = new DefaultSubmodelElementList.Builder().idShort("submodelIds").value(submodelIdProperties).build(); - SubmodelElement typeProperty = createTypeProperty(type); - - SubmodelElementCollection targetInformationSMC = new DefaultSubmodelElementCollection.Builder().idShort("targetInformation").value(Arrays.asList(aasIdList, submodelIdList, typeProperty)).build(); - - TargetInformation result = aasEnvironmentTargetInformationAdapter.adapt(targetInformationSMC); - - assertTrue(result instanceof AasEnvironmentTargetInformation); - assertEquals(expectedAasIds, ((AasEnvironmentTargetInformation) result).getAasIds()); - assertEquals(expectedSubmodelIds, ((AasEnvironmentTargetInformation) result).getSubmodelIds()); - } - - @Test - public void testAdaptTargetInformationWithEmptyAasIds() { - - List aasIds = Collections.emptyList(); - List submodelIds = Collections.emptyList(); - - TargetInformation targetInformation = new AasEnvironmentTargetInformation(aasIds, submodelIds); - - SubmodelElementCollection result = aasEnvironmentTargetInformationAdapter.adapt(targetInformation); - - assertEquals("targetInformation", result.getIdShort()); - - List elements = result.getValue(); - assertEquals(3, elements.size()); - - SubmodelElementList aasIdList = (SubmodelElementList) elements.get(0); - assertEquals("aasIds", aasIdList.getIdShort()); - - SubmodelElementList submodelIdList = (SubmodelElementList) elements.get(1); - assertEquals("submodelIds", submodelIdList.getIdShort()); - - Property typeProperty = (Property) elements.get(2); - assertEquals("@type", typeProperty.getIdShort()); - - List actualAasIds = aasIdList.getValue().stream() - .map(Property.class::cast) - .map(Property::getValue) - .map(String::valueOf) - .collect(Collectors.toList()); - assertTrue(actualAasIds.isEmpty()); - - List actualSubmodelIds = submodelIdList.getValue().stream() - .map(Property.class::cast) - .map(Property::getValue) - .map(String::valueOf) - .collect(Collectors.toList()); - assertTrue(actualSubmodelIds.isEmpty()); - - String actualType = typeProperty.getValue(); - assertTrue(actualType.equals("aas-environment")); - } - - @Test(expected = InvalidTargetInformationException.class) - public void testAdaptSubmodelElementCollectionWithInvalidStructure() { - - SubmodelElementCollection targetInformationSMC = new DefaultSubmodelElementCollection.Builder().idShort("targetInformation") - .value(Collections.singletonList(new DefaultProperty.Builder().idShort("invalidElement").value("value").build())) - .build(); - - aasEnvironmentTargetInformationAdapter.adapt(targetInformationSMC); - } - - @Test(expected = InvalidTargetInformationException.class) - public void testAdaptSubmodelElementCollectionWithoutAasIds() { - - SubmodelElementCollection targetInformationSMC = new DefaultSubmodelElementCollection.Builder().idShort("targetInformation") - .value(Collections.emptyList()) - .build(); - - aasEnvironmentTargetInformationAdapter.adapt(targetInformationSMC); - } - - private SubmodelElement createTypeProperty(String type) { - return new DefaultProperty.Builder().idShort("@type").value(type).build(); - } - -} \ No newline at end of file diff --git a/basyx.aasenvironment/basyx.aasenvironment.component/src/main/resources/application.properties b/basyx.aasenvironment/basyx.aasenvironment.component/src/main/resources/application.properties index bada859f2..aff37727d 100644 --- a/basyx.aasenvironment/basyx.aasenvironment.component/src/main/resources/application.properties +++ b/basyx.aasenvironment/basyx.aasenvironment.component/src/main/resources/application.properties @@ -33,18 +33,11 @@ basyx.backend = InMemory #################################################################################### # Authorization #################################################################################### -#basyx.feature.authorization.enabled = true -#basyx.feature.authorization.type = rbac -#basyx.feature.authorization.jwtBearerTokenProvider = keycloak -#basyx.feature.authorization.rbac.file = classpath:rbac_rules.json -#spring.security.oauth2.resourceserver.jwt.issuer-uri= http://localhost:9097/realms/BaSyx -# -#basyx.feature.authorization.rules.backend=Submodel -#basyx.feature.authorization.rules.backend.submodel.authorization.endpoint=http://localhost:8055/submodels/N0E3MTA0QkRBQjU3RTE4NA== -#basyx.feature.authorization.rules.backend.submodel.authorization.token-endpoint=http://localhost:9097/realms/BaSyx/protocol/openid-connect/token -#basyx.feature.authorization.rules.backend.submodel.authorization.grant-type = CLIENT_CREDENTIALS -#basyx.feature.authorization.rules.backend.submodel.authorization.client-id=workstation-1 -#basyx.feature.authorization.rules.backend.submodel.authorization.client-secret=nY0mjyECF60DGzNmQUjL81XurSl8etom +# basyx.feature.authorization.enabled = true +# basyx.feature.authorization.type = rbac +# basyx.feature.authorization.jwtBearerTokenProvider = keycloak +# basyx.feature.authorization.rbac.file = classpath:rbac_rules.json +# spring.security.oauth2.resourceserver.jwt.issuer-uri= http://localhost:9097/realms/BaSyx ## This is for preconfiguration of a secured AAS Environment # basyx.aasenvironment.authorization.preconfiguration.token-endpoint=http://localhost:9097/realms/BaSyx/protocol/openid-connect/token diff --git a/basyx.aasregistry/basyx.aasregistry-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/aasregistry/feature/authorization/rbac/backend/submodel/AasRegistryTargetInformationAdapter.java b/basyx.aasregistry/basyx.aasregistry-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/aasregistry/feature/authorization/rbac/backend/submodel/AasRegistryTargetInformationAdapter.java index 376eae387..ee37eaadf 100644 --- a/basyx.aasregistry/basyx.aasregistry-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/aasregistry/feature/authorization/rbac/backend/submodel/AasRegistryTargetInformationAdapter.java +++ b/basyx.aasregistry/basyx.aasregistry-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/aasregistry/feature/authorization/rbac/backend/submodel/AasRegistryTargetInformationAdapter.java @@ -52,47 +52,30 @@ public class AasRegistryTargetInformationAdapter implements TargetInformationAda @Override public SubmodelElementCollection adapt(TargetInformation targetInformation) { - SubmodelElementCollection targetInformationSMC = new DefaultSubmodelElementCollection.Builder() - .idShort("targetInformation").build(); + SubmodelElementCollection targetInformationSMC = new DefaultSubmodelElementCollection.Builder().idShort("targetInformation").build(); SubmodelElementList aasId = new DefaultSubmodelElementList.Builder().idShort("aasIds").build(); - Property typeProperty = new DefaultProperty.Builder().idShort("@type").value("aas-registry").build(); - List aasIds = ((AasRegistryTargetInformation) targetInformation).getAasIds().stream() - .map(this::transform).collect(Collectors.toList()); + List aasIds = ((AasRegistryTargetInformation) targetInformation).getAasIds().stream().map(this::transform).collect(Collectors.toList()); aasId.setValue(aasIds); - targetInformationSMC.setValue(Arrays.asList(aasId, typeProperty)); + targetInformationSMC.setValue(Arrays.asList(aasId)); return targetInformationSMC; } @Override public TargetInformation adapt(SubmodelElementCollection targetInformation) { - - String targetInformationType = getTargetInformationType(targetInformation); - - if (!targetInformationType.equals("aas-registry")) - throw new InvalidTargetInformationException( - "The TargetInformation @type: " + targetInformationType + " is not compatible with " - + getClass().getName() + "."); - - SubmodelElement aasIdSubmodelElement = targetInformation.getValue().stream() - .filter(sme -> sme.getIdShort().equals("aasIds")).findAny() - .orElseThrow(() -> new InvalidTargetInformationException( - "The TargetInformation defined in the SubmodelElementCollection Rule with id: " - + targetInformation.getIdShort() + " is not compatible with the " - + getClass().getName())); + + SubmodelElement aasIdSubmodelElement = targetInformation.getValue().stream().filter(sme -> sme.getIdShort().equals("aasIds")).findAny().orElseThrow( + () -> new InvalidTargetInformationException("The TargetInformation defined in the SubmodelElementCollection Rule with id: " + targetInformation.getIdShort() + " is not compatible with the " + getClass().getName())); if (!(aasIdSubmodelElement instanceof SubmodelElementList)) - throw new InvalidTargetInformationException( - "The TargetInformation defined in the SubmodelElementCollection Rule with id: " - + targetInformation.getIdShort() + " is not compatible with the " + getClass().getName()); + throw new InvalidTargetInformationException("The TargetInformation defined in the SubmodelElementCollection Rule with id: " + targetInformation.getIdShort() + " is not compatible with the " + getClass().getName()); SubmodelElementList aasIdList = (SubmodelElementList) aasIdSubmodelElement; - List aasIds = aasIdList.getValue().stream().map(Property.class::cast).map(Property::getValue) - .collect(Collectors.toList()); + List aasIds = aasIdList.getValue().stream().map(Property.class::cast).map(Property::getValue).collect(Collectors.toList()); return new AasRegistryTargetInformation(aasIds); } @@ -101,15 +84,4 @@ private Property transform(String aasId) { return new DefaultProperty.Builder().value(aasId).build(); } - private String getTargetInformationType(SubmodelElementCollection targetInformation) { - - Property typeProperty = (Property) targetInformation.getValue().stream() - .filter(sme -> sme.getIdShort().equals("@type")).findAny() - .orElseThrow(() -> new InvalidTargetInformationException( - "The TargetInformation defined in the SubmodelElementCollection Rule with id: " - + targetInformation.getIdShort() + " does not have @type definition")); - - return typeProperty.getValue(); - } - } diff --git a/basyx.aasregistry/basyx.aasregistry-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/aasregistry/regression/feature/authorization/AasRegistryTargetInformationAdapterTest.java b/basyx.aasregistry/basyx.aasregistry-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/aasregistry/regression/feature/authorization/AasRegistryTargetInformationAdapterTest.java index 5a4ceb1b7..d3bac91be 100644 --- a/basyx.aasregistry/basyx.aasregistry-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/aasregistry/regression/feature/authorization/AasRegistryTargetInformationAdapterTest.java +++ b/basyx.aasregistry/basyx.aasregistry-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/aasregistry/regression/feature/authorization/AasRegistryTargetInformationAdapterTest.java @@ -71,33 +71,24 @@ public void testAdaptTargetInformationToSubmodelElementCollection() { assertEquals("targetInformation", result.getIdShort()); List elements = result.getValue(); - assertEquals(2, elements.size()); + assertEquals(1, elements.size()); SubmodelElementList aasIdList = (SubmodelElementList) elements.get(0); assertEquals("aasIds", aasIdList.getIdShort()); - - Property typeProperty = (Property) elements.get(1); - assertEquals("@type", typeProperty.getIdShort()); List actualAasIds = aasIdList.getValue().stream().map(Property.class::cast).map(Property::getValue).map(String::valueOf).collect(Collectors.toList()); assertEquals(aasIds, actualAasIds); - - String actualType = typeProperty.getValue(); - assertTrue(actualType.equals("aas-registry")); } @Test public void testAdaptSubmodelElementCollectionToTargetInformation() { List expectedAasIds = Arrays.asList("aasId1", "aasId2"); - String type = "aas-registry"; - List aasIdProperties = expectedAasIds.stream().map(aasId -> new DefaultProperty.Builder().value(aasId).build()).collect(Collectors.toList()); SubmodelElementList aasIdList = new DefaultSubmodelElementList.Builder().idShort("aasIds").value(aasIdProperties).build(); - SubmodelElement typeProperty = createTypeProperty(type); - - SubmodelElementCollection targetInformationSMC = new DefaultSubmodelElementCollection.Builder().idShort("targetInformation").value(Arrays.asList(aasIdList, typeProperty)).build(); + + SubmodelElementCollection targetInformationSMC = new DefaultSubmodelElementCollection.Builder().idShort("targetInformation").value(Collections.singletonList(aasIdList)).build(); TargetInformation result = aasRegistryTargetInformationAdapter.adapt(targetInformationSMC); @@ -116,13 +107,10 @@ public void testAdaptTargetInformationWithEmptyAasIds() { assertEquals("targetInformation", result.getIdShort()); List elements = result.getValue(); - assertEquals(2, elements.size()); + assertEquals(1, elements.size()); SubmodelElementList aasIdList = (SubmodelElementList) elements.get(0); assertEquals("aasIds", aasIdList.getIdShort()); - - Property typeProperty = (Property) elements.get(1); - assertEquals("@type", typeProperty.getIdShort()); List actualAasIds = aasIdList.getValue().stream() .map(Property.class::cast) @@ -130,9 +118,6 @@ public void testAdaptTargetInformationWithEmptyAasIds() { .map(String::valueOf) .collect(Collectors.toList()); assertTrue(actualAasIds.isEmpty()); - - String actualType = typeProperty.getValue(); - assertTrue(actualType.equals("aas-registry")); } @Test(expected = InvalidTargetInformationException.class) @@ -154,9 +139,5 @@ public void testAdaptSubmodelElementCollectionWithoutAasIds() { aasRegistryTargetInformationAdapter.adapt(targetInformationSMC); } - - private SubmodelElement createTypeProperty(String type) { - return new DefaultProperty.Builder().idShort("@type").value(type).build(); - } } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/authorization/rbac/backend/submodel/AasTargetInformationAdapter.java b/basyx.aasrepository/basyx.aasrepository-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/authorization/rbac/backend/submodel/AasTargetInformationAdapter.java index db29c1460..1ec0e8fb2 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/authorization/rbac/backend/submodel/AasTargetInformationAdapter.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/authorization/rbac/backend/submodel/AasTargetInformationAdapter.java @@ -52,17 +52,14 @@ public class AasTargetInformationAdapter implements TargetInformationAdapter { @Override public SubmodelElementCollection adapt(TargetInformation targetInformation) { - SubmodelElementCollection targetInformationSMC = new DefaultSubmodelElementCollection.Builder() - .idShort("targetInformation").build(); + SubmodelElementCollection targetInformationSMC = new DefaultSubmodelElementCollection.Builder().idShort("targetInformation").build(); SubmodelElementList aasId = new DefaultSubmodelElementList.Builder().idShort("aasIds").build(); - Property typeProperty = new DefaultProperty.Builder().idShort("@type").value("aas").build(); - List aasIds = ((AasTargetInformation) targetInformation).getAasIds().stream() - .map(this::transform).collect(Collectors.toList()); + List aasIds = ((AasTargetInformation) targetInformation).getAasIds().stream().map(this::transform).collect(Collectors.toList()); aasId.setValue(aasIds); - targetInformationSMC.setValue(Arrays.asList(aasId, typeProperty)); + targetInformationSMC.setValue(Arrays.asList(aasId)); return targetInformationSMC; } @@ -70,28 +67,15 @@ public SubmodelElementCollection adapt(TargetInformation targetInformation) { @Override public TargetInformation adapt(SubmodelElementCollection targetInformation) { - String targetInformationType = getTargetInformationType(targetInformation); - - if (!targetInformationType.equals("aas")) - throw new InvalidTargetInformationException("The TargetInformation @type: " + targetInformationType - + " is not compatible with " + getClass().getName() + "."); - - SubmodelElement aasIdSubmodelElement = targetInformation.getValue().stream() - .filter(sme -> sme.getIdShort().equals("aasIds")).findAny() - .orElseThrow(() -> new InvalidTargetInformationException( - "The TargetInformation defined in the SubmodelElementCollection Rule with id: " - + targetInformation.getIdShort() + " is not compatible with the " - + getClass().getName())); + SubmodelElement aasIdSubmodelElement = targetInformation.getValue().stream().filter(sme -> sme.getIdShort().equals("aasIds")).findAny().orElseThrow( + () -> new InvalidTargetInformationException("The TargetInformation defined in the SubmodelElementCollection Rule with id: " + targetInformation.getIdShort() + " is not compatible with the " + getClass().getName())); if (!(aasIdSubmodelElement instanceof SubmodelElementList)) - throw new InvalidTargetInformationException( - "The TargetInformation defined in the SubmodelElementCollection Rule with id: " - + targetInformation.getIdShort() + " is not compatible with the " + getClass().getName()); + throw new InvalidTargetInformationException("The TargetInformation defined in the SubmodelElementCollection Rule with id: " + targetInformation.getIdShort() + " is not compatible with the " + getClass().getName()); SubmodelElementList aasIdList = (SubmodelElementList) aasIdSubmodelElement; - List aasIds = aasIdList.getValue().stream().map(Property.class::cast).map(Property::getValue) - .collect(Collectors.toList()); + List aasIds = aasIdList.getValue().stream().map(Property.class::cast).map(Property::getValue).collect(Collectors.toList()); return new AasTargetInformation(aasIds); } @@ -99,16 +83,5 @@ public TargetInformation adapt(SubmodelElementCollection targetInformation) { private Property transform(String aasId) { return new DefaultProperty.Builder().value(aasId).build(); } - - private String getTargetInformationType(SubmodelElementCollection targetInformation) { - - Property typeProperty = (Property) targetInformation.getValue().stream() - .filter(sme -> sme.getIdShort().equals("@type")).findAny() - .orElseThrow(() -> new InvalidTargetInformationException( - "The TargetInformation defined in the SubmodelElementCollection Rule with id: " - + targetInformation.getIdShort() + " does not have @type definition")); - - return typeProperty.getValue(); - } } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/authorization/AasTargetInformationAdapterTest.java b/basyx.aasrepository/basyx.aasrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/authorization/AasTargetInformationAdapterTest.java index 8c7b02ef9..b7ed798d5 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/authorization/AasTargetInformationAdapterTest.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/authorization/AasTargetInformationAdapterTest.java @@ -70,33 +70,24 @@ public void testAdaptTargetInformationToSubmodelElementCollection() { assertEquals("targetInformation", result.getIdShort()); List elements = result.getValue(); - assertEquals(2, elements.size()); + assertEquals(1, elements.size()); SubmodelElementList aasIdList = (SubmodelElementList) elements.get(0); assertEquals("aasIds", aasIdList.getIdShort()); - - Property typeProperty = (Property) elements.get(1); - assertEquals("@type", typeProperty.getIdShort()); List actualAasIds = aasIdList.getValue().stream().map(Property.class::cast).map(Property::getValue).map(String::valueOf).collect(Collectors.toList()); assertEquals(aasIds, actualAasIds); - - String actualType = typeProperty.getValue(); - assertTrue(actualType.equals("aas")); } @Test public void testAdaptSubmodelElementCollectionToTargetInformation() { List expectedAasIds = Arrays.asList("aasId1", "aasId2"); - String type = "aas"; - List aasIdProperties = expectedAasIds.stream().map(aasId -> new DefaultProperty.Builder().value(aasId).build()).collect(Collectors.toList()); SubmodelElementList aasIdList = new DefaultSubmodelElementList.Builder().idShort("aasIds").value(aasIdProperties).build(); - SubmodelElement typeProperty = createTypeProperty(type); - SubmodelElementCollection targetInformationSMC = new DefaultSubmodelElementCollection.Builder().idShort("targetInformation").value(Arrays.asList(aasIdList, typeProperty)).build(); + SubmodelElementCollection targetInformationSMC = new DefaultSubmodelElementCollection.Builder().idShort("targetInformation").value(Collections.singletonList(aasIdList)).build(); TargetInformation result = aasTargetInformationAdapter.adapt(targetInformationSMC); @@ -115,13 +106,10 @@ public void testAdaptTargetInformationWithEmptyAasIds() { assertEquals("targetInformation", result.getIdShort()); List elements = result.getValue(); - assertEquals(2, elements.size()); + assertEquals(1, elements.size()); SubmodelElementList aasIdList = (SubmodelElementList) elements.get(0); assertEquals("aasIds", aasIdList.getIdShort()); - - Property typeProperty = (Property) elements.get(1); - assertEquals("@type", typeProperty.getIdShort()); List actualAasIds = aasIdList.getValue().stream() .map(Property.class::cast) @@ -129,9 +117,6 @@ public void testAdaptTargetInformationWithEmptyAasIds() { .map(String::valueOf) .collect(Collectors.toList()); assertTrue(actualAasIds.isEmpty()); - - String actualType = typeProperty.getValue(); - assertTrue(actualType.equals("aas")); } @Test(expected = InvalidTargetInformationException.class) @@ -153,9 +138,5 @@ public void testAdaptSubmodelElementCollectionWithoutAasIds() { aasTargetInformationAdapter.adapt(targetInformationSMC); } - - private SubmodelElement createTypeProperty(String type) { - return new DefaultProperty.Builder().idShort("@type").value(type).build(); - } } diff --git a/basyx.common/basyx.authorization/src/main/java/org/eclipse/digitaltwin/basyx/authorization/CommonSecurityConfiguration.java b/basyx.common/basyx.authorization/src/main/java/org/eclipse/digitaltwin/basyx/authorization/CommonSecurityConfiguration.java index b694515c1..f255dc426 100644 --- a/basyx.common/basyx.authorization/src/main/java/org/eclipse/digitaltwin/basyx/authorization/CommonSecurityConfiguration.java +++ b/basyx.common/basyx.authorization/src/main/java/org/eclipse/digitaltwin/basyx/authorization/CommonSecurityConfiguration.java @@ -49,10 +49,6 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { .authorizeHttpRequests(authorize -> authorize .requestMatchers("/actuator/health/**").permitAll() .requestMatchers(HttpMethod.OPTIONS, "/**").permitAll() - .requestMatchers("/swagger-ui/**").permitAll() - .requestMatchers("/v3/**").permitAll() - .requestMatchers("/api-docs/**").permitAll() - .requestMatchers("api-docs/swagger-config/**").permitAll() .anyRequest().authenticated() ) .oauth2ResourceServer(oauth2 -> oauth2 diff --git a/basyx.conceptdescriptionrepository/basyx.conceptdescriptionrepository-feature-authorization/pom.xml b/basyx.conceptdescriptionrepository/basyx.conceptdescriptionrepository-feature-authorization/pom.xml index f5fa6f5ed..c80d7491a 100644 --- a/basyx.conceptdescriptionrepository/basyx.conceptdescriptionrepository-feature-authorization/pom.xml +++ b/basyx.conceptdescriptionrepository/basyx.conceptdescriptionrepository-feature-authorization/pom.xml @@ -67,10 +67,6 @@ org.eclipse.digitaltwin.basyx basyx.authorization.rules.rbac.backend.inmemory - - - org.eclipse.digitaltwin.basyx - basyx.authorization.rules.rbac.backend.submodel diff --git a/basyx.conceptdescriptionrepository/basyx.conceptdescriptionrepository-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/conceptdescriptionrepository/feature/authorization/AuthorizedConceptDescriptionRepositoryConfiguration.java b/basyx.conceptdescriptionrepository/basyx.conceptdescriptionrepository-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/conceptdescriptionrepository/feature/authorization/AuthorizedConceptDescriptionRepositoryConfiguration.java index 97193f33a..8e1be3a70 100644 --- a/basyx.conceptdescriptionrepository/basyx.conceptdescriptionrepository-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/conceptdescriptionrepository/feature/authorization/AuthorizedConceptDescriptionRepositoryConfiguration.java +++ b/basyx.conceptdescriptionrepository/basyx.conceptdescriptionrepository-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/conceptdescriptionrepository/feature/authorization/AuthorizedConceptDescriptionRepositoryConfiguration.java @@ -31,9 +31,7 @@ import org.eclipse.digitaltwin.basyx.authorization.rbac.SimpleRbacPermissionResolver; import org.eclipse.digitaltwin.basyx.authorization.rbac.RoleProvider; import org.eclipse.digitaltwin.basyx.authorization.rbac.TargetPermissionVerifier; -import org.eclipse.digitaltwin.basyx.authorization.rules.rbac.backend.submodel.TargetInformationAdapter; import org.eclipse.digitaltwin.basyx.conceptdescriptionrepository.feature.authorization.rbac.ConceptDescriptionTargetPermissionVerifier; -import org.eclipse.digitaltwin.basyx.conceptdescriptionrepository.feature.authorization.rbac.backend.submodel.CDTargetInformationAdapter; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -57,11 +55,5 @@ public RbacPermissionResolver getCDPermissi return new SimpleRbacPermissionResolver<>(rbacStorage, roleProvider, targetPermissionVerifier); } - - @Bean - public TargetInformationAdapter getCDTargetInformationAdapter() { - - return new CDTargetInformationAdapter(); - } } diff --git a/basyx.conceptdescriptionrepository/basyx.conceptdescriptionrepository-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/conceptdescriptionrepository/feature/authorization/rbac/backend/submodel/CDTargetInformationAdapter.java b/basyx.conceptdescriptionrepository/basyx.conceptdescriptionrepository-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/conceptdescriptionrepository/feature/authorization/rbac/backend/submodel/CDTargetInformationAdapter.java deleted file mode 100644 index bb26163fa..000000000 --- a/basyx.conceptdescriptionrepository/basyx.conceptdescriptionrepository-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/conceptdescriptionrepository/feature/authorization/rbac/backend/submodel/CDTargetInformationAdapter.java +++ /dev/null @@ -1,114 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2024 the Eclipse BaSyx Authors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * SPDX-License-Identifier: MIT - ******************************************************************************/ - -package org.eclipse.digitaltwin.basyx.conceptdescriptionrepository.feature.authorization.rbac.backend.submodel; - -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import org.eclipse.digitaltwin.aas4j.v3.model.Property; -import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElement; -import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElementCollection; -import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElementList; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultProperty; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSubmodelElementCollection; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSubmodelElementList; -import org.eclipse.digitaltwin.basyx.authorization.rbac.TargetInformation; -import org.eclipse.digitaltwin.basyx.authorization.rules.rbac.backend.submodel.TargetInformationAdapter; -import org.eclipse.digitaltwin.basyx.conceptdescriptionrepository.feature.authorization.ConceptDescriptionTargetInformation; -import org.eclipse.digitaltwin.basyx.core.exceptions.InvalidTargetInformationException; - -/** - * An implementation of the {@link TargetInformationAdapter} to adapt with Aas - * {@link TargetInformation} - * - * @author danish - */ -public class CDTargetInformationAdapter implements TargetInformationAdapter { - - @Override - public SubmodelElementCollection adapt(TargetInformation targetInformation) { - - SubmodelElementCollection targetInformationSMC = new DefaultSubmodelElementCollection.Builder() - .idShort("targetInformation").build(); - - SubmodelElementList aasId = new DefaultSubmodelElementList.Builder().idShort("conceptDescriptionIds").build(); - Property typeProperty = new DefaultProperty.Builder().idShort("@type").value("concept-description").build(); - - List aasIds = ((ConceptDescriptionTargetInformation) targetInformation) - .getConceptDescriptionIds().stream().map(this::transform).collect(Collectors.toList()); - aasId.setValue(aasIds); - - targetInformationSMC.setValue(Arrays.asList(aasId, typeProperty)); - - return targetInformationSMC; - } - - @Override - public TargetInformation adapt(SubmodelElementCollection targetInformation) { - - String targetInformationType = getTargetInformationType(targetInformation); - - if (!targetInformationType.equals("concept-description")) - throw new InvalidTargetInformationException("The TargetInformation @type: " + targetInformationType - + " is not compatible with " + getClass().getName() + "."); - - SubmodelElement aasIdSubmodelElement = targetInformation.getValue().stream() - .filter(sme -> sme.getIdShort().equals("conceptDescriptionIds")).findAny() - .orElseThrow(() -> new InvalidTargetInformationException( - "The TargetInformation defined in the SubmodelElementCollection Rule with id: " - + targetInformation.getIdShort() + " is not compatible with the " - + getClass().getName())); - - if (!(aasIdSubmodelElement instanceof SubmodelElementList)) - throw new InvalidTargetInformationException( - "The TargetInformation defined in the SubmodelElementCollection Rule with id: " - + targetInformation.getIdShort() + " is not compatible with the " + getClass().getName()); - - SubmodelElementList aasIdList = (SubmodelElementList) aasIdSubmodelElement; - - List aasIds = aasIdList.getValue().stream().map(Property.class::cast).map(Property::getValue) - .collect(Collectors.toList()); - - return new ConceptDescriptionTargetInformation(aasIds); - } - - private Property transform(String aasId) { - return new DefaultProperty.Builder().value(aasId).build(); - } - - private String getTargetInformationType(SubmodelElementCollection targetInformation) { - - Property typeProperty = (Property) targetInformation.getValue().stream() - .filter(sme -> sme.getIdShort().equals("@type")).findAny() - .orElseThrow(() -> new InvalidTargetInformationException( - "The TargetInformation defined in the SubmodelElementCollection Rule with id: " - + targetInformation.getIdShort() + " does not have @type definition")); - - return typeProperty.getValue(); - } - -} diff --git a/basyx.conceptdescriptionrepository/basyx.conceptdescriptionrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/conceptdescriptionrepository/feature/authorization/CDTargetInformationAdapterTest.java b/basyx.conceptdescriptionrepository/basyx.conceptdescriptionrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/conceptdescriptionrepository/feature/authorization/CDTargetInformationAdapterTest.java deleted file mode 100644 index 8b90f8b87..000000000 --- a/basyx.conceptdescriptionrepository/basyx.conceptdescriptionrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/conceptdescriptionrepository/feature/authorization/CDTargetInformationAdapterTest.java +++ /dev/null @@ -1,161 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2024 the Eclipse BaSyx Authors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * SPDX-License-Identifier: MIT - ******************************************************************************/ - -package org.eclipse.digitaltwin.basyx.conceptdescriptionrepository.feature.authorization; - -import static org.junit.Assert.*; -import org.eclipse.digitaltwin.aas4j.v3.model.Property; -import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElement; -import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElementCollection; -import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElementList; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultProperty; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSubmodelElementCollection; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSubmodelElementList; -import org.junit.Before; -import org.junit.Test; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - -import org.eclipse.digitaltwin.basyx.authorization.rbac.TargetInformation; -import org.eclipse.digitaltwin.basyx.conceptdescriptionrepository.feature.authorization.rbac.backend.submodel.CDTargetInformationAdapter; -import org.eclipse.digitaltwin.basyx.core.exceptions.InvalidTargetInformationException; - -/** - * Tests {@link AasRegistryTargetInformationAdapter} - * - * @author danish - */ -public class CDTargetInformationAdapterTest { - - private CDTargetInformationAdapter cdTargetInformationAdapter; - - @Before - public void setUp() { - cdTargetInformationAdapter = new CDTargetInformationAdapter(); - } - - @Test - public void testAdaptTargetInformationToSubmodelElementCollection() { - - List conceptDescriptiornIds = Arrays.asList("cdId1", "cdId2"); - TargetInformation targetInformation = new ConceptDescriptionTargetInformation(conceptDescriptiornIds); - - SubmodelElementCollection result = cdTargetInformationAdapter.adapt(targetInformation); - - assertEquals("targetInformation", result.getIdShort()); - - List elements = result.getValue(); - assertEquals(2, elements.size()); - - SubmodelElementList aasIdList = (SubmodelElementList) elements.get(0); - assertEquals("conceptDescriptionIds", aasIdList.getIdShort()); - - Property typeProperty = (Property) elements.get(1); - assertEquals("@type", typeProperty.getIdShort()); - - List actualAasIds = aasIdList.getValue().stream().map(Property.class::cast).map(Property::getValue).map(String::valueOf).collect(Collectors.toList()); - assertEquals(conceptDescriptiornIds, actualAasIds); - - String actualType = typeProperty.getValue(); - assertTrue(actualType.equals("concept-description")); - } - - @Test - public void testAdaptSubmodelElementCollectionToTargetInformation() { - - List expectedCDIds = Arrays.asList("cdId1", "cdId2"); - String type = "concept-description"; - - List aasIdProperties = expectedCDIds.stream().map(aasId -> new DefaultProperty.Builder().value(aasId).build()).collect(Collectors.toList()); - - SubmodelElementList aasIdList = new DefaultSubmodelElementList.Builder().idShort("conceptDescriptionIds").value(aasIdProperties).build(); - SubmodelElement typeProperty = createTypeProperty(type); - - SubmodelElementCollection targetInformationSMC = new DefaultSubmodelElementCollection.Builder().idShort("targetInformation").value(Arrays.asList(aasIdList, typeProperty)).build(); - - TargetInformation result = cdTargetInformationAdapter.adapt(targetInformationSMC); - - assertTrue(result instanceof ConceptDescriptionTargetInformation); - assertEquals(expectedCDIds, ((ConceptDescriptionTargetInformation) result).getConceptDescriptionIds()); - } - - @Test - public void testAdaptTargetInformationWithEmptyAasIds() { - - List cdIds = Collections.emptyList(); - TargetInformation targetInformation = new ConceptDescriptionTargetInformation(cdIds); - - SubmodelElementCollection result = cdTargetInformationAdapter.adapt(targetInformation); - - assertEquals("targetInformation", result.getIdShort()); - - List elements = result.getValue(); - assertEquals(2, elements.size()); - - SubmodelElementList aasIdList = (SubmodelElementList) elements.get(0); - assertEquals("conceptDescriptionIds", aasIdList.getIdShort()); - - Property typeProperty = (Property) elements.get(1); - assertEquals("@type", typeProperty.getIdShort()); - - List actualAasIds = aasIdList.getValue().stream() - .map(Property.class::cast) - .map(Property::getValue) - .map(String::valueOf) - .collect(Collectors.toList()); - assertTrue(actualAasIds.isEmpty()); - - String actualType = typeProperty.getValue(); - assertTrue(actualType.equals("concept-description")); - } - - @Test(expected = InvalidTargetInformationException.class) - public void testAdaptSubmodelElementCollectionWithInvalidStructure() { - - SubmodelElementCollection targetInformationSMC = new DefaultSubmodelElementCollection.Builder().idShort("targetInformation") - .value(Collections.singletonList(new DefaultProperty.Builder().idShort("invalidElement").value("value").build())) - .build(); - - cdTargetInformationAdapter.adapt(targetInformationSMC); - } - - @Test(expected = InvalidTargetInformationException.class) - public void testAdaptSubmodelElementCollectionWithoutCDIds() { - - SubmodelElementCollection targetInformationSMC = new DefaultSubmodelElementCollection.Builder().idShort("targetInformation") - .value(Collections.emptyList()) - .build(); - - cdTargetInformationAdapter.adapt(targetInformationSMC); - } - - private SubmodelElement createTypeProperty(String type) { - return new DefaultProperty.Builder().idShort("@type").value(type).build(); - } - -} \ No newline at end of file diff --git a/basyx.submodelregistry/basyx.submodelregistry-feature-authorization/pom.xml b/basyx.submodelregistry/basyx.submodelregistry-feature-authorization/pom.xml index 9475ffa81..64ec4f3e5 100644 --- a/basyx.submodelregistry/basyx.submodelregistry-feature-authorization/pom.xml +++ b/basyx.submodelregistry/basyx.submodelregistry-feature-authorization/pom.xml @@ -61,9 +61,5 @@ org.eclipse.digitaltwin.basyx basyx.authorization.rules.rbac.backend.inmemory - - org.eclipse.digitaltwin.basyx - basyx.authorization.rules.rbac.backend.submodel - diff --git a/basyx.submodelregistry/basyx.submodelregistry-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/submodelregistry/feature/authorization/AuthorizedSubmodelRegistryConfiguration.java b/basyx.submodelregistry/basyx.submodelregistry-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/submodelregistry/feature/authorization/AuthorizedSubmodelRegistryConfiguration.java index 17204f7f4..4e8532b5e 100644 --- a/basyx.submodelregistry/basyx.submodelregistry-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/submodelregistry/feature/authorization/AuthorizedSubmodelRegistryConfiguration.java +++ b/basyx.submodelregistry/basyx.submodelregistry-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/submodelregistry/feature/authorization/AuthorizedSubmodelRegistryConfiguration.java @@ -31,9 +31,7 @@ import org.eclipse.digitaltwin.basyx.authorization.rbac.RoleProvider; import org.eclipse.digitaltwin.basyx.authorization.rbac.SimpleRbacPermissionResolver; import org.eclipse.digitaltwin.basyx.authorization.rbac.TargetPermissionVerifier; -import org.eclipse.digitaltwin.basyx.authorization.rules.rbac.backend.submodel.TargetInformationAdapter; import org.eclipse.digitaltwin.basyx.submodelregistry.feature.authorization.rbac.SubmodelRegistryTargetPermissionVerifier; -import org.eclipse.digitaltwin.basyx.submodelregistry.feature.authorization.rbac.backend.submodel.SubmodelRegistryTargetInformationAdapter; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -56,11 +54,5 @@ public TargetPermissionVerifier getSubmodelRe public RbacPermissionResolver getSubmodelRegistryPermissionResolver(RbacStorage rbacStorage, RoleProvider roleProvider, TargetPermissionVerifier targetPermissionVerifier) { return new SimpleRbacPermissionResolver<>(rbacStorage, roleProvider, targetPermissionVerifier); } - - @Bean - public TargetInformationAdapter getSubmdoelRegistryTargetInformationAdapter() { - - return new SubmodelRegistryTargetInformationAdapter(); - } } diff --git a/basyx.submodelregistry/basyx.submodelregistry-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/submodelregistry/feature/authorization/rbac/backend/submodel/SubmodelRegistryTargetInformationAdapter.java b/basyx.submodelregistry/basyx.submodelregistry-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/submodelregistry/feature/authorization/rbac/backend/submodel/SubmodelRegistryTargetInformationAdapter.java deleted file mode 100644 index 0e9f68c14..000000000 --- a/basyx.submodelregistry/basyx.submodelregistry-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/submodelregistry/feature/authorization/rbac/backend/submodel/SubmodelRegistryTargetInformationAdapter.java +++ /dev/null @@ -1,114 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2024 the Eclipse BaSyx Authors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * SPDX-License-Identifier: MIT - ******************************************************************************/ - -package org.eclipse.digitaltwin.basyx.submodelregistry.feature.authorization.rbac.backend.submodel; - -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import org.eclipse.digitaltwin.aas4j.v3.model.Property; -import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElement; -import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElementCollection; -import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElementList; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultProperty; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSubmodelElementCollection; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSubmodelElementList; -import org.eclipse.digitaltwin.basyx.authorization.rbac.TargetInformation; -import org.eclipse.digitaltwin.basyx.authorization.rules.rbac.backend.submodel.TargetInformationAdapter; -import org.eclipse.digitaltwin.basyx.core.exceptions.InvalidTargetInformationException; -import org.eclipse.digitaltwin.basyx.submodelregistry.feature.authorization.SubmodelRegistryTargetInformation; - -/** - * An implementation of the {@link TargetInformationAdapter} to adapt with Aas - * {@link TargetInformation} - * - * @author danish - */ -public class SubmodelRegistryTargetInformationAdapter implements TargetInformationAdapter { - - @Override - public SubmodelElementCollection adapt(TargetInformation targetInformation) { - - SubmodelElementCollection targetInformationSMC = new DefaultSubmodelElementCollection.Builder() - .idShort("targetInformation").build(); - - SubmodelElementList aasId = new DefaultSubmodelElementList.Builder().idShort("submodelIds").build(); - Property typeProperty = new DefaultProperty.Builder().idShort("@type").value("submodel-registry").build(); - - List aasIds = ((SubmodelRegistryTargetInformation) targetInformation).getSubmodelIds().stream() - .map(this::transform).collect(Collectors.toList()); - aasId.setValue(aasIds); - - targetInformationSMC.setValue(Arrays.asList(aasId, typeProperty)); - - return targetInformationSMC; - } - - @Override - public TargetInformation adapt(SubmodelElementCollection targetInformation) { - - String targetInformationType = getTargetInformationType(targetInformation); - - if (!targetInformationType.equals("submodel-registry")) - throw new InvalidTargetInformationException("The TargetInformation @type: " + targetInformationType - + " is not compatible with " + getClass().getName() + "."); - - SubmodelElement aasIdSubmodelElement = targetInformation.getValue().stream() - .filter(sme -> sme.getIdShort().equals("submodelIds")).findAny() - .orElseThrow(() -> new InvalidTargetInformationException( - "The TargetInformation defined in the SubmodelElementCollection Rule with id: " - + targetInformation.getIdShort() + " is not compatible with the " - + getClass().getName())); - - if (!(aasIdSubmodelElement instanceof SubmodelElementList)) - throw new InvalidTargetInformationException( - "The TargetInformation defined in the SubmodelElementCollection Rule with id: " - + targetInformation.getIdShort() + " is not compatible with the " + getClass().getName()); - - SubmodelElementList aasIdList = (SubmodelElementList) aasIdSubmodelElement; - - List aasIds = aasIdList.getValue().stream().map(Property.class::cast).map(Property::getValue) - .collect(Collectors.toList()); - - return new SubmodelRegistryTargetInformation(aasIds); - } - - private Property transform(String aasId) { - return new DefaultProperty.Builder().value(aasId).build(); - } - - private String getTargetInformationType(SubmodelElementCollection targetInformation) { - - Property typeProperty = (Property) targetInformation.getValue().stream() - .filter(sme -> sme.getIdShort().equals("@type")).findAny() - .orElseThrow(() -> new InvalidTargetInformationException( - "The TargetInformation defined in the SubmodelElementCollection Rule with id: " - + targetInformation.getIdShort() + " does not have @type definition")); - - return typeProperty.getValue(); - } - -} \ No newline at end of file diff --git a/basyx.submodelregistry/basyx.submodelregistry-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/submodelregistry/regression/feature/authorization/SubmodelRegistryTargetInformationAdapterTest.java b/basyx.submodelregistry/basyx.submodelregistry-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/submodelregistry/regression/feature/authorization/SubmodelRegistryTargetInformationAdapterTest.java deleted file mode 100644 index 1b3836fd6..000000000 --- a/basyx.submodelregistry/basyx.submodelregistry-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/submodelregistry/regression/feature/authorization/SubmodelRegistryTargetInformationAdapterTest.java +++ /dev/null @@ -1,163 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2024 the Eclipse BaSyx Authors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * SPDX-License-Identifier: MIT - ******************************************************************************/ - -package org.eclipse.digitaltwin.basyx.submodelregistry.regression.feature.authorization; - -import static org.junit.Assert.*; -import org.eclipse.digitaltwin.aas4j.v3.model.Property; -import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElement; -import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElementCollection; -import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElementList; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultProperty; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSubmodelElementCollection; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSubmodelElementList; -import org.junit.Before; -import org.junit.Test; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - -import org.eclipse.digitaltwin.basyx.authorization.rbac.TargetInformation; -import org.eclipse.digitaltwin.basyx.core.exceptions.InvalidTargetInformationException; -import org.eclipse.digitaltwin.basyx.submodelregistry.feature.authorization.SubmodelRegistryTargetInformation; -import org.eclipse.digitaltwin.basyx.submodelregistry.feature.authorization.rbac.backend.submodel.SubmodelRegistryTargetInformationAdapter; - -/** - * Tests {@link AasRegistryTargetInformationAdapter} - * - * @author danish - */ -public class SubmodelRegistryTargetInformationAdapterTest { - - private SubmodelRegistryTargetInformationAdapter aasRegistryTargetInformationAdapter; - - @Before - public void setUp() { - aasRegistryTargetInformationAdapter = new SubmodelRegistryTargetInformationAdapter(); - } - - @Test - public void testAdaptTargetInformationToSubmodelElementCollection() { - - List aasIds = Arrays.asList("aasId1", "aasId2"); - TargetInformation targetInformation = new SubmodelRegistryTargetInformation(aasIds); - - SubmodelElementCollection result = aasRegistryTargetInformationAdapter.adapt(targetInformation); - - assertEquals("targetInformation", result.getIdShort()); - - List elements = result.getValue(); - assertEquals(2, elements.size()); - - SubmodelElementList aasIdList = (SubmodelElementList) elements.get(0); - assertEquals("submodelIds", aasIdList.getIdShort()); - - Property typeProperty = (Property) elements.get(1); - assertEquals("@type", typeProperty.getIdShort()); - - List actualAasIds = aasIdList.getValue().stream().map(Property.class::cast).map(Property::getValue).map(String::valueOf).collect(Collectors.toList()); - assertEquals(aasIds, actualAasIds); - - String actualType = typeProperty.getValue(); - assertTrue(actualType.equals("submodel-registry")); - } - - @Test - public void testAdaptSubmodelElementCollectionToTargetInformation() { - - List expectedAasIds = Arrays.asList("aasId1", "aasId2"); - String type = "submodel-registry"; - - List aasIdProperties = expectedAasIds.stream().map(aasId -> new DefaultProperty.Builder().value(aasId).build()).collect(Collectors.toList()); - - SubmodelElementList aasIdList = new DefaultSubmodelElementList.Builder().idShort("submodelIds").value(aasIdProperties).build(); - SubmodelElement typeProperty = createTypeProperty(type); - - SubmodelElementCollection targetInformationSMC = new DefaultSubmodelElementCollection.Builder().idShort("targetInformation").value(Arrays.asList(aasIdList, typeProperty)).build(); - - TargetInformation result = aasRegistryTargetInformationAdapter.adapt(targetInformationSMC); - - assertTrue(result instanceof SubmodelRegistryTargetInformation); - assertEquals(expectedAasIds, ((SubmodelRegistryTargetInformation) result).getSubmodelIds()); - } - - @Test - public void testAdaptTargetInformationWithEmptyAasIds() { - - List aasIds = Collections.emptyList(); - TargetInformation targetInformation = new SubmodelRegistryTargetInformation(aasIds); - - SubmodelElementCollection result = aasRegistryTargetInformationAdapter.adapt(targetInformation); - - assertEquals("targetInformation", result.getIdShort()); - - List elements = result.getValue(); - assertEquals(2, elements.size()); - - SubmodelElementList aasIdList = (SubmodelElementList) elements.get(0); - assertEquals("submodelIds", aasIdList.getIdShort()); - - Property typeProperty = (Property) elements.get(1); - assertEquals("@type", typeProperty.getIdShort()); - - List actualAasIds = aasIdList.getValue().stream() - .map(Property.class::cast) - .map(Property::getValue) - .map(String::valueOf) - .collect(Collectors.toList()); - assertTrue(actualAasIds.isEmpty()); - - String actualType = typeProperty.getValue(); - assertTrue(actualType.equals("submodel-registry")); - } - - @Test(expected = InvalidTargetInformationException.class) - public void testAdaptSubmodelElementCollectionWithInvalidStructure() { - - SubmodelElementCollection targetInformationSMC = new DefaultSubmodelElementCollection.Builder().idShort("targetInformation") - .value(Collections.singletonList(new DefaultProperty.Builder().idShort("invalidElement").value("value").build())) - .build(); - - aasRegistryTargetInformationAdapter.adapt(targetInformationSMC); - } - - @Test(expected = InvalidTargetInformationException.class) - public void testAdaptSubmodelElementCollectionWithoutAasIds() { - - SubmodelElementCollection targetInformationSMC = new DefaultSubmodelElementCollection.Builder().idShort("targetInformation") - .value(Collections.emptyList()) - .build(); - - aasRegistryTargetInformationAdapter.adapt(targetInformationSMC); - } - - private SubmodelElement createTypeProperty(String type) { - return new DefaultProperty.Builder().idShort("@type").value(type).build(); - } - - -} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-authorization/pom.xml b/basyx.submodelrepository/basyx.submodelrepository-feature-authorization/pom.xml index e701fdb00..dccab08e1 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-authorization/pom.xml +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-authorization/pom.xml @@ -63,29 +63,7 @@ org.eclipse.digitaltwin.basyx basyx.authorization.rules.rbac.backend.inmemory - - - org.eclipse.digitaltwin.basyx - basyx.authorization.rules.rbac.backend.submodel - - - org.eclipse.digitaltwin.basyx - basyx.submodelrepository-client - - - org.eclipse.digitaltwin.basyx - basyx.submodelrepository-core - - - org.eclipse.digitaltwin.basyx - basyx.submodelservice-core - - - org.eclipse.digitaltwin.basyx - basyx.submodelservice-client - - - + org.apache.httpcomponents.client5 httpclient5 diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/authorization/AuthorizedSubmodelRepositoryConfiguration.java b/basyx.submodelrepository/basyx.submodelrepository-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/authorization/AuthorizedSubmodelRepositoryConfiguration.java index 6d10b8f13..5a6c79fa2 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/authorization/AuthorizedSubmodelRepositoryConfiguration.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/authorization/AuthorizedSubmodelRepositoryConfiguration.java @@ -31,9 +31,7 @@ import org.eclipse.digitaltwin.basyx.authorization.rbac.SimpleRbacPermissionResolver; import org.eclipse.digitaltwin.basyx.authorization.rbac.RoleProvider; import org.eclipse.digitaltwin.basyx.authorization.rbac.TargetPermissionVerifier; -import org.eclipse.digitaltwin.basyx.authorization.rules.rbac.backend.submodel.TargetInformationAdapter; import org.eclipse.digitaltwin.basyx.submodelrepository.feature.authorization.rbac.SubmodelTargetPermissionVerifier; -import org.eclipse.digitaltwin.basyx.submodelrepository.feature.authorization.rbac.backend.submodel.SubmodelTargetInformationAdapter; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -57,11 +55,5 @@ public RbacPermissionResolver getSubmodelPermissionRe return new SimpleRbacPermissionResolver<>(rbacStorage, roleProvider, targetPermissionVerifier); } - - @Bean - public TargetInformationAdapter getSubmodelTargetInformationAdapter() { - - return new SubmodelTargetInformationAdapter(); - } } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/authorization/rbac/backend/submodel/SubmodelTargetInformationAdapter.java b/basyx.submodelrepository/basyx.submodelrepository-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/authorization/rbac/backend/submodel/SubmodelTargetInformationAdapter.java deleted file mode 100644 index 489da521a..000000000 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-authorization/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/authorization/rbac/backend/submodel/SubmodelTargetInformationAdapter.java +++ /dev/null @@ -1,130 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2024 the Eclipse BaSyx Authors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * SPDX-License-Identifier: MIT - ******************************************************************************/ - -package org.eclipse.digitaltwin.basyx.submodelrepository.feature.authorization.rbac.backend.submodel; - -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import org.eclipse.digitaltwin.aas4j.v3.model.Property; -import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElement; -import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElementCollection; -import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElementList; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultProperty; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSubmodelElementCollection; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSubmodelElementList; -import org.eclipse.digitaltwin.basyx.authorization.rbac.TargetInformation; -import org.eclipse.digitaltwin.basyx.authorization.rules.rbac.backend.submodel.TargetInformationAdapter; -import org.eclipse.digitaltwin.basyx.core.exceptions.InvalidTargetInformationException; -import org.eclipse.digitaltwin.basyx.submodelrepository.feature.authorization.SubmodelTargetInformation; - -/** - * An implementation of the {@link TargetInformationAdapter} to adapt with Aas - * {@link TargetInformation} - * - * @author danish - */ -public class SubmodelTargetInformationAdapter implements TargetInformationAdapter { - - @Override - public SubmodelElementCollection adapt(TargetInformation targetInformation) { - - SubmodelElementCollection targetInformationSMC = new DefaultSubmodelElementCollection.Builder() - .idShort("targetInformation").build(); - - SubmodelElementList submodelId = new DefaultSubmodelElementList.Builder().idShort("submodelIds").build(); - SubmodelElementList submodelElementId = new DefaultSubmodelElementList.Builder() - .idShort("submodelElementIdShortPaths").build(); - Property typeProperty = new DefaultProperty.Builder().idShort("@type").value("submodel").build(); - - List submodelIds = ((SubmodelTargetInformation) targetInformation).getSubmodelIds().stream() - .map(this::transform).collect(Collectors.toList()); - List submodelElementIds = ((SubmodelTargetInformation) targetInformation) - .getSubmodelElementIdShortPaths().stream().map(this::transform).collect(Collectors.toList()); - submodelId.setValue(submodelIds); - submodelElementId.setValue(submodelElementIds); - - targetInformationSMC.setValue(Arrays.asList(submodelId, submodelElementId, typeProperty)); - - return targetInformationSMC; - } - - @Override - public TargetInformation adapt(SubmodelElementCollection targetInformation) { - - String targetInformationType = getTargetInformationType(targetInformation); - - if (!targetInformationType.equals("submodel")) - throw new InvalidTargetInformationException("The TargetInformation @type: " + targetInformationType - + " is not compatible with " + getClass().getName() + "."); - - SubmodelElement submodelIdSubmodelElement = targetInformation.getValue().stream() - .filter(sme -> sme.getIdShort().equals("submodelIds")).findAny() - .orElseThrow(() -> new InvalidTargetInformationException( - "The TargetInformation defined in the SubmodelElementCollection Rule with id: " - + targetInformation.getIdShort() + " is not compatible with the " - + getClass().getName())); - - SubmodelElement smeIdSubmodelElement = targetInformation.getValue().stream() - .filter(sme -> sme.getIdShort().equals("submodelElementIdShortPaths")).findAny() - .orElseThrow(() -> new InvalidTargetInformationException( - "The TargetInformation defined in the SubmodelElementCollection Rule with id: " - + targetInformation.getIdShort() + " is not compatible with the " - + getClass().getName())); - - if (!(submodelIdSubmodelElement instanceof SubmodelElementList) - || !(smeIdSubmodelElement instanceof SubmodelElementList)) - throw new InvalidTargetInformationException( - "The TargetInformation defined in the SubmodelElementCollection Rule with id: " - + targetInformation.getIdShort() + " is not compatible with the " + getClass().getName()); - - SubmodelElementList submodelIdList = (SubmodelElementList) submodelIdSubmodelElement; - SubmodelElementList smeIdList = (SubmodelElementList) smeIdSubmodelElement; - - List submodelIds = submodelIdList.getValue().stream().map(Property.class::cast).map(Property::getValue) - .collect(Collectors.toList()); - List smeIds = smeIdList.getValue().stream().map(Property.class::cast).map(Property::getValue) - .collect(Collectors.toList()); - - return new SubmodelTargetInformation(submodelIds, smeIds); - } - - private Property transform(String aasId) { - return new DefaultProperty.Builder().value(aasId).build(); - } - - private String getTargetInformationType(SubmodelElementCollection targetInformation) { - - Property typeProperty = (Property) targetInformation.getValue().stream() - .filter(sme -> sme.getIdShort().equals("@type")).findAny() - .orElseThrow(() -> new InvalidTargetInformationException( - "The TargetInformation defined in the SubmodelElementCollection Rule with id: " - + targetInformation.getIdShort() + " does not have @type definition")); - - return typeProperty.getValue(); - } - -} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/authorization/SubmodelTargetInformationAdapterTest.java b/basyx.submodelrepository/basyx.submodelrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/authorization/SubmodelTargetInformationAdapterTest.java deleted file mode 100644 index 2d6bed23f..000000000 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/authorization/SubmodelTargetInformationAdapterTest.java +++ /dev/null @@ -1,185 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2024 the Eclipse BaSyx Authors - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * SPDX-License-Identifier: MIT - ******************************************************************************/ - -package org.eclipse.digitaltwin.basyx.submodelrepository.feature.authorization; - -import static org.junit.Assert.*; -import org.eclipse.digitaltwin.aas4j.v3.model.Property; -import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElement; -import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElementCollection; -import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElementList; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultProperty; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSubmodelElementCollection; -import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSubmodelElementList; -import org.junit.Before; -import org.junit.Test; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - -import org.eclipse.digitaltwin.basyx.authorization.rbac.TargetInformation; -import org.eclipse.digitaltwin.basyx.core.exceptions.InvalidTargetInformationException; -import org.eclipse.digitaltwin.basyx.submodelrepository.feature.authorization.rbac.backend.submodel.SubmodelTargetInformationAdapter; - -/** - * Tests {@link AasRegistryTargetInformationAdapter} - * - * @author danish - */ -public class SubmodelTargetInformationAdapterTest { - - private SubmodelTargetInformationAdapter submodelTargetInformationAdapter; - - @Before - public void setUp() { - submodelTargetInformationAdapter = new SubmodelTargetInformationAdapter(); - } - - @Test - public void testAdaptTargetInformationToSubmodelElementCollection() { - - List submodelIds = Arrays.asList("aasId1", "aasId2"); - List smeIds = Arrays.asList("sme1.sme2", "sme4.sme5.sme6", "sme7"); - - TargetInformation targetInformation = new SubmodelTargetInformation(submodelIds, smeIds); - - SubmodelElementCollection result = submodelTargetInformationAdapter.adapt(targetInformation); - - assertEquals("targetInformation", result.getIdShort()); - - List elements = result.getValue(); - assertEquals(3, elements.size()); - - SubmodelElementList submodelIdList = (SubmodelElementList) elements.get(0); - assertEquals("submodelIds", submodelIdList.getIdShort()); - - SubmodelElementList smeIdList = (SubmodelElementList) elements.get(1); - assertEquals("submodelElementIdShortPaths", smeIdList.getIdShort()); - - Property typeProperty = (Property) elements.get(2); - assertEquals("@type", typeProperty.getIdShort()); - - List actualSubmodelIds = submodelIdList.getValue().stream().map(Property.class::cast).map(Property::getValue).map(String::valueOf).collect(Collectors.toList()); - List actualSmeIds = smeIdList.getValue().stream().map(Property.class::cast).map(Property::getValue).map(String::valueOf).collect(Collectors.toList()); - assertEquals(submodelIds, actualSubmodelIds); - assertEquals(smeIds, actualSmeIds); - - String actualType = typeProperty.getValue(); - assertTrue(actualType.equals("submodel")); - } - - @Test - public void testAdaptSubmodelElementCollectionToTargetInformation() { - - List expectedSubmodelIds = Arrays.asList("aasId1", "aasId2"); - List expectedSmeIds = Arrays.asList("sme1.sme2", "sme4.sme5.sme6", "sme7"); - String type = "submodel"; - - List submodelIdProperties = expectedSubmodelIds.stream().map(submodelId -> new DefaultProperty.Builder().value(submodelId).build()).collect(Collectors.toList()); - List smeIdProperties = expectedSmeIds.stream().map(smeId -> new DefaultProperty.Builder().value(smeId).build()).collect(Collectors.toList()); - - SubmodelElementList submodelIdList = new DefaultSubmodelElementList.Builder().idShort("submodelIds").value(submodelIdProperties).build(); - SubmodelElementList smeIdList = new DefaultSubmodelElementList.Builder().idShort("submodelElementIdShortPaths").value(smeIdProperties).build(); - SubmodelElement typeProperty = createTypeProperty(type); - - SubmodelElementCollection targetInformationSMC = new DefaultSubmodelElementCollection.Builder().idShort("targetInformation").value(Arrays.asList(submodelIdList, smeIdList, typeProperty)).build(); - - TargetInformation result = submodelTargetInformationAdapter.adapt(targetInformationSMC); - - assertTrue(result instanceof SubmodelTargetInformation); - assertEquals(expectedSubmodelIds, ((SubmodelTargetInformation) result).getSubmodelIds()); - assertEquals(expectedSmeIds, ((SubmodelTargetInformation) result).getSubmodelElementIdShortPaths()); - } - - @Test - public void testAdaptTargetInformationWithEmptyAasIds() { - - List submodelIds = Collections.emptyList(); - List smeIds = Collections.emptyList(); - - TargetInformation targetInformation = new SubmodelTargetInformation(submodelIds, smeIds); - - SubmodelElementCollection result = submodelTargetInformationAdapter.adapt(targetInformation); - - assertEquals("targetInformation", result.getIdShort()); - - List elements = result.getValue(); - assertEquals(3, elements.size()); - - SubmodelElementList submodelIdList = (SubmodelElementList) elements.get(0); - assertEquals("submodelIds", submodelIdList.getIdShort()); - - SubmodelElementList smeIdList = (SubmodelElementList) elements.get(1); - assertEquals("submodelElementIdShortPaths", smeIdList.getIdShort()); - - Property typeProperty = (Property) elements.get(2); - assertEquals("@type", typeProperty.getIdShort()); - - List actualSubmodelIds = submodelIdList.getValue().stream() - .map(Property.class::cast) - .map(Property::getValue) - .map(String::valueOf) - .collect(Collectors.toList()); - assertTrue(actualSubmodelIds.isEmpty()); - - List actualSmeIds = smeIdList.getValue().stream() - .map(Property.class::cast) - .map(Property::getValue) - .map(String::valueOf) - .collect(Collectors.toList()); - assertTrue(actualSmeIds.isEmpty()); - - String actualType = typeProperty.getValue(); - assertTrue(actualType.equals("submodel")); - } - - @Test(expected = InvalidTargetInformationException.class) - public void testAdaptSubmodelElementCollectionWithInvalidStructure() { - - SubmodelElementCollection targetInformationSMC = new DefaultSubmodelElementCollection.Builder().idShort("targetInformation") - .value(Collections.singletonList(new DefaultProperty.Builder().idShort("invalidElement").value("value").build())) - .build(); - - submodelTargetInformationAdapter.adapt(targetInformationSMC); - } - - @Test(expected = InvalidTargetInformationException.class) - public void testAdaptSubmodelElementCollectionWithoutSubmodelIds() { - - SubmodelElementCollection targetInformationSMC = new DefaultSubmodelElementCollection.Builder().idShort("targetInformation") - .value(Collections.emptyList()) - .build(); - - submodelTargetInformationAdapter.adapt(targetInformationSMC); - } - - private SubmodelElement createTypeProperty(String type) { - return new DefaultProperty.Builder().idShort("@type").value(type).build(); - } - - -} diff --git a/ci/docker-compose.yml b/ci/docker-compose.yml index 10fecd1b9..92e30a58b 100644 --- a/ci/docker-compose.yml +++ b/ci/docker-compose.yml @@ -108,7 +108,7 @@ services: BASYX_FEATURE_AUTHORIZATION_ENABLED: true BASYX_FEATURE_AUTHORIZATION_TYPE: rbac BASYX_FEATURE_AUTHORIZATION_JWTBEARERTOKENPROVIDER: keycloak - SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: http://keycloak-fixed:8080/realms/BaSyx + SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: http://keycloak:8080/realms/BaSyx BASYX_FEATURE_AUTHORIZATION_RBAC_FILE: file:/rbac/rbac_rules.json volumes: - ./keycloak/rules/rbac_rules-aas-registry.json:/rbac/rbac_rules.json:ro @@ -126,7 +126,7 @@ services: BASYX_FEATURE_AUTHORIZATION_ENABLED: true BASYX_FEATURE_AUTHORIZATION_TYPE: rbac BASYX_FEATURE_AUTHORIZATION_JWTBEARERTOKENPROVIDER: keycloak - SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: http://keycloak-fixed:8080/realms/BaSyx + SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: http://keycloak:8080/realms/BaSyx BASYX_FEATURE_AUTHORIZATION_RBAC_FILE: file:/rbac/rbac_rules.json volumes: - ./keycloak/rules/rbac_rules-sm-registry.json:/rbac/rbac_rules.json:ro @@ -141,9 +141,17 @@ services: container_name: configuration-sm-repo ports: - "8055:8081" + environment: + SERVER_SERVLET_CONTEXT_PATH: / + BASYX_CORS_ALLOWED_ORIGINS: '*' + BASYX_CORS_ALLOWED_METHODS: GET,POST,PATCH,DELETE,PUT,OPTIONS,HEAD + BASYX_FEATURE_AUTHORIZATION_ENABLED: true + BASYX_FEATURE_AUTHORIZATION_TYPE: rbac + BASYX_FEATURE_AUTHORIZATION_JWTBEARERTOKENPROVIDER: keycloak + SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: http://keycloak:8080/realms/BaSyx + BASYX_FEATURE_AUTHORIZATION_RBAC_FILE: file:/rbac/rbac_rules.json volumes: - - ./rules/sm-repo-rbac_rules.json:/application/rbac_rules.json - - ./rules/sm-repo.properties:/application/application.properties + - ./keycloak/rules/rbac_rules-conf-sm-repo.json:/rbac/rbac_rules.json:ro restart: always networks: - basyx-java-server-sdk @@ -166,10 +174,10 @@ services: build: context: ./keycloak dockerfile: Dockerfile.keycloak - container_name: keycloak-fixed + container_name: keycloak-fixed-uri environment: KC_HOSTNAME: localhost - KC_SPI_INITIALIZER_ISSUER_BASE_URI: http://keycloak-fixed:8080 + KC_SPI_INITIALIZER_ISSUER_BASE_URI: http://keycloak:8080 KEYCLOAK_ADMIN: admin KEYCLOAK_ADMIN_PASSWORD: keycloak-admin command: ["start-dev", "--import-realm"] diff --git a/ci/rules/sm-repo-rbac_rules.json b/ci/rules/sm-repo-rbac_rules.json deleted file mode 100644 index ef11e18f6..000000000 --- a/ci/rules/sm-repo-rbac_rules.json +++ /dev/null @@ -1,155 +0,0 @@ -[ - { - "role": "basyx-reader", - "action": "READ", - "targetInformation": { - "@type": "submodel", - "submodelIds": "*", - "submodelElementIdShortPaths": "*" - } - }, - { - "role": "admin", - "action": ["CREATE", "READ", "UPDATE", "DELETE", "EXECUTE"], - "targetInformation": { - "@type": "submodel", - "submodelIds": "*", - "submodelElementIdShortPaths": "*" - } - }, - { - "role": "basyx-reader-two", - "action": "READ", - "targetInformation": { - "@type": "submodel", - "submodelIds": "specificSubmodelId", - "submodelElementIdShortPaths": "*" - } - }, - { - "role": "basyx-sme-reader", - "action": "READ", - "targetInformation": { - "@type": "submodel", - "submodelIds": ["specificSubmodelId", "testSMId1", "testSMId2"], - "submodelElementIdShortPaths": ["testSMEIdShortPath1","smc2.specificSubmodelElementIdShort","testSMEIdShortPath2"] - } - }, - { - "role": "basyx-sme-reader-two", - "action": "READ", - "targetInformation": { - "@type": "submodel", - "submodelIds": "specificSubmodelId", - "submodelElementIdShortPaths": "smc2.specificFileSubmodelElementIdShort" - } - }, - { - "role": "basyx-creator", - "action": "CREATE", - "targetInformation": { - "@type": "submodel", - "submodelIds": "*", - "submodelElementIdShortPaths": "*" - } - }, - { - "role": "basyx-updater", - "action": "UPDATE", - "targetInformation": { - "@type": "submodel", - "submodelIds": "*", - "submodelElementIdShortPaths": "*" - } - }, - { - "role": "basyx-updater-two", - "action": "UPDATE", - "targetInformation": { - "@type": "submodel", - "submodelIds": "specificSubmodelId", - "submodelElementIdShortPaths": "*" - } - }, - { - "role": "basyx-sme-updater", - "action": "UPDATE", - "targetInformation": { - "@type": "submodel", - "submodelIds": "specificSubmodelId", - "submodelElementIdShortPaths": "smc2.specificFileSubmodelElementIdShort" - } - }, - { - "role": "basyx-sme-updater-two", - "action": "UPDATE", - "targetInformation": { - "@type": "submodel", - "submodelIds": "specificSubmodelId", - "submodelElementIdShortPaths": "smc2" - } - }, - { - "role": "basyx-sme-updater-three", - "action": "UPDATE", - "targetInformation": { - "@type": "submodel", - "submodelIds": "specificSubmodelId-2", - "submodelElementIdShortPaths": "smc1.specificSubmodelElementIdShort-2" - } - }, - { - "role": "basyx-file-sme-updater", - "action": "UPDATE", - "targetInformation": { - "@type": "submodel", - "submodelIds": "specificSubmodelId-2", - "submodelElementIdShortPaths": "smc2.specificFileSubmodelElementIdShort" - } - }, - { - "role": "basyx-deleter", - "action": "DELETE", - "targetInformation": { - "@type": "submodel", - "submodelIds": "*", - "submodelElementIdShortPaths": "*" - } - }, - { - "role": "basyx-deleter-two", - "action": "DELETE", - "targetInformation": { - "@type": "submodel", - "submodelIds": "specificSubmodelId-2", - "submodelElementIdShortPaths": "*" - } - }, - { - "role": "basyx-executor", - "action": "EXECUTE", - "targetInformation": { - "@type": "submodel", - "submodelIds": "*", - "submodelElementIdShortPaths": "*" - } - }, - { - "role": "basyx-executor-two", - "action": "EXECUTE", - "targetInformation": { - "@type": "submodel", - "submodelIds": "specificSubmodelId", - "submodelElementIdShortPaths": "square" - } - }, - { - "role": "basyx-file-sme-reader", - "action": "READ", - "targetInformation": { - "@type": "submodel", - "submodelIds": "specificSubmodelId-2", - "submodelElementIdShortPaths": "smc2.specificFileSubmodelElementIdShort" - } - } -] \ No newline at end of file diff --git a/ci/rules/sm-repo.properties b/ci/rules/sm-repo.properties deleted file mode 100644 index 1229e3457..000000000 --- a/ci/rules/sm-repo.properties +++ /dev/null @@ -1,10 +0,0 @@ -server.port=8081 -basyx.backend=InMemory -basyx.cors.allowed-origins=* -basyx.cors.allowed-methods=GET,POST,PATCH,DELETE,PUT,OPTIONS,HEAD - -basyx.feature.authorization.enabled = true -basyx.feature.authorization.type = rbac -basyx.feature.authorization.jwtBearerTokenProvider = keycloak -basyx.feature.authorization.rbac.file = file:/application/rbac_rules.json -spring.security.oauth2.resourceserver.jwt.issuer-uri= http://keycloak-fixed:8080/realms/BaSyx \ No newline at end of file