Author: ito
Date: Tue Jan 25 10:19:53 2011
New Revision: 1063206

URL: http://svn.apache.org/viewvc?rev=1063206&view=rev
Log:
CLEREZZA-393: add permission to access logging manager

Added:
    
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.logging/core/src/main/java/org/apache/clerezza/platform/logging/LoggingManagerAccessPermission.java
Modified:
    
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.logging/core/src/main/java/org/apache/clerezza/platform/logging/LoggingManager.java

Modified: 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.logging/core/src/main/java/org/apache/clerezza/platform/logging/LoggingManager.java
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.logging/core/src/main/java/org/apache/clerezza/platform/logging/LoggingManager.java?rev=1063206&r1=1063205&r2=1063206&view=diff
==============================================================================
--- 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.logging/core/src/main/java/org/apache/clerezza/platform/logging/LoggingManager.java
 (original)
+++ 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.logging/core/src/main/java/org/apache/clerezza/platform/logging/LoggingManager.java
 Tue Jan 25 10:19:53 2011
@@ -16,16 +16,16 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-
 package org.apache.clerezza.platform.logging;
 
 import java.io.IOException;
 import java.io.StringReader;
 import java.io.StringWriter;
 import java.net.URISyntaxException;
+import java.security.AccessControlException;
+import java.security.AccessController;
 import java.util.Dictionary;
 import java.util.Enumeration;
-import java.util.Hashtable;
 import java.util.HashSet;
 import java.util.Properties;
 import java.util.Set;
@@ -42,7 +42,6 @@ import org.apache.clerezza.jaxrs.utils.T
 import org.apache.clerezza.platform.dashboard.GlobalMenuItem;
 import org.apache.clerezza.platform.dashboard.GlobalMenuItemsProvider;
 import org.apache.clerezza.platform.logging.ontologies.LOGGING;
-import org.apache.clerezza.platform.graphprovider.content.ContentGraphProvider;
 import org.apache.clerezza.platform.typerendering.RenderletManager;
 import 
org.apache.clerezza.platform.typerendering.scalaserverpages.ScalaServerPagesRenderlet;
 import org.apache.clerezza.rdf.core.BNode;
@@ -61,56 +60,57 @@ import org.osgi.service.cm.Configuration
 import org.osgi.service.cm.ConfigurationAdmin;
 import org.osgi.service.component.ComponentContext;
 
-
-
 @Component
 @Services({
-       @Service(value=Object.class),
-       @Service(value=GlobalMenuItemsProvider.class)
+       @Service(value = Object.class),
+       @Service(value = GlobalMenuItemsProvider.class)
 })
