This commit is contained in:
Lucio Lelii 2018-12-17 17:27:20 +00:00
parent 250fce291f
commit ea6406e460
1 changed files with 12 additions and 5 deletions

View File

@ -1,11 +1,15 @@
package org.gcube.data.access.storagehub.services;
import static org.gcube.common.storagehub.model.Constants.enchriptedPrefix;
import static org.gcube.common.storagehub.model.Constants.versionPrefix;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64;
import java.util.Collections;
import java.util.Deque;
import java.util.LinkedList;
@ -78,7 +82,6 @@ import org.gcube.data.access.storagehub.handlers.VersionHandler;
import org.gcube.smartgears.utils.InnerMethodName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.gcube.common.storagehub.model.Constants.*;
@Path("items")
@ -246,6 +249,8 @@ public class ItemsManager {
@AuthorizationControl(allowed={"URIResolver"}, exception=MyAuthException.class)
public Response resolvePublicLink() {
InnerMethodName.instance.set("resolvePubliclink");
log.warn("arrived id is {}",id);
Session ses = null;
try{
String login = AuthorizationProvider.instance.get().getClient().getId();
@ -262,7 +267,7 @@ public class ItemsManager {
}
ScopeProvider.instance.set(bean.toString());
complexId = StringEncrypter.getEncrypter().encrypt(id.replace(enchriptedPrefix, ""));
complexId = StringEncrypter.getEncrypter().decrypt(new String(Base64.getUrlDecoder().decode(id.replace(enchriptedPrefix, ""))));
}catch(Exception e){
throw new BackendGenericError("invalid public url",e);
}finally {
@ -280,7 +285,9 @@ public class ItemsManager {
versionName = split[1];
}
Node selectedNode = ses.getNodeByIdentifier(id);
log.warn("item id to retrieve is {}",itemId);
Node selectedNode = ses.getNodeByIdentifier(itemId);
Item item = node2Item.getItem(selectedNode, Arrays.asList(NodeConstants.ACCOUNTING_NAME, NodeConstants.METADATA_NAME));
@ -360,7 +367,7 @@ public class ItemsManager {
String enchriptedQueryString = StringEncrypter.getEncrypter().encrypt(toEnchript);
url = createPublicLink(enchriptedQueryString);
url = createPublicLink(new String(Base64.getUrlEncoder().encode(enchriptedQueryString.getBytes())));
}catch(Exception e){
throw new BackendGenericError(e);
}finally {
@ -386,7 +393,7 @@ public class ItemsManager {
private String createPublicLink(String enchriptedString) {
String basepath = context.getInitParameter("resolver-basepath");
String filePublicUrl = String.format("%s/%s%s",basepath, enchriptedPrefix, id);
String filePublicUrl = String.format("%s/%s%s",basepath, enchriptedPrefix, enchriptedString);
return filePublicUrl;
}