Author: chathura
Date: Tue Jan 29 00:16:56 2008
New Revision: 13110

Log:


Formatted date.
Gave permissions for system collection only to system and admins.



Modified:
   
branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/servlet/RegistryServlet.java
   
branches/registry/1_0/modules/webapps/src/main/java/org/wso2/registry/web/utils/CommonUtil.java

Modified: 
branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/servlet/RegistryServlet.java
==============================================================================
--- 
branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/servlet/RegistryServlet.java
     (original)
+++ 
branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/servlet/RegistryServlet.java
     Tue Jan 29 00:16:56 2008
@@ -21,10 +21,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.wso2.registry.Registry;
-import org.wso2.registry.RegistryConstants;
-import org.wso2.registry.RegistryException;
-import org.wso2.registry.Resource;
+import org.wso2.registry.*;
 import org.wso2.registry.config.DataBaseConfiguration;
 import org.wso2.registry.config.RegistryConfigurationProcessor;
 import org.wso2.registry.config.RegistryContext;
@@ -36,6 +33,9 @@
 import org.wso2.registry.jdbc.utils.RegistryDataSource;
 import org.wso2.registry.secure.SecureRegistry;
 import org.wso2.registry.servlet.utils.Utils;
+import org.wso2.usermanager.AccessControlAdmin;
+import org.wso2.usermanager.UserManagerException;
+import org.wso2.usermanager.UserManagerConstants;
 
 import javax.naming.Context;
 import javax.naming.InitialContext;
@@ -125,6 +125,45 @@
                                                                coreRegistry,
                                                                registryRealm);
 
+            // create system resources
+            Resource systemCollection = new Resource();
+            systemCollection.setDirectory(true);
+            String systemDesc = "This collection is used to store system data 
of the " +
+                    "WSO2 Registry server. User nor the admins of the registry 
are not expected " +
+                    "to edit any content of this collection. Changing content 
of this collection " +
+                    "may result in unexpected behaviors.";
+            systemCollection.setDescription(systemDesc);
+            systemRegistry.put("/system", systemCollection);
+
+            try {
+                AccessControlAdmin ac = registryRealm.getAccessControlAdmin();
+                ac.clearRoleAuthorization(
+                        RegistryConstants.EVERYONE_ROLE, "/system", 
ActionConstants.GET);
+
+                ac.authorizeUser(RegistryConstants.SYSTEM_USER, "/system", 
ActionConstants.GET);
+                ac.authorizeUser(RegistryConstants.SYSTEM_USER, "/system", 
ActionConstants.PUT);
+                ac.authorizeUser(RegistryConstants.SYSTEM_USER, "/system", 
ActionConstants.DELETE);
+                ac.authorizeUser(
+                        RegistryConstants.SYSTEM_USER, "/system", 
UserManagerConstants.AUTHORIZE);
+
+                ac.authorizeUser(RegistryConstants.ADMIN_USER, "/system", 
ActionConstants.GET);
+                ac.authorizeUser(RegistryConstants.ADMIN_USER, "/system", 
ActionConstants.PUT);
+                ac.authorizeUser(RegistryConstants.ADMIN_USER, "/system", 
ActionConstants.DELETE);
+                ac.authorizeUser(
+                        RegistryConstants.ADMIN_USER, "/system", 
UserManagerConstants.AUTHORIZE);
+
+                ac.authorizeRole(RegistryConstants.ADMIN_ROLE, "/system", 
ActionConstants.GET);
+                ac.authorizeRole(RegistryConstants.ADMIN_ROLE, "/system", 
ActionConstants.PUT);
+                ac.authorizeRole(RegistryConstants.ADMIN_ROLE, "/system", 
ActionConstants.DELETE);
+                ac.authorizeRole(
+                        RegistryConstants.ADMIN_ROLE, "/system", 
UserManagerConstants.AUTHORIZE);
+
+            } catch (UserManagerException e) {
+                String msg = "Failed to set permissions for the system 
collection.";
+                log.fatal(msg, e);
+                throw new RegistryException(msg, e);
+            }
+
             // todo: we should make this decision according to the 
registry.xml or web.xml config
             //try {
             //    RemoteRegistry remote = new RemoteRegistry(new 
URL("http://localhost:8080/wso2registry/atom";));

Modified: 
branches/registry/1_0/modules/webapps/src/main/java/org/wso2/registry/web/utils/CommonUtil.java
==============================================================================
--- 
branches/registry/1_0/modules/webapps/src/main/java/org/wso2/registry/web/utils/CommonUtil.java
     (original)
+++ 
branches/registry/1_0/modules/webapps/src/main/java/org/wso2/registry/web/utils/CommonUtil.java
     Tue Jan 29 00:16:56 2008
@@ -27,10 +27,19 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.ServletContext;
 import java.util.Date;
+import java.util.Calendar;
 import java.text.DateFormat;
+import java.text.SimpleDateFormat;
 
 public class CommonUtil {
 
+    /**
+     * Constants used for formatting dates.
+     */
+    private static final long ONEMINUTE = 60 * 1000;
+    private static final long ONEHOUR = 60 * ONEMINUTE;
+    private static final long ONEDAY = 24 * ONEHOUR;
+
     public static SecureRegistry getUserRegistry(HttpServletRequest request)
             throws RegistryException {
 
@@ -66,7 +75,33 @@
         request.getSession().invalidate();
     }
 
-    public static String formatDate(Date date) {
-        return DateFormat.getDateTimeInstance(DateFormat.LONG, 
DateFormat.LONG).format(date);
+    public static String formatDate(Date dateToParse) {
+        
+        Calendar now = Calendar.getInstance();
+        Calendar date = Calendar.getInstance();
+        date.setTime(dateToParse);
+
+        String value = "";
+        if (now.getTimeInMillis() - date.getTimeInMillis() < ONEDAY) {
+            long hours = 0;
+            if (now.getTimeInMillis() - date.getTimeInMillis() > ONEHOUR) {
+                hours = ((now.getTimeInMillis() - date.getTimeInMillis()) / 
ONEHOUR);
+                value += hours + "h ";
+            }
+            if (hours < 6) {
+                long minutes = ((now.getTimeInMillis() - 
date.getTimeInMillis()) / ONEMINUTE);
+                value += (minutes - hours * 60) + "m ";
+            }
+            value += "ago";
+        } else {
+            SimpleDateFormat formatter = new SimpleDateFormat("dd MMM");
+            value = formatter.format(dateToParse);
+
+            if (date.get(Calendar.YEAR) != now.get(Calendar.YEAR)) {
+                formatter = new SimpleDateFormat("yyyy");
+                value += " " + formatter.format(dateToParse);
+            }
+        }
+        return value;
     }
 }

_______________________________________________
Registry-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/registry-dev

Reply via email to