You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by at...@apache.org on 2008/09/04 13:27:04 UTC

svn commit: r691972 - in /portals/jetspeed-2/portal/branches/security-refactoring: components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/ jetspeed-api/src/main/java/org/apache/jetspeed/security/

Author: ate
Date: Thu Sep  4 04:27:02 2008
New Revision: 691972

URL: http://svn.apache.org/viewvc?rev=691972&view=rev
Log:
Adding transient JetspeedPrincipal instances support which are needed for:
- finding principals by example (needing a transient principal which is fully modifiable)
- fully external authentication and authorization providers allowing to create a Subject for an authenticated user without Jetspeed security authorization backend

Added:
    portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/PersistentJetspeedPrincipal.java   (contents, props changed)
      - copied, changed from r691921, portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/BaseJetspeedPrincipal.java
    portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/TransientJetspeedPrincipal.java   (with props)
Removed:
    portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/BaseJetspeedPrincipal.java
Modified:
    portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/GroupImpl.java
    portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/RoleImpl.java
    portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/SecurityAttributeImpl.java
    portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/SecurityAttributesImpl.java
    portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/UserImpl.java
    portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/JetspeedPrincipal.java
    portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/JetspeedPrincipalManager.java

Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/GroupImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/GroupImpl.java?rev=691972&r1=691971&r2=691972&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/GroupImpl.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/GroupImpl.java Thu Sep  4 04:27:02 2008
@@ -22,7 +22,7 @@
  * <p>Represents a security 'group' extending BaseJetspeedPrincipal.</p>
  * @version $Id$
  */
