directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cp...@apache.org
Subject [01/10] directory-fortress-core git commit: basic initial pattern for property manager
Date Mon, 28 Nov 2016 21:13:28 GMT
Repository: directory-fortress-core
Updated Branches:
  refs/heads/master 2fdea368d -> 4178bd6e2


basic initial pattern for property manager


Project: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/commit/3b7de7d5
Tree: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/tree/3b7de7d5
Diff: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/diff/3b7de7d5

Branch: refs/heads/master
Commit: 3b7de7d568e82799d463cd7a93e4ab0e0fee0c70
Parents: 6c64b32
Author: clp207 <clp207@psu.edu>
Authored: Tue Oct 25 13:26:04 2016 -0400
Committer: clp207 <clp207@psu.edu>
Committed: Tue Oct 25 13:26:04 2016 -0400

----------------------------------------------------------------------
 .../directory/fortress/core/PropertyMgr.java    | 35 ++++++++
 .../fortress/core/impl/PropertyDAO.java         | 71 ++++++++++++++++
 .../fortress/core/impl/PropertyMgrImpl.java     | 87 ++++++++++++++++++++
 .../directory/fortress/core/impl/PropertyP.java | 49 +++++++++++
 .../fortress/core/impl/PropertyProvider.java    | 30 +++++++
 .../directory/fortress/core/impl/RoleDAO.java   | 25 +++++-
 .../directory/fortress/core/model/Role.java     | 67 ++++++++++++++-
 7 files changed, 359 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/3b7de7d5/src/main/java/org/apache/directory/fortress/core/PropertyMgr.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/PropertyMgr.java b/src/main/java/org/apache/directory/fortress/core/PropertyMgr.java
