summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/persistency
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2014-06-12 19:59:32 +0200
committerAndrew Branson <andrew.branson@cern.ch>2014-06-12 19:59:32 +0200
commit2a324c450839410293c5d5e2c56dc291b4a98634 (patch)
tree5933f63473dca9b02765dd5e9b39a972f12c6a4a /src/main/java/com/c2kernel/persistency
parent14e2fe28c2b7ecaae53a10d1aa7aa4b921b6efbc (diff)
Refactored LDAP into its own module.
Diffstat (limited to 'src/main/java/com/c2kernel/persistency')
-rw-r--r--src/main/java/com/c2kernel/persistency/LDAPClientReader.java43
-rw-r--r--src/main/java/com/c2kernel/persistency/LDAPClusterStorage.java176
-rw-r--r--src/main/java/com/c2kernel/persistency/NextKeyManager.java3
3 files changed, 3 insertions, 219 deletions
diff --git a/src/main/java/com/c2kernel/persistency/LDAPClientReader.java b/src/main/java/com/c2kernel/persistency/LDAPClientReader.java
deleted file mode 100644
index ac9215c..0000000
--- a/src/main/java/com/c2kernel/persistency/LDAPClientReader.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package com.c2kernel.persistency;
-
-import com.c2kernel.entity.C2KLocalObject;
-
-/** Allows clients to directly load properties and collections from the LDAP
-* so no CORBA calls need to be made during normal browsing
-*/
-
-public class LDAPClientReader extends LDAPClusterStorage {
- // return all readwrite support as readonly
- @Override
- public short queryClusterSupport(String clusterType) {
- return (short)(super.queryClusterSupport(clusterType) & READ);
- }
-
-
- /**
- * @see com.c2kernel.persistency.ClusterStorage#delete(Integer, String)
- */
- @Override
- public void delete(Integer sysKey, String path)
- throws ClusterStorageException {
- throw new ClusterStorageException("Writing not supported in ClientReader");
- }
-
- /**
- * @see com.c2kernel.persistency.ClusterStorage#getName()
- */
- @Override
- public String getName() {
- return "LDAP Client Cluster Reader";
- }
-
- /**
- * @see com.c2kernel.persistency.ClusterStorage#put(Integer, String, C2KLocalObject)
- */
-
- public void put(Integer sysKey, String path, C2KLocalObject obj)
- throws ClusterStorageException {
- throw new ClusterStorageException("Writing not supported in ClientReader");
- }
-
-}
diff --git a/src/main/java/com/c2kernel/persistency/LDAPClusterStorage.java b/src/main/java/com/c2kernel/persistency/LDAPClusterStorage.java
deleted file mode 100644
index 4762a33..0000000
--- a/src/main/java/com/c2kernel/persistency/LDAPClusterStorage.java
+++ /dev/null
@@ -1,176 +0,0 @@
-package com.c2kernel.persistency;
-import java.util.ArrayList;
-import java.util.StringTokenizer;
-
-import com.c2kernel.common.ObjectNotFoundException;
-import com.c2kernel.entity.C2KLocalObject;
-import com.c2kernel.lookup.InvalidItemPathException;
-import com.c2kernel.lookup.ItemPath;
-import com.c2kernel.lookup.Lookup;
-import com.c2kernel.lookup.ldap.LDAPLookup;
-import com.c2kernel.lookup.ldap.LDAPPropertyManager;
-import com.c2kernel.process.Gateway;
-import com.c2kernel.process.auth.Authenticator;
-import com.c2kernel.property.Property;
-import com.c2kernel.utils.Logger;
-
-public class LDAPClusterStorage extends ClusterStorage {
- LDAPPropertyManager ldapStore;
-
- @Override
- public void open(Authenticator auth) throws ClusterStorageException {
- Lookup lookup = Gateway.getLookup();
- if (lookup instanceof LDAPLookup)
- ldapStore = ((LDAPLookup)lookup).getPropManager();
- else
- throw new ClusterStorageException("Cannot use LDAP cluster storage without LDAP Lookup");
-
- }
-
- @Override
- public void close() throws ClusterStorageException {
- }
-
- // introspection
- @Override
- public short queryClusterSupport(String clusterType) {
- if (clusterType.equals(PROPERTY))
- return READWRITE;
- else
- return NONE;
- }
-
- @Override
- public String getName() {
- return "LDAP Cluster Storage";
- }
-
- @Override
- public String getId() {
- return "LDAP";
- }
-
- // retrieve object by path
- @Override
- public C2KLocalObject get(Integer sysKey, String path) throws ClusterStorageException {
- Logger.msg(6, "LDAPClusterStorage.get() - "+sysKey+"/"+path);
- StringTokenizer tok = new StringTokenizer(path, "/");
- int pathLength = tok.countTokens();
- if (pathLength != 2)
- throw new ClusterStorageException("Path length was invalid: "+path);
- String type = tok.nextToken();
-
- ItemPath thisEntity;
- try {
- thisEntity = new ItemPath(sysKey.intValue());
- } catch (InvalidItemPathException e) {
- throw new ClusterStorageException("Invalid Syskey:"+sysKey);
- }
-
- String objName = tok.nextToken();
- C2KLocalObject newObj;
-
- if (type.equals(PROPERTY)) {
- try {
- Property newProperty = ldapStore.getProperty(thisEntity, objName);
- newObj = newProperty;
- } catch (ObjectNotFoundException ex) {
- throw new ClusterStorageException("Property "+objName+" not found in "+sysKey);
- }
-
- }
- else
- throw new ClusterStorageException("Cluster type "+type+" not supported.");
-
- return newObj;
- }
- // store object by path
- @Override
- public void put(Integer sysKey, C2KLocalObject obj) throws ClusterStorageException {
- Logger.msg(6, "LDAPClusterStorage.put() - "+sysKey+"/"+ClusterStorage.getPath(obj));
-
- String type = obj.getClusterType();
-
- ItemPath thisEntity;
- try {
- thisEntity = new ItemPath(sysKey.intValue());
- } catch (InvalidItemPathException e) {
- throw new ClusterStorageException("Invalid Syskey:"+sysKey);
- }
-
- if (type.equals(PROPERTY)) {
- try {
- ldapStore.setProperty(thisEntity, (Property)obj);
- } catch (Exception e1) {
- Logger.error(e1);
- throw new ClusterStorageException("LDAPClusterStorage - could not write property");
- }
- }
- else
- throw new ClusterStorageException("Cluster type "+type+" not supported.");
-
- }
- // delete cluster
- @Override
- public void delete(Integer sysKey, String path) throws ClusterStorageException {
- StringTokenizer tok = new StringTokenizer(path, "/");
- int pathLength = tok.countTokens();
- if (pathLength != 2)
- throw new ClusterStorageException("Path length was invalid: "+path);
- String type = tok.nextToken();
-
- ItemPath thisEntity;
- try {
- thisEntity = new ItemPath(sysKey.intValue());
- } catch (InvalidItemPathException e) {
- throw new ClusterStorageException("Invalid Syskey:"+sysKey);
- }
-
- if (type.equals(PROPERTY)) {
- try {
- ldapStore.deleteProperty(thisEntity, tok.nextToken());
- } catch (Exception e1) {
- Logger.error(e1);
- throw new ClusterStorageException("LDAPClusterStorage - could not delete property");
- }
- }
- else
- throw new ClusterStorageException("Cluster type "+type+" not supported.");
-
- }
-
- /* navigation */
-
- // directory listing
- @Override
- public String[] getClusterContents(Integer sysKey, String path) throws ClusterStorageException {
- Logger.msg(6, "LDAPClusterStorage.getClusterContents() - "+sysKey+"/"+path);
- StringTokenizer tok = new StringTokenizer(path, "/");
- int pathLength = tok.countTokens();
- if (pathLength > 1)
- return new String[0];
-
- String type = getClusterType(path);
- try
- {
- ItemPath thisEntity = new ItemPath(sysKey.intValue());
- if (type.equals(PROPERTY))
- return ldapStore.getPropertyNames(thisEntity);
- else
- if (type.equals("")) { // root query
- String[] allClusters = new String[0];
- ArrayList<String> clusterList = new ArrayList<String>();
- if (ldapStore.hasProperties(thisEntity))
- clusterList.add(PROPERTY);
- allClusters = clusterList.toArray(allClusters);
- return allClusters;
- }
- else
- throw new ClusterStorageException("Cluster type "+type+" not supported.");
- } catch (InvalidItemPathException e) {
- throw new ClusterStorageException("Invalid Syskey:"+sysKey);
- } catch (ObjectNotFoundException e) {
- throw new ClusterStorageException("Entity "+sysKey+" does not exist");
- }
- }
-}
diff --git a/src/main/java/com/c2kernel/persistency/NextKeyManager.java b/src/main/java/com/c2kernel/persistency/NextKeyManager.java
index 5afc872..48fa5af 100644
--- a/src/main/java/com/c2kernel/persistency/NextKeyManager.java
+++ b/src/main/java/com/c2kernel/persistency/NextKeyManager.java
@@ -4,6 +4,7 @@ import com.c2kernel.common.ObjectCannotBeUpdated;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.ItemPath;
+import com.c2kernel.process.auth.Authenticator;
/**
* @author abranson
@@ -11,6 +12,8 @@ import com.c2kernel.lookup.ItemPath;
*/
public interface NextKeyManager {
+
+ public void open(Authenticator auth);
/**
*
* @return