-public class GroupImpl extends BaseJetspeedPrincipal implements Group
+public class GroupImpl extends PersistentJetspeedPrincipal implements Group
 {
     private static final long serialVersionUID = 5484179899807809619L;
 

Copied: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/PersistentJetspeedPrincipal.java (from r691921, portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/BaseJetspeedPrincipal.java)
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/PersistentJetspeedPrincipal.java?p2=portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/PersistentJetspeedPrincipal.java&p1=portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/BaseJetspeedPrincipal.java&r1=691921&r2=691972&rev=691972&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/BaseJetspeedPrincipal.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/PersistentJetspeedPrincipal.java Thu Sep  4 04:27:02 2008
@@ -23,9 +23,6 @@
 import java.util.Collection;
 import java.util.Map;
 
-import org.apache.jetspeed.security.JetspeedPrincipal;
-import org.apache.jetspeed.security.JetspeedPrincipalManagerProvider;
-import org.apache.jetspeed.security.JetspeedPrincipalType;
 import org.apache.jetspeed.security.PrincipalReadOnlyException;
 import org.apache.jetspeed.security.SecurityAttributes;
 import org.apache.ojb.broker.PersistenceBroker;
@@ -36,14 +33,9 @@
  * @version $Id$
  *
  */
-public abstract class BaseJetspeedPrincipal implements JetspeedPrincipal, PersistenceBrokerAware, Serializable
+public abstract class PersistentJetspeedPrincipal extends TransientJetspeedPrincipal implements PersistenceBrokerAware, Serializable
 {
-    private static final long serialVersionUID = 5484179899807809619L;
-    
-    private static JetspeedPrincipalManagerProvider jpmp;
-    
     private Long id;
-    private String name;    
     private Timestamp creationDate;
     private Timestamp modifiedDate;
     private boolean enabled = true;
@@ -51,18 +43,11 @@
     private boolean readOnly;
     private boolean removable = true;
     private boolean extendable = true;
+
     @SuppressWarnings("unchecked")
-    private Collection attributeValues;
+    protected Collection attributeValues;
     
-    private transient JetspeedPrincipalType jpt;
-    private transient SecurityAttributes attributes;
-    
-    public static void setJetspeedPrincipalManagerProvider(JetspeedPrincipalManagerProvider jpmp)
-    {
-        BaseJetspeedPrincipal.jpmp = jpmp;
-    }
-    
-    public BaseJetspeedPrincipal()
+    public PersistentJetspeedPrincipal()
     {   
     }
     
@@ -71,25 +56,11 @@
         return id;
     }
 
-    public String getName()
-    {
-        return name;
-    }
-    
     public void setName(String name)
     {
         this.name = name;
     }
 
-    public synchronized JetspeedPrincipalType getType()
-    {
-        if (jpt == null)
-        {
-            jpt = jpmp.getPrincipalTypeByClassName(getClass().getName());
-        }
-        return jpt;
-    }
-
     public Timestamp getCreationDate()
     {
         return creationDate;
@@ -114,6 +85,11 @@
         this.enabled = enabled;
     }
     
+    public boolean isTransient()
+    {
+        return false;
+    }
+    
     public boolean isMapped()
     {
         return mapped;
@@ -154,12 +130,6 @@
         this.extendable = extendable;
     }
     
-    public synchronized void setAttributeValues(Collection<SecurityAttributeValue> attributeValues)
-    {
-        this.attributeValues = attributeValues;
-        this.attributes = null;
-    }
-    
     public synchronized SecurityAttributes getSecurityAttributes()
     {
         if (attributes == null)

Propchange: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/PersistentJetspeedPrincipal.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/PersistentJetspeedPrincipal.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/PersistentJetspeedPrincipal.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/RoleImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/RoleImpl.java?rev=691972&r1=691971&r2=691972&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/RoleImpl.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/RoleImpl.java Thu Sep  4 04:27:02 2008
@@ -22,7 +22,7 @@
  * <p>Represents a security 'role' extending BaseJetspeedPrincipal.</p>
  * @version $Id$
  */
-public class RoleImpl extends BaseJetspeedPrincipal implements Role
+public class RoleImpl extends PersistentJetspeedPrincipal implements Role
 {
     private static final long serialVersionUID = 5484179899807809619L;
 

Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/SecurityAttributeImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/SecurityAttributeImpl.java?rev=691972&r1=691971&r2=691972&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/SecurityAttributeImpl.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/SecurityAttributeImpl.java Thu Sep  4 04:27:02 2008
@@ -27,11 +27,13 @@
 {
     private SecurityAttributeType type;
     private SecurityAttributeValue value;
+    private boolean persistent;
     
-    public SecurityAttributeImpl(SecurityAttributeType type, SecurityAttributeValue value)
+    public SecurityAttributeImpl(SecurityAttributeType type, SecurityAttributeValue value, boolean persistent)
     {
         this.type = type;
         this.value = value;
+        this.persistent = persistent;
     }
     
     public SecurityAttributeValue getSecurityAttributeValue()
@@ -66,12 +68,12 @@
 
     public boolean isReadOnly()
     {
-        return type.isReadOnly();
+        return persistent ? type.isReadOnly() : false;
     }
 
     public boolean isRequired()
     {
-        return type.isRequired();
+        return persistent ? type.isRequired() : false;
     }
 
     public boolean isRegistered()

Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/SecurityAttributesImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/SecurityAttributesImpl.java?rev=691972&r1=691971&r2=691972&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/SecurityAttributesImpl.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/SecurityAttributesImpl.java Thu Sep  4 04:27:02 2008
@@ -17,6 +17,7 @@
 
 package org.apache.jetspeed.security.impl;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -52,14 +53,30 @@
     private Collection avColl;
     private boolean readOnly;
     private boolean extendable;
+    private boolean persistent;
     
     private HashMap<String, SecurityAttributeImpl> saMap = new HashMap<String, SecurityAttributeImpl>();
     
     @SuppressWarnings("unchecked")
+    public SecurityAttributesImpl(JetspeedPrincipal jp)
+    {
+        this.jp = jp;
+        if (!jp.isTransient())
+        {
+            throw new IllegalArgumentException("Provided JetspeedPrincipal is not transient");
+        }
+        this.avColl =  new ArrayList<SecurityAttributeValue>();
+        this.persistent = false;
+        this.readOnly = false;
+        this.extendable = false;
+    }
+
+    @SuppressWarnings("unchecked")
     public SecurityAttributesImpl(JetspeedPrincipal jp, Collection avColl, boolean readOnly, boolean extendable)
     {
         this.jp = jp;
         this.avColl = avColl;
+        this.persistent = true;
         this.readOnly = jp.getType().getAttributeTypes().isReadOnly() ? true : readOnly;
         this.extendable = jp.getType().getAttributeTypes().isExtendable() ? true : extendable;
         
@@ -68,7 +85,7 @@
         {
             SecurityAttributeValue av = (SecurityAttributeValue)avObj;
             SecurityAttributeType sat = stMap.get(av.getName());
-            saMap.put(av.getName(), new SecurityAttributeImpl(sat != null ? sat : new SecurityAttributeTypeImpl(av.getName()), av));
+            saMap.put(av.getName(), new SecurityAttributeImpl(sat != null ? sat : new SecurityAttributeTypeImpl(av.getName()), av, true));
         }
     }
 
@@ -184,7 +201,7 @@
         
         SecurityAttributeValue value = new SecurityAttributeValue(name);
         avColl.add(value);
-        return saMap.put(name, new SecurityAttributeImpl(sat, value));
+        return saMap.put(name, new SecurityAttributeImpl(sat, value, persistent));
     }
 
     public SecurityAttribute addNewInfoAttribute(String name, DataType type)
@@ -210,7 +227,7 @@
         // TODO: making use of the DataType parameter (now ignored)
         SecurityAttributeValue value = new SecurityAttributeValue(name);
         avColl.add(value);
-        return saMap.put(name, new SecurityAttributeImpl(new SecurityAttributeTypeImpl(name), value));
+        return saMap.put(name, new SecurityAttributeImpl(new SecurityAttributeTypeImpl(name), value, persistent));
     }
 
     public void removeAttribute(String name) throws AttributesReadOnlyException, AttributeReadOnlyException, AttributeRequiredException

Added: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/TransientJetspeedPrincipal.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/TransientJetspeedPrincipal.java?rev=691972&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/TransientJetspeedPrincipal.java (added)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/TransientJetspeedPrincipal.java Thu Sep  4 04:27:02 2008
@@ -0,0 +1,154 @@
+/*
+ * 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.jetspeed.security.impl;
+
+import java.io.Serializable;
+import java.sql.Timestamp;
+import java.util.Map;
+
+import org.apache.jetspeed.security.JetspeedPrincipal;
+import org.apache.jetspeed.security.JetspeedPrincipalManagerProvider;
+import org.apache.jetspeed.security.JetspeedPrincipalType;
+import org.apache.jetspeed.security.PrincipalReadOnlyException;
+import org.apache.jetspeed.security.SecurityAttributes;
+
+/**
+ * @$
+ *
+ */
+public abstract class TransientJetspeedPrincipal implements JetspeedPrincipal, Serializable
+{
+    protected static JetspeedPrincipalManagerProvider jpmp;
+    
+    protected String name;    
+    
+    protected transient JetspeedPrincipalType jpt;
+    protected transient SecurityAttributes attributes;
+    
+    public static void setJetspeedPrincipalManagerProvider(JetspeedPrincipalManagerProvider jpmp)
+    {
+        TransientJetspeedPrincipal.jpmp = jpmp;
+    }
+    
+    public TransientJetspeedPrincipal()
+    {   
+    }
+    
+    public Long getId()
+    {
+        return null;
+    }
+
+    public String getName()
+    {
+        return name;
+    }
+    
+    public void setName(String name)
+    {
+        this.name = name;
+    }
+
+    public synchronized JetspeedPrincipalType getType()
+    {
+        if (jpt == null)
+        {
+            jpt = jpmp.getPrincipalTypeByClassName(getClass().getName());
+        }
+        return jpt;
+    }
+
+    public Timestamp getCreationDate()
+    {
+        return null;
+    }
+    
+    public Timestamp getModifiedDate()
+    {
+        return null;
+    }
+    
+    public boolean isTransient()
+    {
+        return true;
+    }
+    
+    public boolean isEnabled()
+    {
+        return true;
+    }
+
+    public void setEnabled(boolean enabled) throws PrincipalReadOnlyException
+    {
+        throw new UnsupportedOperationException();
+    }
+    
+    public boolean isMapped()
+    {
+        return false;
+    }
+    
+    public void setMapped(boolean mapped)
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    public boolean isReadOnly()
+    {
+        return false;
+    }
+    
+    public void setReadOnly(boolean readOnly)
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    public boolean isRemovable()
+    {
+        return false;
+    }
+    
+    public void setRemovable(boolean removable)
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    public boolean isExtendable()
+    {
+        return true;
+    }
+    
+    public void setExtendable(boolean extendable)
+    {
+        throw new UnsupportedOperationException();
+    }
+    
+    public synchronized SecurityAttributes getSecurityAttributes()
+    {
+        if (attributes == null)
+        {
+            attributes = new SecurityAttributesImpl(this);
+        }
+        return attributes;
+    }
+    
+    public Map<String, String> getInfoMap()
+    {
+        return getSecurityAttributes().getInfoMap();
+    }
+}

Propchange: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/TransientJetspeedPrincipal.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/TransientJetspeedPrincipal.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/TransientJetspeedPrincipal.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/UserImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/UserImpl.java?rev=691972&r1=691971&r2=691972&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/UserImpl.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/UserImpl.java Thu Sep  4 04:27:02 2008
@@ -29,7 +29,7 @@
  * <p>Represents a security 'user' extending BaseJetspeedPrincipal.</p>
  * @version $Id$
  */
-public class UserImpl extends BaseJetspeedPrincipal implements User
+public class UserImpl extends PersistentJetspeedPrincipal implements User
 {
     private static final long serialVersionUID = 5484179899807809619L;
 

Modified: portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/JetspeedPrincipal.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/JetspeedPrincipal.java?rev=691972&r1=691971&r2=691972&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/JetspeedPrincipal.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/JetspeedPrincipal.java Thu Sep  4 04:27:02 2008
@@ -38,6 +38,8 @@
 
     void setEnabled(boolean enabled) throws PrincipalReadOnlyException;
 
+    boolean isTransient();
+
     boolean isMapped(); // true if managed (mapped) through an external authorization provider (e.g. LDAP)
 
     boolean isReadOnly(); // true if enabled may not be modified, nor mapped associations, permissions and attributes

Modified: portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/JetspeedPrincipalManager.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/JetspeedPrincipalManager.java?rev=691972&r1=691971&r2=691972&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/JetspeedPrincipalManager.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/JetspeedPrincipalManager.java Thu Sep  4 04:27:02 2008
@@ -43,7 +43,9 @@
 
     List<JetspeedPrincipal> getPrincipals(String nameFilter);
     
-    JetspeedPrincipal newPrincipal(String name,boolean mapped);
+    JetspeedPrincipal newPrincipal(String name, boolean mapped);
+
+    JetspeedPrincipal newTransientPrincipal(String name);
     
     void removePrincipal(String name) throws PrincipalNotFoundException, PrincipalNotRemovableException, DependentPrincipalException;
 



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