new file mode 100644
index 0000000..9e7ba34
--- /dev/null
+++ b/src/main/java/org/apache/directory/fortress/core/PropertyMgr.java
@@ -0,0 +1,35 @@
+/*
+ *   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.directory.fortress.core;
+
+import java.util.Properties;
+
+import org.apache.directory.fortress.core.model.FortEntity;
+
+public interface PropertyMgr
+{
+    FortEntity add( FortEntity entity, Properties props ) throws SecurityException;
+    
+    FortEntity update( FortEntity entity, Properties props ) throws SecurityException;
+    
+    void delete( FortEntity entity, Properties props ) throws SecurityException;
+    
+    String get( FortEntity entity, String key ) throws SecurityException;
+}

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/3b7de7d5/src/main/java/org/apache/directory/fortress/core/impl/PropertyDAO.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/impl/PropertyDAO.java b/src/main/java/org/apache/directory/fortress/core/impl/PropertyDAO.java
new file mode 100644
index 0000000..d8febdf
--- /dev/null
+++ b/src/main/java/org/apache/directory/fortress/core/impl/PropertyDAO.java
@@ -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.directory.fortress.core.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.commons.lang.ArrayUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.directory.api.ldap.model.constants.SchemaConstants;
+import org.apache.directory.api.ldap.model.entry.DefaultModification;
+import org.apache.directory.api.ldap.model.entry.Modification;
+import org.apache.directory.api.ldap.model.entry.ModificationOperation;
+import org.apache.directory.api.ldap.model.exception.LdapException;
+import org.apache.directory.fortress.core.FinderException;
+import org.apache.directory.fortress.core.GlobalErrIds;
+import org.apache.directory.fortress.core.GlobalIds;
+import org.apache.directory.fortress.core.UpdateException;
+import org.apache.directory.fortress.core.ldap.LdapDataProvider;
+import org.apache.directory.fortress.core.model.ConstraintUtil;
+import org.apache.directory.fortress.core.model.FortEntity;
+import org.apache.directory.fortress.core.util.Config;
+import org.apache.directory.fortress.core.util.PropUtil;
+import org.apache.directory.ldap.client.api.LdapConnection;
+
+public class PropertyDAO extends LdapDataProvider
+{
+
+    public FortEntity addProperties( FortEntity entity, Properties properties, PropertyProvider
propProvider ) throws UpdateException, FinderException{ 
+        LdapConnection ld = null;
+        String entityDn = propProvider.getDn( entity );
+
+        try
+        {
+            List<Modification> mods = new ArrayList<Modification>();
+            loadProperties( properties, mods, GlobalIds.PROPS, false );
+
+            ld = getAdminConnection();
+            modify( ld, entityDn, mods, entity );            
+        }
+        catch ( LdapException e )
+        {
+            String error = "add entity properties[" + entity.getClass().getSimpleName() +
"] caught LDAPException=" + e.getMessage();
+            throw new UpdateException( GlobalErrIds.USER_UPDATE_FAILED, error, e );
+        }
+        finally
+        {
+            closeAdminConnection( ld );
+        }
+
+        return propProvider.getEntity( entity );
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/3b7de7d5/src/main/java/org/apache/directory/fortress/core/impl/PropertyMgrImpl.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/impl/PropertyMgrImpl.java b/src/main/java/org/apache/directory/fortress/core/impl/PropertyMgrImpl.java
new file mode 100644
index 0000000..3e55e2f
--- /dev/null
+++ b/src/main/java/org/apache/directory/fortress/core/impl/PropertyMgrImpl.java
@@ -0,0 +1,87 @@
+/*
+ *   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.directory.fortress.core.impl;
+
+import java.io.Serializable;
+import java.util.Properties;
+
+import org.apache.directory.fortress.core.PropertyMgr;
+import org.apache.directory.fortress.core.ReviewMgr;
+import org.apache.directory.fortress.core.SecurityException;
+import org.apache.directory.fortress.core.model.FortEntity;
+import org.apache.directory.fortress.core.model.Role;
+
+public class PropertyMgrImpl extends Manageable implements PropertyMgr, Serializable
+{
+
+    private PropertyP propP = new PropertyP();
+    
+    @Override
+    public FortEntity add( FortEntity entity, Properties props ) throws SecurityException
+    {
+        checkPropertyUpdateAccess( entity );
+        entity.setContextId( this.contextId );
+        return propP.addProperties( entity, props );
+    }
+
+    @Override
+    public FortEntity update( FortEntity entity, Properties props ) throws SecurityException
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public void delete( FortEntity entity, Properties props ) throws SecurityException
+    {
+        // TODO Auto-generated method stub
+        
+    }
+
+    @Override
+    public String get( FortEntity entity, String key ) throws SecurityException
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+    
+    private void checkPropertyUpdateAccess( FortEntity entity ) throws SecurityException{
+        if( entity instanceof Role ){
+            checkAccess( AdminMgrImpl.class.getName(), "updateRole" );
+        }
+        //TODO: add checks for other instances
+        else{
+            //TODO: valid error code
+            throw new SecurityException( 1, "Properties not allowed on supplied entity" );
+        }
+    }
+    
+    private void checkPropertyGetAccess( FortEntity entity ) throws SecurityException{
+        if( entity instanceof Role ){
+            checkAccess( ReviewMgrImpl.class.getName(), "readRole" );
+        }
+        //TODO: add checks for other instances
+        else{
+            //TODO: valid error code
+            throw new SecurityException( 1, "Properties not allowed on supplied entity" );
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/3b7de7d5/src/main/java/org/apache/directory/fortress/core/impl/PropertyP.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/impl/PropertyP.java b/src/main/java/org/apache/directory/fortress/core/impl/PropertyP.java
new file mode 100644
index 0000000..84985dc
--- /dev/null
+++ b/src/main/java/org/apache/directory/fortress/core/impl/PropertyP.java
@@ -0,0 +1,49 @@
+/*
+ *   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.directory.fortress.core.impl;
+
+import java.util.Properties;
+
+import org.apache.directory.fortress.core.FinderException;
+import org.apache.directory.fortress.core.UpdateException;
+import org.apache.directory.fortress.core.model.FortEntity;
+import org.apache.directory.fortress.core.model.Role;
+
+public class PropertyP
+{
+    private PropertyDAO propDAO = new PropertyDAO();
+    private RoleDAO rDAO = new RoleDAO();
+    
+    public FortEntity addProperties( FortEntity entity, Properties props ) throws UpdateException,
FinderException {
+        
+        return propDAO.addProperties( entity, props, this.getPropertyProvider( entity ) );
+    }
+    
+    private PropertyProvider getPropertyProvider( FortEntity entity ){
+        if( entity instanceof Role ){
+            return rDAO;
+        }
+        //TODO: add rest of DAOs
+        else{
+            //TODO: throw exception
+            return null;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/3b7de7d5/src/main/java/org/apache/directory/fortress/core/impl/PropertyProvider.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/impl/PropertyProvider.java b/src/main/java/org/apache/directory/fortress/core/impl/PropertyProvider.java
new file mode 100644
index 0000000..1ce4074
--- /dev/null
+++ b/src/main/java/org/apache/directory/fortress/core/impl/PropertyProvider.java
@@ -0,0 +1,30 @@
+/*
+ *   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.directory.fortress.core.impl;
+
+import org.apache.directory.fortress.core.FinderException;
+import org.apache.directory.fortress.core.model.FortEntity;
+
+public interface PropertyProvider<T>
+{
+    String getDn( T entity );
+    
+    FortEntity getEntity( T entity ) throws FinderException;
+}

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/3b7de7d5/src/main/java/org/apache/directory/fortress/core/impl/RoleDAO.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/impl/RoleDAO.java b/src/main/java/org/apache/directory/fortress/core/impl/RoleDAO.java
index 0f7b988..bff96db 100755
--- a/src/main/java/org/apache/directory/fortress/core/impl/RoleDAO.java
+++ b/src/main/java/org/apache/directory/fortress/core/impl/RoleDAO.java
@@ -49,6 +49,7 @@ import org.apache.directory.fortress.core.model.Graphable;
 import org.apache.directory.fortress.core.model.Group;
 import org.apache.directory.fortress.core.model.ObjectFactory;
 import org.apache.directory.fortress.core.model.Role;
+import org.apache.directory.fortress.core.util.PropUtil;
 import org.apache.directory.ldap.client.api.LdapConnection;
 
 
@@ -97,7 +98,7 @@ import org.apache.directory.ldap.client.api.LdapConnection;
  *
  * @author Kevin McKinney
  */
