summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/lookup
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2013-02-18 15:01:46 +0100
committerAndrew Branson <andrew.branson@cern.ch>2013-03-18 14:03:53 +0100
commitd6cfc7505be13b3b09adf423206cf75d9f806c12 (patch)
tree8689ba2c6fdb7fba16ca7db9f9b11e90c010970b /src/main/java/com/c2kernel/lookup
parent843f2d127ca11a93de706bda4025dd27eeaed97c (diff)
Initial Interface creation. Some compilation problems remain.
Diffstat (limited to 'src/main/java/com/c2kernel/lookup')
-rw-r--r--src/main/java/com/c2kernel/lookup/AgentPath.java8
-rw-r--r--src/main/java/com/c2kernel/lookup/DomainPath.java2
-rw-r--r--src/main/java/com/c2kernel/lookup/LDAPLookup.java39
-rw-r--r--src/main/java/com/c2kernel/lookup/LDAPPathSet.java2
-rw-r--r--src/main/java/com/c2kernel/lookup/LDAPRoleManager.java24
-rw-r--r--src/main/java/com/c2kernel/lookup/Lookup.java100
-rw-r--r--src/main/java/com/c2kernel/lookup/Path.java10
-rw-r--r--src/main/java/com/c2kernel/lookup/RoleManager.java79
-rw-r--r--src/main/java/com/c2kernel/lookup/RolePath.java6
9 files changed, 233 insertions, 37 deletions
diff --git a/src/main/java/com/c2kernel/lookup/AgentPath.java b/src/main/java/com/c2kernel/lookup/AgentPath.java
index 5ff6988..8c83251 100644
--- a/src/main/java/com/c2kernel/lookup/AgentPath.java
+++ b/src/main/java/com/c2kernel/lookup/AgentPath.java
@@ -70,7 +70,7 @@ public class AgentPath extends EntityPath
if (mAgentName==null)
{
try {
- LDAPEntry agentEntry = LDAPLookupUtils.getEntry(Gateway.getLDAPLookup().getConnection(), this.getDN() + mLocalPath);
+ LDAPEntry agentEntry = LDAPLookupUtils.getEntry(Gateway.getLookup().getConnection(), this.getDN() + mLocalPath);
mAgentName = LDAPLookupUtils.getFirstAttributeValue(agentEntry,"uid");
} catch (ObjectNotFoundException e) {
mAgentName = "";
@@ -81,16 +81,16 @@ public class AgentPath extends EntityPath
public RolePath[] getRoles()
{
- return Gateway.getLDAPLookup().getRoleManager().getRoles(this);
+ return Gateway.getLookup().getRoleManager().getRoles(this);
}
public boolean hasRole(RolePath role) {
- return Gateway.getLDAPLookup().getRoleManager().hasRole(this, role);
+ return Gateway.getLookup().getRoleManager().hasRole(this, role);
}
public boolean hasRole(String role) {
try {
- return hasRole(Gateway.getLDAPLookup().getRoleManager().getRolePath(role));
+ return hasRole(Gateway.getLookup().getRoleManager().getRolePath(role));
} catch (ObjectNotFoundException ex) {
return false;
}
diff --git a/src/main/java/com/c2kernel/lookup/DomainPath.java b/src/main/java/com/c2kernel/lookup/DomainPath.java
index ce849ce..523ac49 100644
--- a/src/main/java/com/c2kernel/lookup/DomainPath.java
+++ b/src/main/java/com/c2kernel/lookup/DomainPath.java
@@ -108,7 +108,7 @@ public class DomainPath extends Path
public void checkType() {
try {
- setEntity(Gateway.getLDAPLookup().resolvePath(this));
+ setEntity(Gateway.getLookup().resolvePath(this));
} catch (InvalidEntityPathException ex) {
Logger.error(ex);
mType = CONTEXT;
diff --git a/src/main/java/com/c2kernel/lookup/LDAPLookup.java b/src/main/java/com/c2kernel/lookup/LDAPLookup.java
index d581dfd..ab5992c 100644
--- a/src/main/java/com/c2kernel/lookup/LDAPLookup.java
+++ b/src/main/java/com/c2kernel/lookup/LDAPLookup.java
@@ -37,7 +37,7 @@ import com.novell.ldap.LDAPSearchResults;
* @author $Author: abranson $
*/
-public class LDAPLookup
+public class LDAPLookup implements Lookup
{
private LDAPConnection mLDAPConn;
@@ -111,7 +111,8 @@ public class LDAPLookup
* Gets the entity key generator, used to get a unique system key for new entities.
* @return the global NextKeyManager
*/
- public NextKeyManager getNextKeyManager()
+ @Override
+ public NextKeyManager getNextKeyManager()
{
return mNextKeyManager;
}
@@ -127,7 +128,8 @@ public class LDAPLookup
* Gets the role manager, that is used to add and remove roles and agents.
* @return Returns the mRoleManager.
*/
- public LDAPRoleManager getRoleManager() {
+ @Override
+ public LDAPRoleManager getRoleManager() {
return mRoleManager;
}
@@ -149,7 +151,8 @@ public class LDAPLookup
/**
* Disconnects the connection with the LDAP server during shutdown
*/
- public void disconnect() {
+ @Override
+ public void disconnect() {
Logger.msg(1, "LDAP Lookup: Shutting down LDAP connection.");
if (mLDAPConn != null) {
try {
@@ -167,7 +170,8 @@ public class LDAPLookup
* @return the CORBA object
* @throws ObjectNotFoundException When the path does not exist
*/
- public org.omg.CORBA.Object getIOR(Path path)
+ @Override
+ public org.omg.CORBA.Object resolve(Path path)
throws ObjectNotFoundException
{
return resolveObject(path.getFullDN());
@@ -208,7 +212,8 @@ public class LDAPLookup
* @throws InvalidEntityPathException
* @throws ObjectNotFoundException
*/
- protected EntityPath resolvePath(DomainPath domPath)
+ @Override
+ public EntityPath resolvePath(DomainPath domPath)
throws InvalidEntityPathException, ObjectNotFoundException {
EntityPath referencedPath = null;
LDAPEntry domEntry = LDAPLookupUtils.getEntry(getConnection(), domPath
@@ -228,7 +233,8 @@ public class LDAPLookup
}
- public LDAPEntry add(Path path)
+ @Override
+ public void add(Path path)
throws ObjectCannotBeUpdated, ObjectAlreadyExistsException
{
try {
@@ -238,7 +244,6 @@ public class LDAPLookup
LDAPLookupUtils.addEntry(getConnection(),newEntry);
if (path instanceof DomainPath)
EntityProxyManager.sendProxyEvent(new ProxyMessage(ProxyMessage.NA, path.toString(), ProxyMessage.ADDED));
- return newEntry;
} catch (LDAPException ex) {
if (ex.getResultCode() == LDAPException.ENTRY_ALREADY_EXISTS)
throw new ObjectAlreadyExistsException(ex.getLDAPErrorMessage(), "");
@@ -249,7 +254,8 @@ public class LDAPLookup
//deletes a node
//throws LDAPexception if node cannot be deleted (eg node is not a leaf)
- public void delete(Path path) throws ObjectCannotBeUpdated
+ @Override
+ public void delete(Path path) throws ObjectCannotBeUpdated
{
try {
LDAPLookupUtils.delete(getConnection(),path.getDN()+Path.mLocalPath);
@@ -302,7 +308,8 @@ public class LDAPLookup
LDAPLookupUtils.createCristalContext(getConnection(), Path.mLocalPath);
}
- public void install() throws ObjectNotFoundException
+ @Override
+ public void install() throws ObjectNotFoundException
{
createBootTree();
initTree( Resource.getTextResource(null, "boot/LDAPboot.txt"));
@@ -322,7 +329,8 @@ public class LDAPLookup
}
//typically search for cn=barcode
- public LDAPPathSet search(Path start, String filter)
+ @Override
+ public LDAPPathSet search(Path start, String filter)
{
Logger.msg(8,"LDAPLookup::search() From " + start.getDN() + " for cn=" + filter );
return search(start.getFullDN(),"cn="+LDAPLookupUtils.escapeSearchFilter(filter));
@@ -364,7 +372,8 @@ public class LDAPLookup
return search(startDN,LDAPConnection.SCOPE_SUB,filter,searchCons);
}
- public LDAPPathSet searchEntities(Path start) {
+ @Override
+ public LDAPPathSet searchEntities(Path start) {
LDAPSearchConstraints searchCons = new LDAPSearchConstraints();
searchCons.setBatchSize(0);
searchCons.setDereference(LDAPSearchConstraints.DEREF_SEARCHING);
@@ -378,11 +387,13 @@ public class LDAPLookup
return search(start.getFullDN(), LDAPConnection.SCOPE_SUB, "objectClass=aliasObject", searchCons);
}
- public boolean exists(Path path) {
+ @Override
+ public boolean exists(Path path) {
return LDAPLookupUtils.exists(getConnection(), path.getFullDN());
}
- public Class<?> getEntityClass(Path path) throws ObjectNotFoundException {
+ @Override
+ public Class<?> getEntityClass(Path path) throws ObjectNotFoundException {
String[] attr = { LDAPConnection.ALL_USER_ATTRS };
try {
LDAPEntry anEntry=getConnection().read(path.getDN()+Path.mLocalPath,attr);
diff --git a/src/main/java/com/c2kernel/lookup/LDAPPathSet.java b/src/main/java/com/c2kernel/lookup/LDAPPathSet.java
index d3cf7d9..1ebd97d 100644
--- a/src/main/java/com/c2kernel/lookup/LDAPPathSet.java
+++ b/src/main/java/com/c2kernel/lookup/LDAPPathSet.java
@@ -54,7 +54,7 @@ public class LDAPPathSet implements Enumeration<Path> {
try {
if (nextEntry == null)
nextEntry = results.next();
- Path nextPath = Gateway.getLDAPLookup().nodeToPath(nextEntry);
+ Path nextPath = ((LDAPLookup)Gateway.getLookup()).nodeToPath(nextEntry);
nextEntry = null;
return nextPath;
} catch (Exception ex) {
diff --git a/src/main/java/com/c2kernel/lookup/LDAPRoleManager.java b/src/main/java/com/c2kernel/lookup/LDAPRoleManager.java
index 0536d6c..e046550 100644
--- a/src/main/java/com/c2kernel/lookup/LDAPRoleManager.java
+++ b/src/main/java/com/c2kernel/lookup/LDAPRoleManager.java
@@ -22,7 +22,7 @@ import com.novell.ldap.LDAPSearchConstraints;
**************************************************************************/
// public static final String codeRevision = "$Revision: 1.1 $ $Date: 2005/04/26 06:48:12 $ $Author: abranson $";
-public class LDAPRoleManager {
+public class LDAPRoleManager implements RoleManager {
/**
*
@@ -41,7 +41,8 @@ public class LDAPRoleManager {
//NOTE: A role must have at LEAST 1 userDN, cannot be empty...
//Creates a cristalRole
//CristalRole is-a specialized CristalContext which contains multi-valued uniqueMember attribute pointing to cristalagents
- public RolePath createRole(String roleName, boolean jobList)
+ @Override
+ public RolePath createRole(String roleName, boolean jobList)
throws ObjectAlreadyExistsException, ObjectCannotBeUpdated
{
@@ -74,7 +75,8 @@ public class LDAPRoleManager {
}
}
- protected void addRole(AgentPath agent, RolePath role)
+ @Override
+ public void addRole(AgentPath agent, RolePath role)
throws ObjectCannotBeUpdated, ObjectNotFoundException
{
LDAPEntry roleEntry = LDAPLookupUtils.getEntry(mLdap.getConnection(), role.getFullDN());
@@ -85,7 +87,7 @@ public class LDAPRoleManager {
throw new ObjectCannotBeUpdated("Agent " + agent.getAgentName() + " already has role " + role.getName());
}
- protected void removeRole(AgentPath agent, RolePath role)
+ public void removeRole(AgentPath agent, RolePath role)
throws ObjectCannotBeUpdated, ObjectNotFoundException
{
LDAPEntry roleEntry = LDAPLookupUtils.getEntry(mLdap.getConnection(), role.getFullDN());
@@ -95,7 +97,7 @@ public class LDAPRoleManager {
throw new ObjectCannotBeUpdated("Agent did not have that role");
}
- protected boolean hasRole(AgentPath agent, RolePath role) {
+ public boolean hasRole(AgentPath agent, RolePath role) {
String filter = "(&(objectclass=cristalrole)(uniqueMember="+agent.getFullDN()+")(cn="+role.getName()+"))";
LDAPSearchConstraints searchCons = new LDAPSearchConstraints();
searchCons.setBatchSize(0);
@@ -103,7 +105,8 @@ public class LDAPRoleManager {
return mLdap.search(mRolePath,LDAPConnection.SCOPE_SUB,filter,searchCons).hasMoreElements();
}
- protected AgentPath[] getAgents(RolePath role)
+ @Override
+ public AgentPath[] getAgents(RolePath role)
throws ObjectNotFoundException
{
//get the roleDN entry, and its uniqueMember entry pointing to
@@ -133,7 +136,8 @@ public class LDAPRoleManager {
}
//returns the role/s of a user
- protected RolePath[] getRoles(AgentPath agentPath)
+ @Override
+ public RolePath[] getRoles(AgentPath agentPath)
{
//search the mDomainPath tree uniqueMember=userDN
//filter = objectclass=cristalrole AND uniqueMember=userDN
@@ -163,7 +167,8 @@ public class LDAPRoleManager {
* @return
* @throws ObjectNotFoundException
*/
- public AgentPath getAgentPath(String agentName) throws ObjectNotFoundException
+ @Override
+ public AgentPath getAgentPath(String agentName) throws ObjectNotFoundException
{
//search to get the userDN equivalent of the userID
LDAPSearchConstraints searchCons = new LDAPSearchConstraints();
@@ -180,7 +185,8 @@ public class LDAPRoleManager {
throw new ObjectNotFoundException("Entry was not an Agent");
}
- public RolePath getRolePath(String roleName) throws ObjectNotFoundException
+ @Override
+ public RolePath getRolePath(String roleName) throws ObjectNotFoundException
{
LDAPSearchConstraints searchCons = new LDAPSearchConstraints();
searchCons.setBatchSize(0);
diff --git a/src/main/java/com/c2kernel/lookup/Lookup.java b/src/main/java/com/c2kernel/lookup/Lookup.java
new file mode 100644
index 0000000..0ddc448
--- /dev/null
+++ b/src/main/java/com/c2kernel/lookup/Lookup.java
@@ -0,0 +1,100 @@
+/*
+ * Lookup.java
+ *
+ * Copyright (c) 2013, The CRISTAL Consortium. All rights reserved.
+ *
+ * CRISTAL kernel is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see:
+ * http://www.gnu.org/licenses/
+ */
+
+package com.c2kernel.lookup;
+
+import java.util.Enumeration;
+
+import org.omg.CORBA.Object;
+
+import com.c2kernel.common.ObjectAlreadyExistsException;
+import com.c2kernel.common.ObjectCannotBeUpdated;
+import com.c2kernel.common.ObjectNotFoundException;
+
+public interface Lookup {
+
+ /**
+ * @param path
+ * @return
+ */
+ public Class<?> getEntityClass(Path path) throws ObjectNotFoundException;
+
+ /**
+ * @return
+ */
+ public NextKeyManager getNextKeyManager();
+
+ /**
+ * @return
+ */
+ public RoleManager getRoleManager();
+
+ /**
+ * @param path
+ * @return
+ */
+ public Object resolve(Path path) throws ObjectNotFoundException;
+
+ /**
+ * @param path
+ * @param name
+ * @return
+ */
+ public Enumeration<Path> search(Path path, String name);
+
+ /**
+ * @param newPath
+ */
+ public void add(Path newPath) throws ObjectCannotBeUpdated, ObjectAlreadyExistsException;
+
+ /**
+ * @param domainPath
+ * @return
+ */
+ public Enumeration<Path> searchEntities(Path path);
+
+ /**
+ * @param path
+ */
+ public void delete(Path path) throws ObjectCannotBeUpdated;
+
+ /**
+ * @param path
+ * @return
+ */
+ public boolean exists(Path path);
+
+ /**
+ * @param domainPath
+ * @return
+ */
+ public EntityPath resolvePath(DomainPath domainPath) throws InvalidEntityPathException, ObjectNotFoundException;
+
+ /**
+ *
+ */
+ public void disconnect();
+
+ /**
+ *
+ */
+ public void install() throws ObjectNotFoundException;
+
+}
diff --git a/src/main/java/com/c2kernel/lookup/Path.java b/src/main/java/com/c2kernel/lookup/Path.java
index 16d4f07..3ede4b6 100644
--- a/src/main/java/com/c2kernel/lookup/Path.java
+++ b/src/main/java/com/c2kernel/lookup/Path.java
@@ -227,7 +227,7 @@ public abstract class Path implements Serializable
}
public boolean exists() {
- return Gateway.getLDAPLookup().exists(this);
+ return Gateway.getLookup().exists(this);
}
/** Queries the lookup for the IOR
@@ -236,9 +236,9 @@ public abstract class Path implements Serializable
public org.omg.CORBA.Object getIOR() {
org.omg.CORBA.Object newIOR = null;
if (mIOR==null) { // if not cached try to resolve
- LDAPLookup myLookup = Gateway.getLDAPLookup();
+ Lookup myLookup = Gateway.getLookup();
try {
- newIOR = myLookup.getIOR(this);
+ newIOR = myLookup.resolve(this);
} catch (ObjectNotFoundException ex) {
}
setIOR(newIOR);
@@ -264,11 +264,11 @@ public abstract class Path implements Serializable
LDAPSearchConstraints searchCons = new LDAPSearchConstraints();
searchCons.setBatchSize(10);
searchCons.setDereference(LDAPSearchConstraints.DEREF_FINDING );
- return Gateway.getLDAPLookup().search(getFullDN(), LDAPConnection.SCOPE_ONE,filter,searchCons);
+ return Gateway.getLookup().search(getFullDN(), LDAPConnection.SCOPE_ONE,filter,searchCons);
}
public Path find(String name) throws ObjectNotFoundException {
- Enumeration<Path> e = Gateway.getLDAPLookup().search(this, name);
+ Enumeration<Path> e = Gateway.getLookup().search(this, name);
if (e.hasMoreElements()) {
Path thisPath = e.nextElement();
if (e.hasMoreElements())
diff --git a/src/main/java/com/c2kernel/lookup/RoleManager.java b/src/main/java/com/c2kernel/lookup/RoleManager.java
new file mode 100644
index 0000000..a483559
--- /dev/null
+++ b/src/main/java/com/c2kernel/lookup/RoleManager.java
@@ -0,0 +1,79 @@
+/*
+ * RoleManager.java
+ *
+ * Copyright (c) 2013, The CRISTAL Consortium. All rights reserved.
+ *
+ * CRISTAL kernel is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see:
+ * http://www.gnu.org/licenses/
+ */
+
+package com.c2kernel.lookup;
+
+import com.c2kernel.common.ObjectAlreadyExistsException;
+import com.c2kernel.common.ObjectCannotBeUpdated;
+import com.c2kernel.common.ObjectNotFoundException;
+
+public interface RoleManager {
+
+ /**
+ * @param agentName
+ * @return
+ */
+ public AgentPath getAgentPath(String agentName) throws ObjectNotFoundException;
+
+ /**
+ * @param roleName
+ * @return
+ */
+ public RolePath getRolePath(String roleName) throws ObjectNotFoundException;
+
+ /**
+ * @param role
+ * @param b
+ * @return
+ */
+ public RolePath createRole(String role, boolean b) throws ObjectAlreadyExistsException, ObjectCannotBeUpdated;
+
+ /**
+ * @param agent
+ * @param rolePath
+ */
+ public void addRole(AgentPath agent, RolePath rolePath) throws ObjectCannotBeUpdated, ObjectNotFoundException;
+
+ /**
+ * @param rolePath
+ * @return
+ */
+ public AgentPath[] getAgents(RolePath rolePath) throws ObjectNotFoundException;
+
+ /**
+ * @param agentPath
+ * @return
+ */
+ public RolePath[] getRoles(AgentPath agentPath);
+
+ /**
+ * @param agentPath
+ * @param role
+ * @return
+ */
+ public boolean hasRole(AgentPath agentPath, RolePath role);
+
+ /**
+ * @param agent
+ * @param rolePath
+ */
+ public void removeRole(AgentPath agent, RolePath role) throws ObjectCannotBeUpdated, ObjectNotFoundException;
+
+}
diff --git a/src/main/java/com/c2kernel/lookup/RolePath.java b/src/main/java/com/c2kernel/lookup/RolePath.java
index e6593ea..cdda034 100644
--- a/src/main/java/com/c2kernel/lookup/RolePath.java
+++ b/src/main/java/com/c2kernel/lookup/RolePath.java
@@ -73,7 +73,7 @@ public class RolePath extends DomainPath
public AgentPath[] getAgentsWithRole() {
try {
- return Gateway.getLDAPLookup().getRoleManager().getAgents(this);
+ return Gateway.getLookup().getRoleManager().getAgents(this);
} catch (ObjectNotFoundException ex) {
Logger.error("Cannot retrieve agent list. Role "+getName()+" does not exist in LDAP");
return new AgentPath[0];
@@ -81,11 +81,11 @@ public class RolePath extends DomainPath
}
public void addAgent(AgentPath agent) throws ObjectCannotBeUpdated, ObjectNotFoundException {
- Gateway.getLDAPLookup().getRoleManager().addRole(agent, this);
+ Gateway.getLookup().getRoleManager().addRole(agent, this);
}
public void removeAgent(AgentPath agent) throws ObjectCannotBeUpdated, ObjectNotFoundException {
- Gateway.getLDAPLookup().getRoleManager().removeRole(agent, this);
+ Gateway.getLookup().getRoleManager().removeRole(agent, this);
}
@Override