Skip to content

Commit 0ef409d

Browse files
committed
Fixes failing tests
1 parent 3dd9034 commit 0ef409d

22 files changed

Lines changed: 423 additions & 71 deletions

File tree

basyx.aasregistry/basyx.aasregistry-feature-hierarchy-example/src/main/docker/Dockerfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
FROM eclipse-temurin:17 as builder
2+
WORKDIR /workspace
23
COPY maven/${project.build.finalName}.jar ./
3-
RUN java -Djarmode=layertools -jar ${project.build.finalName}.jar extract
4+
RUN java -Djarmode=tools -jar ${project.build.finalName}.jar extract --layers --launcher --destination . --force
45

56
FROM eclipse-temurin:17
67
RUN mkdir /workspace
78
WORKDIR /workspace
8-
COPY --from=builder dependencies/ ./
9-
COPY --from=builder snapshot-dependencies/ ./
9+
COPY --from=builder /workspace/dependencies/ ./
10+
COPY --from=builder /workspace/snapshot-dependencies/ ./
1011
RUN true
11-
COPY --from=builder spring-boot-loader/ ./
12-
COPY --from=builder application/ ./
12+
COPY --from=builder /workspace/spring-boot-loader/ ./
13+
COPY --from=builder /workspace/application/ ./
1314
ENV SPRING_PROFILES_ACTIVE=logEvents,inMemoryStorage,hierarchy
1415
ARG PORT=8080
1516
ENV SERVER_PORT=${PORT}

basyx.aasregistry/basyx.aasregistry-service-release-kafka-mem/src/main/docker/Dockerfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
FROM eclipse-temurin:17 as builder
2+
WORKDIR /workspace
23
ARG HTTP_PROXY
34
ARG HTTPS_PROXY
45
ARG FINAL_NAME=${project.build.finalName}
56
COPY maven/${FINAL_NAME}.jar ./
6-
RUN java -Djarmode=layertools -jar ${FINAL_NAME}.jar extract
7+
RUN java -Djarmode=tools -jar ${FINAL_NAME}.jar extract --layers --launcher --destination . --force
78

89
FROM eclipse-temurin:17
910
ARG HTTP_PROXY
1011
ARG HTTPS_PROXY
1112
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
1213
RUN mkdir /workspace
1314
WORKDIR /workspace
14-
COPY --from=builder dependencies/ ./
15-
COPY --from=builder snapshot-dependencies/ ./
15+
COPY --from=builder /workspace/dependencies/ ./
16+
COPY --from=builder /workspace/snapshot-dependencies/ ./
1617
RUN true
17-
COPY --from=builder spring-boot-loader/ ./
18-
COPY --from=builder application/ ./
18+
COPY --from=builder /workspace/spring-boot-loader/ ./
19+
COPY --from=builder /workspace/application/ ./
1920
ENV SPRING_PROFILES_ACTIVE=kafkaEvents,inMemoryStorage
2021
ARG PORT=8080
2122
ENV SERVER_PORT=${PORT}

basyx.aasregistry/basyx.aasregistry-service-release-kafka-mongodb/src/main/docker/Dockerfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
FROM eclipse-temurin:17 as builder
2+
WORKDIR /workspace
23
ARG HTTP_PROXY
34
ARG HTTPS_PROXY
45
ARG FINAL_NAME=${project.build.finalName}
56
COPY maven/${FINAL_NAME}.jar ./
6-
RUN java -Djarmode=layertools -jar ${FINAL_NAME}.jar extract
7+
RUN java -Djarmode=tools -jar ${FINAL_NAME}.jar extract --layers --launcher --destination . --force
78

89
FROM eclipse-temurin:17
910
ARG HTTP_PROXY
1011
ARG HTTPS_PROXY
1112
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
1213
RUN mkdir /workspace
1314
WORKDIR /workspace
14-
COPY --from=builder dependencies/ ./
15-
COPY --from=builder snapshot-dependencies/ ./
15+
COPY --from=builder /workspace/dependencies/ ./
16+
COPY --from=builder /workspace/snapshot-dependencies/ ./
1617
RUN true
17-
COPY --from=builder spring-boot-loader/ ./
18-
COPY --from=builder application/ ./
18+
COPY --from=builder /workspace/spring-boot-loader/ ./
19+
COPY --from=builder /workspace/application/ ./
1920
ENV SPRING_PROFILES_ACTIVE=kafkaEvents,mongoDbStorage
2021
ARG PORT=8080
2122
ENV SERVER_PORT=${PORT}