-final class RoleDAO extends LdapDataProvider
+final class RoleDAO extends LdapDataProvider implements PropertyProvider<Role>
 {
     /*
       *  *************************************************************************
@@ -118,7 +119,8 @@ final class RoleDAO extends LdapDataProvider
             SchemaConstants.DESCRIPTION_AT,
             GlobalIds.CONSTRAINT,
             SchemaConstants.ROLE_OCCUPANT_AT,
-            GlobalIds.PARENT_NODES
+            GlobalIds.PARENT_NODES,
+            GlobalIds.PROPS
     };
 
     /**
@@ -721,9 +723,10 @@ final class RoleDAO extends LdapDataProvider
         entity.setOccupants( getAttributes( le, SchemaConstants.ROLE_OCCUPANT_AT ) );
         //entity.setParents(RoleUtil.getParents(entity.getName().toUpperCase(), contextId));
         entity.setChildren( RoleUtil.getInstance().getChildren( entity.getName().toUpperCase(),
contextId ) );
-        entity.setParents( getAttributeSet( le, GlobalIds.PARENT_NODES ) );
+        entity.setParents( getAttributeSet( le, GlobalIds.PARENT_NODES ) );        
         unloadTemporal( le, entity );
-        entity.setDn( le.getDn().getName() );
+        entity.setDn( le.getDn().getName() );        
+        entity.addProperties( PropUtil.getProperties( getAttributes( le, GlobalIds.PROPS
) ) );
         return entity;
     }
 
@@ -732,4 +735,18 @@ final class RoleDAO extends LdapDataProvider
     {
         return SchemaConstants.CN_AT + "=" + name + "," + getRootDn( contextId, GlobalIds.ROLE_ROOT
);
     }
+
+
+    @Override
+    public String getDn( Role entity )
+    {
+        return this.getDn( entity.getName(), entity.getContextId() );
+    }
+
+
+    @Override
+    public Role getEntity( Role entity ) throws FinderException
+    {
+        return this.getRole( entity );
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/3b7de7d5/src/main/java/org/apache/directory/fortress/core/model/Role.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/model/Role.java b/src/main/java/org/apache/directory/fortress/core/model/Role.java
index f86012f..2447037 100755
--- a/src/main/java/org/apache/directory/fortress/core/model/Role.java
+++ b/src/main/java/org/apache/directory/fortress/core/model/Role.java
@@ -21,8 +21,10 @@ package org.apache.directory.fortress.core.model;
 
 
 import java.util.ArrayList;
+import java.util.Enumeration;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Properties;
 import java.util.Set;
 import java.util.UUID;
 
@@ -209,7 +211,8 @@ import javax.xml.bind.annotation.XmlType;
         "endLockDate",
         "endTime",
         "timeout",
-        "dn"
+        "dn",
+        "props"
 })
 @XmlSeeAlso(
     {
@@ -234,6 +237,7 @@ public class Role extends FortEntity implements Constraint, Graphable,
java.io.S
     private String endLockDate; // this attribute is ftCstr
     private String dayMask; // this attribute is ftCstr
     private int timeout; // this attribute is ftCstr
+    private Props props = new Props();
     
     
     /**
@@ -897,4 +901,65 @@ public class Role extends FortEntity implements Constraint, Graphable,
java.io.S
     {
         return toString( "" );
     }
+    
+    /**
+     * Add name/value pair to list of properties associated with User.  These values are
not constrained by Fortress.
+     * Properties are optional.
+     *
+     * @param key   contains property name and maps to 'ftProps' attribute in 'ftProperties'
aux object class.
+     * @param value The property value to add
+     */
+    private void addProperty( String key, String value )
+    {
+        Props.Entry entry = new Props.Entry();
+        entry.setKey( key );
+        entry.setValue( value );
+        props.getEntry().add( entry );
+    }
+    
+    /**
+     * Add new collection of name/value pairs to attributes associated with User.  These
values are not constrained by Fortress.
+     * Properties are optional.
+     *
+     * @param props contains collection of name/value pairs and maps to 'ftProps' attribute
in 'ftProperties' aux object class.
+     */
+    public void addProperties( Properties props )
+    {
+        if ( props != null )
+        {
+            for ( Enumeration<?> e = props.propertyNames(); e.hasMoreElements(); )
+            {
+                // This LDAP attr is stored as a name-value pair separated by a ':'.
+                String key = ( String ) e.nextElement();
+                String val = props.getProperty( key );
+                addProperty( key, val );
+            }
+        }
+    }
+    
+    /**
+     * Return the collection of name/value pairs to attributes associated with User.  These
values are not constrained by Fortress.
+     * Properties are optional.
+     *
+     * @return Properties contains collection of name/value pairs and maps to 'ftProps' attribute
in 'ftProperties' aux object class.
+     */
+    public Properties getProperties()
+    {
+        Properties properties = null;
+        List<Props.Entry> props = this.props.getEntry();
+
+        if ( props.size() > 0 )
+        {
+            properties = new Properties();
+
+            for ( Props.Entry entry : props )
+            {
+                String key = entry.getKey();
+                String val = entry.getValue();
+                properties.setProperty( key, val );
+            }
+        }
+
+        return properties;
+    }
 }


Mime
View raw message