Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Apache Kafka Event Interface For Repositories #523

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private void assertAssetLinkCreationReponse(String submodelJSON, CloseableHttpRe
assertEquals(HttpStatus.CREATED.value(), creationResponse.getCode());

String response = BaSyxHttpTestUtils.getResponseAsString(creationResponse);

BaSyxHttpTestUtils.assertSameJSONContent(submodelJSON, response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
import org.eclipse.digitaltwin.basyx.aasenvironment.AasEnvironmentFactory;
import org.eclipse.digitaltwin.basyx.aasenvironment.feature.AasEnvironmentFeature;
import org.eclipse.digitaltwin.basyx.aasenvironment.feature.DecoratedAasEnvironmentFactory;
import org.eclipse.digitaltwin.basyx.aasenvironment.http.AASEnvironmentConfiguration;
import org.eclipse.digitaltwin.basyx.aasenvironment.preconfiguration.AasEnvironmentPreconfigurationLoader;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -55,7 +57,8 @@ public static AasEnvironment getAasEnvironment(AasEnvironmentFactory aasEnvironm

@Bean
@ConditionalOnMissingBean
public static AasEnvironmentPreconfigurationLoader getPreconfigurationLoaderForAasEnvironment(ResourceLoader resourceLoader, List<String> pathsToLoad) {
public static AasEnvironmentPreconfigurationLoader getPreconfigurationLoaderForAasEnvironment(ResourceLoader resourceLoader,
@Value(AasEnvironmentPreconfigurationLoader.PATHS_TO_LOAD_EXPR) List<String> pathsToLoad) {
return new AasEnvironmentPreconfigurationLoader(resourceLoader, pathsToLoad);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@
*
*/
public class AasEnvironmentPreconfigurationLoader {

public static final String PATHS_TO_LOAD_EXPR = "${basyx.environment:#{null}}";

private Logger logger = LoggerFactory.getLogger(AasEnvironmentPreconfigurationLoader.class);

@Value("${basyx.environment:#{null}}")

private List<String> pathsToLoad;

private ResourceLoader resourceLoader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class AuthorizedAASEnvironmentPreconfigurationLoader extends AasEnvironme
@Value("${basyx.aasenvironment.authorization.preconfiguration.scopes:#{null}}")
private Collection<String> scopes;

@Value("${basyx.environment:#{null}}")
@Value(AasEnvironmentPreconfigurationLoader.PATHS_TO_LOAD_EXPR)
private String basyxEnvironment;

private AccessTokenProvider tokenProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,26 @@

package org.eclipse.digitaltwin.basyx.aasenvironment.feature.authorization;

import java.util.List;

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;
import org.eclipse.digitaltwin.basyx.authorization.rbac.RbacStorage;
import org.eclipse.digitaltwin.basyx.authorization.rbac.SimpleRbacPermissionResolver;
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.conceptdescriptionrepository.feature.authorization.rbac.backend.submodel.CDTargetInformationAdapter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.io.ResourceLoader;

import java.util.List;

/**
* Configuration for authorized {@link AasEnvironment}
*
Expand All @@ -61,13 +61,13 @@ public TargetPermissionVerifier<AasEnvironmentTargetInformation> getAasEnvironme

@Bean
public RbacPermissionResolver<AasEnvironmentTargetInformation> getAasEnvironmentPermissionResolver(RbacStorage rbacStorage, RoleProvider roleProvider, TargetPermissionVerifier<AasEnvironmentTargetInformation> targetPermissionVerifier) {

return new SimpleRbacPermissionResolver<>(rbacStorage, roleProvider, targetPermissionVerifier);
}

@Bean
@Primary
public static AasEnvironmentPreconfigurationLoader getAuthorizedAasEnvironmentPreconfigurationLoader(ResourceLoader resourceLoader, List<String> pathsToLoad) {
public static AasEnvironmentPreconfigurationLoader getAuthorizedAasEnvironmentPreconfigurationLoader(ResourceLoader resourceLoader,
@Value(AasEnvironmentPreconfigurationLoader.PATHS_TO_LOAD_EXPR) List<String> pathsToLoad) {
return new AuthorizedAASEnvironmentPreconfigurationLoader(resourceLoader, pathsToLoad);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import java.io.IOException;
import java.security.interfaces.RSAPublicKey;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.core5.http.Header;
Expand All @@ -53,7 +55,6 @@
import org.eclipse.digitaltwin.basyx.submodelrepository.SubmodelRepository;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.boot.SpringApplication;
Expand Down Expand Up @@ -84,8 +85,7 @@ public class TestAuthorizedAasEnvironmentSerialization {
public static void setUp() throws FileNotFoundException, IOException {
tokenProvider = new AccessTokenProvider(authenticaltionServerTokenEndpoint, clientId);

appContext = new SpringApplication(DummyAasEnvironmentComponent.class).run(new String[] {});

appContext = new SpringApplication(DummyAasEnvironmentComponent.class).run(new String[] {});
submodelRepo = appContext.getBean(SubmodelRepository.class);
aasRepo = appContext.getBean(AasRepository.class);
conceptDescriptionRepo = appContext.getBean(ConceptDescriptionRepository.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import java.io.IOException;
import java.security.interfaces.RSAPublicKey;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
Expand Down Expand Up @@ -80,9 +82,8 @@ public class TestAuthorizedAasEnvironmentUpload {
@BeforeClass
public static void setUp() throws FileNotFoundException, IOException {
tokenProvider = new AccessTokenProvider(authenticaltionServerTokenEndpoint, clientId);

appContext = new SpringApplication(DummyAasEnvironmentComponent.class).run(new String[] {});

appContext = new SpringApplication(DummyAasEnvironmentComponent.class).run(new String[] {});
submodelRepo = appContext.getBean(SubmodelRepository.class);
aasRepo = appContext.getBean(AasRepository.class);
conceptDescriptionRepo = appContext.getBean(ConceptDescriptionRepository.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
server.port=8081
spring.application.name=AAS Environment
basyx.environment=
basyx.backend=InMemory
basyx.environment=
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:9096/realms/BaSyx
basyx.aasenvironment.authorization.preconfiguration.token-endpoint=http://localhost:9096/realms/BaSyx/protocol/openid-connect/token
basyx.aasenvironment.authorization.preconfiguration.grant-type = CLIENT_CREDENTIALS
basyx.aasenvironment.authorization.preconfiguration.client-id=workstation-1
basyx.aasenvironment.authorization.preconfiguration.client-secret=nY0mjyECF60DGzNmQUjL81XurSl8etom
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.eclipse.digitaltwin.basyx.submodelrepository.SubmodelRepository;
import org.eclipse.digitaltwin.basyx.submodelservice.DummySubmodelFactory;
import org.eclipse.digitaltwin.basyx.submodelservice.SubmodelServiceHelper;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.ResourceLoader;
Expand All @@ -63,7 +64,8 @@ public AasEnvironment createAasEnvironmentSerialization(AasRepository aasReposit
}

@Bean
public AasEnvironmentPreconfigurationLoader createAasEnvironmentPreconfigurationLoader(ResourceLoader resourceLoader, List<String> pathsToLoad) {
public AasEnvironmentPreconfigurationLoader createAasEnvironmentPreconfigurationLoader(ResourceLoader resourceLoader,
@Value(AasEnvironmentPreconfigurationLoader.PATHS_TO_LOAD_EXPR) List<String> pathsToLoad) {
return new AasEnvironmentPreconfigurationLoader(resourceLoader, pathsToLoad);
}

Expand Down
36 changes: 34 additions & 2 deletions basyx.aasenvironment/basyx.aasenvironment.component/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,32 @@
<groupId>org.eclipse.digitaltwin.basyx</groupId>
<artifactId>basyx.aasenvironment-feature-authorization</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.digitaltwin.basyx</groupId>
<artifactId>basyx.aasrepository-feature-kafka</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.digitaltwin.basyx</groupId>
<artifactId>basyx.submodelrepository-feature-kafka</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.digitaltwin.basyx</groupId>
<artifactId>basyx.aasrepository-feature-kafka</artifactId>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.digitaltwin.basyx</groupId>
<artifactId>basyx.submodelservice-feature-kafka</artifactId>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.digitaltwin.basyx</groupId>
<artifactId>basyx.submodelrepository-feature-kafka</artifactId>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.digitaltwin.basyx</groupId>
<artifactId>basyx.http</artifactId>
Expand All @@ -100,8 +126,14 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.digitaltwin.basyx</groupId>
<artifactId>basyx.mongodbcore</artifactId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.eclipse.digitaltwin.basyx.aasenvironment.feature.AasEnvironmentFeature;
import org.eclipse.digitaltwin.basyx.aasenvironment.feature.DecoratedAasEnvironmentFactory;
import org.eclipse.digitaltwin.basyx.aasenvironment.preconfiguration.AasEnvironmentPreconfigurationLoader;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -54,7 +55,9 @@ public static AasEnvironment getAasEnvironment(AasEnvironmentFactory aasEnvironm

@Bean
@ConditionalOnMissingBean
public static AasEnvironmentPreconfigurationLoader getAasEnvironmentPreconfigurationLoader(ResourceLoader resourceLoader, List<String> pathsToLoad) {
public static AasEnvironmentPreconfigurationLoader getAasEnvironmentPreconfigurationLoader(
ResourceLoader resourceLoader,
@Value(AasEnvironmentPreconfigurationLoader.PATHS_TO_LOAD_EXPR) List<String> pathsToLoad) {
return new AasEnvironmentPreconfigurationLoader(resourceLoader, pathsToLoad);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ spring.application.name=AAS Environment

basyx.backend = InMemory

basyx.aasrepository.feature.kafka.topic.name=aas-events
basyx.submodelrepository.feature.kafka.topic.name=submodel-events
spring.kafka.producer.properties.client.id=repo-events


#basyx.backend = MongoDB
# spring.data.mongodb.host=mongo
# or spring.data.mongodb.host=127.0.0.1
Expand Down
Loading
Loading