directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r491541 - in /directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc: ./ data/
Date Mon, 01 Jan 2007 06:32:45 GMT
Author: djencks
Date: Sun Dec 31 22:32:44 2006
New Revision: 491541

URL: http://svn.apache.org/viewvc?view=rev&rev=491541
Log:
untested jacc implementation of installing jee role>>permission mapping into triplesec

Added:
    directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/DataPolicyConfiguration.java
  (with props)
    directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/data/
    directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/data/Context.java
  (with props)
    directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/data/Permission.java
  (with props)
    directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/data/PermissionClass.java
  (with props)
    directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/data/Role.java
  (with props)
Modified:
    directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/TripleSecPolicyConfiguration.java
    directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/TripleSecPolicyConfigurationFactory.java

Added: directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/DataPolicyConfiguration.java
URL: http://svn.apache.org/viewvc/directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/DataPolicyConfiguration.java?view=auto&rev=491541
==============================================================================
--- directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/DataPolicyConfiguration.java
(added)
+++ directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/DataPolicyConfiguration.java
Sun Dec 31 22:32:44 2006
@@ -0,0 +1,140 @@
+/*
+ * 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.triplesec.jacc;
+
+import java.security.Permission;
+import java.security.PermissionCollection;
+import java.util.Enumeration;
+
+import javax.security.jacc.PolicyConfiguration;
+import javax.security.jacc.PolicyContextException;
+
+import org.apache.directory.triplesec.jacc.data.Context;
+import org.apache.directory.triplesec.jacc.data.PermissionClass;
+import org.apache.directory.triplesec.jacc.data.Role;
+import org.safehaus.triplesec.admin.DataAccessException;
+import org.safehaus.triplesec.admin.dao.DaoFactory;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public class DataPolicyConfiguration implements PolicyConfiguration {
+
+    public static final String UNCHECKED_ROLE_NAME = "org.apache.directory.triplesec.jacc.unchecked";
+    public static final String EXCLUDED_ROLE_NAME = "org.apache.directory.triplesec.jacc.excluded";
+
+    private final Context context;
+    private final TripleSecPolicyConfigurationFactory policyConfigurationFactory;
+
+    public DataPolicyConfiguration(String contextID, TripleSecPolicyConfigurationFactory
policyConfigurationFactory) {
+        context = new Context(contextID);
+        this.policyConfigurationFactory = policyConfigurationFactory;
+        context.addRole(new Role(UNCHECKED_ROLE_NAME));
+        context.addRole(new Role(EXCLUDED_ROLE_NAME));
+    }
+
+    public String getContextID() throws PolicyContextException {
+        return context.getContextID();
+    }
+
+    public void addToRole(String roleName, PermissionCollection permissionCollection) throws
PolicyContextException {
+        Role role = context.getRole(roleName);
+        for (Enumeration<Permission> permissions = permissionCollection.elements();
permissions.hasMoreElements();) {
+            Permission permission = permissions.nextElement();
+            addToGrants(permission, role);
+        }
+    }
+
+    public void addToRole(String roleName, Permission permission) throws PolicyContextException
{
+        Role role = context.getRole(roleName);
+        addToGrants(permission, role);
+    }
+
+    public void addToUncheckedPolicy(PermissionCollection permissionCollection) throws PolicyContextException
{
+        addToRole(UNCHECKED_ROLE_NAME, permissionCollection);
+    }
+
+    public void addToUncheckedPolicy(Permission permission) throws PolicyContextException
{
+        addToRole(UNCHECKED_ROLE_NAME, permission);
+    }
+
+    private void addToGrants(Permission permission, Role role) {
+        String permissionClassName = permission.getClass().getName();
+        String permissionName = permission.getName();
+        String permissionActions = permission.getActions();
+        PermissionClass permissionClass = role.getPermissionClass(permissionClassName);
+        permissionClass.addGrant(permissionName, permissionActions);
+    }
+
+    public void addToExcludedPolicy(PermissionCollection permissionCollection) throws PolicyContextException
{
+        Role role = context.getRole(EXCLUDED_ROLE_NAME);
+        for (Enumeration<Permission> permissions = permissionCollection.elements();
permissions.hasMoreElements();) {
+            Permission permission = permissions.nextElement();
+            addToDenials(permission, role);
+        }
+    }
+
+    public void addToExcludedPolicy(Permission permission) throws PolicyContextException
{
+        Role role = context.getRole(EXCLUDED_ROLE_NAME);
+        addToDenials(permission, role);
+    }
+
+    private void addToDenials(Permission permission, Role role) {
+        String permissionClassName = permission.getClass().getName();
+        String permissionName = permission.getName();
+        String permissionActions = permission.getActions();
+        PermissionClass permissionClass = role.getPermissionClass(permissionClassName);
+        permissionClass.addDenial(permissionName, permissionActions);
+    }
+
+    public void removeRole(String roleName) throws PolicyContextException {
+        context.getRoleMap().remove(roleName);
+    }
+
+    public void removeUncheckedPolicy() throws PolicyContextException {
+        context.getRole(UNCHECKED_ROLE_NAME).getPermissionClassMap().clear();
+    }
+
+    public void removeExcludedPolicy() throws PolicyContextException {
+        context.getRole(EXCLUDED_ROLE_NAME).getPermissionClassMap().clear();
+    }
+
+    public void linkConfiguration(PolicyConfiguration policyConfiguration) throws PolicyContextException
{
+    }
+
+    public void delete() throws PolicyContextException {
+        //TODO read spec on what to do. Most likely we want to remove all permissions from
all roles.
+    }
+
+    public void commit() throws PolicyContextException {
+        DaoFactory daoFactory = policyConfigurationFactory.getDaoFactory();
+        try {
+            context.commit(daoFactory);
+        } catch (DataAccessException e) {
+            throw new PolicyContextException("Failed to store data in ldap", e);
+        }
+    }
+
+    public boolean inService() throws PolicyContextException {
+        return false;
+    }
+
+}

Propchange: directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/DataPolicyConfiguration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/DataPolicyConfiguration.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/DataPolicyConfiguration.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/TripleSecPolicyConfiguration.java
URL: http://svn.apache.org/viewvc/directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/TripleSecPolicyConfiguration.java?view=diff&rev=491541&r1=491540&r2=491541
==============================================================================
--- directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/TripleSecPolicyConfiguration.java
(original)
+++ directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/TripleSecPolicyConfiguration.java
Sun Dec 31 22:32:44 2006
@@ -21,14 +21,10 @@
 import java.security.PermissionCollection;
 import java.security.Principal;
 import java.security.ProtectionDomain;
-import java.util.Enumeration;
 
 import javax.security.jacc.PolicyConfiguration;
 import javax.security.jacc.PolicyContextException;
 
-import org.safehaus.triplesec.admin.DataAccessException;
-import org.safehaus.triplesec.admin.dao.DaoFactory;
-import org.safehaus.triplesec.admin.dao.RoleDao;
 import org.safehaus.triplesec.guardian.Profile;
 import org.safehaus.triplesec.jaas.SafehausPrincipal;
 
@@ -42,18 +38,14 @@
     final static int DELETED = 3;
 
     private final String contextID;
-    private RoleDao roleDao;
+    private final TripleSecPolicyConfigurationFactory factory;
+    private DataPolicyConfiguration dataPolicyConfiguration;
     private int state;
 
-
-    TripleSecPolicyConfiguration(String contextID, DaoFactory daoFactory) throws PolicyContextException
{
+    TripleSecPolicyConfiguration(String contextID, TripleSecPolicyConfigurationFactory factory)
throws PolicyContextException {
         this.contextID = contextID;
         this.state = OPEN;
-        try {
-            roleDao = daoFactory.getRoleDao();
-        } catch (DataAccessException e) {
-            throw new PolicyContextException("Could not access RoleDao", e);
-        }
+        this.factory = factory;
     }
 
     public String getContextID() throws PolicyContextException {
@@ -78,80 +70,52 @@
     }
 
     public void addToRole(String roleName, PermissionCollection permissions) throws PolicyContextException
{
-        if (state != OPEN) throw new UnsupportedOperationException("Not in an open state");
-
-        Enumeration e = permissions.elements();
-        while (e.hasMoreElements()) {
-            addToRole(roleName, (Permission) e.nextElement());
-        }
+        getDataPolicyConfiguration().addToRole(roleName, permissions);
     }
 
     public void addToRole(String roleName, Permission permission) throws PolicyContextException
{
-        if (state != OPEN) throw new UnsupportedOperationException("Not in an open state");
-
-        //TODO Install contextId/rolename to permission association in TripleSec LDAP
+        getDataPolicyConfiguration().addToRole(roleName, permission);
     }
 
     public void addToUncheckedPolicy(PermissionCollection permissions) throws PolicyContextException
{
-        if (state != OPEN) throw new UnsupportedOperationException("Not in an open state");
-
-        Enumeration e = permissions.elements();
-        while (e.hasMoreElements()) {
-            addToUncheckedPolicy((Permission) e.nextElement());
-        }
+        getDataPolicyConfiguration().addToUncheckedPolicy(permissions);
     }
 
     public void addToUncheckedPolicy(Permission permission) throws PolicyContextException
{
-        if (state != OPEN) throw new UnsupportedOperationException("Not in an open state");
-
-        //TODO Install permission association in TripleSec LDAP unchecked role
+        getDataPolicyConfiguration().addToUncheckedPolicy(permission);
     }
 
     public void addToExcludedPolicy(PermissionCollection permissions) throws PolicyContextException
{
-        if (state != OPEN) throw new UnsupportedOperationException("Not in an open state");
-
-        Enumeration e = permissions.elements();
-        while (e.hasMoreElements()) {
-            addToExcludedPolicy((Permission) e.nextElement());
-        }
+        getDataPolicyConfiguration().addToExcludedPolicy(permissions);
     }
 
     public void addToExcludedPolicy(Permission permission) throws PolicyContextException
{
-        if (state != OPEN) throw new UnsupportedOperationException("Not in an open state");
-
-        //TODO Install permission association in TripleSec LDAP excluded (denied) role
+        getDataPolicyConfiguration().addToExcludedPolicy(permission);
     }
 
     public void removeRole(String roleName) throws PolicyContextException {
-        if (state != OPEN) throw new UnsupportedOperationException("Not in an open state");
-
-        //TODO remove contextId/role (?? maybe role in all contextIds?) from TripleSec LDAP
+        getDataPolicyConfiguration().removeRole(roleName);
     }
 
     public void removeUncheckedPolicy() throws PolicyContextException {
-        if (state != OPEN) throw new UnsupportedOperationException("Not in an open state");
-
-        //TODO remove contextId/unchecked (?? maybe unchecked in all contextIds?) from TripleSec
LDAP
+        getDataPolicyConfiguration().removeUncheckedPolicy();
     }
 
     public void removeExcludedPolicy() throws PolicyContextException {
-        if (state != OPEN) throw new UnsupportedOperationException("Not in an open state");
-
-        //TODO remove contextId/excluded (?? maybe excluded in all contextIds?) from TripleSec
LDAP
+        getDataPolicyConfiguration().removeExcludedPolicy();
     }
 
     public void linkConfiguration(javax.security.jacc.PolicyConfiguration link) throws PolicyContextException
{
-        if (state != OPEN) throw new UnsupportedOperationException("Not in an open state");
+        getDataPolicyConfiguration().linkConfiguration(link);
     }
 
     public void delete() throws PolicyContextException {
         state = DELETED;
+        getDataPolicyConfiguration().delete();
     }
 
     public void commit() throws PolicyContextException {
-        if (state != OPEN) throw new UnsupportedOperationException("Not in an open state");
-
-        state = IN_SERVICE;
+        getDataPolicyConfiguration().commit();
     }
 
     public boolean inService() throws PolicyContextException {
@@ -173,4 +137,13 @@
     int getState() {
         return state;
     }
+
+    private synchronized PolicyConfiguration getDataPolicyConfiguration() {
+        if (state != OPEN) throw new UnsupportedOperationException("Not in an open state");
+        if (dataPolicyConfiguration == null) {
+            dataPolicyConfiguration = new DataPolicyConfiguration(contextID, factory);
+        }
+        return dataPolicyConfiguration;
+    }
+
 }

Modified: directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/TripleSecPolicyConfigurationFactory.java
URL: http://svn.apache.org/viewvc/directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/TripleSecPolicyConfigurationFactory.java?view=diff&rev=491541&r1=491540&r2=491541
==============================================================================
--- directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/TripleSecPolicyConfigurationFactory.java
(original)
+++ directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/TripleSecPolicyConfigurationFactory.java
Sun Dec 31 22:32:44 2006
@@ -17,6 +17,11 @@
 
 package org.apache.directory.triplesec.jacc;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
@@ -27,8 +32,8 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.safehaus.triplesec.admin.dao.DaoFactory;
 import org.safehaus.triplesec.admin.DataAccessException;
+import org.safehaus.triplesec.admin.dao.DaoFactory;
 
 /**
  * @version $Rev$ $Date$
@@ -38,8 +43,12 @@
     private final Log log = LogFactory.getLog(TripleSecPolicyConfigurationFactory.class);
     private static TripleSecPolicyConfigurationFactory singleton;
 
-    private final DaoFactory daoFactory;
+    private Properties ldapProperties;
+    private DaoFactory daoFactory;
+
     private Map<String, TripleSecPolicyConfiguration> configurations = new HashMap<String,
TripleSecPolicyConfiguration>();
+    private static final String LDAP_PROPERTIES_LOCATON_KEY = "org.apache.directory.triplesec.jacc.ldap.properties";
+    private static final String LDAP_PROPERTIES_LOCATION_DEFAULT = "triplesec_jacc_ldap.properties";
 
     public TripleSecPolicyConfigurationFactory() {
         synchronized (TripleSecPolicyConfigurationFactory.class) {
@@ -47,13 +56,6 @@
                 log.error("Singleton already assigned.  There may be more than one TripleSecPolicyConfigurationFactory
being used.");
                 throw new IllegalStateException("Singleton already assigned");
             }
-            Properties props = new Properties();
-            //TODO fill in the properties
-            try {
-                daoFactory = DaoFactory.createInstance(props);
-            } catch (DataAccessException e) {
-                throw new RuntimeException("Could not create DaoFactory", e);
-            }
             singleton = this;
         }
     }
@@ -62,7 +64,7 @@
         TripleSecPolicyConfiguration configuration = configurations.get(contextID);
 
         if (configuration == null) {
-            configuration = new TripleSecPolicyConfiguration(contextID, daoFactory);
+            configuration = new TripleSecPolicyConfiguration(contextID, this);
             configurations.put(contextID, configuration);
         } else {
             configuration.open(remove);
@@ -85,5 +87,49 @@
 
     public TripleSecPolicyConfiguration getTripleSecPolicyConfiguration(String contextID)
{
         return configurations.get(contextID);
+    }
+
+    public synchronized void setLdapProperties(Properties ldapProperties) {
+        this.ldapProperties = ldapProperties;
+    }
+
+    public synchronized DaoFactory getDaoFactory() throws PolicyContextException {
+        if (daoFactory == null) {
+            if (ldapProperties == null) {
+                InputStream in = null;
+                String fileLocation = System.getProperty(LDAP_PROPERTIES_LOCATON_KEY, LDAP_PROPERTIES_LOCATION_DEFAULT);
+                File propertiesFile = new File(fileLocation);
+                if (propertiesFile.exists()) {
+                    try {
+                        in = new FileInputStream(propertiesFile);
+                    } catch (FileNotFoundException e) {
+                        //should not happen.... we just checked
+                    }
+                }
+                if (in == null) {
+                    ClassLoader cl = Thread.currentThread().getContextClassLoader();
+                    if (cl == null) {
+                        cl = this.getClass().getClassLoader();
+                    }
+                    in = cl.getResourceAsStream(fileLocation);
+                }
+                if (in == null) {
+                    throw new PolicyContextException("Could not find properties to initialize
ldap");
+                }
+                ldapProperties = new Properties();
+                try {
+                    ldapProperties.load(in);
+                } catch (IOException e) {
+                    throw new PolicyContextException("Could not load ldap properties from
" + fileLocation, e);
+                }
+            }
+            try {
+                daoFactory = DaoFactory.createInstance(ldapProperties);
+            } catch (DataAccessException e) {
+                throw new PolicyContextException("Could not construct dir context", e);
+            }
+        }
+
+        return daoFactory;
     }
 }

Added: directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/data/Context.java
URL: http://svn.apache.org/viewvc/directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/data/Context.java?view=auto&rev=491541
==============================================================================
--- directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/data/Context.java
(added)
+++ directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/data/Context.java
Sun Dec 31 22:32:44 2006
@@ -0,0 +1,80 @@
+/*
+ * 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.triplesec.jacc.data;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.safehaus.triplesec.admin.DataAccessException;
+import org.safehaus.triplesec.admin.dao.ApplicationDao;
+import org.safehaus.triplesec.admin.dao.DaoFactory;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public class Context {
+
+    private final String contextID;
+    private final Map<String, Role> roles = new HashMap<String, Role>();
+
+    public Context(String contextID) {
+        this.contextID = contextID;
+    }
+
+    public String getContextID() {
+        return contextID;
+    }
+
+    public Map<String, Role> getRoleMap() {
+        return roles;
+    }
+
+    public Collection<Role> getRoles() {
+        return roles.values();
+    }
+
+    public void addRole(Role role) {
+        roles.put(role.getRoleName(), role);
+    }
+
+    public Role getRole(String roleName) {
+        Role role = getRoleMap().get(roleName);
+        if (role == null) {
+            role = new Role(roleName);
+            addRole(role);
+        }
+        return role;
+    }
+
+    public void commit(DaoFactory daoFactory) throws DataAccessException {
+        ApplicationDao applicationDao = daoFactory.getApplicationDao();
+        try {
+            applicationDao.load(contextID);
+        } catch (DataAccessException e) {
+            //presume not there, create it
+            applicationDao.add(contextID, null, null);
+        }
+        for (Role role: getRoles()) {
+            role.commit(contextID, daoFactory);
+        }
+    }
+}

Propchange: directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/data/Context.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/data/Context.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/data/Context.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/data/Permission.java
URL: http://svn.apache.org/viewvc/directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/data/Permission.java?view=auto&rev=491541
==============================================================================
--- directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/data/Permission.java
(added)
+++ directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/data/Permission.java
Sun Dec 31 22:32:44 2006
@@ -0,0 +1,64 @@
+/*
+ * 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.triplesec.jacc.data;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.safehaus.triplesec.admin.DataAccessException;
+import org.safehaus.triplesec.admin.dao.DaoFactory;
+import org.safehaus.triplesec.admin.dao.PermissionActionsDao;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public class Permission {
+
+    private final String name;
+    private final Set<String> actionsSet = new HashSet<String>();
+
+    public Permission(String name, String action) {
+        this.name = name;
+        this.actionsSet.add(action);
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public Set<String> getActionsSet() {
+        return actionsSet;
+    }
+
+    public void addActions(String actions) {
+        actionsSet.add(actions);
+    }
+
+    public void commit(String contextDn, boolean isGrant, DaoFactory daoFactory) throws DataAccessException
{
+        PermissionActionsDao permissionActionsDao = daoFactory.getPermissionActionsDao();
+        try {
+            permissionActionsDao.load(contextDn, isGrant, name);
+            permissionActionsDao.modify(null, null, contextDn, isGrant, name, actionsSet,
null);
+        } catch (DataAccessException e) {
+            permissionActionsDao.add(contextDn, isGrant, name, actionsSet);
+        }
+    }
+}

Propchange: directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/data/Permission.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/data/Permission.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/data/Permission.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/data/PermissionClass.java
URL: http://svn.apache.org/viewvc/directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/data/PermissionClass.java?view=auto&rev=491541
==============================================================================
--- directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/data/PermissionClass.java
(added)
+++ directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/data/PermissionClass.java
Sun Dec 31 22:32:44 2006
@@ -0,0 +1,100 @@
+/*
+ * 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.triplesec.jacc.data;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Collection;
+
+import org.safehaus.triplesec.admin.dao.DaoFactory;
+import org.safehaus.triplesec.admin.dao.PermissionClassDao;
+import org.safehaus.triplesec.admin.DataAccessException;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public class PermissionClass {
+
+    private final String permissionClassName;
+    private final Map<String, Permission> grants = new HashMap<String, Permission>();
+    private final Map<String, Permission> denials = new HashMap<String, Permission>();
+
+    public PermissionClass(String permissionClass) {
+        this.permissionClassName = permissionClass;
+    }
+
+    public String getPermissionClassName() {
+        return permissionClassName;
+    }
+
+    public Collection<Permission> getGrants() {
+        return grants.values();
+    }
+
+    public void addGrant(String permissionName, String actions) {
+        addPermission(permissionName, actions, grants);
+    }
+
+    public Collection<Permission> getDenials() {
+        return denials.values();
+    }
+
+    public void addDenial(String permissionName, String actions) {
+        addPermission(permissionName, actions, denials);
+    }
+
+    public void commit(String contextDn, DaoFactory daoFactory) throws DataAccessException
{
+        PermissionClassDao permissionClassDao = daoFactory.getPermissionClassDao();
+        try {
+            permissionClassDao.load(contextDn, permissionClassName );
+        } catch (DataAccessException e) {
+            permissionClassDao.add(contextDn, permissionClassName, null, null);
+        }
+        String pcContextDn = getRelativeDn(contextDn, permissionClassName);
+        for (Permission grant: grants.values()) {
+            grant.commit(pcContextDn, true, daoFactory);
+        }
+        for (Permission denial : denials.values()) {
+            denial.commit(pcContextDn, false, daoFactory);
+        }
+
+    }
+
+    private String getRelativeDn( String contextDn, String permName )
+    {
+        StringBuffer buf = new StringBuffer();
+        buf.append( "permClassName=" ).append( permName );
+        buf.append(",").append( contextDn );
+        buf.append(",");
+        return buf.toString();
+    }
+
+    private void addPermission(String permissionName, String actions, Map<String, Permission>
permissionMap) {
+        Permission permission = permissionMap.get(permissionName);
+        if (permission == null) {
+            permission = new Permission(permissionName, actions);
+            permissionMap.put(permissionName, permission);
+        } else {
+            permission.addActions(actions);
+        }
+    }
+
+}

Propchange: directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/data/PermissionClass.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/data/PermissionClass.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/data/PermissionClass.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/data/Role.java
URL: http://svn.apache.org/viewvc/directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/data/Role.java?view=auto&rev=491541
==============================================================================
--- directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/data/Role.java
(added)
+++ directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/data/Role.java
Sun Dec 31 22:32:44 2006
@@ -0,0 +1,88 @@
+/*
+ * 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.triplesec.jacc.data;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Collection;
+
+import org.safehaus.triplesec.admin.DataAccessException;
+import org.safehaus.triplesec.admin.dao.DaoFactory;
+import org.safehaus.triplesec.admin.dao.RoleDao;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public class Role {
+
+    private final String roleName;
+    private final Map<String, PermissionClass> permissionClasses = new HashMap<String,
PermissionClass>();
+
+    public Role(String roleName) {
+        this.roleName = roleName;
+    }
+
+    public String getRoleName() {
+        return roleName;
+    }
+
+    public Map<String, PermissionClass> getPermissionClassMap() {
+        return permissionClasses;
+    }
+
+    public Collection<PermissionClass> getPermissionClasses() {
+        return permissionClasses.values();
+    }
+
+    public void addPermissionClass(PermissionClass permissionClass) {
+        permissionClasses.put(permissionClass.getPermissionClassName(), permissionClass);
+    }
+
+    public PermissionClass getPermissionClass(String permissionClassName) {
+        PermissionClass permissionClass = permissionClasses.get(permissionClassName);
+        if (permissionClass == null) {
+            permissionClass = new PermissionClass(permissionClassName);
+        }
+        return permissionClass;
+    }
+
+    public void commit(String contextID, DaoFactory daoFactory) throws DataAccessException
{
+        RoleDao roleDao = daoFactory.getRoleDao();
+        try {
+            roleDao.load(contextID, roleName);
+        } catch (DataAccessException e) {
+            roleDao.add(contextID, roleName, null, null);
+        }
+        String contextDn = getRelativeDn(contextID, roleName);
+        for (PermissionClass permissionClass : getPermissionClasses()) {
+            permissionClass.commit(contextDn, daoFactory);
+        }
+    }
+    private String getRelativeDn( String appName, String roleName )
+    {
+        StringBuffer buf = new StringBuffer();
+        buf.append( "roleName=" ).append( roleName );
+        buf.append( ",ou=Roles,appName=" ).append( appName );
+        buf.append( ",ou=Applications," );
+        return buf.toString();
+    }
+
+}

Propchange: directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/data/Role.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/data/Role.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: directory/sandbox/triplesec-jacc/jacc/src/main/java/org/apache/directory/triplesec/jacc/data/Role.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message