basyx.aasregistry/basyx.aasregistry-service-release-log-mem/src/main/docker/Dockerfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
FROM eclipse-temurin:17 as builder
2+
WORKDIR /workspace
23
ARG HTTP_PROXY
34
ARG HTTPS_PROXY
45
ARG FINAL_NAME=${project.build.finalName}
56
COPY maven/${FINAL_NAME}.jar ./
6-
RUN java -Djarmode=layertools -jar ${FINAL_NAME}.jar extract
7+
RUN java -Djarmode=tools -jar ${FINAL_NAME}.jar extract --layers --launcher --destination . --force
78

89
FROM eclipse-temurin:17
910
ARG HTTP_PROXY
1011
ARG HTTPS_PROXY
1112
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
1213
RUN mkdir /workspace
1314
WORKDIR /workspace
14-
COPY --from=builder dependencies/ ./
15-
COPY --from=builder snapshot-dependencies/ ./
15+
COPY --from=builder /workspace/dependencies/ ./
16+
COPY --from=builder /workspace/snapshot-dependencies/ ./
1617
RUN true
17-
COPY --from=builder spring-boot-loader/ ./
18-
COPY --from=builder application/ ./
18+
COPY --from=builder /workspace/spring-boot-loader/ ./
19+
COPY --from=builder /workspace/application/ ./
1920
ENV SPRING_PROFILES_ACTIVE=logEvents,inMemoryStorage
2021
ARG PORT=8080
2122
ENV SERVER_PORT=${PORT}

basyx.aasregistry/basyx.aasregistry-service-release-log-mongodb/src/main/docker/Dockerfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
FROM eclipse-temurin:17 as builder
2+
WORKDIR /workspace
23
ARG HTTP_PROXY
34
ARG HTTPS_PROXY
45
ARG FINAL_NAME=${project.build.finalName}
56
COPY maven/${FINAL_NAME}.jar ./
6-
RUN java -Djarmode=layertools -jar ${FINAL_NAME}.jar extract
7+
RUN java -Djarmode=tools -jar ${FINAL_NAME}.jar extract --layers --launcher --destination . --force
78

89
FROM eclipse-temurin:17
910
ARG HTTP_PROXY
1011
ARG HTTPS_PROXY
1112
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
1213
RUN mkdir /workspace
1314
WORKDIR /workspace
14-
COPY --from=builder dependencies/ ./
15-
COPY --from=builder snapshot-dependencies/ ./
15+
COPY --from=builder /workspace/dependencies/ ./
16+
COPY --from=builder /workspace/snapshot-dependencies/ ./
1617
RUN true
17-
COPY --from=builder spring-boot-loader/ ./
18-
COPY --from=builder application/ ./
18+
COPY --from=builder /workspace/spring-boot-loader/ ./
19+
COPY --from=builder /workspace/application/ ./
1920
ENV SPRING_PROFILES_ACTIVE=logEvents,mongoDbStorage
2021
ARG PORT=8080
2122
ENV SERVER_PORT=${PORT}

basyx.aasrepository/basyx.aasrepository-http/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/http/AasRepositoryApiHTTPController.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.eclipse.digitaltwin.basyx.core.exceptions.CollidingSubmodelReferenceException;
4444
import org.eclipse.digitaltwin.basyx.core.pagination.CursorResult;
4545
import org.eclipse.digitaltwin.basyx.core.pagination.PaginationInfo;
46+
import org.eclipse.digitaltwin.basyx.http.BaSyxMediaType;
4647
import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier;
4748
import org.eclipse.digitaltwin.basyx.http.pagination.Base64UrlEncodedCursor;
4849
import org.eclipse.digitaltwin.basyx.http.pagination.PagedResult;
@@ -199,10 +200,14 @@ public ResponseEntity<Void> deleteThumbnailAasRepository(Base64UrlEncodedIdentif
199200

200201
@Override
201202
public ResponseEntity<Resource> getThumbnailAasRepository(Base64UrlEncodedIdentifier aasIdentifier) {
202-
Resource resource = new FileSystemResource(aasRepository.getThumbnail(aasIdentifier.getIdentifier()));
203+
String aasId = aasIdentifier.getIdentifier();
204+
Resource resource = new FileSystemResource(aasRepository.getThumbnail(aasId));
205+
String contentType = aasRepository.getAssetInformation(aasId).getDefaultThumbnail().getContentType();
203206

204-
return new ResponseEntity<>(resource, HttpStatus.OK);
205-
}
207+
return ResponseEntity.ok()
208+
.contentType(BaSyxMediaType.parseOrOctetStream(contentType))
209+
.body(resource);
210+
}
206211

