Skip to content

Commit 5605ba3

Browse files
authored
Merge pull request #410 from eclipse-arrowhead/development
Release 4.6.0
2 parents 2271711 + 35b0315 commit 5605ba3

672 files changed

Lines changed: 45001 additions & 10893 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

authorization/src/main/java/eu/arrowhead/core/authorization/AuthorizationController.java

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
package eu.arrowhead.core.authorization;
1616

1717
import java.security.PublicKey;
18+
import java.time.ZonedDateTime;
19+
import java.time.format.DateTimeParseException;
1820
import java.util.Base64;
1921
import java.util.HashSet;
2022
import java.util.List;
@@ -29,6 +31,7 @@
2931
import org.apache.logging.log4j.Logger;
3032
import org.springframework.beans.factory.annotation.Autowired;
3133
import org.springframework.beans.factory.annotation.Value;
34+
import org.springframework.boot.logging.LogLevel;
3235
import org.springframework.data.domain.Sort.Direction;
3336
import org.springframework.http.HttpHeaders;
3437
import org.springframework.http.MediaType;
@@ -50,6 +53,10 @@
5053
import eu.arrowhead.common.CoreUtilities;
5154
import eu.arrowhead.common.Defaults;
5255
import eu.arrowhead.common.Utilities;
56+
import eu.arrowhead.common.CoreUtilities.ValidatedPageParams;
57+
import eu.arrowhead.common.core.CoreSystem;
58+
import eu.arrowhead.common.database.entity.Logs;
59+
import eu.arrowhead.common.database.service.CommonDBService;
5360
import eu.arrowhead.common.dto.internal.AuthorizationInterCloudCheckRequestDTO;
5461
import eu.arrowhead.common.dto.internal.AuthorizationInterCloudCheckResponseDTO;
5562
import eu.arrowhead.common.dto.internal.AuthorizationInterCloudListResponseDTO;
@@ -63,7 +70,9 @@
6370
import eu.arrowhead.common.dto.internal.AuthorizationSubscriptionCheckRequestDTO;
6471
import eu.arrowhead.common.dto.internal.AuthorizationSubscriptionCheckResponseDTO;
6572
import eu.arrowhead.common.dto.internal.IdIdListDTO;
73+
import eu.arrowhead.common.dto.internal.LogEntryListResponseDTO;
6674
import eu.arrowhead.common.dto.internal.TokenDataDTO;
75+
import eu.arrowhead.common.dto.internal.TokenGenerationMultiServiceResponseDTO;
6776
import eu.arrowhead.common.dto.internal.TokenGenerationProviderDTO;
6877
import eu.arrowhead.common.dto.internal.TokenGenerationRequestDTO;
6978
import eu.arrowhead.common.dto.internal.TokenGenerationResponseDTO;
@@ -93,6 +102,7 @@ public class AuthorizationController {
93102
private static final String ID_NOT_VALID_ERROR_MESSAGE = "Id must be greater than 0.";
94103

95104
private static final String TOKEN_DESCRIPTION = "Generates tokens for a consumer which can be used to access the specified service of the specified providers";
105+
private static final String TOKEN_MULTI_SERVICE_DESCRIPTION = "Generates tokens for different services and different consumers which can be used to access the specified services of the specified providers";
96106
private static final String TOKEN_HTTP_200_MESSAGE = "Tokens returned";
97107
private static final String TOKEN_HTTP_400_MESSAGE = "Could not generate tokens";
98108

@@ -127,6 +137,9 @@ public class AuthorizationController {
127137

128138
@Autowired
129139
private AuthorizationDBService authorizationDBService;
140+
141+
@Autowired
142+
private CommonDBService commonDBService;
130143

131144
@Autowired
132145
private TokenGenerationService tokenGenerationService;
@@ -155,6 +168,48 @@ public String echoService() {
155168
return "Got it!";
156169
}
157170

171+
//-------------------------------------------------------------------------------------------------
172+
@ApiOperation(value = "Return requested log entries by the given parameters", response = LogEntryListResponseDTO.class, tags = { CoreCommonConstants.SWAGGER_TAG_MGMT })
173+
@ApiResponses(value = {
174+
@ApiResponse(code = HttpStatus.SC_OK, message = CoreCommonConstants.QUERY_LOG_ENTRIES_HTTP_200_MESSAGE),
175+
@ApiResponse(code = HttpStatus.SC_BAD_REQUEST, message = CoreCommonConstants.QUERY_LOG_ENTRIES_HTTP_400_MESSAGE),
176+
@ApiResponse(code = HttpStatus.SC_UNAUTHORIZED, message = CoreCommonConstants.SWAGGER_HTTP_401_MESSAGE),
177+
@ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = CoreCommonConstants.SWAGGER_HTTP_500_MESSAGE)
178+
})
179+
@GetMapping(path = CoreCommonConstants.OP_QUERY_LOG_ENTRIES, produces = MediaType.APPLICATION_JSON_VALUE)
180+
@ResponseBody public LogEntryListResponseDTO getLogEntries(
181+
@RequestParam(name = CoreCommonConstants.REQUEST_PARAM_PAGE, required = false) final Integer page,
182+
@RequestParam(name = CoreCommonConstants.REQUEST_PARAM_ITEM_PER_PAGE, required = false) final Integer size,
183+
@RequestParam(name = CoreCommonConstants.REQUEST_PARAM_DIRECTION, defaultValue = CoreDefaults.DEFAULT_REQUEST_PARAM_DIRECTION_VALUE) final String direction,
184+
@RequestParam(name = CoreCommonConstants.REQUEST_PARAM_SORT_FIELD, defaultValue = Logs.FIELD_NAME_ID) final String sortField,
185+
@RequestParam(name = CoreCommonConstants.REQUEST_PARAM_LOG_LEVEL, required = false) final String logLevel,
186+
@RequestParam(name = CoreCommonConstants.REQUEST_PARAM_FROM, required = false) final String from,
187+
@RequestParam(name = CoreCommonConstants.REQUEST_PARAM_TO, required = false) final String to,
188+
@RequestParam(name = CoreCommonConstants.REQUEST_PARAM_LOGGER, required = false) final String loggerStr) {
189+
logger.debug("New getLogEntries GET request received with page: {} and item_per page: {}", page, size);
190+
191+
final String origin = CommonConstants.AUTHORIZATION_URI + CoreCommonConstants.OP_QUERY_LOG_ENTRIES;
192+
final ValidatedPageParams validParameters = CoreUtilities.validatePageParameters(page, size, direction, origin);
193+
final List<LogLevel> logLevels = CoreUtilities.getLogLevels(logLevel, origin);
194+
195+
try {
196+
final ZonedDateTime _from = Utilities.parseUTCStringToLocalZonedDateTime(from);
197+
final ZonedDateTime _to = Utilities.parseUTCStringToLocalZonedDateTime(to);
198+
199+
if (_from != null && _to != null && _to.isBefore(_from)) {
200+
throw new BadPayloadException("Invalid time interval", HttpStatus.SC_BAD_REQUEST, origin);
201+
}
202+
203+
final LogEntryListResponseDTO response = commonDBService.getLogEntriesResponse(validParameters.getValidatedPage(), validParameters.getValidatedSize(), validParameters.getValidatedDirection(), sortField, CoreSystem.AUTHORIZATION,
204+
logLevels, _from, _to, loggerStr);
205+
206+
logger.debug("Log entries with page: {} and item_per page: {} retrieved successfully", page, size);
207+
return response;
208+
} catch (final DateTimeParseException ex) {
209+
throw new BadPayloadException("Invalid time parameter", HttpStatus.SC_BAD_REQUEST, origin, ex);
210+
}
211+
}
212+
158213
//-------------------------------------------------------------------------------------------------
159214
@ApiOperation(value = "Return requested AuthorizationIntraCloud entries by the given parameters", response = AuthorizationIntraCloudListResponseDTO.class,
160215
tags = { CoreCommonConstants.SWAGGER_TAG_MGMT })
@@ -617,6 +672,27 @@ public void removeAuthorizationInterCloudById(@PathVariable(value = PATH_VARIABL
617672
return response;
618673
}
619674

675+
//-------------------------------------------------------------------------------------------------
676+
@ApiOperation(value = TOKEN_MULTI_SERVICE_DESCRIPTION, response = TokenGenerationMultiServiceResponseDTO.class, tags = { CoreCommonConstants.SWAGGER_TAG_PRIVATE })
677+
@ApiResponses(value = {
678+
@ApiResponse(code = HttpStatus.SC_OK, message = TOKEN_HTTP_200_MESSAGE),
679+
@ApiResponse(code = HttpStatus.SC_BAD_REQUEST, message = TOKEN_HTTP_400_MESSAGE),
680+
@ApiResponse(code = HttpStatus.SC_UNAUTHORIZED, message = CoreCommonConstants.SWAGGER_HTTP_401_MESSAGE),
681+
@ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = CoreCommonConstants.SWAGGER_HTTP_500_MESSAGE)
682+
})
683+
@PostMapping(path = CommonConstants.OP_AUTH_TOKEN_MULTI_SERVICE_URI, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
684+
@ResponseBody public TokenGenerationMultiServiceResponseDTO generateMultiServiceTokens(@RequestBody final List<TokenGenerationRequestDTO> requestList) {
685+
logger.debug("New multi-service token generation request received");
686+
for (final TokenGenerationRequestDTO request : requestList) {
687+
checkTokenGenerationRequest(request);
688+
}
689+
690+
final TokenGenerationMultiServiceResponseDTO response = tokenGenerationService.generateMultiServiceTokensResponse(requestList);
691+
logger.debug("Multi-service token generation request has been finished");
692+
693+
return response;
694+
}
695+
620696
//-------------------------------------------------------------------------------------------------
621697
@ApiOperation(value = PUBLIC_KEY_DESCRIPTION, response = String.class, tags = { CoreCommonConstants.SWAGGER_TAG_CLIENT })
622698
@ApiResponses(value = {

authorization/src/main/java/eu/arrowhead/core/authorization/security/AuthAccessControlFilter.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class AuthAccessControlFilter extends CoreSystemAccessControlFilter {
3333

3434
private static final String AUTHORIZATION_INTRA_CLOUD_MGMT_URI = CoreCommonConstants.MGMT_URI + "/intracloud";
3535
private static final CoreSystem[] allowedCoreSystemsForChecks = { CoreSystem.ORCHESTRATOR, CoreSystem.GATEKEEPER };
36+
private static final CoreSystem[] allowedCoreSystemsForTokenGenerations = { CoreSystem.ORCHESTRATOR, CoreSystem.CHOREOGRAPHER };
3637
private static final CoreSystem[] allowedCoreSystemsForSubscriptionChecks = { CoreSystem.EVENTHANDLER };
3738
private static final CoreSystem[] allowedCoreSystemsForRuleMgmt = { CoreSystem.ONBOARDINGCONTROLLER, CoreSystem.MSCV };
3839

@@ -55,12 +56,14 @@ protected void checkClientAuthorized(final String clientCN, final String method,
5556
} else if (requestTarget.contains(CoreCommonConstants.MGMT_URI)) {
5657
// Only the local System Operator can use these methods
5758
checkIfLocalSystemOperator(clientCN, cloudCN, requestTarget);
58-
} else if (requestTarget.endsWith(CommonConstants.OP_AUTH_TOKEN_URI) || requestTarget.endsWith(CommonConstants.OP_AUTH_INTRA_CHECK_URI) ||
59-
requestTarget.endsWith(CommonConstants.OP_AUTH_INTER_CHECK_URI)) {
60-
// Only the specified core systems can use all the other methods
59+
} else if (requestTarget.endsWith(CommonConstants.OP_AUTH_TOKEN_URI) || requestTarget.endsWith(CommonConstants.OP_AUTH_TOKEN_MULTI_SERVICE_URI)) {
60+
// Only the specified core systems can use this methods
61+
checkIfClientIsAnAllowedCoreSystem(clientCN, cloudCN, allowedCoreSystemsForTokenGenerations, requestTarget);
62+
} else if (requestTarget.endsWith(CommonConstants.OP_AUTH_INTRA_CHECK_URI) || requestTarget.endsWith(CommonConstants.OP_AUTH_INTER_CHECK_URI)) {
63+
// Only the specified core systems can use all these methods
6164
checkIfClientIsAnAllowedCoreSystem(clientCN, cloudCN, allowedCoreSystemsForChecks, requestTarget);
6265
} else if (requestTarget.endsWith(CommonConstants.OP_AUTH_SUBSCRIPTION_CHECK_URI)) {
63-
// Only the specified core systems can use all the other methods
66+
// Only the specified core systems can use this method
6467
checkIfClientIsAnAllowedCoreSystem(clientCN, cloudCN, allowedCoreSystemsForSubscriptionChecks, requestTarget);
6568
}
6669
}

authorization/src/main/java/eu/arrowhead/core/authorization/token/TokenGenerationService.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
1+
/********************************************************************************
2+
* Copyright (c) 2019 AITIA
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* AITIA - implementation
12+
* Arrowhead Consortia - conceptualization
13+
********************************************************************************/
14+
115
package eu.arrowhead.core.authorization.token;
216

317
import java.security.PrivateKey;
418
import java.security.PublicKey;
19+
import java.util.ArrayList;
520
import java.util.HashMap;
621
import java.util.List;
722
import java.util.Map;
@@ -24,6 +39,8 @@
2439
import eu.arrowhead.common.database.entity.Cloud;
2540
import eu.arrowhead.common.database.service.CommonDBService;
2641
import eu.arrowhead.common.dto.internal.DTOConverter;
42+
import eu.arrowhead.common.dto.internal.TokenGenerationDetailedResponseDTO;
43+
import eu.arrowhead.common.dto.internal.TokenGenerationMultiServiceResponseDTO;
2744
import eu.arrowhead.common.dto.internal.TokenGenerationProviderDTO;
2845
import eu.arrowhead.common.dto.internal.TokenGenerationRequestDTO;
2946
import eu.arrowhead.common.dto.internal.TokenGenerationResponseDTO;
@@ -121,6 +138,24 @@ public TokenGenerationResponseDTO generateTokensResponse(final TokenGenerationRe
121138
final Map<SystemRequestDTO,Map<String,String>> tokenMap = generateTokens(request);
122139
return DTOConverter.convertTokenMapToTokenGenerationResponseDTO(tokenMap);
123140
}
141+
142+
//-------------------------------------------------------------------------------------------------
143+
public TokenGenerationMultiServiceResponseDTO generateMultiServiceTokensResponse(final List<TokenGenerationRequestDTO> requestList) {
144+
logger.debug("generateMultiServiceTokensResponse started...");
145+
146+
final List<TokenGenerationDetailedResponseDTO> data = new ArrayList<>();
147+
for (final TokenGenerationRequestDTO request : requestList) {
148+
final TokenGenerationDetailedResponseDTO tokenDetails = new TokenGenerationDetailedResponseDTO();
149+
tokenDetails.setService(request.getService());
150+
tokenDetails.setConsumerName(request.getConsumer().getSystemName());
151+
tokenDetails.setConsumerAdress(request.getConsumer().getAddress());
152+
tokenDetails.setConsumerPort(request.getConsumer().getPort());
153+
tokenDetails.setTokenData(generateTokensResponse(request).getTokenData());
154+
data.add(tokenDetails);
155+
}
156+
157+
return new TokenGenerationMultiServiceResponseDTO(data);
158+
}
124159

125160
//=================================================================================================
126161
// assistant methods

authorization/src/main/resources/log4j2.xml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
<Property name="LOG_PATTERN">
55
%d{yyyy-MM-dd HH:mm:ss.SSS} %5p ${hostName} --- [%15.15t] %-40.40c{1.} : %m%n%ex
66
</Property>
7+
<Property name="SYSTEM_NAME">AUTHORIZATION</Property>
78
<Property name="JDBC_LEVEL">INFO</Property>
89
<Property name="CONSOLE_FILE_LEVEL">INFO</Property>
910
<Property name="LOG_DIR">.</Property>
1011
</Properties>
1112
<Appenders>
1213
<Console name="ConsoleAppender" target="SYSTEM_OUT" follow="true">
1314
<PatternLayout pattern="${LOG_PATTERN}"/>
14-
</Console>
15+
<ThresholdFilter level="${CONSOLE_FILE_LEVEL}" onMatch="ACCEPT" onMismatch="DENY"/>
16+
</Console>
1517
<RollingFile name="FileAppender" fileName="${LOG_DIR}/authorization.log" filePattern="${LOG_DIR}/authorization-%d{yyyy-MM-dd}-%i.log">
1618
<PatternLayout>
1719
<Pattern>${LOG_PATTERN}</Pattern>
@@ -20,15 +22,17 @@
2022
<SizeBasedTriggeringPolicy size="100MB" />
2123
</Policies>
2224
<DefaultRolloverStrategy max="10" />
25+
<ThresholdFilter level="${CONSOLE_FILE_LEVEL}" onMatch="ACCEPT" onMismatch="DENY"/>
2326
</RollingFile>
2427
<JDBC name="MySQLDatabase" tableName="logs">
2528
<ConnectionFactory class="eu.arrowhead.common.log4j2.JDBCConnectionFactoryForLog4J2" method="getConnection" />
2629
<Column name="log_id" pattern="%u" />
2730
<Column name="entry_date" isEventTimestamp="true" />
2831
<Column name="logger" pattern="%logger" />
29-
<Column name="log_level" pattern="%level" />
32+
<Column name="system_name" literal="'${SYSTEM_NAME}'" />
33+
<Column name="log_level" pattern="%level" />
3034
<Column name="message" pattern="%m" />
31-
<Column name="exception" pattern="%throwable " />
35+
<Column name="exception" pattern="%throwable" />
3236
<ThresholdFilter level="${JDBC_LEVEL}" onMatch="ACCEPT" onMismatch="DENY"/>
3337
</JDBC>
3438
</Appenders>
@@ -37,10 +41,16 @@
3741
<AppenderRef ref="ConsoleAppender" /> <!-- comment out this one in production environment -->
3842
<AppenderRef ref="FileAppender" />
3943
</Root>
40-
<AsyncLogger name="eu.arrowhead" level="${JDBC_LEVEL}" additivity="true">
41-
<AppenderRef ref="MySQLDatabase" />
44+
<AsyncLogger name="eu.arrowhead" level="ALL" additivity="true">
45+
<AppenderRef ref="MySQLDatabase" />
46+
</AsyncLogger>
47+
<Logger name="eu.arrowhead.core" level="ALL" additivity="true"></Logger>
48+
<Logger name="eu.arrowhead.common" level="ALL" additivity="true"></Logger>
49+
<AsyncLogger name="org" level="WARN" additivity="true">
50+
<AppenderRef ref="MySQLDatabase" />
51+
</AsyncLogger>
52+
<AsyncLogger name="com" level="WARN" additivity="true">
53+
<AppenderRef ref="MySQLDatabase" />
4254
</AsyncLogger>
43-
<Logger name="eu.arrowhead.common" level="${CONSOLE_FILE_LEVEL}" additivity="true"></Logger>
44-
<Logger name="eu.arrowhead.core" level="${CONSOLE_FILE_LEVEL}" additivity="true"></Logger>
4555
</Loggers>
4656
</Configuration>

authorization/src/test/java/eu/arrowhead/core/authorization/AuthorizationControllerInterCloudTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import eu.arrowhead.common.dto.internal.CloudResponseDTO;
6262
import eu.arrowhead.common.dto.internal.DTOConverter;
6363
import eu.arrowhead.common.dto.internal.IdIdListDTO;
64+
import eu.arrowhead.common.dto.shared.AddressType;
6465
import eu.arrowhead.common.dto.shared.CloudRequestDTO;
6566
import eu.arrowhead.core.authorization.database.service.AuthorizationDBService;
6667

@@ -461,7 +462,7 @@ private List<Long> createIdList(final int firstNum, final int lastNum) {
461462
private Page<AuthorizationInterCloud> createPageForMockingAuthorizationDBService(final int numberOfRequestedEntry) {
462463
final List<AuthorizationInterCloud> entries = new ArrayList<>(numberOfRequestedEntry);
463464
final Cloud cloud = getValidTestCloud();
464-
final System provider = new System("testSystem", "testAddr", 2000, "TOKEN", null);
465+
final System provider = new System("testSystem", "testAddr", AddressType.HOSTNAME, 2000, "TOKEN", null);
465466
for (int i = 1; i <= numberOfRequestedEntry; ++i) {
466467
final ServiceDefinition serviceDefinition = new ServiceDefinition("testService" + i);
467468
serviceDefinition.setId(i);

authorization/src/test/java/eu/arrowhead/core/authorization/AuthorizationControllerIntraCloudTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import eu.arrowhead.common.dto.internal.AuthorizationIntraCloudResponseDTO;
5757
import eu.arrowhead.common.dto.internal.DTOConverter;
5858
import eu.arrowhead.common.dto.internal.IdIdListDTO;
59+
import eu.arrowhead.common.dto.shared.AddressType;
5960
import eu.arrowhead.common.dto.shared.SystemRequestDTO;
6061
import eu.arrowhead.common.dto.shared.SystemResponseDTO;
6162
import eu.arrowhead.core.authorization.database.service.AuthorizationDBService;
@@ -507,13 +508,13 @@ public void testCheckAuthorizationIntraCloudRequestDBCall() throws Exception {
507508
//-------------------------------------------------------------------------------------------------
508509
private Page<AuthorizationIntraCloud> createPageForMockingAuthorizationDBService(final int numberOfRequestedEntry) {
509510
final List<AuthorizationIntraCloud> entries = new ArrayList<>(numberOfRequestedEntry);
510-
final System consumer = new System("Consumer", "0.0.0.0.", 1000, null, null);
511+
final System consumer = new System("Consumer", "0.0.0.0.", AddressType.IPV4, 1000, null, null);
511512
consumer.setId(1);
512513

513514
for (int i = 1; i <= numberOfRequestedEntry; ++i) {
514515
final ServiceDefinition serviceDefinition = new ServiceDefinition("testService" + i);
515516
serviceDefinition.setId(i);
516-
final System provider = new System("Provider" + i, i + "." + i + "." + i + "." + i, i * 1000, null, null);
517+
final System provider = new System("Provider" + i, i + "." + i + "." + i + "." + i, AddressType.IPV4, i * 1000, null, null);
517518
provider.setId(i);
518519
final AuthorizationIntraCloud entry = new AuthorizationIntraCloud(consumer, provider, serviceDefinition);
519520
entry.setId(i);

0 commit comments

Comments
 (0)