Skip to content
Snippets Groups Projects
Commit db9a2c6c authored by Renan Souza's avatar Renan Souza
Browse files

adding ibm's indexer

parent 99633b91
No related branches found
No related tags found
1 merge request!6Trusted ibm
Showing
with 1088 additions and 0 deletions
# Maven
# Build your Java project and run tests with Apache Maven.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/java
trigger:
branches:
include:
- master
paths:
exclude:
- README.md
- .gitignore
pool:
name: Hosted Ubuntu 1604
demands: maven
steps:
- task: Maven@3
displayName: 'build, test, code coverage'
inputs:
mavenPomFile: 'pom.xml'
options: '--settings ./indexer-core/maven/settings.xml -DVSTS_FEED_TOKEN=$(VSTS_FEED_TOKEN)'
testResultsFiles: '**/*/TEST-*.xml'
codeCoverageToolOption: JaCoCo
goals: 'install'
- task: Maven@3
displayName: 'build, test, code coverage'
inputs:
mavenPomFile: 'pom.xml'
options: '--settings ./provider/indexer-azure/maven/settings.xml -DVSTS_FEED_TOKEN=$(VSTS_FEED_TOKEN) -P indexer-azure'
testResultsFiles: '**/*/TEST-*.xml'
codeCoverageToolOption: JaCoCo
goals: 'package'
- task: CopyFiles@2
displayName: 'Copy Azure artifacts for maven deploy to: $(build.artifactstagingdirectory)'
inputs:
SourceFolder:
Contents: |
pom.xml
provider/indexer-azure/maven/settings.xml
provider/indexer-azure/pom.xml
provider/indexer-azure/target/*-spring-boot.jar
TargetFolder: '$(build.artifactstagingdirectory)'
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: drop'
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
condition: succeededOrFailed()
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2019 IBM Corp. All Rights Reserved.
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.
-->
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>azure-auth</id>
<configuration>
<tenant>${AZURE_DEPLOY_TENANT}</tenant>
<client>${AZURE_DEPLOY_CLIENT_ID}</client>
<key>${AZURE_DEPLOY_CLIENT_SECRET}</key>
<environment>AZURE</environment>
</configuration>
</server>
</servers>
</settings>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2019 IBM Corp. All Rights Reserved.
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.opengroup.osdu.indexer</groupId>
<artifactId>indexer-service</artifactId>
<version>1.0.2</version>
<relativePath>../..</relativePath>
</parent>
<artifactId>indexer-ibm</artifactId>
<version>1.0.0</version>
<name>indexer-ibm</name>
<description>Indexer Service IBM</description>
<packaging>jar</packaging>
<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>
<!-- OSDU core service dependencies -->
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>os-core-common</artifactId>
<version>0.0.8</version>
</dependency>
<dependency>
<groupId>org.opengroup.osdu.indexer</groupId>
<artifactId>indexer-core</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>os-core-lib-ibm</artifactId>
<version>0.1.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>2.3.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-jwt</artifactId>
<version>1.0.10.RELEASE</version>
</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>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>6.6.2</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-client</artifactId>
<version>6.6.2</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>6.6.2</version>
</dependency>
<!-- Test Dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.powermock/powermock-api-mockito2 -->
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>2.0.2</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.powermock/powermock-module-junit4 -->
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>2.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.7</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>spring-boot</classifier>
<mainClass>
org.opengroup.osdu.indexer.ibm.IndexerAzureApplication
</mainClass>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-webapp-maven-plugin</artifactId>
<version>1.7.0</version>
<configuration>
<schemaVersion>V2</schemaVersion>
<authentication>
<serverId>azure-auth</serverId>
</authentication>
<subscriptionId>${azure.appservice.subscription}</subscriptionId>
<resourceGroup>${azure.appservice.resourcegroup}</resourceGroup>
<appServicePlanName>${azure.appservice.plan}</appServicePlanName>
<appName>${azure.appservice.appname}</appName>
<appSettings>
<property>
<name>JAVA_OPTS</name>
<value>-Dserver.port=80</value>
</property>
</appSettings>
<deployment>
<resources>
<resource>
<directory>${project.basedir}/target</directory>
<includes>
<include>*spring-boot.jar</include>
</includes>
</resource>
</resources>
</deployment>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
<threadCount>1</threadCount>
</configuration>
</plugin>
</plugins>
</build>
</project>
// Copyright 2019 IBM Corp. All Rights Reserved.
//
// 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.ibm;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@SpringBootApplication
@ComponentScan({"org.opengroup.osdu.core.common", "org.opengroup.osdu.indexer"})
public class IndexerIBMApplication {
public static void main(String[] args) {
SpringApplication.run(IndexerIBMApplication.class, args);
}
}
// Copyright 2019 IBM Corp. All Rights Reserved.
//
// 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.ibm;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(IndexerIBMApplication.class);
}
}
// Copyright 2019 IBM Corp. All Rights Reserved.
//
// 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.ibm.api;
import org.opengroup.osdu.indexer.ibm.util.ServiceAccountJwtClientImpl;
import org.springframework.http.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.inject.Inject;
@Controller
public class AADController {
@Inject
ServiceAccountJwtClientImpl service;
@RequestMapping("/obo_api")
@PostMapping
public ResponseEntity<String> callOboApi() throws Throwable {
String token = service.getIdToken("common");
return new ResponseEntity<String>(token, HttpStatus.OK);
}
}
// 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.opengroup.osdu.indexer.ibm.cache;
import org.opengroup.osdu.core.common.model.core.cache.VmCache;
import org.opengroup.osdu.core.common.spi.coreis.IAttributesCache;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.Set;
@Component
public class AttributesCache implements IAttributesCache<String,Set> {
private VmCache<String, Set> cache;
public AttributesCache(@Value("${INDEX_CACHE_EXPIRATION}") final String INDEX_CACHE_EXPIRATION,
@Value("${MAX_CACHE_VALUE_SIZE}") final String MAX_CACHE_VALUE_SIZE) {
cache = new VmCache<>(Integer.parseInt(INDEX_CACHE_EXPIRATION) * 60,
Integer.parseInt(MAX_CACHE_VALUE_SIZE));
}
@Override
public void put(String key, Set value) {
this.cache.put(key, value);
}
@Override
public Set get(String key) {
return this.cache.get(key);
}
@Override
public void delete(String key) {
this.cache.delete(key);
}
@Override
public void clearAll() {
this.cache.clearAll();
}
}
\ No newline at end of file
//// Copyright 2019 IBM Corp. All Rights Reserved.
////
//// 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.ibm.cache;
//
//
//import org.opengroup.osdu.core.common.model.core.cache.VmCache;
//import org.opengroup.osdu.core.common.model.storage.Schema;
//import org.springframework.stereotype.Component;
//
//@Component
//public class CosmosDBSchemaCache extends VmCache<String, Schema> {
// public CosmosDBSchemaCache() {
// super(5 * 60, 1000);
// }
//}
package org.opengroup.osdu.indexer.ibm.cache;
import org.opengroup.osdu.core.common.model.core.cache.VmCache;
import org.opengroup.osdu.core.common.model.core.ClusterSettings;
import org.opengroup.osdu.core.common.spi.coreis.IElasticCredentialsCache;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Component
public class ElasticCredentialsCache implements IElasticCredentialsCache<String, ClusterSettings> {
private VmCache<String, ClusterSettings> cache;
public ElasticCredentialsCache(@Value("${ELASTIC_CACHE_EXPIRATION}") final String ELASTIC_CACHE_EXPIRATION,
@Value("${MAX_CACHE_VALUE_SIZE}") final String MAX_CACHE_VALUE_SIZE) {
cache = new VmCache<>(Integer.parseInt(ELASTIC_CACHE_EXPIRATION) * 60,
Integer.parseInt(MAX_CACHE_VALUE_SIZE));
}
@Override
public void put(String s, ClusterSettings o) {
this.cache.put(s,o);
}
@Override
public ClusterSettings get(String s) {
return this.cache.get(s);
}
@Override
public void delete(String s) {
this.cache.delete(s);
}
@Override
public void clearAll() {
this.cache.clearAll();
}
}
package org.opengroup.osdu.indexer.ibm.cache;
import org.opengroup.osdu.core.common.model.core.cache.VmCache;
import org.opengroup.osdu.core.common.spi.coreis.IIndexCache;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Component
public class IndexCache implements IIndexCache<String, Boolean> {
private VmCache<String, Boolean> cache;
public IndexCache(@Value("${INDEX_CACHE_EXPIRATION}") final String INDEX_CACHE_EXPIRATION,
@Value("${MAX_CACHE_VALUE_SIZE}") final String MAX_CACHE_VALUE_SIZE) {
cache = new VmCache<>(Integer.parseInt(INDEX_CACHE_EXPIRATION) * 60,
Integer.parseInt(MAX_CACHE_VALUE_SIZE));
}
@Override
public void put(String s, Boolean o) {
this.cache.put(s, o);
}
@Override
public Boolean get(String s) {
return this.cache.get(s);
}
@Override
public void delete(String s) {
this.cache.delete(s);
}
@Override
public void clearAll() {
this.cache.clearAll();
}
}
package org.opengroup.osdu.indexer.ibm.cache;
import org.opengroup.osdu.core.common.model.core.cache.VmCache;
import org.opengroup.osdu.core.common.model.coreis.IdToken;
import org.opengroup.osdu.core.common.spi.coreis.IJwtCache;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Component
public class JwtCache implements IJwtCache<String, IdToken> {
private VmCache<String, IdToken> cache;
// Azure service account id_token can be requested only for 1 hr
private final static int EXPIRED_AFTER = 59;
public JwtCache(@Value("${MAX_CACHE_VALUE_SIZE}") final String MAX_CACHE_VALUE_SIZE) {
cache = new VmCache<>(EXPIRED_AFTER * 60, Integer.parseInt(MAX_CACHE_VALUE_SIZE));
}
@Override
public void put(String s, IdToken o) {
this.cache.put(s, o);
}
@Override
public IdToken get(String s) {
return this.cache.get(s);
}
@Override
public void delete(String s) {
this.cache.delete(s);
}
@Override
public void clearAll() {
this.cache.clearAll();
}
}
package org.opengroup.osdu.indexer.ibm.cache;
import org.opengroup.osdu.core.common.model.core.cache.VmCache;
import org.opengroup.osdu.core.common.spi.coreis.IKindsCache;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.Set;
@Component
public class KindsCache implements IKindsCache<String, Set> {
private VmCache<String, Set> cache;
public KindsCache(@Value("${KINDS_CACHE_EXPIRATION}") final String KINDS_CACHE_EXPIRATION,
@Value("${MAX_CACHE_VALUE_SIZE}") final String MAX_CACHE_VALUE_SIZE) {
cache = new VmCache<>(Integer.parseInt(KINDS_CACHE_EXPIRATION) * 60,
Integer.parseInt(MAX_CACHE_VALUE_SIZE));
}
@Override
public void put(String s, Set o) {
this.cache.put(s, o);
}
@Override
public Set get(String s) {
return this.cache.get(s);
}
@Override
public void delete(String s) {
this.cache.delete(s);
}
@Override
public void clearAll() {
this.cache.clearAll();
}
}
package org.opengroup.osdu.indexer.ibm.cache;
import org.opengroup.osdu.core.common.model.core.cache.VmCache;
import org.opengroup.osdu.core.common.spi.indexer.ISchemaCache;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Component
public class SchemaCache implements ISchemaCache<String, String> {
private VmCache<String, String> cache;
public SchemaCache(@Value("${SCHEMA_CACHE_EXPIRATION}") final String SCHEMA_CACHE_EXPIRATION,
@Value("${MAX_CACHE_VALUE_SIZE}") final String MAX_CACHE_VALUE_SIZE) {
cache = new VmCache<>(Integer.parseInt(SCHEMA_CACHE_EXPIRATION) * 60,
Integer.parseInt(MAX_CACHE_VALUE_SIZE));
}
@Override
public void put(String s, String o) {
this.cache.put(s, o);
}
@Override
public String get(String s) {
return this.cache.get(s);
}
@Override
public void delete(String s) {
this.cache.delete(s);
}
@Override
public void clearAll() {
this.cache.clearAll();
}
}
// Copyright 2019 IBM Corp. All Rights Reserved.
//
// 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.ibm.di;
import org.opengroup.osdu.core.common.model.core.DpsLog;
import org.opengroup.osdu.core.common.service.core.Log;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope;
@Component
@RequestScope
public class DpsLogFactory implements FactoryBean<DpsLog> {
@Override
public DpsLog getObject() throws Exception {
return new Log();
}
@Override
public Class<?> getObjectType() {
return DpsLog.class;
}
}
//// Copyright 2019 IBM Corp. All Rights Reserved.
////
//// 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.ibm.di;
//
//import org.opengroup.osdu.core.common.model.core.DpsHeaders;
//import org.opengroup.osdu.core.common.service.core.entitlements.IEntitlementsFactory;
//import org.opengroup.osdu.core.common.service.core.entitlements.IEntitlementsService;
//import org.springframework.context.annotation.Primary;
//import org.springframework.stereotype.Component;
//
//@Component
//@Primary
//public class EntitlementsFactoryIBM implements IEntitlementsFactory {
// @Override
// public IEntitlementsService create(DpsHeaders dpsHeaders) {
// return new EntitlementsServiceIBM(dpsHeaders);
// }
//}
// Copyright 2019 IBM Corp. All Rights Reserved.
//
// 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.ibm.di;
import org.apache.http.HttpStatus;
import org.opengroup.osdu.core.common.model.core.DpsHeaders;
import org.opengroup.osdu.core.common.model.core.entitlements.*;
import org.opengroup.osdu.core.common.service.core.entitlements.IEntitlementsService;
import org.opengroup.osdu.core.common.service.core.HttpResponse;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class EntitlementsServiceIBM implements IEntitlementsService {
//service principals don't have UPN or email
static final String INTEGRATION_TEST_ADMIN_ROLE = "data.test.admin@opendes.ibm.com";
public static final String PREFIX = "ROLE_";
DpsHeaders headers;
public EntitlementsServiceIBM(DpsHeaders headers){
this.headers = headers;
}
@Override
public MemberInfo addMember(GroupEmail groupEmail, MemberInfo memberInfo) throws EntitlementsException {
return null;
}
@Override
public Members getMembers(GroupEmail groupEmail, GetMembers getMembers) throws EntitlementsException {
return null;
}
@Override
public Groups getGroups() throws EntitlementsException {
//TODO implement
return null;
}
// @Override
// public Groups getGroups() throws EntitlementsException {
// final Authentication auth = SecurityContextHolder.getContext().getAuthentication();
// final UserPrincipal current = (UserPrincipal) auth.getPrincipal();
// String email = current.getUpn();
//
// List<GroupInfo> giList = new ArrayList();
// Collection<? extends GrantedAuthority> authorities = auth.getAuthorities();
// for(GrantedAuthority authority : authorities)
// {
// GroupInfo gi = new GroupInfo();
// String role = authority.getAuthority();
// if (role.startsWith(PREFIX)){
// role = role.substring(PREFIX.length());
// }
// gi.setName(role);
// if ((email == null || email.isEmpty()) && role.equalsIgnoreCase(INTEGRATION_TEST_ADMIN_ROLE)) {
// email = INTEGRATION_TEST_ADMIN_ROLE;
// gi.setEmail(email);
// giList.add(0, gi);
// }
// else {
// gi.setEmail(email);
// giList.add(gi);
// }
// }
// if (giList.size() > 0)
// {
// Groups groups = new Groups();
// groups.setGroups(giList);
// groups.setDesId(email);
// return groups;
// }
//
// HttpResponse response = new HttpResponse();
// response.setResponseCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
// throw new EntitlementsException("no authorities found", response);
// }
@Override
public GroupInfo createGroup(CreateGroup createGroup) throws EntitlementsException {
return null;
}
@Override
public void deleteMember(String s, String s1) throws EntitlementsException {
}
@Override
public Groups authorizeAny(String... strings) throws EntitlementsException {
return null;
}
@Override
public void authenticate() throws EntitlementsException {
}
}
// Copyright 2019 IBM Corp. All Rights Reserved.
//
// 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.ibm.di;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
import org.opengroup.osdu.core.common.model.core.ICache;
import org.opengroup.osdu.core.common.model.core.ITenantFactory;
import org.opengroup.osdu.core.common.model.core.TenantInfo;
import org.opengroup.osdu.core.ibm.cloudant.IBMCloudantClientFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope;
import com.cloudant.client.api.Database;
@Component
@RequestScope
public class TenantFactoryImpl implements ITenantFactory {
private static final Logger logger = LoggerFactory.getLogger(TenantFactoryImpl.class);
@Autowired
private IBMCloudantClientFactory cloudantFactory;
private Database db;
@PostConstruct
public void init(){
try {
db = cloudantFactory.getClient().database(TenantInfoDoc.DB_NAME, true);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
private Map<String, TenantInfo> tenants;
public boolean exists(String tenantName)
{
if (this.tenants == null)
initTenants();
return this.tenants.containsKey(tenantName);
}
public TenantInfo getTenantInfo(String tenantName) {
if (this.tenants == null)
initTenants();
return this.tenants.get(tenantName);
}
public Collection<TenantInfo> listTenantInfo() {
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)
{
return null;
}
public void flushCache() {}
private void initTenants() {
this.tenants = new HashMap<>();
// TODO implement limit, cursor
// TODO refactor a more efficient way, with index
List<TenantInfoDoc> allDocs = null;
try {
allDocs = db.getAllDocsRequestBuilder().build().getResponse().getDocsAs(TenantInfoDoc.class);
} catch (IOException e) {
e.printStackTrace();
}
if (allDocs == null) {
logger.error("Could not get all documents for " + TenantInfoDoc.class.getCanonicalName() + " in the DB.");
return;
}
allDocs.forEach(doc -> {
TenantInfo ti = new TenantInfo();
String tenantName = doc.getId();
ti.setName(tenantName);
ti.setServiceAccount(doc.getServiceprincipalAppId());
this.tenants.put(tenantName, ti) ;
});
}
}
// Copyright 2019 IBM Corp. All Rights Reserved.
//
// 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.ibm.di;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class TenantInfoDoc {
public static final String DB_NAME = "TenantInfo"; //collection name
@Id
private String id;
private String serviceprincipalAppId;
}
// Copyright 2019 IBM Corp. All Rights Reserved.
//
// 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.ibm.di;
import javax.inject.Inject;
import org.opengroup.osdu.core.common.model.core.DpsHeaders;
import org.opengroup.osdu.core.common.model.core.ITenantFactory;
import org.opengroup.osdu.core.common.model.core.TenantInfo;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.config.AbstractFactoryBean;
import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope;
@Component
@RequestScope
public class TenantInfoFactory extends AbstractFactoryBean<TenantInfo> {
@Inject
private ITenantFactory tenantFactory;
@Inject
@Qualifier("dpsHeaderFactorySearch")
private DpsHeaders headers;
@Override
protected TenantInfo createInstance() throws Exception {
String id = this.headers.getPartitionIdWithFallbackToAccountId();
return this.tenantFactory.getTenantInfo(id);
}
@Override
public Class<?> getObjectType() {
return TenantInfo.class;
}
}
// Copyright 2019 IBM Corp. All Rights Reserved.
//
// 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.ibm.model;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Getter
@Setter
@Component
@ConfigurationProperties("aad")
public class AADConfiguration {
String clientId;
String authority;
String secretKey;
String oboApi;
public String getAuthority(){
if (!authority.endsWith("/")) {
authority += "/";
}
return authority;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment