Skip to content
Snippets Groups Projects
Commit 9813ed43 authored by Jagan Gottimukkula's avatar Jagan Gottimukkula
Browse files

Merge branch 'indexer-boot-jagan' of...

Merge branch 'indexer-boot-jagan' of ssh.dev.azure.com:v3/slb-des-ext-collaboration/open-data-ecosystem/dps-indexer-boot-mvn into indexer-boot-jagan
parents 5397a52b e2a69ff9
Branches
Tags
1 merge request!6Trusted ibm
Showing
with 485 additions and 59 deletions
......@@ -33,4 +33,5 @@ build/
### Other ###
.mvn
target/*
*/target
\ No newline at end of file
*/target
/mvn
......@@ -18,27 +18,37 @@
<properties>
<azure.version>2.1.7</azure.version>
<azure.appservice.resourcegroup></azure.appservice.resourcegroup>
<azure.appservice.plan></azure.appservice.plan>
<azure.appservice.appname></azure.appservice.appname>
<azure.appservice.subscription></azure.appservice.subscription>
</properties>
<dependencies>
<dependency>
<groupId>org.opendes.indexer</groupId>
<artifactId>indexer-service-root</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-active-directory-spring-boot-starter</artifactId>
<version>${azure.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-jose</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-cosmosdb-spring-boot-starter</artifactId>
<version>${azure.version}</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId >
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-storage-spring-boot-starter</artifactId>
<version>${azure.version}</version>
</dependency>
......@@ -47,7 +57,46 @@
<artifactId>azure-servicebus-spring-boot-starter</artifactId>
<version>${azure.version}</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>applicationinsights-logging-logback</artifactId>
<version>[2.0,)</version>
</dependency>
<dependency>
<groupId>org.opendes.indexer</groupId>
<artifactId>indexer-service-root</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-active-directory-spring-boot-starter</artifactId>
<version>${azure.version}</version>
</dependency>
<!-- Key vault dependency-->
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-keyvault-secrets-spring-boot-starter</artifactId>
<version>${azure.version}</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-keyvault</artifactId>
<exclusions>
<exclusion>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-client-runtime</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-client-authentication</artifactId>
</dependency>
<!-- end KeyVault dependencies-->
</dependencies>
<build>
......
package org.opendes.indexer.azure;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@SpringBootApplication
@SpringBootApplication(exclude = { SecurityAutoConfiguration.class, ManagementWebSecurityAutoConfiguration.class })
@Configuration
@ComponentScan({"org.opendes.core", "org.opendes.indexer"})
public class IndexerAzureApplication {
public static void main(String[] args) {
......
package org.opendes.indexer.azure.api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping
public class Hello {
@GetMapping("/hello")
public String Default() {
return "Hello Azure Indexer!!!";
}
}
// Copyright 2017-2019, Schlumberger
//
// 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.opendes.indexer.azure.di;
import org.opendes.client.logging.DpsLog;
import org.opendes.client.logging.Log;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.stereotype.Component;
@Component
public class DpsLogFactory implements FactoryBean<DpsLog> {
@Override
public DpsLog getObject() throws Exception {
return new Log();
}
@Override
public Class<?> getObjectType() {
return DpsLog.class;
}
}
......@@ -3,37 +3,35 @@ package org.opendes.indexer.azure.di;
import org.opendes.client.cache.ICache;
import org.opendes.client.multitenancy.ITenantFactory;
import org.opendes.client.multitenancy.TenantInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.*;
@Component
public class TenantFactoryImpl implements ITenantFactory {
public static final String DefaultTenantName = "common";
private List<TenantInfo> tenants;
@Autowired
private CosmosDBTenantInfo db;
public TenantFactoryImpl()
{
TenantInfo ti = new TenantInfo();
ti.setName(DefaultTenantName);
this.tenants = new ArrayList<>();
this.tenants.add(ti);
}
private Map<String, TenantInfo> tenants;
public boolean exists(String tenantName)
{
return true;
if (this.tenants == null)
initTenants();
return this.tenants.containsKey(tenantName);
}
public TenantInfo getTenantInfo(String tenantName) {
// we are not checking tenantName yet, we have only 1 tenant
return this.tenants.get(0);
if (this.tenants == null)
initTenants();
return this.tenants.get(tenantName);
}
public Collection<TenantInfo> listTenantInfo() {
return this.tenants;
if (this.tenants == null)
initTenants();
return this.tenants.values();
}
public <V> ICache<String, V> createCache(String tenantName, String host, int port, int expireTimeSeconds, Class<V> classOfV)
......@@ -42,4 +40,18 @@ public class TenantFactoryImpl implements ITenantFactory {
}
public void flushCache() {}
private void initTenants() {
this.tenants = new HashMap<>();
db.findAll().forEach(doc -> {
TenantInfo ti = new TenantInfo();
String tenantName = doc.getId();
ti.setName(tenantName);
String complianceRuleSet = doc.getComplianceRuleSet();
ti.setComplianceRuleSet(complianceRuleSet);
this.tenants.put(tenantName, ti) ;
});
}
}
// Copyright 2017-2019, Schlumberger
//
// 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.opendes.indexer.azure.di;
import lombok.extern.java.Log;
import org.opendes.client.multitenancy.ITenantFactory;
import org.springframework.beans.factory.config.AbstractFactoryBean;
import org.springframework.stereotype.Component;
@Log
@Component
public class TenantFactoryService extends AbstractFactoryBean<ITenantFactory> {
@Override
protected ITenantFactory createInstance() throws Exception {
return new TenantFactoryImpl();
}
@Override
public Class<?> getObjectType() {
return ITenantFactory.class;
}
}
\ No newline at end of file
package org.opendes.indexer.azure.di;
import com.microsoft.azure.spring.data.cosmosdb.core.mapping.Document;
import com.microsoft.azure.spring.data.cosmosdb.core.mapping.PartitionKey;
import com.microsoft.azure.spring.data.cosmosdb.repository.DocumentDbRepository;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Document(collection = "TenantInfo") //collection name
public class TenantInfoDoc {
@PartitionKey
@Id
private String id;
private String complianceRuleSet;
}
interface CosmosDBTenantInfo extends DocumentDbRepository<TenantInfoDoc, String> {}
package org.opendes.indexer.azure.persistence;
import org.opendes.client.multitenancy.TenantInfo;
import org.opendes.core.kms.IKmsClient;
import org.opendes.core.model.ClusterSettings;
import org.opendes.core.persistence.ElasticRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class ElasticRepositoryCosmosDB implements ElasticRepository {
static final String HOST = "host";
static final String PORT = "port";
static final String XPACK_RESTCLIENT_CONFIGURATION = "configuration";
@Autowired
private IKmsClient kmsClient;
@Override
public ClusterSettings getElasticClusterSettings(TenantInfo tenantInfo) {
return null;
......
// Copyright 2017-2019, Schlumberger
//
// 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.opendes.indexer.azure.publish;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.reflect.TypeToken;
import com.microsoft.azure.servicebus.IMessage;
import com.microsoft.azure.servicebus.TopicClient;
import com.microsoft.azure.servicebus.primitives.ConnectionStringBuilder;
import org.elasticsearch.common.Strings;
import org.opendes.client.api.DpsHeaders;
import org.opendes.client.multitenancy.ITenantFactory;
import org.opendes.core.model.DeploymentEnvironment;
import org.opendes.core.model.RecordChangedMessages;
import org.opendes.core.util.Config;
import org.opendes.indexer.model.RecordStatus;
import org.opendes.indexer.publish.IPublisher;
import org.opendes.indexer.util.JobStatus;
import org.reactivestreams.Publisher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Component
public class PublisherImpl implements IPublisher {
private static final Map<String, Publisher> PUBSUB_CLIENTS = new HashMap<>();
private static final String TOPIC_ID = "indexing-progress";
private String TOPIC_NAME = "recordstopic";
private String CONNECTION_STRING = "Endpoint=sb://pliuopendes.servicebus.windows.net/;\" +\n" +
" \"SharedAccessKeyName=RootManageSharedAccessKey;\" +\n" +
" \"SharedAccessKey=km8Nscc0gf299Ck6npmM3D14VU5Tx1lJYRdlHcExIvY=";
@Override
public void publishStatusChangedTagsToTopic(DpsHeaders headers, JobStatus indexerBatchStatus) throws Exception {
String tenant = headers.getPartitionId();
if (Strings.isNullOrEmpty(tenant))
tenant = headers.getAccountId();
TopicClient publisher = new TopicClient(new ConnectionStringBuilder(CONNECTION_STRING, TOPIC_NAME));
RecordChangedMessages recordChangedMessages = getRecordChangedMessage(headers, indexerBatchStatus);
publisher.send((IMessage) recordChangedMessages);
}
private RecordChangedMessages getRecordChangedMessage(DpsHeaders headers, JobStatus indexerBatchStatus) {
Gson gson = new GsonBuilder().create();
Map<String, String> attributesMap = new HashMap<>();
Type listType = new TypeToken<List<RecordStatus>>() {
}.getType();
JsonElement statusChangedTagsJson = gson.toJsonTree(indexerBatchStatus.getStatusesList(), listType);
String statusChangedTagsData = (statusChangedTagsJson.toString());
String tenant = headers.getPartitionId();
// This code it to provide backward compatibility to slb-account-id
if (!Strings.isNullOrEmpty(tenant)) {
attributesMap.put(DpsHeaders.DATA_PARTITION_ID, headers.getPartitionId());
} else {
attributesMap.put(DpsHeaders.ACCOUNT_ID, headers.getAccountId());
}
attributesMap.put(DpsHeaders.CORRELATION_ID, headers.getCorrelationId());
RecordChangedMessages recordChangedMessages = new RecordChangedMessages();
// statusChangedTagsData is not ByteString but String
recordChangedMessages.setData(statusChangedTagsData);
recordChangedMessages.setAttributes(attributesMap);
return recordChangedMessages;
}
}
// 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.opendes.indexer.azure.security;
import com.microsoft.azure.spring.autoconfigure.aad.AADAppRoleStatelessAuthenticationFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled = true)
public class AADSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private AADAppRoleStatelessAuthenticationFilter appRoleAuthFilter;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER)
.and()
.authorizeRequests()
.antMatchers("/", "/index.html",
"/v2/api-docs",
"/configuration/ui",
"/swagger-resources/**",
"/configuration/security",
"/swagger",
"/swagger-ui.html",
"/webjars/**").permitAll()
.anyRequest().authenticated()
.and()
.addFilterBefore(appRoleAuthFilter, UsernamePasswordAuthenticationFilter.class);
}
}
// 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.opendes.indexer.azure.security;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class WhoamiController {
@RequestMapping(value = "/whoami")
@ResponseBody
public String whoami() {
final Authentication auth = SecurityContextHolder.getContext().getAuthentication();
String userName = auth.getName();
String roles = String.valueOf(auth.getAuthorities());
String details = String.valueOf(auth.getPrincipal());
return "user: " + userName + "<BR>" +
"roles: " + roles + "<BR>" +
"details: " + details + "<BR>";
}
}
// Copyright 2017-2019, Schlumberger
//
// 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.opendes.indexer.azure.util;
import com.google.common.base.Strings;
import lombok.extern.java.Log;
import org.opendes.client.api.DpsHeaders;
import org.opendes.core.model.SlbHeaders;
import org.opendes.core.util.IHeadersInfo;
import org.opendes.core.util.Preconditions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.HashSet;
import java.util.Map;
import java.util.stream.Collectors;
@Log
@Component
public class HeadersInfoAzureImpl implements IHeadersInfo {
@Autowired
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);
}
private static final HashSet<String> FORWARDED_HEADERS = new HashSet<>();
@Override
public DpsHeaders getHeaders() {
if (headersMap == null) {
log.info("Headers Map DpsHeaders is null");
// headersMap = this.getCoreServiceHeaders(httpHeaders.toSingleValueMap());
}
return headersMap;
}
@Override
public String getUser() {
return getHeaders().getUserEmail();
}
@Override
public String getPartitionId() {
return getHeaders().getPartitionIdWithFallbackToAccountId();
}
@Override
public String getPrimaryPartitionId() {
return getHeadersMap().get(SlbHeaders.PRIMARY_PARTITION_ID);
}
@Override
public Map<String, String> getHeadersMap() {
return getHeaders().getHeaders();
}
@Override
public DpsHeaders getCoreServiceHeaders(Map<String, String> input) {
Preconditions.checkNotNull(input, "input headers cannot be null");
DpsHeaders output = DpsHeaders.createFromMap(input);
output.addCorrelationIdIfMissing();
return output;
}
@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
......@@ -72,40 +72,12 @@
<artifactId>appengine-gcs-client</artifactId>
<version>0.8</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.mockito</groupId>-->
<!-- <artifactId>mockito-core</artifactId>-->
<!-- <scope>test</scope>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>junit</groupId>-->
<!-- <artifactId>junit</artifactId>-->
<!-- <scope>test</scope>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.powermock</groupId>-->
<!-- <artifactId>powermock-core</artifactId>-->
<!-- <version>2.0.2</version>-->
<!-- <scope>test</scope>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.powermock</groupId>-->
<!-- <artifactId>powermock-api-mockito2</artifactId>-->
<!-- <version>2.0.2</version>-->
<!-- <scope>test</scope>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.springframework</groupId>-->
<!-- <artifactId>spring-test</artifactId>-->
<!-- <version>5.1.9.RELEASE</version>-->
<!-- <scope>test</scope>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.springframework</groupId>-->
<!-- <artifactId>spring-test</artifactId>-->
<!-- <version>5.1.9.RELEASE</version>-->
<!-- <scope>test</scope>-->
<!-- </dependency>-->
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-spring-boot</artifactId>
<version>2.1.7</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment