- added a few more mime-types when attempting to identify mime-type from the file...
[pithos] / src / gr / ebs / gss / server / Login.java
index f9c6b51..cf9fe7a 100644 (file)
@@ -79,6 +79,11 @@ public class Login extends HttpServlet {
        private static final char COOKIE_SEPARATOR = '|';
 
        /**
+        * The name of the the webdav cookie.
+        */
+       public static final String WEBDAV_COOKIE = "_gss_wd";
+
+       /**
         * The logger.
         */
        private static Log logger = LogFactory.getLog(Login.class);
@@ -138,6 +143,9 @@ public class Login extends HttpServlet {
                Object snAttr = request.getAttribute("HTTP_SHIB_PERSON_SURNAME"); // Multi-valued
                Object mailAttr = request.getAttribute("HTTP_SHIB_INETORGPERSON_MAIL"); // Multi-valued
                Object userclassAttr = request.getAttribute("HTTP_SHIB_EP_UNSCOPEDAFFILIATION"); // Multi-valued
+               // Use a configured test username if found, as a shortcut for development deployments.
+               if (getConfiguration().getString("testUsername") != null)
+                       usernameAttr = getConfiguration().getString("testUsername");
                if (usernameAttr == null) {
                        String authErrorUrl = "authenticationError.jsp";
                        authErrorUrl += "?name=" + (nameAttr==null? "-": nameAttr.toString());
@@ -190,10 +198,25 @@ public class Login extends HttpServlet {
                                return;
                        }
                        // Update the user name and e-mail if modified.
-                       if (!user.getName().equals(name) || !user.getEmail().equals(mail))
-                               user = getService().updateUser(username, name, mail);
+                       boolean update = false;
+                       if (!user.getName().equals(name)) {
+                               user.setName(name);
+                               update = true;
+                       }
+                       if (!user.getEmail().equals(mail)) {
+                               user.setEmail(mail);
+                               update = true;
+                       }
                        if (user.getAuthToken() == null)
                                user = getService().updateUserToken(user.getId());
+                       // Set WebDAV password to token if it's never been set.
+                       if (user.getWebDAVPassword()==null || user.getWebDAVPassword().length()==0) {
+                               String tokenEncoded = new String(Base64.encodeBase64(user.getAuthToken()), "US-ASCII");
+                               user.setWebDAVPassword(tokenEncoded);
+                               update = true;
+                       }
+                       if (update)
+                               getService().updateUser(user);
                } catch (RpcException e) {
                        String error = "An error occurred while communicating with the service";
                        logger.error(error, e);
@@ -224,6 +247,11 @@ public class Login extends HttpServlet {
                        cookie.setDomain(domain);
                        cookie.setPath(path);
                    response.addCookie(cookie);
+                   cookie = new Cookie(WEBDAV_COOKIE, user.getWebDAVPassword());
+                       cookie.setMaxAge(-1);
+                       cookie.setDomain(domain);
+                       cookie.setPath(path);
+                   response.addCookie(cookie);
                    response.sendRedirect(nextUrl);
                } else if (nonce != null) {
                        nonce = URLEncoder.encode(nonce, "US-ASCII");