001
014
015 package com.liferay.portal.webdav;
016
017 import com.liferay.portal.kernel.util.StringPool;
018 import com.liferay.portal.kernel.webdav.BaseResourceImpl;
019 import com.liferay.portal.kernel.webdav.BaseWebDAVStorageImpl;
020 import com.liferay.portal.kernel.webdav.Resource;
021 import com.liferay.portal.kernel.webdav.WebDAVException;
022 import com.liferay.portal.kernel.webdav.WebDAVRequest;
023 import com.liferay.portal.kernel.webdav.WebDAVUtil;
024 import com.liferay.portal.model.Group;
025
026 import java.util.ArrayList;
027 import java.util.List;
028
029
032 public class GroupWebDAVStorageImpl extends BaseWebDAVStorageImpl {
033
034 @Override
035 public Resource getResource(WebDAVRequest webDavRequest)
036 throws WebDAVException {
037
038 verifyGroup(webDavRequest);
039
040 String path = getRootPath() + webDavRequest.getPath();
041
042 return new BaseResourceImpl(path, StringPool.BLANK, StringPool.BLANK);
043 }
044
045 @Override
046 public List<Resource> getResources(WebDAVRequest webDavRequest)
047 throws WebDAVException {
048
049 verifyGroup(webDavRequest);
050
051 List<Resource> resources = new ArrayList<Resource>();
052
053 String path = getRootPath() + webDavRequest.getPath();
054
055 for (String token : WebDAVUtil.getStorageTokens()) {
056 resources.add(new BaseResourceImpl(path, token, token));
057 }
058
059 return resources;
060 }
061
062 protected void verifyGroup(WebDAVRequest webDavRequest)
063 throws WebDAVException {
064
065 String path = webDavRequest.getPath();
066
067 try {
068 long userId = webDavRequest.getUserId();
069
070 List<Group> groups = WebDAVUtil.getGroups(userId);
071
072 for (Group group : groups) {
073 if (path.equals(group.getFriendlyURL())) {
074 return;
075 }
076 }
077 }
078 catch (Exception e) {
079 }
080
081 throw new WebDAVException(
082 "Invalid group for given credentials " +
083 webDavRequest.getRootPath() + path);
084 }
085
086 }