Skip to content

Commit

Permalink
Issue #148 converting encryption decryption to batch
Browse files Browse the repository at this point in the history
  • Loading branch information
jyotsnaraveendran committed May 9, 2018
1 parent 9f1179d commit 9ecf36c
Show file tree
Hide file tree
Showing 11 changed files with 544 additions and 308 deletions.
6 changes: 6 additions & 0 deletions java/registry/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>23.0</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.neo4j</groupId>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.opensaber.registry.service;

import java.util.Map;

import io.opensaber.registry.exception.EncryptionException;

public interface EncryptionService {
Expand All @@ -8,6 +10,10 @@ public interface EncryptionService {

public String decrypt(Object propertyValue) throws EncryptionException;

public Map<String,Object> encrypt(Map<String,Object> propertyValue) throws EncryptionException;

public Map<String,Object> decrypt(Map<String,Object> propertyValue) throws EncryptionException;

public boolean isEncryptionServiceUp();

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package io.opensaber.registry.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.neo4j.driver.v1.exceptions.ServiceUnavailableException;
Expand All @@ -8,6 +11,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.stereotype.Component;
Expand All @@ -16,6 +21,10 @@
import org.springframework.web.client.ResourceAccessException;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import io.opensaber.registry.exception.EncryptionException;
import io.opensaber.registry.schema.config.SchemaConfigurator;
import io.opensaber.registry.service.EncryptionService;
Expand All @@ -28,10 +37,19 @@ public class EncryptionServiceImpl implements EncryptionService {

@Value("${decryption.uri}")
private String decryptionUri;

@Value("${encryption.batch.uri}")
private String encryptionBatchUri;

@Value("${decryption.batch.uri}")
private String decryptionBatchUri;

@Value("${encryption.base}")
private String encryptionServiceHealthCheckUri;

@Autowired
private Gson gson;

@Autowired
SchemaConfigurator schemaConfigurator;

Expand Down Expand Up @@ -78,6 +96,53 @@ public String decrypt(Object propertyValue) throws EncryptionException {
}
}

@Override
public Map<String, Object> encrypt(Map<String, Object> propertyValue) throws EncryptionException {
Map<String, Object> map= new HashMap<String, Object>();
map.put("value", propertyValue);

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<String> entity = new HttpEntity<String>(gson.toJson(map),headers);
try {
ResponseEntity<String> response = new RestTemplate().postForEntity(encryptionBatchUri, entity, String.class);
return gson.fromJson(response.getBody(), new TypeToken<HashMap<String, Object>>(){}.getType());
}catch(ResourceAccessException e) {
logger.error("Exception while connecting enryption service : ", e);
throw new EncryptionException("Exception while connecting enryption service! ");
}catch(ServiceUnavailableException e) {
logger.error("Service not available exception !: ", e);
throw new EncryptionException("Encryption service is not available !");
}catch(Exception e) {
logger.error("Exception in encryption servie !: ", e);
throw new EncryptionException("Exception in encryption service ! ");
}
}

@Override
public Map<String, Object> decrypt(Map<String, Object> propertyValue) throws EncryptionException {
Map<String, Object> map= new HashMap<String, Object>();
map.put("value", propertyValue);

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<String> entity = new HttpEntity<String>(gson.toJson(map),headers);

try {
ResponseEntity<String> response = new RestTemplate().postForEntity(decryptionBatchUri, entity, String.class);
return gson.fromJson(response.getBody(), new TypeToken<HashMap<String, Object>>(){}.getType());
}catch(ResourceAccessException e) {
logger.error("Exception while connecting dcryption service : ", e);
throw new EncryptionException("Exception while connecting enryption service ! ");
}catch(ServiceUnavailableException e) {
logger.error("Service not available exception ! ", e);
throw new EncryptionException("Encryption service is not available !");
}catch(Exception e) {
logger.error("Exception in decryption service !: ", e);
throw new EncryptionException("Exception in encryption service ! ");
}
}

/**
* This method is used to check if the sunbird encryption service is up
* @return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

import io.opensaber.registry.controller.RegistryControllerTest;
import io.opensaber.registry.dao.impl.EncryptionDaoImplTest;
import io.opensaber.registry.dao.impl.RegistryDaoImplTest;
import io.opensaber.registry.service.impl.RegistryEncryptionServiceImplTest;
import io.opensaber.registry.service.impl.EncryptionServiceImplTest;
import io.opensaber.registry.service.impl.RegistryServiceImplTest;
import junit.framework.Test;
import junit.framework.TestSuite;

@SuiteClasses({RegistryDaoImplTest.class, RegistryControllerTest.class, RegistryServiceImplTest.class,
EncryptionDaoImplTest.class, RegistryEncryptionServiceImplTest.class})
@SuiteClasses({RegistryDaoImplTest.class, RegistryServiceImplTest.class,
EncryptionDaoImplTest.class, EncryptionServiceImplTest.class})
@RunWith(Suite.class)
public class RegistryTestSuite {

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ public Model getNewValidRdf(String fileName){
setJsonldWithNewRootLabel();
return ShaclexValidator.parse(jsonld, FORMAT);
}

public Model getNewValidRdfFromJsonString(String json){
return ShaclexValidator.parse(json, FORMAT);
}

public Model getNewValidRdf(String fileName, String contextConstant, String rootNodeLabel){
setJsonld(fileName);
Expand Down
Loading

0 comments on commit 9ecf36c

Please sign in to comment.