Some more fixes on Issue 16 - handling a CastException. Also working Issue 14 - when...
authorNatasa Kapravelou <akapravelou@gmail.com>
Tue, 14 Sep 2010 15:17:04 +0000 (18:17 +0300)
committerNatasa Kapravelou <akapravelou@gmail.com>
Tue, 14 Sep 2010 15:17:04 +0000 (18:17 +0300)
src/gr/ebs/gss/client/commands/GetUserCommand.java
src/gr/ebs/gss/client/commands/PropertiesCommand.java
src/gr/ebs/gss/server/rest/FilesHandler.java
src/gr/ebs/gss/server/webdav/Webdav.java

index 7c0cb8e..dcfe6a4 100644 (file)
@@ -54,6 +54,7 @@ public class GetUserCommand implements Command{
 
        @Override
        public void execute() {
+               //this generates a java.lang.StringIndexOutOfBoundsException: String index out of range: -1
                String nameOfUserName = userName.substring(0,userName.indexOf("@"));
                String path = GSS.get().getApiPath() + "users/" + URL.encodeComponent(nameOfUserName);
 
@@ -71,7 +72,7 @@ public class GetUserCommand implements Command{
                        @Override
                        public void onError(Throwable t) {
                                GWT.log("", t);
-                               GSS.get().displayError("Unable to user full name from username " + userName);
+                               GSS.get().displayError("Unable to fetch user's full name from the given username " + userName);
                        }
                };
                DeferredCommand.addCommand(gg);
index d0b8079..c4b3fbf 100644 (file)
@@ -64,6 +64,8 @@ public class PropertiesCommand implements Command {
 
        private String userName;
 
+       private boolean isFile = false;
+
        /**
         * @param _containerPanel
         * @param _newImages the images of all the possible delete dialogs
@@ -177,7 +179,7 @@ public class PropertiesCommand implements Command {
 
        private boolean canContinue() {
                String userFullNameFromMap = GSS.get().findUserFullName(userName);
-               if (groups == null || versions == null || userFullNameFromMap == null)
+               if(groups == null || versions == null || isFile && userFullNameFromMap == null)
                        return false;
                return true;
        }
@@ -274,9 +276,13 @@ public class PropertiesCommand implements Command {
        }
 
        private void getOwnerFullName() {
-               FileResource fileResource = (FileResource) GSS.get().getCurrentSelection();
-               userName = fileResource.getOwner();
-               GSS.get().getUserFullName(userName);
+               if(GSS.get().getCurrentSelection() instanceof FileResource){
+                       isFile = true;
+                       FileResource fileResource = (FileResource) GSS.get().getCurrentSelection();
+                       userName = fileResource.getOwner();
+                       GSS.get().getUserFullName(userName);
+
+               }
        }
 
 }
index 166332b..ce4481a 100644 (file)
@@ -195,7 +195,7 @@ public class FilesHandler extends RequestHandler {
                }
        String progress = req.getParameter(PROGRESS_PARAMETER);
 
-       if (logger.isDebugEnabled())
+       if (logger.isDebugEnabled())                    
                        if (content)
                        logger.debug("Serving resource '" +     path + "' headers and data");
                else
@@ -203,7 +203,6 @@ public class FilesHandler extends RequestHandler {
 
        User user = getUser(req);
        User owner = getOwner(req);
-       if (user == null) user = owner;
         boolean exists = true;
         Object resource = null;
         FileHeaderDTO file = null;
@@ -217,33 +216,23 @@ public class FilesHandler extends RequestHandler {
                        return;
                }
 
-       if (!exists) {
-                       if (authDeferred) {
-                               // We do not want to leak information if the request
-                               // was not authenticated.
-                               resp.sendError(HttpServletResponse.SC_FORBIDDEN);
-                               return;
-                       }
-               // A request for upload progress.
-               if (progress != null && content) {
-                       serveProgress(req, resp, progress, user, null);
-                               return;
-               }
-
-               resp.sendError(HttpServletResponse.SC_NOT_FOUND, req.getRequestURI());
+       if (!exists && authDeferred) {
+               // We do not want to leak information if the request
+               // was not authenticated.
+               resp.sendError(HttpServletResponse.SC_FORBIDDEN);
                return;
        }
 
        if (resource instanceof FolderDTO)
                folder = (FolderDTO) resource;
        else
-               file = (FileHeaderDTO) resource;
+               file = (FileHeaderDTO) resource;        // Note that file will be null, if (!exists).
 
        // Now it's time to perform the deferred authentication check.
                // Since regular signature checking was already performed,
                // we need to check the read-all flag or the signature-in-parameters.
                if (authDeferred)
-                       if (file != null && !file.isReadForAll() && content) {
+                       if (file != null && !file.isReadForAll() && content) {                          
                                // Check for GET with the signature in the request parameters.
                                String auth = req.getParameter(AUTHORIZATION_PARAMETER);
                                String dateParam = req.getParameter(DATE_PARAMETER);
@@ -337,8 +326,21 @@ public class FilesHandler extends RequestHandler {
                                        return;
                                }
                                }
-                       } else if (file != null && !file.isReadForAll() || folder != null && !folder.isReadForAll()) {
-                               // Check for a read-for-all file request.
+                       } else if (user == null) {
+                               if (file != null && file.isReadForAll()){                                       
+                                       // For a read-for-all file request, pretend the owner is making it.
+                                       user = owner;
+                                       req.setAttribute(USER_ATTRIBUTE, user);
+                               }else if(folder != null && folder.isReadForAll()){
+                                       // For a read-for-all folder request, pretend the owner is making it.
+                                       user = owner;
+                                       req.setAttribute(USER_ATTRIBUTE, user);
+                               }
+                               else{
+                                       resp.sendError(HttpServletResponse.SC_FORBIDDEN);
+                                       return;
+                               }
+                       }else{
                                resp.sendError(HttpServletResponse.SC_FORBIDDEN);
                                return;
                        }
@@ -358,8 +360,8 @@ public class FilesHandler extends RequestHandler {
        // A request for upload progress.
        if (progress != null && content) {
                if (file == null) {
-                       resp.sendError(HttpServletResponse.SC_BAD_REQUEST);
-                       return;
+                       resp.sendError(HttpServletResponse.SC_NOT_FOUND, req.getRequestURI());
+                       return;
                }
                serveProgress(req, resp, progress, user, file);
                        return;
@@ -476,10 +478,7 @@ public class FilesHandler extends RequestHandler {
                                else
                                        throw e;
                }
-       if (folder != null
-                               || (ranges == null || ranges.isEmpty())
-                                                       && req.getHeader("Range") == null
-                                                       || ranges == FULL) {
+       if (folder != null || (ranges == null || ranges.isEmpty()) && req.getHeader("Range") == null || ranges == FULL) {
                // Set the appropriate output headers
                if (contentType != null) {
                        if (logger.isDebugEnabled())
index c614ca7..1b29beb 100644 (file)
@@ -2311,9 +2311,6 @@ public class Webdav extends HttpServlet {
                IOException exception = null;
                InputStream resourceInputStream = null;
                User user = getUser(req);
-               // Files open for all will not have specified a calling user in the request.
-               if (user == null)
-                       user = getOwner(req);
                if (user == null)
                        throw new ObjectNotFoundException("No user or owner specified");
                if (file != null)
@@ -2381,7 +2378,7 @@ public class Webdav extends HttpServlet {
                                HttpServletRequest req, FileBodyDTO oldBody) throws IOException,
                                ObjectNotFoundException, InsufficientPermissionsException, RpcException {
                IOException exception = null;
-
+               
                User user = getUser(req);
                InputStream resourceInputStream = null;
                if (file != null)
@@ -2587,8 +2584,6 @@ public class Webdav extends HttpServlet {
                                ObjectNotFoundException, InsufficientPermissionsException, RpcException {
                IOException exception = null;
                User user = getUser(req);
-               if (user == null)
-                       user = getOwner(req);
                InputStream resourceInputStream = oldBody == null ?
                                        getService().getFileContents(user.getId(), file.getId()) :
                                        getService().getFileContents(user.getId(), file.getId(), oldBody.getId());