-@Property(name="javax.ws.rs", boolValue=true)
+@Property(name = "javax.ws.rs", boolValue = true)
 @Path("admin/logging")
 public class LoggingManager implements GlobalMenuItemsProvider {
 
        @Reference
        private RenderletManager renderletManager;
-
        @Reference
        private ConfigurationAdmin configurationAdmin;
-
        private String paxLoggingLocation = null;
-       public void activate(ComponentContext context) throws 
URISyntaxException, IOException {
+
+       public void activate(ComponentContext context)
+                       throws URISyntaxException, IOException {
                
renderletManager.registerRenderlet(ScalaServerPagesRenderlet.class.getName(),
                                new UriRef(getClass().getResource(
                                "config-page-naked.ssp").toURI().toString()),
                                LOGGING.LoggingConfigPage, "naked",
                                MediaType.APPLICATION_XHTML_XML_TYPE, true);
-               
+
                for (Bundle bundle : context.getBundleContext().getBundles()) {
                        if 
(bundle.getSymbolicName().equals("org.ops4j.pax.logging.pax-logging-service")) {
                                paxLoggingLocation = bundle.getLocation();
                                break;
                        }
                }
-               
+
        }
 
-       private void setProperties(Dictionary props) throws IOException {
+       private void setProperties(Dictionary props)
+                       throws IOException {
                Configuration config = getServiceConfig();
                config.update(props);
        }
 
        /*private void setProperties(Hashtable properties) {
-               setProperties
+       setProperties
        }*/
-
-       private Configuration getServiceConfig() throws IOException {
+       private Configuration getServiceConfig()
+                       throws IOException {
                Configuration config = 
configurationAdmin.getConfiguration("org.ops4j.pax.logging", 
paxLoggingLocation);
                return config;
        }
 
        @GET
-       public GraphNode entry(@Context UriInfo uriInfo) throws IOException {
+       public GraphNode entry(@Context UriInfo uriInfo)
+                       throws IOException {
+               AccessController.checkPermission(new 
LoggingManagerAccessPermission());
                TrailingSlash.enforcePresent(uriInfo);
                SimpleMGraph resultMGraph = new SimpleMGraph();
                GraphNode result = new GraphNode(new BNode(), resultMGraph);
@@ -120,7 +120,8 @@ public class LoggingManager implements G
                return result;
        }
 
-       private String getPropertiesAsString() throws IOException {
+       private String getPropertiesAsString()
+                       throws IOException {
                Configuration config = getServiceConfig();
                Properties properties = new Properties();
                Dictionary propertyDictionary = config.getProperties();
@@ -134,11 +135,12 @@ public class LoggingManager implements G
                return stringWriter.toString();
        }
 
-
        @POST
        @Path("setConfiguration")
        public Response setConfiguration(@Context UriInfo uriInfo,
-                       @FormParam("configuration") String configuration) 
throws IOException {
+                       @FormParam("configuration") String configuration)
+                       throws IOException {
+               AccessController.checkPermission(new 
LoggingManagerAccessPermission());
                Properties properties = new Properties();
                properties.load(new StringReader(configuration));
                setProperties(properties);
@@ -146,18 +148,16 @@ public class LoggingManager implements G
        }
 
        @Override
-    public Set<GlobalMenuItem> getMenuItems() {
-        Set<GlobalMenuItem> items = new HashSet<GlobalMenuItem>();
-
-        items.add(new GlobalMenuItem("/admin/logging", "Logging", "Logging", 3,
-                "Administration"));
-
-
-        return items;
-
-
-    }
-
-
+       public Set<GlobalMenuItem> getMenuItems() {
+               Set<GlobalMenuItem> items = new HashSet<GlobalMenuItem>();
+               try {
+                       AccessController.checkPermission(new 
LoggingManagerAccessPermission());
+               } catch (AccessControlException e) {
+                       return items;
+               }
+               items.add(new GlobalMenuItem("/admin/logging", "Logging", 
"Logging", 3,
+                               "Administration"));
+               return items;
 
-}
\ No newline at end of file
+       }
+}

Added: 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.logging/core/src/main/java/org/apache/clerezza/platform/logging/LoggingManagerAccessPermission.java
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.logging/core/src/main/java/org/apache/clerezza/platform/logging/LoggingManagerAccessPermission.java?rev=1063206&view=auto
==============================================================================
--- 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.logging/core/src/main/java/org/apache/clerezza/platform/logging/LoggingManagerAccessPermission.java
 (added)
+++ 
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.logging/core/src/main/java/org/apache/clerezza/platform/logging/LoggingManagerAccessPermission.java
 Tue Jan 25 10:19:53 2011
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.clerezza.platform.logging;
+
+import java.security.Permission;
+import org.apache.clerezza.permissiondescriptions.PermissionInfo;
+
+/**
+ * Grants access to the logging manager. Additionally the user needs 
permission to
+ * update the configuration via ConfigurationAdmin.
+ *
+ *
+ * @author tio
+ */
+@PermissionInfo(value="Logging Manager Access Permission", description="Grants 
access " +
+       "to the logging manager.")
+public class LoggingManagerAccessPermission extends Permission {
+
+       public LoggingManagerAccessPermission() {
+               super("LoggingMangerAccess");
+       }
+
+       public LoggingManagerAccessPermission(String name, String actions) {
+               super("LoggingMangerAccess");
+       }
+
+       @Override
+       public boolean implies(Permission permission) {
+               return (permission instanceof LoggingManagerAccessPermission);
+       }
+
+       @Override
+       public boolean equals(Object obj) {
+               if (obj == null) {
+                       return false;
+               }
+               if (getClass() != obj.getClass()) {
+                       return false;
+               }
+               return true;
+       }
+
+       @Override
+       public String getActions() {
+               return "";
+       }
+
+       @Override
+       public int hashCode() {
+               int hash = 13;
+               hash = 101 * hash + "LoggingMangerAccess".hashCode();
+               return hash;
+       }
+}


Reply via email to