/**
*
*/
package com.dotmarketing.webdav;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import com.dotcms.repackage.com.bradmcevoy.http.Auth;
import com.dotcms.repackage.com.bradmcevoy.http.CollectionResource;
import com.dotcms.repackage.com.bradmcevoy.http.FolderResource;
import com.dotcms.repackage.com.bradmcevoy.http.LockInfo;
import com.dotcms.repackage.com.bradmcevoy.http.LockResult;
import com.dotcms.repackage.com.bradmcevoy.http.LockTimeout;
import com.dotcms.repackage.com.bradmcevoy.http.LockToken;
import com.dotcms.repackage.com.bradmcevoy.http.LockingCollectionResource;
import com.dotcms.repackage.com.bradmcevoy.http.Range;
import com.dotcms.repackage.com.bradmcevoy.http.Request;
import com.dotcms.repackage.com.bradmcevoy.http.Resource;
import com.dotcms.repackage.com.bradmcevoy.http.Request.Method;
import com.dotcms.repackage.com.bradmcevoy.http.exceptions.NotAuthorizedException;
import com.dotmarketing.business.Role;
import com.dotmarketing.util.Logger;
import com.liferay.portal.model.User;
/**
* @author jasontesser
*
*/
public class SystemRootResourceImpl implements FolderResource, LockingCollectionResource {
private DotWebdavHelper dotDavHelper;
public SystemRootResourceImpl() {
dotDavHelper = new DotWebdavHelper();
}
/* (non-Javadoc)
* @see com.dotcms.repackage.com.bradmcevoy.http.MakeCollectionableResource#createCollection(java.lang.String)
*/
public CollectionResource createCollection(String newName) {
return null;
}
/* (non-Javadoc)
* @see com.dotcms.repackage.com.bradmcevoy.http.CollectionResource#child(java.lang.String)
*/
public Resource child(String childName) {
return new LanguageFolderResourceImpl("");
}
/* (non-Javadoc)
* @see com.dotcms.repackage.com.bradmcevoy.http.CollectionResource#getChildren()
*/
public List<? extends Resource> getChildren() {
List<Resource> result = new ArrayList<Resource>();
LanguageFolderResourceImpl lfr = new LanguageFolderResourceImpl("");
result.add(lfr);
return result;
}
/* (non-Javadoc)
* @see com.dotcms.repackage.com.bradmcevoy.http.Resource#authenticate(java.lang.String, java.lang.String)
*/
public Object authenticate(String username, String password) {
try {
User user = dotDavHelper.authorizePrincipal(username, password);
//Get the Administrator Role to validate if the user has permission
Role cmsAdminRole = com.dotmarketing.business.APILocator.getRoleAPI().loadCMSAdminRole();
if(com.dotmarketing.business.APILocator.getRoleAPI().doesUserHaveRole(user, cmsAdminRole.getId())){
return user;
}else{
return null;
}
} catch (Exception e) {
Logger.error(this, e.getMessage(), e);
return null;
}
}
/* (non-Javadoc)
* @see com.dotcms.repackage.com.bradmcevoy.http.Resource#authorise(com.dotcms.repackage.com.bradmcevoy.http.Request, com.dotcms.repackage.com.bradmcevoy.http.Request.Method, com.dotcms.repackage.com.bradmcevoy.http.Auth)
*/
public boolean authorise(Request req, Method method, Auth auth) {
if(auth == null)
return false;
else{
return true;
}
}
/* (non-Javadoc)
* @see com.dotcms.repackage.com.bradmcevoy.http.Resource#checkRedirect(com.dotcms.repackage.com.bradmcevoy.http.Request)
*/
public String checkRedirect(Request req) {
return null;
}
/* (non-Javadoc)
* @see com.dotcms.repackage.com.bradmcevoy.http.Resource#getContentLength()
*/
public Long getContentLength() {
return (long)0;
}
/* (non-Javadoc)
* @see com.dotcms.repackage.com.bradmcevoy.http.Resource#getContentType(java.lang.String)
*/
public String getContentType(String arg0) {
return null;
}
/* (non-Javadoc)
* @see com.dotcms.repackage.com.bradmcevoy.http.Resource#getModifiedDate()
*/
public Date getModifiedDate() {
return new Date();
}
/* (non-Javadoc)
* @see com.dotcms.repackage.com.bradmcevoy.http.Resource#getRealm()
*/
public String getRealm() {
return null;
}
/* (non-Javadoc)
* @see com.dotcms.repackage.com.bradmcevoy.http.Resource#getUniqueId()
*/
public String getUniqueId() {
return "system".hashCode() + "";
}
/* (non-Javadoc)
* @see com.dotcms.repackage.com.bradmcevoy.http.PutableResource#createNew(java.lang.String, java.io.InputStream, java.lang.Long, java.lang.String)
*/
public Resource createNew(String newName, InputStream in, Long length, String contentType) throws IOException {
return null;
}
/* (non-Javadoc)
* @see com.dotcms.repackage.com.bradmcevoy.http.CopyableResource#copyTo(com.dotcms.repackage.com.bradmcevoy.http.CollectionResource, java.lang.String)
*/
public void copyTo(CollectionResource collRes, String name) {
throw new RuntimeException("Not allowed to implement copy");
}
/* (non-Javadoc)
* @see com.dotcms.repackage.com.bradmcevoy.http.DeletableResource#delete()
*/
public void delete() {
throw new RuntimeException("Cannot Delete System Folder");
}
/* (non-Javadoc)
* @see com.dotcms.repackage.com.bradmcevoy.http.GetableResource#getMaxAgeSeconds()
*/
public Long getMaxAgeSeconds() {
return new Long(60);
}
/* (non-Javadoc)
* @see com.dotcms.repackage.com.bradmcevoy.http.GetableResource#sendContent(java.io.OutputStream, com.dotcms.repackage.com.bradmcevoy.http.Range, java.util.Map)
*/
public void sendContent(OutputStream arg0, Range arg1, Map<String, String> arg2, String arg3) throws IOException {
return;
}
/* (non-Javadoc)
* @see com.dotcms.repackage.com.bradmcevoy.http.MoveableResource#moveTo(com.dotcms.repackage.com.bradmcevoy.http.CollectionResource, java.lang.String)
*/
public void moveTo(CollectionResource collRes, String name) {
throw new RuntimeException("Not allowed to implement move");
}
/* (non-Javadoc)
* @see com.dotcms.repackage.com.bradmcevoy.http.PropFindableResource#getCreateDate()
*/
public Date getCreateDate() {
return new Date();
}
public String getName() {
return "system";
}
public int compareTo(Object o) {
// TODO Auto-generated method stub
return 0;
}
public LockResult lock(LockTimeout timeout, LockInfo lockInfo) {
return dotDavHelper.lock(timeout, lockInfo, getUniqueId());
// return dotDavHelper.lock(lockInfo, user, file.getIdentifier() + "");
}
public LockResult refreshLock(String token) {
return dotDavHelper.refreshLock(getUniqueId());
// return dotDavHelper.refreshLock(token);
}
public void unlock(String tokenId) {
dotDavHelper.unlock(getUniqueId());
// dotDavHelper.unlock(tokenId);
}
public LockToken getCurrentLock() {
return dotDavHelper.getCurrentLock(getUniqueId());
}
public Long getMaxAgeSeconds(Auth arg0) {
// TODO Auto-generated method stub
return null;
}
public LockToken createAndLock(String name, LockTimeout timeout, LockInfo lockInfo)
throws NotAuthorizedException {
createCollection(name);
return lock(timeout, lockInfo).getLockToken();
}
}