Skip to content

Commit

Permalink
Merge pull request #410 from eclipse-arrowhead/development
Browse files Browse the repository at this point in the history
Release 4.6.0
  • Loading branch information
tsvetlin authored Sep 21, 2022
2 parents 2271711 + 35b0315 commit 5605ba3
Show file tree
Hide file tree
Showing 672 changed files with 45,001 additions and 10,893 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package eu.arrowhead.core.authorization;

import java.security.PublicKey;
import java.time.ZonedDateTime;
import java.time.format.DateTimeParseException;
import java.util.Base64;
import java.util.HashSet;
import java.util.List;
Expand All @@ -29,6 +31,7 @@
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.logging.LogLevel;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
Expand All @@ -50,6 +53,10 @@
import eu.arrowhead.common.CoreUtilities;
import eu.arrowhead.common.Defaults;
import eu.arrowhead.common.Utilities;
import eu.arrowhead.common.CoreUtilities.ValidatedPageParams;
import eu.arrowhead.common.core.CoreSystem;
import eu.arrowhead.common.database.entity.Logs;
import eu.arrowhead.common.database.service.CommonDBService;
import eu.arrowhead.common.dto.internal.AuthorizationInterCloudCheckRequestDTO;
import eu.arrowhead.common.dto.internal.AuthorizationInterCloudCheckResponseDTO;
import eu.arrowhead.common.dto.internal.AuthorizationInterCloudListResponseDTO;
Expand All @@ -63,7 +70,9 @@
import eu.arrowhead.common.dto.internal.AuthorizationSubscriptionCheckRequestDTO;
import eu.arrowhead.common.dto.internal.AuthorizationSubscriptionCheckResponseDTO;
import eu.arrowhead.common.dto.internal.IdIdListDTO;
import eu.arrowhead.common.dto.internal.LogEntryListResponseDTO;
import eu.arrowhead.common.dto.internal.TokenDataDTO;
import eu.arrowhead.common.dto.internal.TokenGenerationMultiServiceResponseDTO;
import eu.arrowhead.common.dto.internal.TokenGenerationProviderDTO;
import eu.arrowhead.common.dto.internal.TokenGenerationRequestDTO;
import eu.arrowhead.common.dto.internal.TokenGenerationResponseDTO;
Expand Down Expand Up @@ -93,6 +102,7 @@ public class AuthorizationController {
private static final String ID_NOT_VALID_ERROR_MESSAGE = "Id must be greater than 0.";

private static final String TOKEN_DESCRIPTION = "Generates tokens for a consumer which can be used to access the specified service of the specified providers";
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";
private static final String TOKEN_HTTP_200_MESSAGE = "Tokens returned";
private static final String TOKEN_HTTP_400_MESSAGE = "Could not generate tokens";

Expand Down Expand Up @@ -127,6 +137,9 @@ public class AuthorizationController {

@Autowired
private AuthorizationDBService authorizationDBService;

@Autowired
private CommonDBService commonDBService;

@Autowired
private TokenGenerationService tokenGenerationService;
Expand Down Expand Up @@ -155,6 +168,48 @@ public String echoService() {
return "Got it!";
}

//-------------------------------------------------------------------------------------------------
@ApiOperation(value = "Return requested log entries by the given parameters", response = LogEntryListResponseDTO.class, tags = { CoreCommonConstants.SWAGGER_TAG_MGMT })
@ApiResponses(value = {
@ApiResponse(code = HttpStatus.SC_OK, message = CoreCommonConstants.QUERY_LOG_ENTRIES_HTTP_200_MESSAGE),
@ApiResponse(code = HttpStatus.SC_BAD_REQUEST, message = CoreCommonConstants.QUERY_LOG_ENTRIES_HTTP_400_MESSAGE),
@ApiResponse(code = HttpStatus.SC_UNAUTHORIZED, message = CoreCommonConstants.SWAGGER_HTTP_401_MESSAGE),
@ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = CoreCommonConstants.SWAGGER_HTTP_500_MESSAGE)
})
@GetMapping(path = CoreCommonConstants.OP_QUERY_LOG_ENTRIES, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody public LogEntryListResponseDTO getLogEntries(
@RequestParam(name = CoreCommonConstants.REQUEST_PARAM_PAGE, required = false) final Integer page,
@RequestParam(name = CoreCommonConstants.REQUEST_PARAM_ITEM_PER_PAGE, required = false) final Integer size,
@RequestParam(name = CoreCommonConstants.REQUEST_PARAM_DIRECTION, defaultValue = CoreDefaults.DEFAULT_REQUEST_PARAM_DIRECTION_VALUE) final String direction,
@RequestParam(name = CoreCommonConstants.REQUEST_PARAM_SORT_FIELD, defaultValue = Logs.FIELD_NAME_ID) final String sortField,
@RequestParam(name = CoreCommonConstants.REQUEST_PARAM_LOG_LEVEL, required = false) final String logLevel,
@RequestParam(name = CoreCommonConstants.REQUEST_PARAM_FROM, required = false) final String from,
@RequestParam(name = CoreCommonConstants.REQUEST_PARAM_TO, required = false) final String to,
@RequestParam(name = CoreCommonConstants.REQUEST_PARAM_LOGGER, required = false) final String loggerStr) {
logger.debug("New getLogEntries GET request received with page: {} and item_per page: {}", page, size);

final String origin = CommonConstants.AUTHORIZATION_URI + CoreCommonConstants.OP_QUERY_LOG_ENTRIES;
final ValidatedPageParams validParameters = CoreUtilities.validatePageParameters(page, size, direction, origin);
final List<LogLevel> logLevels = CoreUtilities.getLogLevels(logLevel, origin);

try {
final ZonedDateTime _from = Utilities.parseUTCStringToLocalZonedDateTime(from);
final ZonedDateTime _to = Utilities.parseUTCStringToLocalZonedDateTime(to);

if (_from != null && _to != null && _to.isBefore(_from)) {
throw new BadPayloadException("Invalid time interval", HttpStatus.SC_BAD_REQUEST, origin);
}

final LogEntryListResponseDTO response = commonDBService.getLogEntriesResponse(validParameters.getValidatedPage(), validParameters.getValidatedSize(), validParameters.getValidatedDirection(), sortField, CoreSystem.AUTHORIZATION,
logLevels, _from, _to, loggerStr);

logger.debug("Log entries with page: {} and item_per page: {} retrieved successfully", page, size);
return response;
} catch (final DateTimeParseException ex) {
throw new BadPayloadException("Invalid time parameter", HttpStatus.SC_BAD_REQUEST, origin, ex);
}
}

//-------------------------------------------------------------------------------------------------
@ApiOperation(value = "Return requested AuthorizationIntraCloud entries by the given parameters", response = AuthorizationIntraCloudListResponseDTO.class,
tags = { CoreCommonConstants.SWAGGER_TAG_MGMT })
Expand Down Expand Up @@ -617,6 +672,27 @@ public void removeAuthorizationInterCloudById(@PathVariable(value = PATH_VARIABL
return response;
}

//-------------------------------------------------------------------------------------------------
@ApiOperation(value = TOKEN_MULTI_SERVICE_DESCRIPTION, response = TokenGenerationMultiServiceResponseDTO.class, tags = { CoreCommonConstants.SWAGGER_TAG_PRIVATE })
@ApiResponses(value = {
@ApiResponse(code = HttpStatus.SC_OK, message = TOKEN_HTTP_200_MESSAGE),
@ApiResponse(code = HttpStatus.SC_BAD_REQUEST, message = TOKEN_HTTP_400_MESSAGE),
@ApiResponse(code = HttpStatus.SC_UNAUTHORIZED, message = CoreCommonConstants.SWAGGER_HTTP_401_MESSAGE),
@ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = CoreCommonConstants.SWAGGER_HTTP_500_MESSAGE)
})
@PostMapping(path = CommonConstants.OP_AUTH_TOKEN_MULTI_SERVICE_URI, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody public TokenGenerationMultiServiceResponseDTO generateMultiServiceTokens(@RequestBody final List<TokenGenerationRequestDTO> requestList) {
logger.debug("New multi-service token generation request received");
for (final TokenGenerationRequestDTO request : requestList) {
checkTokenGenerationRequest(request);
}

final TokenGenerationMultiServiceResponseDTO response = tokenGenerationService.generateMultiServiceTokensResponse(requestList);
logger.debug("Multi-service token generation request has been finished");

return response;
}

//-------------------------------------------------------------------------------------------------
@ApiOperation(value = PUBLIC_KEY_DESCRIPTION, response = String.class, tags = { CoreCommonConstants.SWAGGER_TAG_CLIENT })
@ApiResponses(value = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class AuthAccessControlFilter extends CoreSystemAccessControlFilter {

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

Expand All @@ -55,12 +56,14 @@ protected void checkClientAuthorized(final String clientCN, final String method,
} else if (requestTarget.contains(CoreCommonConstants.MGMT_URI)) {
// Only the local System Operator can use these methods
checkIfLocalSystemOperator(clientCN, cloudCN, requestTarget);
} else if (requestTarget.endsWith(CommonConstants.OP_AUTH_TOKEN_URI) || requestTarget.endsWith(CommonConstants.OP_AUTH_INTRA_CHECK_URI) ||
requestTarget.endsWith(CommonConstants.OP_AUTH_INTER_CHECK_URI)) {
// Only the specified core systems can use all the other methods
} else if (requestTarget.endsWith(CommonConstants.OP_AUTH_TOKEN_URI) || requestTarget.endsWith(CommonConstants.OP_AUTH_TOKEN_MULTI_SERVICE_URI)) {
// Only the specified core systems can use this methods
checkIfClientIsAnAllowedCoreSystem(clientCN, cloudCN, allowedCoreSystemsForTokenGenerations, requestTarget);
} else if (requestTarget.endsWith(CommonConstants.OP_AUTH_INTRA_CHECK_URI) || requestTarget.endsWith(CommonConstants.OP_AUTH_INTER_CHECK_URI)) {
// Only the specified core systems can use all these methods
checkIfClientIsAnAllowedCoreSystem(clientCN, cloudCN, allowedCoreSystemsForChecks, requestTarget);
} else if (requestTarget.endsWith(CommonConstants.OP_AUTH_SUBSCRIPTION_CHECK_URI)) {
// Only the specified core systems can use all the other methods
// Only the specified core systems can use this method
checkIfClientIsAnAllowedCoreSystem(clientCN, cloudCN, allowedCoreSystemsForSubscriptionChecks, requestTarget);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
/********************************************************************************
* Copyright (c) 2019 AITIA
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* AITIA - implementation
* Arrowhead Consortia - conceptualization
********************************************************************************/

package eu.arrowhead.core.authorization.token;

import java.security.PrivateKey;
import java.security.PublicKey;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -24,6 +39,8 @@
import eu.arrowhead.common.database.entity.Cloud;
import eu.arrowhead.common.database.service.CommonDBService;
import eu.arrowhead.common.dto.internal.DTOConverter;
import eu.arrowhead.common.dto.internal.TokenGenerationDetailedResponseDTO;
import eu.arrowhead.common.dto.internal.TokenGenerationMultiServiceResponseDTO;
import eu.arrowhead.common.dto.internal.TokenGenerationProviderDTO;
import eu.arrowhead.common.dto.internal.TokenGenerationRequestDTO;
import eu.arrowhead.common.dto.internal.TokenGenerationResponseDTO;
Expand Down Expand Up @@ -121,6 +138,24 @@ public TokenGenerationResponseDTO generateTokensResponse(final TokenGenerationRe
final Map<SystemRequestDTO,Map<String,String>> tokenMap = generateTokens(request);
return DTOConverter.convertTokenMapToTokenGenerationResponseDTO(tokenMap);
}

//-------------------------------------------------------------------------------------------------
public TokenGenerationMultiServiceResponseDTO generateMultiServiceTokensResponse(final List<TokenGenerationRequestDTO> requestList) {
logger.debug("generateMultiServiceTokensResponse started...");

final List<TokenGenerationDetailedResponseDTO> data = new ArrayList<>();
for (final TokenGenerationRequestDTO request : requestList) {
final TokenGenerationDetailedResponseDTO tokenDetails = new TokenGenerationDetailedResponseDTO();
tokenDetails.setService(request.getService());
tokenDetails.setConsumerName(request.getConsumer().getSystemName());
tokenDetails.setConsumerAdress(request.getConsumer().getAddress());
tokenDetails.setConsumerPort(request.getConsumer().getPort());
tokenDetails.setTokenData(generateTokensResponse(request).getTokenData());
data.add(tokenDetails);
}

return new TokenGenerationMultiServiceResponseDTO(data);
}

//=================================================================================================
// assistant methods
Expand Down
24 changes: 17 additions & 7 deletions authorization/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
<Property name="LOG_PATTERN">
%d{yyyy-MM-dd HH:mm:ss.SSS} %5p ${hostName} --- [%15.15t] %-40.40c{1.} : %m%n%ex
</Property>
<Property name="SYSTEM_NAME">AUTHORIZATION</Property>
<Property name="JDBC_LEVEL">INFO</Property>
<Property name="CONSOLE_FILE_LEVEL">INFO</Property>
<Property name="LOG_DIR">.</Property>
</Properties>
<Appenders>
<Console name="ConsoleAppender" target="SYSTEM_OUT" follow="true">
<PatternLayout pattern="${LOG_PATTERN}"/>
</Console>
<ThresholdFilter level="${CONSOLE_FILE_LEVEL}" onMatch="ACCEPT" onMismatch="DENY"/>
</Console>
<RollingFile name="FileAppender" fileName="${LOG_DIR}/authorization.log" filePattern="${LOG_DIR}/authorization-%d{yyyy-MM-dd}-%i.log">
<PatternLayout>
<Pattern>${LOG_PATTERN}</Pattern>
Expand All @@ -20,15 +22,17 @@
<SizeBasedTriggeringPolicy size="100MB" />
</Policies>
<DefaultRolloverStrategy max="10" />
<ThresholdFilter level="${CONSOLE_FILE_LEVEL}" onMatch="ACCEPT" onMismatch="DENY"/>
</RollingFile>
<JDBC name="MySQLDatabase" tableName="logs">
<ConnectionFactory class="eu.arrowhead.common.log4j2.JDBCConnectionFactoryForLog4J2" method="getConnection" />
<Column name="log_id" pattern="%u" />
<Column name="entry_date" isEventTimestamp="true" />
<Column name="logger" pattern="%logger" />
<Column name="log_level" pattern="%level" />
<Column name="system_name" literal="'${SYSTEM_NAME}'" />
<Column name="log_level" pattern="%level" />
<Column name="message" pattern="%m" />
<Column name="exception" pattern="%throwable " />
<Column name="exception" pattern="%throwable" />
<ThresholdFilter level="${JDBC_LEVEL}" onMatch="ACCEPT" onMismatch="DENY"/>
</JDBC>
</Appenders>
Expand All @@ -37,10 +41,16 @@
<AppenderRef ref="ConsoleAppender" /> <!-- comment out this one in production environment -->
<AppenderRef ref="FileAppender" />
</Root>
<AsyncLogger name="eu.arrowhead" level="${JDBC_LEVEL}" additivity="true">
<AppenderRef ref="MySQLDatabase" />
<AsyncLogger name="eu.arrowhead" level="ALL" additivity="true">
<AppenderRef ref="MySQLDatabase" />
</AsyncLogger>
<Logger name="eu.arrowhead.core" level="ALL" additivity="true"></Logger>
<Logger name="eu.arrowhead.common" level="ALL" additivity="true"></Logger>
<AsyncLogger name="org" level="WARN" additivity="true">
<AppenderRef ref="MySQLDatabase" />
</AsyncLogger>
<AsyncLogger name="com" level="WARN" additivity="true">
<AppenderRef ref="MySQLDatabase" />
</AsyncLogger>
<Logger name="eu.arrowhead.common" level="${CONSOLE_FILE_LEVEL}" additivity="true"></Logger>
<Logger name="eu.arrowhead.core" level="${CONSOLE_FILE_LEVEL}" additivity="true"></Logger>
</Loggers>
</Configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import eu.arrowhead.common.dto.internal.CloudResponseDTO;
import eu.arrowhead.common.dto.internal.DTOConverter;
import eu.arrowhead.common.dto.internal.IdIdListDTO;
import eu.arrowhead.common.dto.shared.AddressType;
import eu.arrowhead.common.dto.shared.CloudRequestDTO;
import eu.arrowhead.core.authorization.database.service.AuthorizationDBService;

Expand Down Expand Up @@ -461,7 +462,7 @@ private List<Long> createIdList(final int firstNum, final int lastNum) {
private Page<AuthorizationInterCloud> createPageForMockingAuthorizationDBService(final int numberOfRequestedEntry) {
final List<AuthorizationInterCloud> entries = new ArrayList<>(numberOfRequestedEntry);
final Cloud cloud = getValidTestCloud();
final System provider = new System("testSystem", "testAddr", 2000, "TOKEN", null);
final System provider = new System("testSystem", "testAddr", AddressType.HOSTNAME, 2000, "TOKEN", null);
for (int i = 1; i <= numberOfRequestedEntry; ++i) {
final ServiceDefinition serviceDefinition = new ServiceDefinition("testService" + i);
serviceDefinition.setId(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import eu.arrowhead.common.dto.internal.AuthorizationIntraCloudResponseDTO;
import eu.arrowhead.common.dto.internal.DTOConverter;
import eu.arrowhead.common.dto.internal.IdIdListDTO;
import eu.arrowhead.common.dto.shared.AddressType;
import eu.arrowhead.common.dto.shared.SystemRequestDTO;
import eu.arrowhead.common.dto.shared.SystemResponseDTO;
import eu.arrowhead.core.authorization.database.service.AuthorizationDBService;
Expand Down Expand Up @@ -507,13 +508,13 @@ public void testCheckAuthorizationIntraCloudRequestDBCall() throws Exception {
//-------------------------------------------------------------------------------------------------
private Page<AuthorizationIntraCloud> createPageForMockingAuthorizationDBService(final int numberOfRequestedEntry) {
final List<AuthorizationIntraCloud> entries = new ArrayList<>(numberOfRequestedEntry);
final System consumer = new System("Consumer", "0.0.0.0.", 1000, null, null);
final System consumer = new System("Consumer", "0.0.0.0.", AddressType.IPV4, 1000, null, null);
consumer.setId(1);

for (int i = 1; i <= numberOfRequestedEntry; ++i) {
final ServiceDefinition serviceDefinition = new ServiceDefinition("testService" + i);
serviceDefinition.setId(i);
final System provider = new System("Provider" + i, i + "." + i + "." + i + "." + i, i * 1000, null, null);
final System provider = new System("Provider" + i, i + "." + i + "." + i + "." + i, AddressType.IPV4, i * 1000, null, null);
provider.setId(i);
final AuthorizationIntraCloud entry = new AuthorizationIntraCloud(consumer, provider, serviceDefinition);
entry.setId(i);
Expand Down
Loading

0 comments on commit 5605ba3

Please sign in to comment.