package gr.ebs.gss.server.webdav.milton;
import static gr.ebs.gss.server.configuration.GSSConfigurationFactory.getConfiguration;
-import gr.ebs.gss.client.exceptions.ObjectNotFoundException;
-import gr.ebs.gss.client.exceptions.RpcException;
+import gr.ebs.gss.common.exceptions.ObjectNotFoundException;
+import gr.ebs.gss.common.exceptions.RpcException;
+import gr.ebs.gss.server.domain.FileHeader;
+import gr.ebs.gss.server.domain.Folder;
import gr.ebs.gss.server.domain.User;
-import gr.ebs.gss.server.domain.dto.FileHeaderDTO;
-import gr.ebs.gss.server.domain.dto.FolderDTO;
-import gr.ebs.gss.server.domain.dto.UserDTO;
import gr.ebs.gss.server.ejb.ExternalAPI;
import gr.ebs.gss.server.ejb.TransactionHelper;
HttpManager httpManager;
@Override
public Resource getResource(String host, String url) {
- log.debug("getResource: host: " + host + " - url:" + url);
+
+
+
+ log.debug("getResource: host: " + host + " - url:" + url);
url = stripContext(url);
- if(url==null||url.trim().equals(""))
+ if(url==null||url.trim().equals("")||url.equals("/")){
url="/";
- try {
+ }
+ /*//log.info("URL:"+url);
+ if(url.equals("/OthersShared")||url.equals("/OthersShared/")){
+ //log.info("[returning others]");
+ return new GssOthersResource(host, this);
+ }
+ if(url.startsWith("/OthersShared")){
- Object r = getResourceGss(url);
- if(r==null)
+ }*/
+ try {
+ User user =null;
+ if(HttpManager.request().getAuthorization()!=null && HttpManager.request().getAuthorization().getTag()==null){
+ String username = HttpManager.request().getAuthorization().getUser();
+ if(username !=null)
+ user = getService().getUserByUserName(username);
+ }
+ else if(HttpManager.request().getAuthorization()!=null&&HttpManager.request().getAuthorization().getTag()!=null){
+ user =(User) HttpManager.request().getAuthorization().getTag();
+ }
+
+ if(user==null){
+ //create a resource based on path if no resource exists at this path it will be handled by subsequent webdav method calls
+ return new GssRootFolderResource(host, this, null,url);
+ }
+
+ Object r = getResourceGss(url,user);
+ if(r==null){
+
return null;
- if(r instanceof FolderDTO)
- return new GssFolderResource(host, this,r );
+ }
+ if(r instanceof Folder){
+
+ return new GssFolderResource(host, this,r ,user);
+ }
else
- return new GssFileResource(host, this,r);
+ return new GssFileResource(host, this,r,user);
} catch (RpcException e) {
e.printStackTrace();
}
public Long maxAgeSeconds(GssResource resource) {
return maxAgeSeconds;
}
- private Object getResourceGss(String path) throws RpcException{
- UserDTO user = getService().getUserByUserName("past@ebs.gr");
+ protected Object getResourceGss(String path, User user) throws RpcException{
+
+ if(user ==null){
+ if(HttpManager.request().getAuthorization()!=null && HttpManager.request().getAuthorization().getTag()==null){
+ String username = HttpManager.request().getAuthorization().getUser();
+ if(username !=null)
+ user = getService().getUserByUserName(username);
+ }
+ else if(HttpManager.request().getAuthorization()!=null&&HttpManager.request().getAuthorization().getTag()!=null){
+ user =(User) HttpManager.request().getAuthorization().getTag();
+ }
+ }
+
+ if(user==null){
+ return null;
+ }
boolean exists = true;
Object resource = null;
- FileHeaderDTO file = null;
- FolderDTO folder = null;
try {
resource = getService().getResourceAtPath(user.getId(), path, true);
} catch (ObjectNotFoundException e) {
return null;
}
-
+ if(resource instanceof Folder){
+ try {
+ resource = getService().expandFolder((Folder) resource);
+ } catch (ObjectNotFoundException e) {
+ // TODO Auto-generated catch block
+ return null;
+ }
+ }
+ else if(resource instanceof FileHeader){
+ try {
+ resource = getService().expandFile((FileHeader) resource);
+ } catch (ObjectNotFoundException e) {
+ // TODO Auto-generated catch block
+ return null;
+ }
+ }
return resource;
}
public void setHttpManager(HttpManager httpManager) {
this.httpManager = httpManager;
}
-
+
+
+
+ public static String getUsernameFromAuthHeader(String header) {
+ String first = header.split(",")[0];
+ int indx = first.indexOf("\"");
+ return first.substring(indx+1,first.length()-1);
+ }
}