portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r377037 - in /portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed: decoration/DecoratorAction.java decoration/PageActionAccess.java velocity/DecoratorAction.java velocity/PageActionAccess.java
Date Sat, 11 Feb 2006 20:04:30 GMT
Author: ate
Date: Sat Feb 11 12:04:28 2006
New Revision: 377037

URL: http://svn.apache.org/viewcvs?rev=377037&view=rev
Log:
Enhancing PageActionAccess with the new Page "edit" state component interface.
Also moving it together with the related DecoratorAction class to the decoration package.
See http://issues.apache.org/jira/browse/JS2-468.

Added:
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/decoration/DecoratorAction.java
  (contents, props changed)
      - copied, changed from r375241, portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/velocity/DecoratorAction.java
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/decoration/PageActionAccess.java
  (with props)
Removed:
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/velocity/DecoratorAction.java
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/velocity/PageActionAccess.java

Copied: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/decoration/DecoratorAction.java
(from r375241, portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/velocity/DecoratorAction.java)
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/decoration/DecoratorAction.java?p2=portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/decoration/DecoratorAction.java&p1=portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/velocity/DecoratorAction.java&r1=375241&r2=377037&rev=377037&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/velocity/DecoratorAction.java
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/decoration/DecoratorAction.java
Sat Feb 11 12:04:28 2006
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jetspeed.velocity;
+package org.apache.jetspeed.decoration;
 
 import java.io.Serializable;
 

Propchange: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/decoration/DecoratorAction.java
------------------------------------------------------------------------------
    cvs2svn:cvs-rev = 1.2

Propchange: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/decoration/DecoratorAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/decoration/DecoratorAction.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/decoration/PageActionAccess.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/decoration/PageActionAccess.java?rev=377037&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/decoration/PageActionAccess.java
(added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/decoration/PageActionAccess.java
Sat Feb 11 12:04:28 2006
@@ -0,0 +1,186 @@
+/*
+ * Copyright 2000-2001,2004 The Apache Software Foundation.
+ * 
+ * Licensed 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.jetspeed.decoration;
+
+import java.io.Serializable;
+import java.security.AccessControlException;
+import java.security.AccessController;
+import java.util.HashMap;
+
+import javax.portlet.PortletMode;
+import javax.portlet.WindowState;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jetspeed.JetspeedActions;
+import org.apache.jetspeed.om.page.Page;
+import org.apache.jetspeed.security.PortletPermission;
+
+/**
+ * PageActionAccess
+ *
+ * @author <a href="mailto:ate@douma.nu">Ate Douma</a>
+ * @version $Id$
+ */
+public class PageActionAccess implements PageEditAccess, Serializable
+{
+    protected static final Log log = LogFactory.getLog(PageActionAccess.class);
+
+    private static final class ActionAccess implements Serializable
+    {
+        int checkedFlags;
+        int actionFlags;
+    }
+    
+    private boolean anonymous;
+    private boolean editAllowed;
+    private boolean editing;
+    private HashMap fragmentActionAccess;
+    
+    public PageActionAccess(boolean anonymous, Page page)
+    {
+        this.anonymous = anonymous;        
+        this.editAllowed = checkEditPage(page);
+        this.fragmentActionAccess = new HashMap();
+    }
+    
+    public void checkReset(boolean anonymous, Page page)
+    {
+        if (this.anonymous != anonymous)
+        {
+            this.anonymous = anonymous;
+            this.editAllowed = checkEditPage(page);
+            this.fragmentActionAccess.clear();
+            this.editing = false;
+        }
+    }
+    
+    public boolean isAnonymous()
+    {
+        return anonymous;
+    }
+    
+    public boolean isEditAllowed()
+    {
+        return editAllowed;
+    }
+    
+    public boolean isEditing()
+    {
+        return editing;
+    }
+    
+    public void setEditing(boolean editing)
+    {
+        if ( editing && ! editAllowed )
+        {
+            throw new SecurityException();
+        }
+        this.editing = editing;
+    }
+    
+    public boolean checkPortletMode(String fragmentId, String portletName, PortletMode mode)
+    {
+        return checkActionAccess(fragmentId, portletName, mode.toString());
+    }
+
+    public boolean checkWindowState(String fragmentId, String portletName, WindowState state)
+    {
+        return checkActionAccess(fragmentId, portletName, state.toString());
+    }
+    
+    protected synchronized boolean checkActionAccess(String fragmentId, String portletName,
String action)
+    {
+        try
+        {
+            int actionIndex = getActionMask(action);
+            ActionAccess actionAccess = (ActionAccess)fragmentActionAccess.get(fragmentId);
+            if ( actionAccess == null )
+            {
+                actionAccess = new ActionAccess();
+                fragmentActionAccess.put(fragmentId, actionAccess);
+            }
+            if ( (actionAccess.checkedFlags & actionIndex) != actionIndex )
+            {
+                // TODO: not handling PortletPermission checks yet 
+                // boolean access = checkPermission(portletName, action);
+                boolean access = true;
+
+                if ( access )
+                {
+                    actionAccess.actionFlags |= actionIndex;
+                }
+                actionAccess.checkedFlags |= actionIndex;            
+            }
+            return ((actionAccess.actionFlags & actionIndex) == actionIndex);
+        }
+        catch (IndexOutOfBoundsException e)
+        {
+            log.error("Unknown action: "+action, e);
+            return false;
+        }
+    }
+    
+    /**
+     * Determines whether the access request indicated by the specified
+     * permission should be allowed or denied, based on the security policy
+     * currently in effect.
+     * 
+     * @param resource
+     *                  The fully qualified resource name of the portlet
+     *                  (PA::portletName)
+     * @param action
+     *                  The action to perform on this resource (i.e. view, edit, help,
+     *                  max, min...)
+     * @return true if the action is allowed, false if it is not
+     */
+    protected boolean checkPermission( String resource, String action )
+    {
+        try
+        {
+            // TODO: it may be better to check the PagePermission for the outer
+            // most
+            // fragment (i.e. the PSML page)
+            AccessController.checkPermission(new PortletPermission(resource, action));
+        }
+        catch (AccessControlException e)
+        {
+            return false;
+        }
+        return true;
+    }
+    
+    protected boolean checkEditPage(Page page)
+    {
+        boolean allowed = false;
+        try
+        {
+            page.checkAccess(JetspeedActions.EDIT);
+            allowed = true;
+        }       
+        catch (SecurityException se) {}
+        return allowed;
+    }
+
+    protected int getActionMask(String action)
+    throws IndexOutOfBoundsException
+    {
+        int i = 0;
+        // will throw IndexOutOfBoundsExceptions on unknown action
+        while ( !JetspeedActions.ACTIONS[i++].equals(action) ) ;
+        return 1<<i;
+    }
+}

Propchange: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/decoration/PageActionAccess.java
------------------------------------------------------------------------------
    cvs2svn:cvs-rev = 1.1

Propchange: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/decoration/PageActionAccess.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/decoration/PageActionAccess.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message