root / src / gr / ebs / gss / server / webdav / milton / GssRootFolderResource.java @ 21a76038
History | View | Annotate | Download (5.4 kB)
1 |
/*
|
---|---|
2 |
* Copyright 2011 Electronic Business Systems Ltd.
|
3 |
*
|
4 |
* This file is part of GSS.
|
5 |
*
|
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.
|
10 |
*
|
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.
|
15 |
*
|
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/>.
|
18 |
*/
|
19 |
package gr.ebs.gss.server.webdav.milton; |
20 |
|
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; |
27 |
|
28 |
import java.util.ArrayList; |
29 |
import java.util.List; |
30 |
|
31 |
import org.slf4j.Logger; |
32 |
import org.slf4j.LoggerFactory; |
33 |
|
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; |
44 |
|
45 |
|
46 |
/**
|
47 |
* @author kman
|
48 |
*
|
49 |
*/
|
50 |
public class GssRootFolderResource extends GssFolderResource{ |
51 |
private static final Logger log = LoggerFactory.getLogger(GssFolderResource.class); |
52 |
String path;
|
53 |
/**
|
54 |
* @param host
|
55 |
* @param factory
|
56 |
* @param resource
|
57 |
*/
|
58 |
public GssRootFolderResource(String host, GSSResourceFactory factory, Object resource,String path) { |
59 |
super(host, factory, resource,null); |
60 |
this.path=path;
|
61 |
try {
|
62 |
this.folder = (Folder) factory.getResourceGss(path,getCurrentUser());
|
63 |
//log.info("ROOT FOLDER:"+folder);
|
64 |
} catch (RpcException e) {
|
65 |
// TODO Auto-generated catch block
|
66 |
} |
67 |
} |
68 |
|
69 |
@Override
|
70 |
public boolean authorise(Request request, Method method, Auth auth) { |
71 |
// TODO Auto-generated method stub
|
72 |
boolean result = factory.getSecurityManager().authorise(request, method, auth, this); |
73 |
if(result){
|
74 |
User user = getCurrentUser(); |
75 |
if(user==null) |
76 |
//log.info("AUTH USER NULL");
|
77 |
if(this.folder==null){ |
78 |
try {
|
79 |
this.folder= (Folder) factory.getResourceGss(path,getCurrentUser());//getService().getFolder(user.getId(), folder.getId()); |
80 |
} catch (RpcException e) {
|
81 |
//log.info("*****AUTH1:"+false+" "+getCurrentUser());
|
82 |
return false; |
83 |
} |
84 |
} |
85 |
//log.info("*****AUTH2:"+true+" "+getCurrentUser());
|
86 |
return true; |
87 |
} |
88 |
//log.info("*****AUTH3:"+result+" "+getCurrentUser()+" "+method);
|
89 |
return result;
|
90 |
} |
91 |
|
92 |
|
93 |
@Override
|
94 |
public Object authenticate(DigestResponse digestRequest) { |
95 |
// TODO Auto-generated method stub
|
96 |
return super.authenticate(digestRequest); |
97 |
} |
98 |
|
99 |
@Override
|
100 |
public String getName() { |
101 |
return path;
|
102 |
} |
103 |
@Override
|
104 |
public String getUniqueId() { |
105 |
if(folder!=null) |
106 |
return "folder:"+folder.getId().toString(); |
107 |
return "folder:"+path; |
108 |
} |
109 |
@Override
|
110 |
public Resource child(String name) { |
111 |
log.info("CALLING ROOT GET CHILD:"+getCurrentUser());
|
112 |
if(this.folder==null) |
113 |
try {
|
114 |
this.folder = (Folder) factory.getResourceGss(path,getCurrentUser());
|
115 |
} catch (RpcException e) {
|
116 |
//
|
117 |
} |
118 |
return super.child(name); |
119 |
} |
120 |
@Override
|
121 |
public List<? extends Resource> getChildren() { |
122 |
//log.info("CALLING ROOT GET CHILDREN:"+getCurrentUser());
|
123 |
if(this.folder==null) |
124 |
try {
|
125 |
this.folder = (Folder) factory.getResourceGss(path,getCurrentUser());
|
126 |
} catch (RpcException e) {
|
127 |
//
|
128 |
} |
129 |
List<Resource> result = new ArrayList<Resource>(); |
130 |
for(Folder f : folder.getSubfolders())
|
131 |
if(!f.isDeleted())
|
132 |
result.add(new GssFolderResource(host, factory, f,getCurrentUser()));
|
133 |
try {
|
134 |
for(FileHeader f : getService().getFiles(getCurrentUser().getId(), folder.getId(), true)) |
135 |
result.add(new GssFileResource(host, factory, f,getCurrentUser()));
|
136 |
} catch (ObjectNotFoundException e) {
|
137 |
//
|
138 |
|
139 |
} catch (InsufficientPermissionsException e) {
|
140 |
//
|
141 |
|
142 |
} catch (RpcException e) {
|
143 |
//
|
144 |
|
145 |
} |
146 |
//result.add(new GssOthersResource(host, factory));
|
147 |
return result;
|
148 |
} |
149 |
|
150 |
/*Disable Locks if folder is null*/
|
151 |
public LockResult lock(LockTimeout timeout, LockInfo lockInfo) throws NotAuthorizedException { |
152 |
if(folder==null) |
153 |
throw new NotAuthorizedException(this); |
154 |
return factory.getLockManager().lock(timeout, lockInfo, this); |
155 |
} |
156 |
|
157 |
public LockResult refreshLock(String token) throws NotAuthorizedException { |
158 |
if(folder==null) |
159 |
throw new NotAuthorizedException(this); |
160 |
return factory.getLockManager().refresh(token, this); |
161 |
} |
162 |
|
163 |
public void unlock(String tokenId) throws NotAuthorizedException { |
164 |
if(folder==null) |
165 |
throw new NotAuthorizedException(this); |
166 |
factory.getLockManager().unlock(tokenId, this);
|
167 |
} |
168 |
|
169 |
public LockToken getCurrentLock() {
|
170 |
if(folder==null) |
171 |
return null; |
172 |
if( factory.getLockManager() != null ) { |
173 |
return factory.getLockManager().getCurrentToken( this ); |
174 |
} else {
|
175 |
log.warn("getCurrentLock called, but no lock manager: file: " + resource);
|
176 |
return null; |
177 |
} |
178 |
} |
179 |
|
180 |
} |