add automatic encryption on new ServiceEndpoint

This commit is contained in:
Roberto Cirillo 2023-02-16 14:41:42 +01:00
parent 09c6155a45
commit 5d4793210e
1 changed files with 22 additions and 1 deletions

View File

@ -100,7 +100,7 @@ public class ServiceEndpointResource {
// profile.accessPoints().add(ap); // profile.accessPoints().add(ap);
// registerSE(newResource); // registerSE(newResource);
// return newResource; // return newResource;
registerSE(resourceProfile); registerSE(encryptResource(resourceProfile));
return resourceProfile; return resourceProfile;
}else{ }else{
throw new RuntimeException("ServiceEndpoint profile is null or user not enabled"); throw new RuntimeException("ServiceEndpoint profile is null or user not enabled");
@ -131,6 +131,18 @@ public class ServiceEndpointResource {
} }
return resource; return resource;
} }
private ServiceEndpoint encryptResource(ServiceEndpoint resource) {
Group<ServiceEndpoint.AccessPoint> 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){ private static String decryptString(String toDecrypt){
try{ try{
@ -139,6 +151,15 @@ public class ServiceEndpointResource {
throw new RuntimeException("Unable to decrypt : "+toDecrypt,e); 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<ServiceEndpoint> getServiceEndpoints(boolean isDecrypt, List<ServiceEndpoint> endpoints) { private List<ServiceEndpoint> getServiceEndpoints(boolean isDecrypt, List<ServiceEndpoint> endpoints) {
if (isDecrypt) { if (isDecrypt) {
if (isRoleEnabled()){ if (isRoleEnabled()){