207212
@Override
208213
public ResponseEntity<Void> putThumbnailAasRepository(Base64UrlEncodedIdentifier aasIdentifier, String fileName, @Valid MultipartFile file) {

basyx.aasrepository/basyx.aasrepository-http/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/http/AasRepositoryHTTPSuite.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,13 @@
3636

3737
import org.apache.hc.client5.http.ClientProtocolException;
3838
import org.apache.hc.client5.http.classic.methods.HttpPut;
39+
import org.apache.hc.client5.http.entity.mime.FileBody;
40+
import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
3941
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
4042
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
4143
import org.apache.hc.client5.http.impl.classic.HttpClients;
44+
import org.apache.hc.core5.http.ContentType;
45+
import org.apache.hc.core5.http.HttpEntity;
4246
import org.apache.hc.core5.http.ParseException;
4347
import org.apache.hc.core5.http.ProtocolException;
4448
import org.apache.hc.core5.http.io.entity.EntityUtils;
@@ -401,6 +405,7 @@ public void getThumbnail() throws FileNotFoundException, IOException, ParseExcep
401405

402406
CloseableHttpResponse response = BaSyxHttpTestUtils.executeGetOnURL(BaSyxHttpTestUtils.getThumbnailAccessURL(getURL(), dummyAasId));
403407
assertEquals(HttpStatus.OK.value(), response.getCode());
408+
assertEquals(ContentType.IMAGE_PNG.getMimeType(), response.getFirstHeader("Content-Type").getValue());
404409

405410
byte[] actualFile = EntityUtils.toByteArray(response.getEntity());
406411

@@ -582,7 +587,14 @@ private CloseableHttpResponse uploadThumbnail(String aasId) throws IOException {
582587

583588
java.io.File file = ResourceUtils.getFile("classpath:" + THUMBNAIL_FILE_PATH);
584589

585-
HttpPut putRequest = BaSyxHttpTestUtils.createPutRequestWithFile(BaSyxHttpTestUtils.getThumbnailAccessURL(getURL(), aasId), THUMBNAIL_FILE_PATH, file);
590+
HttpPut putRequest = new HttpPut(BaSyxHttpTestUtils.getThumbnailAccessURL(getURL(), aasId));
591+
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
592+
builder.addPart("file", new FileBody(file, ContentType.IMAGE_PNG, THUMBNAIL_FILE_PATH));
593+
builder.addTextBody("fileName", THUMBNAIL_FILE_PATH);
594+
builder.setContentType(ContentType.MULTIPART_FORM_DATA);
595+
596+
HttpEntity multipart = builder.build();
597+
putRequest.setEntity(multipart);
586598

587599
return BaSyxHttpTestUtils.executePutRequest(client, putRequest);
588600
}

basyx.common/basyx.authorization/src/main/java/org/eclipse/digitaltwin/basyx/authorization/DisableSpringSecurityIfNoAuthorizationConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.springframework.boot.autoconfigure.condition.NoneNestedConditions;
3131
import org.springframework.boot.security.autoconfigure.SecurityAutoConfiguration;
3232
import org.springframework.boot.security.autoconfigure.actuate.web.servlet.ManagementWebSecurityAutoConfiguration;
33+
import org.springframework.boot.security.autoconfigure.web.servlet.ServletWebSecurityAutoConfiguration;
3334
import org.springframework.boot.security.oauth2.server.resource.autoconfigure.servlet.OAuth2ResourceServerAutoConfiguration;
3435
import org.springframework.context.annotation.Conditional;
3536
import org.springframework.context.annotation.Configuration;
@@ -41,7 +42,7 @@
4142
* @author wege, danish
4243
*/
4344
@Configuration
44-
@EnableAutoConfiguration(exclude = { SecurityAutoConfiguration.class, ManagementWebSecurityAutoConfiguration.class, OAuth2ResourceServerAutoConfiguration.class })
45+
@EnableAutoConfiguration(exclude = { SecurityAutoConfiguration.class, ServletWebSecurityAutoConfiguration.class, ManagementWebSecurityAutoConfiguration.class, OAuth2ResourceServerAutoConfiguration.class })
4546
@Conditional(DisableSpringSecurityIfNoAuthorizationConfig.NoAuthorizationCondition.class)
4647
public class DisableSpringSecurityIfNoAuthorizationConfig {
4748

basyx.common/basyx.authorization/src/main/java/org/eclipse/digitaltwin/basyx/authorization/rbac/CommonRbacConfiguration.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
3535
import org.springframework.context.annotation.Bean;
3636
import org.springframework.context.annotation.Configuration;
37+
import org.springframework.context.annotation.Primary;
3738
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
3839

3940
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -50,6 +51,7 @@
5051
public class CommonRbacConfiguration {
5152

5253
@Bean
54+
@Primary
5355
public ObjectMapper getAasMapper(Jackson2ObjectMapperBuilder builder) {
5456
ObjectMapper mapper = builder.build();
5557

basyx.common/basyx.authorization/src/main/java/org/eclipse/digitaltwin/basyx/authorization/rbac/RbacRuleInitializer.java

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,20 @@
2626
package org.eclipse.digitaltwin.basyx.authorization.rbac;
2727

2828
import com.fasterxml.jackson.core.type.TypeReference;
29+
import com.fasterxml.jackson.databind.DeserializationFeature;
30+
import com.fasterxml.jackson.databind.JsonNode;
2931
import com.fasterxml.jackson.databind.ObjectMapper;
32+
import com.fasterxml.jackson.databind.jsontype.NamedType;
3033
import java.io.File;
3134
import java.io.IOException;
3235
import java.util.HashMap;
36+
import java.util.List;
37+
import java.util.Map;
38+
import java.util.Objects;
39+
import java.util.Set;
3340

3441
import org.eclipse.digitaltwin.basyx.core.exceptions.MissingAuthorizationConfigurationException;
42+
import org.reflections.Reflections;
3543
import org.springframework.core.io.ResourceLoader;
3644

3745
/**
@@ -48,9 +56,12 @@ public class RbacRuleInitializer {
4856
private ResourceLoader resourceLoader;
4957

5058
public RbacRuleInitializer(ObjectMapper objectMapper, String filePath, ResourceLoader resourceLoader) {
51-
this.objectMapper = objectMapper;
59+
this.objectMapper = objectMapper.copy()
60+
.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
61+
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
5262
this.rbacJsonFilePath = filePath;
5363
this.resourceLoader = resourceLoader;
64+
registerTargetInformationSubtypes();
5465
}
5566

5667
/**
@@ -63,8 +74,50 @@ public RbacRuleInitializer(ObjectMapper objectMapper, String filePath, ResourceL
6374
* @throws IOException
6475
*/
6576
public HashMap<String, RbacRule> deserialize() throws IOException {
66-
return objectMapper.readValue(getFile(rbacJsonFilePath), new TypeReference<HashMap<String, RbacRule>>() {
67-
});
77+
JsonNode rules = objectMapper.readTree(getFile(rbacJsonFilePath));
78+
79+
if (rules.isArray()) {
80+
return mapByGeneratedKey(objectMapper.convertValue(rules, new TypeReference<List<RbacRule>>() {
81+
}));
82+
}
83+
84+
if (rules.isObject()) {
85+
Map<String, RbacRule> mappedRules = objectMapper.convertValue(rules, new TypeReference<Map<String, RbacRule>>() {
86+
});
87+
return new HashMap<>(mappedRules);
88+
}
89+
90+
throw new IOException("Unsupported RBAC rules format: " + rules.getNodeType());
91+
}
92+
93+
private HashMap<String, RbacRule> mapByGeneratedKey(List<RbacRule> rbacRules) {
94+
HashMap<String, RbacRule> result = new HashMap<>();
95+
96+
for (RbacRule rule : rbacRules) {
97+
for (Action action : rule.getAction()) {
98+
RbacRule singleActionRule = new RbacRule(rule.getRole(), List.of(action), rule.getTargetInformation());
99+
result.put(createKey(singleActionRule), singleActionRule);
100+
}
101+
}
102+
103+
return result;
104+
}
105+
106+
private String createKey(RbacRule rbacRule) {
107+
return RbacRuleKeyGenerator.generateKey(rbacRule.getRole(), rbacRule.getAction().get(0).toString(), rbacRule.getTargetInformation().getClass().getName());
108+
}
109+
110+
private void registerTargetInformationSubtypes() {
111+
Reflections reflections = new Reflections("org.eclipse.digitaltwin.basyx");
112+
Set<Class<?>> subtypes = reflections.getTypesAnnotatedWith(TargetInformationSubtype.class);
113+
114+
subtypes.stream().map(this::createNamedType).filter(Objects::nonNull).forEach(objectMapper::registerSubtypes);
115+
}
116+
117+
private NamedType createNamedType(Class<?> subType) {
118+
TargetInformationSubtype annotation = subType.getAnnotation(TargetInformationSubtype.class);
119+
120+
return (annotation != null) ? new NamedType(subType, annotation.getValue()) : null;
68121
}
69122

70123
private File getFile(String filePath) {

0 commit comments

Comments
 (0)