Skip to content
Snippets Groups Projects
Commit 05f19287 authored by MIchael Nguyen's avatar MIchael Nguyen
Browse files

readded headerinfo impl.

parent c82f7cf4
No related branches found
No related tags found
1 merge request!6Trusted ibm
// Copyright © Microsoft Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.opengroup.osdu.indexer.aws.util;
import lombok.extern.java.Log;
import org.apache.http.HttpStatus;
import org.opengroup.osdu.core.api.DpsHeaders;
import org.opengroup.osdu.is.core.model.SlbHeaders;
import org.opengroup.osdu.is.core.provider.interfaces.util.IHeadersInfo;
import org.opengroup.osdu.is.core.util.AppException;
import org.opengroup.osdu.is.core.util.Preconditions;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope;
import java.util.HashSet;
import java.util.Map;
import java.util.stream.Collectors;
import javax.inject.Inject;
@Primary
@Log
@Component
public class HeadersInfoAwsImpl implements IHeadersInfo {
@Inject
private DpsHeaders headersMap;
private static final HashSet<String> FORBIDDEN_FROM_LOGGING = new HashSet<>();
static {
FORBIDDEN_FROM_LOGGING.add(DpsHeaders.AUTHORIZATION);
FORBIDDEN_FROM_LOGGING.add(DpsHeaders.ON_BEHALF_OF);
}
/**
* Get list of current headers
* @return DpsHeaders headers
*/
@Override
public DpsHeaders getHeaders() {
if (headersMap == null) {
log.warning("Headers Map DpsHeaders is null");
// throw to prevent null reference exception below
throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Invalid Headers", "Headers Map DpsHeaders is null");
}
DpsHeaders headers = this.getCoreServiceHeaders(headersMap.getHeaders());
return headers;
}
/**
* get current logged in user
* @return userEmail
*/
@Override
public String getUser() {
return getHeaders().getUserEmail();
}
/**
* get partition id and fallback to account id
* @return Partition ID
*/
@Override
public String getPartitionId() {
return getHeaders().getPartitionIdWithFallbackToAccountId();
}
/**
* get the primary partition id
* @return primaryPartitionID
*/
@Override
public String getPrimaryPartitionId() {
return getHeadersMap().get(SlbHeaders.PRIMARY_PARTITION_ID);
}
/**
* get map of the current headers
* @return Map<String, String> headers
*/
@Override
public Map<String, String> getHeadersMap() {
return getHeaders().getHeaders();
}
/**
* supplement the DPSHeaders with any specific core service headers
* @param input Map<String, String> of core headers
* @return DpsHeaders dpsHeaders
*/
@Override
public DpsHeaders getCoreServiceHeaders(Map<String, String> input) {
Preconditions.checkNotNull(input, "input headers cannot be null");
DpsHeaders output = DpsHeaders.createFromMap(input);
return output;
}
/**
* create string representing a comma delimited list of the current headers
* @return
*/
@Override
public String toString() {
return this.getHeadersMap().entrySet().stream().filter(map -> !FORBIDDEN_FROM_LOGGING.contains(map.getKey().toLowerCase())).map(Map.Entry::toString).collect(Collectors.joining(" | "));
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment