2 * Copyright 2011 Electronic Business Systems Ltd.
4 * This file is part of GSS.
6 * GSS is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GSS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GSS. If not, see <http://www.gnu.org/licenses/>.
19 package gr.ebs.gss.server.webdav.milton;
21 import gr.ebs.gss.client.exceptions.InsufficientPermissionsException;
22 import gr.ebs.gss.client.exceptions.ObjectNotFoundException;
23 import gr.ebs.gss.client.exceptions.RpcException;
24 import gr.ebs.gss.server.domain.FileHeader;
25 import gr.ebs.gss.server.domain.Folder;
26 import gr.ebs.gss.server.domain.User;
28 import java.util.ArrayList;
29 import java.util.List;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
34 import com.bradmcevoy.http.Auth;
35 import com.bradmcevoy.http.LockInfo;
36 import com.bradmcevoy.http.LockResult;
37 import com.bradmcevoy.http.LockTimeout;
38 import com.bradmcevoy.http.LockToken;
39 import com.bradmcevoy.http.Request;
40 import com.bradmcevoy.http.Resource;
41 import com.bradmcevoy.http.Request.Method;
42 import com.bradmcevoy.http.exceptions.NotAuthorizedException;
43 import com.bradmcevoy.http.http11.auth.DigestResponse;
50 public class GssRootFolderResource extends GssFolderResource{
51 private static final Logger log = LoggerFactory.getLogger(GssFolderResource.class);
58 public GssRootFolderResource(String host, GSSResourceFactory factory, Object resource,String path) {
59 super(host, factory, resource,null);
62 this.folder = (Folder) factory.getResourceGss(path,getCurrentUser());
63 //log.info("ROOT FOLDER:"+folder);
64 } catch (RpcException e) {
65 // TODO Auto-generated catch block
71 public boolean authorise(Request request, Method method, Auth auth) {
72 // TODO Auto-generated method stub
73 boolean result = factory.getSecurityManager().authorise(request, method, auth, this);
75 User user = getCurrentUser();
77 //log.info("AUTH USER NULL");
78 if(this.folder==null){
80 this.folder= (Folder) factory.getResourceGss(path,getCurrentUser());//getService().getFolder(user.getId(), folder.getId());
81 } catch (RpcException e) {
82 //log.info("*****AUTH1:"+false+" "+getCurrentUser());
86 //log.info("*****AUTH2:"+true+" "+getCurrentUser());
89 //log.info("*****AUTH3:"+result+" "+getCurrentUser()+" "+method);
95 public Object authenticate(DigestResponse digestRequest) {
96 // TODO Auto-generated method stub
97 return super.authenticate(digestRequest);
101 public String getName() {
105 public String getUniqueId() {
107 return "folder:"+folder.getId().toString();
108 return "folder:"+path;
111 public Resource child(String name) {
112 log.info("CALLING ROOT GET CHILD:"+getCurrentUser());
113 if(this.folder==null)
115 this.folder = (Folder) factory.getResourceGss(path,getCurrentUser());
116 } catch (RpcException e) {
117 // TODO Auto-generated catch block
120 return super.child(name);
123 public List<? extends Resource> getChildren() {
124 //log.info("CALLING ROOT GET CHILDREN:"+getCurrentUser());
125 if(this.folder==null)
127 this.folder = (Folder) factory.getResourceGss(path,getCurrentUser());
128 } catch (RpcException e) {
129 // TODO Auto-generated catch block
132 List<Resource> result = new ArrayList<Resource>();
133 for(Folder f : folder.getSubfolders())
135 result.add(new GssFolderResource(host, factory, f,getCurrentUser()));
137 for(FileHeader f : factory.getService().getFiles(getCurrentUser().getId(), folder.getId(), true))
138 result.add(new GssFileResource(host, factory, f,getCurrentUser()));
139 } catch (ObjectNotFoundException e) {
140 // TODO Auto-generated catch block
142 } catch (InsufficientPermissionsException e) {
143 // TODO Auto-generated catch block
145 } catch (RpcException e) {
146 // TODO Auto-generated catch block
149 //result.add(new GssOthersResource(host, factory));
153 /*Disable Locks if folder is null*/
154 public LockResult lock(LockTimeout timeout, LockInfo lockInfo) throws NotAuthorizedException {
156 throw new NotAuthorizedException(this);
157 return factory.getLockManager().lock(timeout, lockInfo, this);
160 public LockResult refreshLock(String token) throws NotAuthorizedException {
162 throw new NotAuthorizedException(this);
163 return factory.getLockManager().refresh(token, this);
166 public void unlock(String tokenId) throws NotAuthorizedException {
168 throw new NotAuthorizedException(this);
169 factory.getLockManager().unlock(tokenId, this);
172 public LockToken getCurrentLock() {
175 if( factory.getLockManager() != null ) {
176 return factory.getLockManager().getCurrentToken( this );
178 log.warn("getCurrentLock called, but no lock manager: file: " + resource);