From 5d4793210e2a7e3a12370198130cadec84cd7a32 Mon Sep 17 00:00:00 2001 From: Roberto Cirillo Date: Thu, 16 Feb 2023 14:41:42 +0100 Subject: [PATCH] add automatic encryption on new ServiceEndpoint --- .../resources/ServiceEndpointResource.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/gcube/informationsystem/icproxy/resources/ServiceEndpointResource.java b/src/main/java/org/gcube/informationsystem/icproxy/resources/ServiceEndpointResource.java index 949fedb..1e50c96 100644 --- a/src/main/java/org/gcube/informationsystem/icproxy/resources/ServiceEndpointResource.java +++ b/src/main/java/org/gcube/informationsystem/icproxy/resources/ServiceEndpointResource.java @@ -100,7 +100,7 @@ public class ServiceEndpointResource { // profile.accessPoints().add(ap); // registerSE(newResource); // return newResource; - registerSE(resourceProfile); + registerSE(encryptResource(resourceProfile)); return resourceProfile; }else{ throw new RuntimeException("ServiceEndpoint profile is null or user not enabled"); @@ -131,6 +131,18 @@ public class ServiceEndpointResource { } return resource; } + + private ServiceEndpoint encryptResource(ServiceEndpoint resource) { + Group aps=resource.profile().accessPoints(); + for (ServiceEndpoint.AccessPoint ap : aps){ + String decrypted =encryptString(ap.password()); + String user= ap.username(); + + ap.credentials(decrypted, user); + } + return resource; + } + private static String decryptString(String toDecrypt){ try{ @@ -139,6 +151,15 @@ public class ServiceEndpointResource { throw new RuntimeException("Unable to decrypt : "+toDecrypt,e); } } + + private static String encryptString(String toEncrypt){ + try{ + return StringEncrypter.getEncrypter().encrypt(toEncrypt); + }catch(Exception e) { + throw new RuntimeException("Unable to encrypt : "+toEncrypt,e); + } + } + private List getServiceEndpoints(boolean isDecrypt, List endpoints) { if (isDecrypt) { if (isRoleEnabled()){