Skip to content

Commit e937f63

Browse files
committed
Fixes some issues with spring
1 parent e4a7271 commit e937f63

11 files changed

Lines changed: 193 additions & 164 deletions

File tree

basyx.aasregistry/basyx.aasregistry-feature-search/src/main/java/org/eclipse/digitaltwin/basyx/aasregistry/feature/search/DisableSearchAasRegistryConfiguration.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import org.springframework.boot.actuate.autoconfigure.data.elasticsearch.ElasticsearchReactiveHealthContributorAutoConfiguration;
2929
import org.springframework.boot.actuate.autoconfigure.metrics.export.elastic.ElasticMetricsExportAutoConfiguration;
3030
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
31-
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
31+
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
3232
import org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchDataAutoConfiguration;
3333
import org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchRepositoriesAutoConfiguration;
3434
import org.springframework.boot.autoconfigure.data.elasticsearch.ReactiveElasticsearchRepositoriesAutoConfiguration;
@@ -39,10 +39,10 @@
3939

4040
/**
4141
* Configuration to prevent Elasticsearch from being injected by Spring
42-
* @author fried
42+
*
4343
*/
4444
@Configuration
45-
@ConditionalOnProperty(name = {SearchAasRegistryFeature.FEATURENAME + ".enabled", "basyx.feature.search.enabled"}, havingValue = "false", matchIfMissing = true)
45+
@ConditionalOnExpression("!(${" + SearchAasRegistryFeature.FEATURENAME + ".enabled:false} || ${basyx.feature.search.enabled:false})")
4646
@EnableAutoConfiguration(exclude = {
4747
ElasticsearchClientAutoConfiguration.class,
4848
ElasticsearchRepositoriesAutoConfiguration.class,
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,46 @@
1-
/*******************************************************************************
2-
* Copyright (C) 2024 the Eclipse BaSyx Authors
3-
*
4-
* Permission is hereby granted, free of charge, to any person obtaining
5-
* a copy of this software and associated documentation files (the
6-
* "Software"), to deal in the Software without restriction, including
7-
* without limitation the rights to use, copy, modify, merge, publish,
8-
* distribute, sublicense, and/or sell copies of the Software, and to
9-
* permit persons to whom the Software is furnished to do so, subject to
10-
* the following conditions:
11-
*
12-
* The above copyright notice and this permission notice shall be
13-
* included in all copies or substantial portions of the Software.
14-
*
15-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16-
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17-
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18-
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19-
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20-
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21-
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22-
*
23-
* SPDX-License-Identifier: MIT
24-
******************************************************************************/
25-
26-
package org.eclipse.digitaltwin.basyx.aasrepository.feature.authorization;
27-
28-
import org.springframework.boot.SpringApplication;
29-
import org.springframework.boot.autoconfigure.SpringBootApplication;
30-
31-
/**
32-
* Spring application configured for tests.
33-
*
34-
* @author danish
35-
*
36-
*/
37-
38-
@SpringBootApplication(scanBasePackages = "org.eclipse.digitaltwin.basyx")
39-
public class DummyAuthorizedAasRepositoryComponent {
40-
41-
public static void main(String[] args) {
42-
SpringApplication.run(DummyAuthorizedAasRepositoryComponent.class, args);
43-
}
44-
}
1+
/*******************************************************************************
2+
* Copyright (C) 2024 the Eclipse BaSyx Authors
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining
5+
* a copy of this software and associated documentation files (the
6+
* "Software"), to deal in the Software without restriction, including
7+
* without limitation the rights to use, copy, modify, merge, publish,
8+
* distribute, sublicense, and/or sell copies of the Software, and to
9+
* permit persons to whom the Software is furnished to do so, subject to
10+
* the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be
13+
* included in all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*
23+
* SPDX-License-Identifier: MIT
24+
******************************************************************************/
25+
26+
package org.eclipse.digitaltwin.basyx.aasrepository.feature.authorization;
27+
28+
import org.springframework.boot.SpringApplication;
29+
import org.springframework.boot.autoconfigure.SpringBootApplication;
30+
import org.springframework.boot.actuate.autoconfigure.elasticsearch.ElasticsearchRestHealthContributorAutoConfiguration;
31+
32+
/**
33+
* Spring application configured for tests.
34+
*
35+
* @author danish
36+
*
37+
*/
38+
39+
@SpringBootApplication(scanBasePackages = "org.eclipse.digitaltwin.basyx",
40+
exclude = {ElasticsearchRestHealthContributorAutoConfiguration.class})
41+
public class DummyAuthorizedAasRepositoryComponent {
42+
43+
public static void main(String[] args) {
44+
SpringApplication.run(DummyAuthorizedAasRepositoryComponent.class, args);
45+
}
46+
}
Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
1-
server.port=8081
2-
server.error.path=/error
3-
4-
spring.application.name=AAS Repository
5-
basyx.aasrepo.name=aas-repo
6-
7-
basyx.backend = InMemory
8-
9-
#basyx.aasrepository.feature.registryintegration=http://host.docker.internal:8050/api/v3.0
10-
#basyx.externalurl=http://localhost:8081
11-
12-
#basyx.backend = MongoDB
13-
#spring.data.mongodb.host=127.0.0.1
14-
#spring.data.mongodb.port=27017
15-
#spring.data.mongodb.database=aas
16-
#spring.data.mongodb.authentication-database=admin
17-
#spring.data.mongodb.username=mongoAdmin
18-
#spring.data.mongodb.password=mongoPassword
19-
20-
21-
# basyx.aasrepository.feature.mqtt.enabled = true
22-
# mqtt.clientId=TestClient
23-
# mqtt.hostname = localhost
24-
# mqtt.port = 1883
25-
26-
# basyx.cors.allowed-origins=http://localhost:3000, http://localhost:4000
27-
28-
####################################################################################
29-
# Authorization
30-
####################################################################################
31-
basyx.feature.authorization.enabled = true
32-
basyx.feature.authorization.type = rbac
33-
basyx.feature.authorization.jwtBearerTokenProvider = keycloak
34-
basyx.feature.authorization.rbac.file = classpath:rbac_rules.json
35-
spring.security.oauth2.resourceserver.jwt.issuer-uri= http://localhost:9096/realms/BaSyx
36-
37-
####################################################################################
38-
# Operation Delegation
39-
####################################################################################
40-
# This feature is enabled by default
41-
1+
server.port=8081
2+
server.error.path=/error
3+
4+
spring.application.name=AAS Repository
5+
basyx.aasrepo.name=aas-repo
6+
7+
basyx.backend = InMemory
8+
9+
#basyx.aasrepository.feature.registryintegration=http://host.docker.internal:8050/api/v3.0
10+
#basyx.externalurl=http://localhost:8081
11+
12+
#basyx.backend = MongoDB
13+
#spring.data.mongodb.host=127.0.0.1
14+
#spring.data.mongodb.port=27017
15+
#spring.data.mongodb.database=aas
16+
#spring.data.mongodb.authentication-database=admin
17+
#spring.data.mongodb.username=mongoAdmin
18+
#spring.data.mongodb.password=mongoPassword
19+
20+
21+
# basyx.aasrepository.feature.mqtt.enabled = true
22+
# mqtt.clientId=TestClient
23+
# mqtt.hostname = localhost
24+
# mqtt.port = 1883
25+
26+
# basyx.cors.allowed-origins=http://localhost:3000, http://localhost:4000
27+
28+
####################################################################################
29+
# Authorization
30+
####################################################################################
31+
basyx.feature.authorization.enabled = true
32+
basyx.feature.authorization.type = rbac
33+
basyx.feature.authorization.jwtBearerTokenProvider = keycloak
34+
basyx.feature.authorization.rbac.file = classpath:rbac_rules.json
35+
spring.security.oauth2.resourceserver.jwt.issuer-uri= http://localhost:9096/realms/BaSyx
36+
37+
####################################################################################
38+
# Operation Delegation
39+
####################################################################################
40+
# This feature is enabled by default
41+
4242
#basyx.submodelrepository.feature.operation.delegation.enabled = false

basyx.aasrepository/basyx.aasrepository-feature-search/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/search/DisableSearchAasRepositoryConfiguration.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
import org.springframework.boot.actuate.autoconfigure.elasticsearch.ElasticsearchRestHealthContributorAutoConfiguration;
2929
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
30-
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
30+
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
3131
import org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchDataAutoConfiguration;
3232
import org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchRepositoriesAutoConfiguration;
3333
import org.springframework.boot.autoconfigure.data.elasticsearch.ReactiveElasticsearchRepositoriesAutoConfiguration;
@@ -38,10 +38,10 @@
3838

3939
/**
4040
* Configuration to prevent Elasticsearch from being injected by Spring
41-
* @author fried
41+
*
4242
*/
4343
@Configuration
44-
@ConditionalOnProperty(name = {SearchAasRepositoryFeature.FEATURENAME + ".enabled", "basyx.feature.search.enabled"}, havingValue = "false", matchIfMissing = true)
44+
@ConditionalOnExpression("!(${" + SearchAasRepositoryFeature.FEATURENAME + ".enabled:false} || ${basyx.feature.search.enabled:false})")
4545
@EnableAutoConfiguration(exclude = {
4646
ElasticsearchClientAutoConfiguration.class,
4747
ElasticsearchRepositoriesAutoConfiguration.class,

basyx.aasrepository/basyx.aasrepository-feature-search/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/search/SearchAasRepositoryConfiguration.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
* "Software"), to deal in the Software without restriction, including
77
* without limitation the rights to use, copy, modify, merge, publish,
88
* distribute, sublicense, and/or sell copies of the Software, and to
9-
* permit persons to whom the Software is furnished to do so, subject to
10-
* the following conditions:
9+
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
1110
*
1211
* The above copyright notice and this permission notice shall be
1312
* included in all copies or substantial portions of the Software.
@@ -25,11 +24,31 @@
2524

2625
package org.eclipse.digitaltwin.basyx.aasrepository.feature.search;
2726

28-
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
27+
import org.springframework.boot.actuate.health.Health;
28+
import org.springframework.boot.actuate.health.HealthIndicator;
29+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
30+
import org.springframework.context.annotation.Bean;
2931
import org.springframework.context.annotation.Configuration;
32+
import org.springframework.context.annotation.Primary;
3033

31-
@ConditionalOnExpression("#{${" + SearchAasRepositoryFeature.FEATURENAME + ".enabled:false} or ${basyx.feature.search.enabled:false}}")
34+
@ConditionalOnProperty(name = SearchAasRepositoryFeature.FEATURENAME + ".enabled", havingValue = "true", matchIfMissing = false)
3235
@Configuration
3336
public class SearchAasRepositoryConfiguration {
3437

3538
}
39+
40+
/**
41+
* Configuration to provide a safe Elasticsearch health indicator when search feature is not enabled
42+
*/
43+
@Configuration
44+
@ConditionalOnProperty(name = SearchAasRepositoryFeature.FEATURENAME + ".enabled", havingValue = "false", matchIfMissing = true)
45+
class SafeElasticsearchHealthConfiguration {
46+
47+
@Bean(name = "elasticsearchHealthIndicator")
48+
@Primary
49+
public HealthIndicator elasticsearchHealthIndicator() {
50+
return () -> Health.up()
51+
.withDetail("elasticsearch", "disabled - search feature not enabled")
52+
.build();
53+
}
54+
}

basyx.aasrepository/basyx.aasrepository-feature-search/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/search/SearchAasRepositoryFeature.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,23 @@
2525

2626
package org.eclipse.digitaltwin.basyx.aasrepository.feature.search;
2727

28-
import co.elastic.clients.elasticsearch.ElasticsearchClient;
2928
import org.eclipse.digitaltwin.basyx.aasrepository.AasRepositoryFactory;
3029
import org.eclipse.digitaltwin.basyx.aasrepository.feature.AasRepositoryFeature;
3130
import org.springframework.beans.factory.annotation.Autowired;
3231
import org.springframework.beans.factory.annotation.Value;
33-
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
32+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
3433
import org.springframework.stereotype.Component;
3534

36-
@ConditionalOnExpression("#{${" + SearchAasRepositoryFeature.FEATURENAME + ".enabled:false} or ${basyx.feature.search.enabled:false}}")
35+
import co.elastic.clients.elasticsearch.ElasticsearchClient;
36+
37+
/**
38+
* Feature for AAS Repository search functionality
39+
*
40+
*/
3741
@Component
42+
@ConditionalOnProperty(name = SearchAasRepositoryFeature.FEATURENAME + ".enabled", havingValue = "true", matchIfMissing = false)
3843
public class SearchAasRepositoryFeature implements AasRepositoryFeature {
44+
3945
public static final String FEATURENAME = "basyx.aasrepository.feature.search";
4046
public static final String DEFAULT_INDEX = "aas-index";
4147
private final ElasticsearchClient esclient;
@@ -50,28 +56,29 @@ public class SearchAasRepositoryFeature implements AasRepositoryFeature {
5056
public SearchAasRepositoryFeature(ElasticsearchClient client) {
5157
this.esclient = client;
5258
}
53-
59+
5460
@Override
55-
public AasRepositoryFactory decorate(AasRepositoryFactory aasServiceFactory) {
56-
return new SearchAasRepositoryFactory(aasServiceFactory, esclient, indexName);
61+
public AasRepositoryFactory decorate(AasRepositoryFactory aasRepositoryFactory) {
62+
return new SearchAasRepositoryFactory(aasRepositoryFactory, esclient, indexName);
5763
}
5864

5965
@Override
60-
public void initialize() {
66+
public String getName() {
67+
return "AAS Repository Search";
6168
}
6269

6370
@Override
64-
public void cleanUp() {
65-
71+
public void initialize() {
72+
// No initialization needed
6673
}
6774

6875
@Override
69-
public String getName() {
70-
return "AasRepository Search";
76+
public void cleanUp() {
77+
// No cleanup needed
7178
}
7279

7380
@Override
7481
public boolean isEnabled() {
75-
return enabled;
82+
return true;
7683
}
7784
}

basyx.aasrepository/basyx.aasrepository-feature-search/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/search/TestSearchAasRepository.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public static void startSmRepo() throws Exception {
5757
searchBackend = appContext.getBean(AasRepository.class);
5858
searchAPI = appContext.getBean(SearchAasRepositoryApiHTTPController.class);
5959
preloadShells();
60+
Thread.sleep(2000);
6061
}
6162

6263
@Test

0 commit comments

Comments
 (0)