diff options
Diffstat (limited to 'pki/base/common/src/com/netscape/cmscore/request')
10 files changed, 661 insertions, 715 deletions
diff --git a/pki/base/common/src/com/netscape/cmscore/request/ARequestQueue.java b/pki/base/common/src/com/netscape/cmscore/request/ARequestQueue.java index 2da14467e..fbc5052de 100644 --- a/pki/base/common/src/com/netscape/cmscore/request/ARequestQueue.java +++ b/pki/base/common/src/com/netscape/cmscore/request/ARequestQueue.java @@ -17,7 +17,6 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.request; - import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -62,31 +61,29 @@ import com.netscape.certsrv.request.PolicyResult; import com.netscape.certsrv.request.RequestId; import com.netscape.certsrv.request.RequestStatus; - /** - * The ARequestQueue class is an abstract class that implements - * most portions of the IRequestQueue interface. This includes - * the state engine as defined for processing IRequest objects. + * The ARequestQueue class is an abstract class that implements most portions of + * the IRequestQueue interface. This includes the state engine as defined for + * processing IRequest objects. * <p> * !Put state machine description here! * <p> - * This class defines several abstract protected functions that - * need to be defined by the concrete implementation. In - * particular, this class does not implement the operations - * for storing requests persistantly. + * This class defines several abstract protected functions that need to be + * defined by the concrete implementation. In particular, this class does not + * implement the operations for storing requests persistantly. * <p> - * This class also provides several accessor functions for setting - * fields in the IRequest object. These functions are provided - * as an aid to saving and restoring the state in the database. + * This class also provides several accessor functions for setting fields in the + * IRequest object. These functions are provided as an aid to saving and + * restoring the state in the database. * <p> - * This class also implements the locking operations specified by - * the IRequestQueue interface. + * This class also implements the locking operations specified by the + * IRequestQueue interface. * <p> + * * @author thayes * @version $Revision$ $Date$ */ -public abstract class ARequestQueue - implements IRequestQueue { +public abstract class ARequestQueue implements IRequestQueue { /** * global request version for tracking request changes. @@ -96,37 +93,34 @@ public abstract class ARequestQueue /** * Create a new (unique) RequestId. (abstract) * <p> - * This method must be implemented by the specialized class to - * generate a new id from data in the persistant store. This id - * is used to create a new request object. + * This method must be implemented by the specialized class to generate a + * new id from data in the persistant store. This id is used to create a new + * request object. * <p> - * @return - * a new RequestId object. - * @exception EBaseException - * indicates that creation of the new id could not be completed. + * + * @return a new RequestId object. + * @exception EBaseException indicates that creation of the new id could not + * be completed. * @see RequestId */ - protected abstract RequestId newRequestId() - throws EBaseException; + protected abstract RequestId newRequestId() throws EBaseException; /** * Read a request from the persistant store. (abstract) * <p> - * This function is called to create the in-memory version of - * a request object. + * This function is called to create the in-memory version of a request + * object. * <p> - * The implementation of this object can use the createRequest - * member function to create a new instance of an IRequest, and - * use the setRequestStatus, setCreationTime and setModificationTime - * functions to set those values. + * The implementation of this object can use the createRequest member + * function to create a new instance of an IRequest, and use the + * setRequestStatus, setCreationTime and setModificationTime functions to + * set those values. * <p> - * @param id - * the id of the request to read. - * @return - * a new IRequest object. null is returned if the object cannot - * be located. - * @exception EBaseException - * TODO: this is not implemented yet + * + * @param id the id of the request to read. + * @return a new IRequest object. null is returned if the object cannot be + * located. + * @exception EBaseException TODO: this is not implemented yet * @see #createRequest * @see #setRequestStatus * @see #setModificationTime @@ -137,56 +131,51 @@ public abstract class ARequestQueue /** * Add the request to the store. (abstract) * <p> - * This function is called when a new request immediately after - * creating a new request. + * This function is called when a new request immediately after creating a + * new request. * <p> - * @param request - * the request to add. - * @exception EBaseException - * TODO: this is not implemented yet + * + * @param request the request to add. + * @exception EBaseException TODO: this is not implemented yet */ protected abstract void addRequest(IRequest request) throws EBaseException; /** * Modify the request in the store. (abstract) * <p> - * Update the persistant copy of this request with the - * current values in the object. + * Update the persistant copy of this request with the current values in the + * object. * <p> - * Currently there are no hints for what has changed, so - * the entire request should be updated. + * Currently there are no hints for what has changed, so the entire request + * should be updated. * <p> + * * @param request - * @exception EBaseException - * TODO: this is not implemented yet + * @exception EBaseException TODO: this is not implemented yet */ protected abstract void modifyRequest(IRequest request); /** - * Get complete list of RequestId values found i this - * queue. + * Get complete list of RequestId values found i this queue. * <p> - * This method can form the basis for creating other types - * of search/list operations (although there are probably more - * efficient ways of doing this. ARequestQueue implements - * default versions of some of the searching by using this - * method as a basis. + * This method can form the basis for creating other types of search/list + * operations (although there are probably more efficient ways of doing + * this. ARequestQueue implements default versions of some of the searching + * by using this method as a basis. * <p> - * TODO: return IRequestList -or- just use listRequests as - * the basic engine. + * TODO: return IRequestList -or- just use listRequests as the basic engine. * <p> - * @return - * an Enumeration that generates RequestId objects. + * + * @return an Enumeration that generates RequestId objects. */ abstract protected Enumeration getRawList(); /** * protected access for setting the current state of a request. * <p> - * @param request - * The request to be modified. - * @param status - * The new value for the request status. + * + * @param request The request to be modified. + * @param status The new value for the request status. */ protected final void setRequestStatus(IRequest request, RequestStatus status) { Request r = (Request) request; @@ -197,10 +186,9 @@ public abstract class ARequestQueue /** * protected access for setting the modification time of a request. * <p> - * @param request - * The request to be modified. - * @param date - * The new value for the time. + * + * @param request The request to be modified. + * @param date The new value for the time. */ protected final void setModificationTime(IRequest request, Date date) { Request r = (Request) request; @@ -211,10 +199,9 @@ public abstract class ARequestQueue /** * protected access for setting the creation time of a request. * <p> - * @param request - * The request to be modified. - * @param date - * The new value for the time. + * + * @param request The request to be modified. + * @param date The new value for the time. */ protected final void setCreationTime(IRequest request, Date date) { Request r = (Request) request; @@ -225,20 +212,19 @@ public abstract class ARequestQueue /** * protected access for creating a new Request object * <p> - * @param id - * The identifier for the new request - * @return - * A new request object. The caller should fill in other data - * values from the datastore. + * + * @param id The identifier for the new request + * @return A new request object. The caller should fill in other data values + * from the datastore. */ protected final IRequest createRequest(RequestId id, String requestType) { Request r; /* * Determine the specialized class to create for this type - * - * TODO: this set of classes is an example only. The real set - * needs to be determined and implemented. + * + * TODO: this set of classes is an example only. The real set needs to + * be determined and implemented. */ if (requestType != null && requestType.equals("enrollment")) { r = new EnrollmentRequest(id); @@ -250,14 +236,15 @@ public abstract class ARequestQueue } /** - * Implements IRequestQueue.newRequest + * Implements IRequestQueue.newRequest * <p> + * * @see IRequestQueue#newRequest */ - public IRequest newRequest(String requestType) - throws EBaseException { + public IRequest newRequest(String requestType) throws EBaseException { if (requestType == null) { - throw new EBaseException(CMS.getUserMessage("CMS_BASE_INVALID_REQUEST_TYPE", "null")); + throw new EBaseException(CMS.getUserMessage( + "CMS_BASE_INVALID_REQUEST_TYPE", "null")); } RequestId rId = newRequestId(); IRequest r = createRequest(rId, requestType); @@ -287,16 +274,17 @@ public abstract class ARequestQueue /** * Implements IRequestQueue.cloneRequest * <p> + * * @see IRequestQueue#cloneRequest */ - public IRequest cloneRequest(IRequest r) - throws EBaseException { - // 1. check for valid state. (Are any invalid ?) + public IRequest cloneRequest(IRequest r) throws EBaseException { + // 1. check for valid state. (Are any invalid ?) RequestStatus rs = r.getRequestStatus(); - if (rs == RequestStatus.BEGIN) throw new EBaseException("Invalid Status"); + if (rs == RequestStatus.BEGIN) + throw new EBaseException("Invalid Status"); - // 2. create new request + // 2. create new request String reqType = r.getRequestType(); IRequest clone = newRequest(reqType); @@ -316,10 +304,10 @@ public abstract class ARequestQueue /** * Implements IRequestQueue.findRequest * <p> + * * @see IRequestQueue#findRequest */ - public IRequest findRequest(RequestId id) - throws EBaseException { + public IRequest findRequest(RequestId id) throws EBaseException { IRequest r; // mTable.lock(id); @@ -327,12 +315,12 @@ public abstract class ARequestQueue r = readRequest(id); // if (r == null) mTable.unlock(id); - + return r; } private IRequestScheduler mRequestScheduler = null; - + public void setRequestScheduler(IRequestScheduler scheduler) { mRequestScheduler = scheduler; } @@ -344,10 +332,10 @@ public abstract class ARequestQueue /** * Implements IRequestQueue.processRequest * <p> + * * @see IRequestQueue#processRequest */ - public final void processRequest(IRequest r) - throws EBaseException { + public final void processRequest(IRequest r) throws EBaseException { // #610553 Thread Scheduler IRequestScheduler scheduler = getRequestScheduler(); @@ -360,7 +348,8 @@ public abstract class ARequestQueue // 1. Check for valid state RequestStatus rs = r.getRequestStatus(); - if (rs != RequestStatus.BEGIN) throw new EBaseException("Invalid Status"); + if (rs != RequestStatus.BEGIN) + throw new EBaseException("Invalid Status"); stateEngine(r); } finally { @@ -373,19 +362,20 @@ public abstract class ARequestQueue /** * Implements IRequestQueue.markRequestPending * <p> + * * @see IRequestQueue#markRequestPending */ - public final void markRequestPending(IRequest r) - throws EBaseException { + public final void markRequestPending(IRequest r) throws EBaseException { // 1. Check for valid state RequestStatus rs = r.getRequestStatus(); - if (rs != RequestStatus.BEGIN) throw new EBaseException("Invalid Status"); + if (rs != RequestStatus.BEGIN) + throw new EBaseException("Invalid Status"); - // 2. Change the request state. This method of making - // a request PENDING does NOT invoke the PENDING notifiers. - // To change this, just call stateEngine at the completion of this - // routine. + // 2. Change the request state. This method of making + // a request PENDING does NOT invoke the PENDING notifiers. + // To change this, just call stateEngine at the completion of this + // routine. setRequestStatus(r, RequestStatus.PENDING); updateRequest(r); @@ -395,10 +385,10 @@ public abstract class ARequestQueue /** * Implements IRequestQueue.cloneAndMarkPending * <p> + * * @see IRequestQueue#cloneAndMarkPending */ - public IRequest cloneAndMarkPending(IRequest r) - throws EBaseException { + public IRequest cloneAndMarkPending(IRequest r) throws EBaseException { IRequest clone = cloneRequest(r); markRequestPending(clone); @@ -408,17 +398,18 @@ public abstract class ARequestQueue /** * Implements IRequestQueue.approveRequest * <p> + * * @see IRequestQueue#approveRequest */ - public final void approveRequest(IRequest r) - throws EBaseException { + public final void approveRequest(IRequest r) throws EBaseException { // 1. Check for valid state RequestStatus rs = r.getRequestStatus(); - if (rs != RequestStatus.PENDING) throw new EBaseException("Invalid Status"); + if (rs != RequestStatus.PENDING) + throw new EBaseException("Invalid Status"); - AgentApprovals aas = AgentApprovals.fromStringVector( - r.getExtDataInStringVector(AgentApprovals.class.getName())); + AgentApprovals aas = AgentApprovals.fromStringVector(r + .getExtDataInStringVector(AgentApprovals.class.getName())); if (aas == null) { aas = new AgentApprovals(); } @@ -426,7 +417,8 @@ public abstract class ARequestQueue // Record agent who did this String agentName = getUserIdentity(); - if (agentName == null) throw new EBaseException("Missing agent information"); + if (agentName == null) + throw new EBaseException("Missing agent information"); aas.addApproval(agentName); r.setExtData(AgentApprovals.class.getName(), aas.toStringVector()); @@ -435,8 +427,7 @@ public abstract class ARequestQueue if (pr == PolicyResult.ACCEPTED) { setRequestStatus(r, RequestStatus.APPROVED); - } else if (pr == PolicyResult.DEFERRED || - pr == PolicyResult.REJECTED) { + } else if (pr == PolicyResult.DEFERRED || pr == PolicyResult.REJECTED) { } // Always update. The policy code may have made changes to the @@ -449,16 +440,17 @@ public abstract class ARequestQueue /** * Implements IRequestQueue.rejectRequest * <p> + * * @see IRequestQueue#rejectRequest */ - public final void rejectRequest(IRequest r) - throws EBaseException { + public final void rejectRequest(IRequest r) throws EBaseException { // 1. Check for valid state RequestStatus rs = r.getRequestStatus(); - if (rs != RequestStatus.PENDING) throw new EBaseException("Invalid Status"); + if (rs != RequestStatus.PENDING) + throw new EBaseException("Invalid Status"); - // 2. Change state + // 2. Change state setRequestStatus(r, RequestStatus.REJECTED); updateRequest(r); @@ -469,10 +461,10 @@ public abstract class ARequestQueue /** * Implments IRequestQueue.cancelRequest * <p> + * * @see IRequestQueue#cancelRequest */ - public final void cancelRequest(IRequest r) - throws EBaseException { + public final void cancelRequest(IRequest r) throws EBaseException { setRequestStatus(r, RequestStatus.CANCELED); updateRequest(r); @@ -488,7 +480,8 @@ public abstract class ARequestQueue setRequestStatus(r, RequestStatus.COMPLETE); updateRequest(r); - if (mNotify != null) mNotify.notify(r); + if (mNotify != null) + mNotify.notify(r); return; } @@ -496,10 +489,10 @@ public abstract class ARequestQueue /** * Implements IRequestQueue.listRequests * <p> - * Should be overridden by the specialized class if - * a more efficient method is available for implementing - * this operation. + * Should be overridden by the specialized class if a more efficient method + * is available for implementing this operation. * <P> + * * @see IRequestQueue#listRequests */ public IRequestList listRequests() { @@ -509,10 +502,10 @@ public abstract class ARequestQueue /** * Implements IRequestQueue.listRequestsByStatus * <p> - * Should be overridden by the specialized class if - * a more efficient method is available for implementing - * this operation. + * Should be overridden by the specialized class if a more efficient method + * is available for implementing this operation. * <P> + * * @see IRequestQueue#listRequestsByStatus */ public IRequestList listRequestsByStatus(RequestStatus s) { @@ -522,6 +515,7 @@ public abstract class ARequestQueue /** * Implements IRequestQueue.releaseRequest * <p> + * * @see IRequestQueue#releaseRequest */ public final void releaseRequest(IRequest request) { @@ -533,17 +527,17 @@ public abstract class ARequestQueue String name = getUserIdentity(); - if (name != null) r.setExtData(IRequest.UPDATED_BY, name); + if (name != null) + r.setExtData(IRequest.UPDATED_BY, name); - // TODO: use a state flag to determine whether to call - // addRequest or modifyRequest (see newRequest as well) + // TODO: use a state flag to determine whether to call + // addRequest or modifyRequest (see newRequest as well) modifyRequest(r); } // PRIVATE functions - private final void stateEngine(IRequest r) - throws EBaseException { + private final void stateEngine(IRequest r) throws EBaseException { boolean complete = false; while (!complete) { @@ -617,14 +611,14 @@ public abstract class ARequestQueue // write the queue name and request id // write who changed it // write what change (which state change) was made - // - new (processRequest) - // - approve - // - reject + // - new (processRequest) + // - approve + // - reject // Ordering - // - make change in memory - // - log change and result - // - update record + // - make change in memory + // - log change and result + // - update record } /** @@ -643,15 +637,15 @@ public abstract class ARequestQueue */ public void recover() { if (CMS.isRunningMode()) { - RecoverThread t = new RecoverThread(this); + RecoverThread t = new RecoverThread(this); - t.start(); + t.start(); } } /** - * recover from a crash. Resends all requests that are in - * the APPROVED state. + * recover from a crash. Resends all requests that are in the APPROVED + * state. */ public void recoverWillBlock() { // Get a list of all requests that are APPROVED @@ -664,7 +658,7 @@ public abstract class ARequestQueue try { request = findRequest(rid); - //if (request == null) log_error + // if (request == null) log_error // Recheck the status - should be the same!! if (request.getRequestStatus() == RequestStatus.APPROVED) { @@ -684,7 +678,7 @@ public abstract class ARequestQueue // Constructor protected ARequestQueue(IPolicy policy, IService service, INotify notify, - INotify pendingNotify) { + INotify pendingNotify) { mPolicy = policy; mService = service; mNotify = notify; @@ -704,44 +698,29 @@ public abstract class ARequestQueue protected ILogger mLogger; } - // // Table of RequestId values that are currently in use by some thread. // The fact that the request is in this table constitutes a lock // on the value. // /* - class RequestIDTable { - public synchronized void lock(RequestId id) { - while (true) { - if (mHashtable.put(id, id) == null) - break; - - try { - wait(); - } catch (InterruptedException e) { - }; - } - } - - public synchronized void unlock(RequestId id) { - mHashtable.remove(id); - - notifyAll(); - } - - // instance variables - Hashtable mHashtable = new Hashtable(); - } + * class RequestIDTable { public synchronized void lock(RequestId id) { while + * (true) { if (mHashtable.put(id, id) == null) break; + * + * try { wait(); } catch (InterruptedException e) { }; } } + * + * public synchronized void unlock(RequestId id) { mHashtable.remove(id); + * + * notifyAll(); } + * + * // instance variables Hashtable mHashtable = new Hashtable(); } */ - // -// Request - implementation of the IRequest interface. This +// Request - implementation of the IRequest interface. This // version is returned by ARequestQueue (and its derivatives) // -class Request - implements IRequest { +class Request implements IRequest { // IRequest.getRequestId public RequestId getRequestId() { return mRequestId; @@ -833,9 +812,9 @@ class Request Enumeration e = req.getExtDataKeys(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); - if (!key.equals(IRequest.ISSUED_CERTS) && - !key.equals(IRequest.ERRORS) && - !key.equals(IRequest.REMOTE_REQID)) { + if (!key.equals(IRequest.ISSUED_CERTS) + && !key.equals(IRequest.ERRORS) + && !key.equals(IRequest.REMOTE_REQID)) { if (req.isSimpleExtDataValue(key)) { setExtData(key, req.getExtDataInString(key)); } else { @@ -847,15 +826,14 @@ class Request /** * This function used to check that the keys obeyed LDAP attribute name - * syntax rules. Keys are being encoded now, so it is changed to just - * filter out null and empty string keys. - * - * @param key The key to check - * @return false if invalid + * syntax rules. Keys are being encoded now, so it is changed to just filter + * out null and empty string keys. + * + * @param key The key to check + * @return false if invalid */ protected boolean isValidExtDataKey(String key) { - return key != null && - (! key.equals("")); + return key != null && (!key.equals("")); } protected boolean isValidExtDataHashtableValue(Hashtable hash) { @@ -865,13 +843,12 @@ class Request Enumeration keys = hash.keys(); while (keys.hasMoreElements()) { Object key = keys.nextElement(); - if (! ((key instanceof String) && - isValidExtDataKey((String)key)) ) { + if (!((key instanceof String) && isValidExtDataKey((String) key))) { return false; } Object value = hash.get(key); - if (! (value instanceof String)) { + if (!(value instanceof String)) { return false; } } @@ -880,7 +857,7 @@ class Request } public boolean setExtData(String key, String value) { - if (! isValidExtDataKey(key)) { + if (!isValidExtDataKey(key)) { return false; } if (value == null) { @@ -892,7 +869,7 @@ class Request } public boolean setExtData(String key, Hashtable value) { - if ( !(isValidExtDataKey(key) && isValidExtDataHashtableValue(value)) ) { + if (!(isValidExtDataKey(key) && isValidExtDataHashtableValue(value))) { return false; } @@ -909,10 +886,10 @@ class Request if (value == null) { return null; } - if (! (value instanceof String)) { + if (!(value instanceof String)) { return null; } - return (String)value; + return (String) value; } public Hashtable getExtDataInHashtable(String key) { @@ -920,10 +897,10 @@ class Request if (value == null) { return null; } - if (! (value instanceof Hashtable)) { + if (!(value instanceof Hashtable)) { return null; } - return new ExtDataHashtable((Hashtable)value); + return new ExtDataHashtable((Hashtable) value); } public Enumeration getExtDataKeys() { @@ -935,7 +912,7 @@ class Request } public boolean setExtData(String key, String subkey, String value) { - if (! (isValidExtDataKey(key) && isValidExtDataKey(subkey)) ) { + if (!(isValidExtDataKey(key) && isValidExtDataKey(subkey))) { return false; } if (isSimpleExtDataValue(key)) { @@ -945,7 +922,7 @@ class Request return false; } - Hashtable existingValue = (Hashtable)mExtData.get(key); + Hashtable existingValue = (Hashtable) mExtData.get(key); if (existingValue == null) { existingValue = new ExtDataHashtable(); mExtData.put(key, existingValue); @@ -959,7 +936,7 @@ class Request if (value == null) { return null; } - return (String)value.get(subkey); + return (String) value.get(subkey); } public boolean setExtData(String key, Integer value) { @@ -1122,7 +1099,8 @@ class Request X509CertImpl[] certArray = new X509CertImpl[stringArray.length]; for (int index = 0; index < stringArray.length; index++) { try { - certArray[index] = new X509CertImpl(CMS.AtoB(stringArray[index])); + certArray[index] = new X509CertImpl( + CMS.AtoB(stringArray[index])); } catch (CertificateException e) { return null; } @@ -1176,7 +1154,8 @@ class Request X509CertInfo[] certArray = new X509CertInfo[stringArray.length]; for (int index = 0; index < stringArray.length; index++) { try { - certArray[index] = new X509CertInfo(CMS.AtoB(stringArray[index])); + certArray[index] = new X509CertInfo( + CMS.AtoB(stringArray[index])); } catch (CertificateException e) { return null; } @@ -1207,7 +1186,8 @@ class Request RevokedCertImpl[] certArray = new RevokedCertImpl[stringArray.length]; for (int index = 0; index < stringArray.length; index++) { try { - certArray[index] = new RevokedCertImpl(CMS.AtoB(stringArray[index])); + certArray[index] = new RevokedCertImpl( + CMS.AtoB(stringArray[index])); } catch (CRLException e) { return null; } catch (X509ExtensionException e) { @@ -1223,7 +1203,7 @@ class Request return false; } try { - stringArray = (String[])stringVector.toArray(new String[0]); + stringArray = (String[]) stringVector.toArray(new String[0]); } catch (ArrayStoreException e) { return false; } @@ -1245,7 +1225,8 @@ class Request return val.equalsIgnoreCase("true") || val.equalsIgnoreCase("ON"); } - public boolean getExtDataInBoolean(String prefix, String type, boolean defVal) { + public boolean getExtDataInBoolean(String prefix, String type, + boolean defVal) { String val = getExtDataInString(prefix, type); if (val == null) return defVal; @@ -1338,8 +1319,7 @@ class Request try { // You must use DerInputStream // using ByteArrayInputStream fails - name = new CertificateSubjectName( - new DerInputStream(nameData)); + name = new CertificateSubjectName(new DerInputStream(nameData)); } catch (IOException e) { return null; } @@ -1374,7 +1354,7 @@ class Request Set arrayKeys = hashValue.keySet(); Vector listValue = new Vector(arrayKeys.size()); for (Iterator iter = arrayKeys.iterator(); iter.hasNext();) { - String arrayKey = (String)iter.next(); + String arrayKey = (String) iter.next(); try { index = Integer.parseInt(arrayKey); } catch (NumberFormatException e) { @@ -1383,10 +1363,9 @@ class Request if (listValue.size() < (index + 1)) { listValue.setSize(index + 1); } - listValue.set(index, - hashValue.get(arrayKey)); + listValue.set(index, hashValue.get(arrayKey)); } - return (String[])listValue.toArray(new String[0]); + return (String[]) listValue.toArray(new String[0]); } public IAttrSet asIAttrSet() { @@ -1425,7 +1404,7 @@ class RequestIAttrSetWrapper implements IAttrSet { public void set(String name, Object obj) throws EBaseException { try { - mRequest.setExtData(name, (String)obj); + mRequest.setExtData(name, (String) obj); } catch (ClassCastException e) { throw new EBaseException(e.toString()); } @@ -1444,21 +1423,16 @@ class RequestIAttrSetWrapper implements IAttrSet { } } - /** * Example of a specialized request class. */ -class EnrollmentRequest - extends Request - implements IEnrollmentRequest { +class EnrollmentRequest extends Request implements IEnrollmentRequest { EnrollmentRequest(RequestId id) { super(id); } } - -class RequestListByStatus - implements IRequestList { +class RequestListByStatus implements IRequestList { public boolean hasMoreElements() { return (mNext != null); } @@ -1501,14 +1475,16 @@ class RequestListByStatus mNext = null; while (mNext == null) { - if (!mEnumeration.hasMoreElements()) break; - + if (!mEnumeration.hasMoreElements()) + break; + rId = (RequestId) mEnumeration.nextElement(); try { IRequest r = mQueue.findRequest(rId); - if (r.getRequestStatus() == mStatus) mNext = rId; + if (r.getRequestStatus() == mStatus) + mNext = rId; mQueue.releaseRequest(r); } catch (Exception e) { @@ -1518,13 +1494,11 @@ class RequestListByStatus protected RequestStatus mStatus; protected IRequestQueue mQueue; - protected Enumeration mEnumeration; + protected Enumeration mEnumeration; protected RequestId mNext; } - -class RequestList - implements IRequestList { +class RequestList implements IRequestList { public boolean hasMoreElements() { return mEnumeration.hasMoreElements(); } @@ -1549,10 +1523,9 @@ class RequestList mEnumeration = e; } - protected Enumeration mEnumeration; + protected Enumeration mEnumeration; } - class RecoverThread extends Thread { private ARequestQueue mQ = null; diff --git a/pki/base/common/src/com/netscape/cmscore/request/ARequestRecord.java b/pki/base/common/src/com/netscape/cmscore/request/ARequestRecord.java index f85beca0a..14a6cbcfa 100644 --- a/pki/base/common/src/com/netscape/cmscore/request/ARequestRecord.java +++ b/pki/base/common/src/com/netscape/cmscore/request/ARequestRecord.java @@ -17,22 +17,19 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.request; - import java.util.Date; import java.util.Hashtable; import com.netscape.certsrv.request.RequestId; import com.netscape.certsrv.request.RequestStatus; - /** - * The low level (attributes only) version of the database - * record object. This exists so that RecordAttr methods can use - * this type definition, + * The low level (attributes only) version of the database record object. This + * exists so that RecordAttr methods can use this type definition, * * RequestRecord refers both to this class and to RecordAttr objects. */ -class ARequestRecord { +class ARequestRecord { RequestId mRequestId; RequestStatus mRequestState; Date mCreateTime; diff --git a/pki/base/common/src/com/netscape/cmscore/request/CertRequestConstants.java b/pki/base/common/src/com/netscape/cmscore/request/CertRequestConstants.java index 7494b5e48..134166f6b 100644 --- a/pki/base/common/src/com/netscape/cmscore/request/CertRequestConstants.java +++ b/pki/base/common/src/com/netscape/cmscore/request/CertRequestConstants.java @@ -17,15 +17,13 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.request; - /** - * temporary location for cert request constants. - * XXX we really need to centralize all these but for now they are here - * as needed. + * temporary location for cert request constants. XXX we really need to + * centralize all these but for now they are here as needed. */ public class CertRequestConstants { - // request types - these have string values. - // made to match policy constants. + // request types - these have string values. + // made to match policy constants. public final static String GETCRL_REQUEST = "getCRL"; public final static String GETCACHAIN_REQUEST = "getCAChain"; public final static String GETREVOCATIONINFO_REQUEST = "getRevocationInfo"; @@ -51,7 +49,7 @@ public class CertRequestConstants { // this has a CRLExtensions value. public final static String CRLEXTS = "CRLExts"; - // this has a String value - it is either null or set. + // this has a String value - it is either null or set. public final static String DOGETCACHAIN = "doGetCAChain"; // this has a CertificateChain value. @@ -64,7 +62,7 @@ public class CertRequestConstants { public final static String CERTIFICATE = "certificate"; // this is an array of EBaseException for service errors when - // there's an error processing an array of something such as + // there's an error processing an array of something such as // certs to renew, certs to revoke, etc. public final static String SVCERRORS = "serviceErrors"; diff --git a/pki/base/common/src/com/netscape/cmscore/request/ExtDataHashtable.java b/pki/base/common/src/com/netscape/cmscore/request/ExtDataHashtable.java index 415908dc3..46493005b 100644 --- a/pki/base/common/src/com/netscape/cmscore/request/ExtDataHashtable.java +++ b/pki/base/common/src/com/netscape/cmscore/request/ExtDataHashtable.java @@ -6,9 +6,9 @@ import java.util.Map; import java.util.Set; /** - * Subclass of Hashtable returned by IRequest.getExtDataInHashtable. Its - * purpose is to hide the fact that LDAP doesn't preserve the case of keys. - * It does this by lowercasing all keys used to access the Hashtable. + * Subclass of Hashtable returned by IRequest.getExtDataInHashtable. Its purpose + * is to hide the fact that LDAP doesn't preserve the case of keys. It does this + * by lowercasing all keys used to access the Hashtable. */ public class ExtDataHashtable extends Hashtable { @@ -38,7 +38,7 @@ public class ExtDataHashtable extends Hashtable { public boolean containsKey(Object o) { if (o instanceof String) { - String key = (String)o; + String key = (String) o; return super.containsKey(key.toLowerCase()); } return super.containsKey(o); @@ -46,7 +46,7 @@ public class ExtDataHashtable extends Hashtable { public Object get(Object o) { if (o instanceof String) { - String key = (String)o; + String key = (String) o; return super.get(key.toLowerCase()); } return super.get(o); @@ -54,7 +54,7 @@ public class ExtDataHashtable extends Hashtable { public Object put(Object oKey, Object val) { if (oKey instanceof String) { - String key = (String)oKey; + String key = (String) oKey; return super.put(key.toLowerCase(), val); } return super.put(oKey, val); @@ -62,8 +62,7 @@ public class ExtDataHashtable extends Hashtable { public void putAll(Map map) { Set keys = map.keySet(); - for (Iterator i = keys.iterator(); - i.hasNext();) { + for (Iterator i = keys.iterator(); i.hasNext();) { Object key = i.next(); put(key, map.get(key)); } @@ -71,7 +70,7 @@ public class ExtDataHashtable extends Hashtable { public Object remove(Object o) { if (o instanceof String) { - String key = (String)o; + String key = (String) o; return super.remove(key.toLowerCase()); } return super.remove(o); diff --git a/pki/base/common/src/com/netscape/cmscore/request/RequestAttr.java b/pki/base/common/src/com/netscape/cmscore/request/RequestAttr.java index 4583a1fac..d7ac32be6 100644 --- a/pki/base/common/src/com/netscape/cmscore/request/RequestAttr.java +++ b/pki/base/common/src/com/netscape/cmscore/request/RequestAttr.java @@ -17,28 +17,24 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.request; - import com.netscape.certsrv.dbs.IDBAttrMapper; import com.netscape.certsrv.dbs.Modification; import com.netscape.certsrv.dbs.ModificationSet; import com.netscape.certsrv.request.IRequest; import com.netscape.certsrv.request.ldap.IRequestMod; - /** - * The RequestAttr class defines the methods used - * to transfer data between the various representations of - * a request. The three forms are: - * 1) LDAPAttributes (and Modifications) - * 2) Database record IDBAttrSet - * 3) IRequest (Request) object + * The RequestAttr class defines the methods used to transfer data between the + * various representations of a request. The three forms are: 1) LDAPAttributes + * (and Modifications) 2) Database record IDBAttrSet 3) IRequest (Request) + * object */ abstract class RequestAttr { /** * */ - + abstract void set(ARequestRecord r, Object o); abstract Object get(ARequestRecord r); diff --git a/pki/base/common/src/com/netscape/cmscore/request/RequestQueue.java b/pki/base/common/src/com/netscape/cmscore/request/RequestQueue.java index b748f23bb..82b906364 100644 --- a/pki/base/common/src/com/netscape/cmscore/request/RequestQueue.java +++ b/pki/base/common/src/com/netscape/cmscore/request/RequestQueue.java @@ -17,7 +17,6 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.request; - import java.math.BigInteger; import java.util.Date; import java.util.Enumeration; @@ -43,13 +42,9 @@ import com.netscape.certsrv.request.ldap.IRequestMod; import com.netscape.cmscore.dbs.DBSubsystem; import com.netscape.cmscore.util.Debug; - -public class RequestQueue - extends ARequestQueue - implements IRequestMod { +public class RequestQueue extends ARequestQueue implements IRequestMod { // ARequestQueue.newRequestId - protected RequestId newRequestId() - throws EBaseException { + protected RequestId newRequestId() throws EBaseException { // get the next request Id BigInteger next = mRepository.getNextSerialNumber(); @@ -62,8 +57,7 @@ public class RequestQueue RequestRecord record; // String name = Schema.LDAP_ATTR_REQUEST_ID + "=" + - String name = "cn" + "=" + - id + "," + mBaseDN; + String name = "cn" + "=" + id + "," + mBaseDN; Object obj = null; IDBSSession dbs = null; @@ -71,29 +65,29 @@ public class RequestQueue try { dbs = mDB.createSession(); obj = dbs.read(name); - } catch (EBaseException e) { - Debug.trace("Error: " + e); + } catch (EBaseException e) { + Debug.trace("Error: " + e); Debug.printStackTrace(e); } finally { // Close session - ignoring errors (UTIL) - if (dbs != null) try { + if (dbs != null) + try { dbs.close(); } catch (EBaseException e) { } } // TODO Errors!!! - if (obj == null || !(obj instanceof RequestRecord)) return null; + if (obj == null || !(obj instanceof RequestRecord)) + return null; record = (RequestRecord) obj; /* - setRequestStatus(r, record.mRequestState); - r.setSourceId(record.mSourceId); - r.setRequestOwner(record.mOwner); - record.storeAttrs(r, record.mRequestAttrs); - setModificationTime(r, record.mModifyTime); - setCreationTime(r, record.mCreateTime); + * setRequestStatus(r, record.mRequestState); + * r.setSourceId(record.mSourceId); r.setRequestOwner(record.mOwner); + * record.storeAttrs(r, record.mRequestAttrs); setModificationTime(r, + * record.mModifyTime); setCreationTime(r, record.mCreateTime); */ return makeRequest(record); } @@ -106,21 +100,21 @@ public class RequestQueue // compute the name of the object // String name = Schema.LDAP_ATTR_REQUEST_ID + "=" + - String name = "cn" + "=" + - record.mRequestId + "," + mBaseDN; + String name = "cn" + "=" + record.mRequestId + "," + mBaseDN; IDBSSession dbs = null; try { dbs = mDB.createSession(); dbs.add(name, record); - } catch (EBaseException e) { - Debug.trace("Error: " + e); + } catch (EBaseException e) { + Debug.trace("Error: " + e); Debug.printStackTrace(e); throw e; } finally { // Close session - ignoring errors (UTIL) - if (dbs != null) try { + if (dbs != null) + try { dbs.close(); } catch (EBaseException e) { } @@ -150,39 +144,38 @@ public class RequestQueue } /* - // - mods.add(IRequestRecord.ATTR_REQUEST_STATE, - Modification.MOD_REPLACE, r.getRequestStatus()); - - mods.add(IRequestRecord.ATTR_SOURCE_ID, - Modification.MOD_REPLACE, r.getSourceId()); - - mods.add(IRequestRecord.ATTR_REQUEST_OWNER, - Modification.MOD_REPLACE, r.getRequestOwner()); - - mods.add(IRequestRecord.ATTR_MODIFY_TIME, - Modification.MOD_REPLACE, r.getModificationTime()); - - java.util.Hashtable ht = RequestRecord.loadAttrs(r); - mods.add(RequestRecord.ATTR_REQUEST_ATTRS, - Modification.MOD_REPLACE, ht); + * // mods.add(IRequestRecord.ATTR_REQUEST_STATE, + * Modification.MOD_REPLACE, r.getRequestStatus()); + * + * mods.add(IRequestRecord.ATTR_SOURCE_ID, Modification.MOD_REPLACE, + * r.getSourceId()); + * + * mods.add(IRequestRecord.ATTR_REQUEST_OWNER, Modification.MOD_REPLACE, + * r.getRequestOwner()); + * + * mods.add(IRequestRecord.ATTR_MODIFY_TIME, Modification.MOD_REPLACE, + * r.getModificationTime()); + * + * java.util.Hashtable ht = RequestRecord.loadAttrs(r); + * mods.add(RequestRecord.ATTR_REQUEST_ATTRS, Modification.MOD_REPLACE, + * ht); */ // String name = Schema.LDAP_ATTR_REQUEST_ID + "=" + - String name = "cn" + "=" + - r.getRequestId() + "," + mBaseDN; + String name = "cn" + "=" + r.getRequestId() + "," + mBaseDN; IDBSSession dbs = null; try { dbs = mDB.createSession(); dbs.modify(name, mods); - } catch (EBaseException e) { - Debug.trace("Error: " + e); + } catch (EBaseException e) { + Debug.trace("Error: " + e); Debug.printStackTrace(e); } finally { // Close session - ignoring errors (UTIL) - if (dbs != null) try { + if (dbs != null) + try { dbs.close(); } catch (EBaseException e) { } @@ -218,34 +211,35 @@ public class RequestQueue /** * Resets serial number. */ - public void resetSerialNumber(BigInteger serial) throws EBaseException - { + public void resetSerialNumber(BigInteger serial) throws EBaseException { mRepository.resetSerialNumber(serial); } - + /** * Removes all objects with this repository. */ - public void removeAllObjects() throws EBaseException - { + public void removeAllObjects() throws EBaseException { mRepository.removeAllObjects(); } - public BigInteger getLastRequestIdInRange(BigInteger reqId_low_bound, BigInteger reqId_upper_bound) - { - CMS.debug("RequestQueue: getLastRequestId: low " + reqId_low_bound + " high " + reqId_upper_bound); - if(reqId_low_bound == null || reqId_upper_bound == null || reqId_low_bound.compareTo(reqId_upper_bound) >= 0) - { + public BigInteger getLastRequestIdInRange(BigInteger reqId_low_bound, + BigInteger reqId_upper_bound) { + CMS.debug("RequestQueue: getLastRequestId: low " + reqId_low_bound + + " high " + reqId_upper_bound); + if (reqId_low_bound == null || reqId_upper_bound == null + || reqId_low_bound.compareTo(reqId_upper_bound) >= 0) { CMS.debug("RequestQueue: getLastRequestId: bad upper and lower bound range."); return null; } - String filter = "(" + "requeststate" + "=*" + ")"; + String filter = "(" + "requeststate" + "=*" + ")"; RequestId fromId = new RequestId(reqId_upper_bound.toString(10)); - CMS.debug("RequestQueue: getLastRequestId: filter " + filter + " fromId " + fromId); - ListEnumeration recList = (ListEnumeration) getPagedRequestsByFilter(fromId,filter,5 * -1,"requestId"); + CMS.debug("RequestQueue: getLastRequestId: filter " + filter + + " fromId " + fromId); + ListEnumeration recList = (ListEnumeration) getPagedRequestsByFilter( + fromId, filter, 5 * -1, "requestId"); int size = recList.getSize(); @@ -262,7 +256,8 @@ public class RequestQueue ret = ret.add(new BigInteger("-1")); - CMS.debug("CertificateRepository:getLastCertRecordSerialNo: returning " + ret); + CMS.debug("CertificateRepository:getLastCertRecordSerialNo: returning " + + ret); return ret; } @@ -272,38 +267,38 @@ public class RequestQueue String reqId = null; - for(int i = 0; i < 5; i++) - { - curRec = recList.getElementAt(i); - - if(curRec != null) { + for (int i = 0; i < 5; i++) { + curRec = recList.getElementAt(i); - curId = curRec.getRequestId(); + if (curRec != null) { - reqId = curId.toString(); + curId = curRec.getRequestId(); - CMS.debug("RequestQueue: curReqId: " + reqId); + reqId = curId.toString(); - BigInteger curIdInt = new BigInteger(reqId); + CMS.debug("RequestQueue: curReqId: " + reqId); + BigInteger curIdInt = new BigInteger(reqId); - if( ((curIdInt.compareTo(reqId_low_bound) == 0) || (curIdInt.compareTo(reqId_low_bound) == 1) ) && - ((curIdInt.compareTo(reqId_upper_bound) == 0) || (curIdInt.compareTo(reqId_upper_bound) == -1) )) - { - CMS.debug("RequestQueue: getLastRequestId : returning value " + curIdInt); - return curIdInt; - } + if (((curIdInt.compareTo(reqId_low_bound) == 0) || (curIdInt + .compareTo(reqId_low_bound) == 1)) + && ((curIdInt.compareTo(reqId_upper_bound) == 0) || (curIdInt + .compareTo(reqId_upper_bound) == -1))) { + CMS.debug("RequestQueue: getLastRequestId : returning value " + + curIdInt); + return curIdInt; + } - } + } } - BigInteger ret = new BigInteger(reqId_low_bound.toString(10)); ret = ret.add(new BigInteger("-1")); - CMS.debug("CertificateRepository:getLastCertRecordSerialNo: returning " + ret); + CMS.debug("CertificateRepository:getLastCertRecordSerialNo: returning " + + ret); return ret; } @@ -311,12 +306,14 @@ public class RequestQueue /** * Implements IRequestQueue.findRequestBySourceId * <p> + * * @see com.netscape.certsrv.request.IRequestQueue#findRequestBySourceId */ public RequestId findRequestBySourceId(String id) { IRequestList irl = findRequestsBySourceId(id); - if (irl == null) return null; + if (irl == null) + return null; return irl.nextRequestId(); } @@ -324,6 +321,7 @@ public class RequestQueue /** * Implements IRequestQueue.findRequestsBySourceId * <p> + * * @see com.netscape.certsrv.request.IRequestQueue#findRequestsBySourceId */ public IRequestList findRequestsBySourceId(String id) { @@ -343,13 +341,15 @@ public class RequestQueue Debug.printStackTrace(e); } finally { // Close session - ignoring errors (UTIL) - if (dbs != null) try { + if (dbs != null) + try { dbs.close(); } catch (EBaseException e) { } } - if (results == null || !results.hasMoreElements()) return null; + if (results == null || !results.hasMoreElements()) + return null; return new SearchEnumeration(this, results); @@ -363,18 +363,20 @@ public class RequestQueue try { dbs = mDB.createSession(); results = dbs.search(mBaseDN, "(requestId=*)"); - } catch (EBaseException e) { - Debug.trace("Error: " + e); + } catch (EBaseException e) { + Debug.trace("Error: " + e); Debug.printStackTrace(e); } finally { // Close session - ignoring errors (UTIL) - if (dbs != null) try { + if (dbs != null) + try { dbs.close(); } catch (EBaseException e) { } } - if (results == null) return null; + if (results == null) + return null; return new SearchEnumeration(this, results); } @@ -389,18 +391,20 @@ public class RequestQueue try { dbs = mDB.createSession(); results = dbs.search(mBaseDN, f); - } catch (EBaseException e) { - Debug.trace("Error: " + e); + } catch (EBaseException e) { + Debug.trace("Error: " + e); Debug.printStackTrace(e); } finally { // Close session - ignoring errors (UTIL) - if (dbs != null) try { + if (dbs != null) + try { dbs.close(); } catch (EBaseException e) { } } - if (results == null) return null; + if (results == null) + return null; return new SearchEnumeration(this, results); } @@ -411,7 +415,7 @@ public class RequestQueue IDBSearchResults results = null; IDBSSession dbs = null; String attrs[] = { IRequestRecord.ATTR_REQUEST_ID }; - + try { dbs = mDB.createSession(); results = dbs.search(mBaseDN, f, maxSize); @@ -420,20 +424,23 @@ public class RequestQueue Debug.printStackTrace(e); } finally { // Close session - ignoring errors (UTIL) - if (dbs != null) try { + if (dbs != null) + try { dbs.close(); } catch (EBaseException e) { } } - - if (results == null) return null; - + + if (results == null) + return null; + return new SearchEnumeration(this, results); } /** */ - public IRequestList listRequestsByFilter(String f, int maxSize, int timeLimit) { + public IRequestList listRequestsByFilter(String f, int maxSize, + int timeLimit) { IDBSearchResults results = null; IDBSSession dbs = null; String attrs[] = { IRequestRecord.ATTR_REQUEST_ID }; @@ -446,13 +453,15 @@ public class RequestQueue Debug.printStackTrace(e); } finally { // Close session - ignoring errors (UTIL) - if (dbs != null) try { + if (dbs != null) + try { dbs.close(); } catch (EBaseException e) { } } - if (results == null) return null; + if (results == null) + return null; return new SearchEnumeration(this, results); } @@ -473,18 +482,20 @@ public class RequestQueue dbs = mDB.createSession(); results = dbs.search(mBaseDN, f1); - } catch (EBaseException e) { - //System.err.println("Error: "+e); - //e.printStackTrace(); + } catch (EBaseException e) { + // System.err.println("Error: "+e); + // e.printStackTrace(); } finally { // Close session - ignoring errors (UTIL) - if (dbs != null) try { + if (dbs != null) + try { dbs.close(); } catch (EBaseException e) { } } - if (results == null) return null; + if (results == null) + return null; return new SearchEnumeration(this, results); } @@ -499,20 +510,18 @@ public class RequestQueue /* * Implements IRequestQueue.getPagedRequestsByFilter */ - public IRequestVirtualList - getPagedRequestsByFilter(String filter, int pageSize, String sortKey) { + public IRequestVirtualList getPagedRequestsByFilter(String filter, + int pageSize, String sortKey) { return getPagedRequestsByFilter(null, filter, pageSize, sortKey); } - public IRequestVirtualList - getPagedRequestsByFilter(RequestId from, String filter, int pageSize, - String sortKey) { - return getPagedRequestsByFilter(from, false, filter, pageSize, sortKey); + public IRequestVirtualList getPagedRequestsByFilter(RequestId from, + String filter, int pageSize, String sortKey) { + return getPagedRequestsByFilter(from, false, filter, pageSize, sortKey); } - public IRequestVirtualList - getPagedRequestsByFilter(RequestId from, boolean jumpToEnd, String filter, int pageSize, - String sortKey) { + public IRequestVirtualList getPagedRequestsByFilter(RequestId from, + boolean jumpToEnd, String filter, int pageSize, String sortKey) { IDBVirtualList results = null; IDBSSession dbs = null; @@ -525,25 +534,26 @@ public class RequestQueue try { if (from == null) { - results = dbs.createVirtualList(mBaseDN, filter, (String[]) null, - sortKey, pageSize); + results = dbs.createVirtualList(mBaseDN, filter, + (String[]) null, sortKey, pageSize); } else { int len = from.toString().length(); String internalRequestId = null; if (jumpToEnd) { - internalRequestId ="99"; - } else { - if (len > 9) { - internalRequestId = Integer.toString(len) + from.toString(); + internalRequestId = "99"; } else { - internalRequestId = "0" + Integer.toString(len) + - from.toString(); + if (len > 9) { + internalRequestId = Integer.toString(len) + + from.toString(); + } else { + internalRequestId = "0" + Integer.toString(len) + + from.toString(); + } } - } - results = dbs.createVirtualList(mBaseDN, filter, (String[]) null, - internalRequestId, sortKey, pageSize); + results = dbs.createVirtualList(mBaseDN, filter, + (String[]) null, internalRequestId, sortKey, pageSize); } } catch (EBaseException e) { return null; @@ -556,7 +566,7 @@ public class RequestQueue try { results.setSortKey(sortKey); - } catch (EBaseException e) {//XXX + } catch (EBaseException e) {// XXX System.out.println(e.toString()); return null; } @@ -564,15 +574,14 @@ public class RequestQueue return new ListEnumeration(this, results); } - public RequestQueue(String name, int increment, IPolicy p, IService s, INotify n, - INotify pendingNotify) - throws EBaseException { + public RequestQueue(String name, int increment, IPolicy p, IService s, + INotify n, INotify pendingNotify) throws EBaseException { super(p, s, n, pendingNotify); mDB = DBSubsystem.getInstance(); mBaseDN = "ou=" + name + ",ou=requests," + mDB.getBaseDN(); - mRepository = new RequestRepository(name, increment, mDB,this); + mRepository = new RequestRepository(name, increment, mDB, this); } @@ -591,8 +600,8 @@ public class RequestQueue } /* - * return request repository - */ + * return request repository + */ public IRepository getRequestRepository() { return (IRepository) mRepository; } @@ -610,15 +619,14 @@ public class RequestQueue protected RequestRepository mRepository; } - -class SearchEnumeration - implements IRequestList { +class SearchEnumeration implements IRequestList { public RequestId nextRequestId() { Object obj; obj = mResults.nextElement(); - if (obj == null || !(obj instanceof RequestRecord)) return null; + if (obj == null || !(obj instanceof RequestRecord)) + return null; RequestRecord r = (RequestRecord) obj; @@ -647,7 +655,8 @@ class SearchEnumeration obj = mResults.nextElement(); - if (obj == null || !(obj instanceof RequestRecord)) return null; + if (obj == null || !(obj instanceof RequestRecord)) + return null; RequestRecord r = (RequestRecord) obj; @@ -655,7 +664,7 @@ class SearchEnumeration } public IRequest nextRequestObject() { - RequestRecord record = (RequestRecord)nextRequest(); + RequestRecord record = (RequestRecord) nextRequest(); if (record != null) return mQueue.makeRequest(record); return null; @@ -665,13 +674,12 @@ class SearchEnumeration protected RequestQueue mQueue; } - -class ListEnumeration - implements IRequestVirtualList { +class ListEnumeration implements IRequestVirtualList { public IRequest getElementAt(int i) { RequestRecord record = (RequestRecord) mList.getElementAt(i); - if (record == null) return null; + if (record == null) + return null; return mQueue.makeRequest(record); } @@ -693,6 +701,7 @@ class ListEnumeration return mList.getSizeAfterJumpTo(); } + ListEnumeration(RequestQueue queue, IDBVirtualList list) { mQueue = queue; mList = list; diff --git a/pki/base/common/src/com/netscape/cmscore/request/RequestRecord.java b/pki/base/common/src/com/netscape/cmscore/request/RequestRecord.java index 76863ca9a..e450ef29d 100644 --- a/pki/base/common/src/com/netscape/cmscore/request/RequestRecord.java +++ b/pki/base/common/src/com/netscape/cmscore/request/RequestRecord.java @@ -17,7 +17,6 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.request; - import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -53,15 +52,13 @@ import com.netscape.cmscore.dbs.DateMapper; import com.netscape.cmscore.dbs.StringMapper; import com.netscape.cmscore.util.Debug; - // // A request record is the stored version of a request. // It has a set of attributes that are mapped into LDAP // attributes for actual directory operations. // -public class RequestRecord - extends ARequestRecord - implements IRequestRecord, IDBObj { +public class RequestRecord extends ARequestRecord implements IRequestRecord, + IDBObj { /** * */ @@ -96,7 +93,8 @@ public class RequestRecord else { RequestAttr ra = (RequestAttr) mAttrTable.get(name); - if (ra != null) return ra.get(this); + if (ra != null) + return ra.get(this); } return null; @@ -119,17 +117,17 @@ public class RequestRecord else if (name.equals(IRequestRecord.ATTR_REQUEST_OWNER)) mOwner = (String) o; else if (name.equals(IRequestRecord.ATTR_EXT_DATA)) - mExtData = (Hashtable)o; + mExtData = (Hashtable) o; else { RequestAttr ra = (RequestAttr) mAttrTable.get(name); - if (ra != null) ra.set(this, o); + if (ra != null) + ra.set(this, o); } } // IDBObj.delete - public void delete(String name) - throws EBaseException { + public void delete(String name) throws EBaseException { throw new EBaseException("Invalid call to delete"); } @@ -175,42 +173,43 @@ public class RequestRecord static void mod(ModificationSet mods, IRequest r) throws EBaseException { // - mods.add(IRequestRecord.ATTR_REQUEST_STATE, - Modification.MOD_REPLACE, r.getRequestStatus()); + mods.add(IRequestRecord.ATTR_REQUEST_STATE, Modification.MOD_REPLACE, + r.getRequestStatus()); - mods.add(IRequestRecord.ATTR_SOURCE_ID, - Modification.MOD_REPLACE, r.getSourceId()); + mods.add(IRequestRecord.ATTR_SOURCE_ID, Modification.MOD_REPLACE, + r.getSourceId()); - mods.add(IRequestRecord.ATTR_REQUEST_OWNER, - Modification.MOD_REPLACE, r.getRequestOwner()); + mods.add(IRequestRecord.ATTR_REQUEST_OWNER, Modification.MOD_REPLACE, + r.getRequestOwner()); - mods.add(IRequestRecord.ATTR_MODIFY_TIME, - Modification.MOD_REPLACE, r.getModificationTime()); + mods.add(IRequestRecord.ATTR_MODIFY_TIME, Modification.MOD_REPLACE, + r.getModificationTime()); - mods.add(IRequestRecord.ATTR_EXT_DATA, - Modification.MOD_REPLACE, loadExtDataFromRequest(r)); + mods.add(IRequestRecord.ATTR_EXT_DATA, Modification.MOD_REPLACE, + loadExtDataFromRequest(r)); for (int i = 0; i < mRequestA.length; i++) { mRequestA[i].mod(mods, r); } } - static void register(IDBSubsystem db) - throws EDBException { + static void register(IDBSubsystem db) throws EDBException { IDBRegistry reg = db.getRegistry(); reg.registerObjectClass(RequestRecord.class.getName(), mOC); - reg.registerAttribute(IRequestRecord.ATTR_REQUEST_ID, new RequestIdMapper()); - reg.registerAttribute(IRequestRecord.ATTR_REQUEST_STATE, new RequestStateMapper()); - reg.registerAttribute(IRequestRecord.ATTR_CREATE_TIME, - new DateMapper(Schema.LDAP_ATTR_CREATE_TIME)); - reg.registerAttribute(IRequestRecord.ATTR_MODIFY_TIME, - new DateMapper(Schema.LDAP_ATTR_MODIFY_TIME)); - reg.registerAttribute(IRequestRecord.ATTR_SOURCE_ID, - new StringMapper(Schema.LDAP_ATTR_SOURCE_ID)); + reg.registerAttribute(IRequestRecord.ATTR_REQUEST_ID, + new RequestIdMapper()); + reg.registerAttribute(IRequestRecord.ATTR_REQUEST_STATE, + new RequestStateMapper()); + reg.registerAttribute(IRequestRecord.ATTR_CREATE_TIME, new DateMapper( + Schema.LDAP_ATTR_CREATE_TIME)); + reg.registerAttribute(IRequestRecord.ATTR_MODIFY_TIME, new DateMapper( + Schema.LDAP_ATTR_MODIFY_TIME)); + reg.registerAttribute(IRequestRecord.ATTR_SOURCE_ID, new StringMapper( + Schema.LDAP_ATTR_SOURCE_ID)); reg.registerAttribute(IRequestRecord.ATTR_REQUEST_OWNER, - new StringMapper(Schema.LDAP_ATTR_REQUEST_OWNER)); + new StringMapper(Schema.LDAP_ATTR_REQUEST_OWNER)); ExtAttrDynMapper extAttrMapper = new ExtAttrDynMapper(); reg.registerAttribute(IRequestRecord.ATTR_EXT_DATA, extAttrMapper); reg.registerDynamicMapper(extAttrMapper); @@ -222,10 +221,11 @@ public class RequestRecord } } - protected static final String mOC[] = - { Schema.LDAP_OC_TOP, Schema.LDAP_OC_REQUEST, Schema.LDAP_OC_EXTENSIBLE }; + protected static final String mOC[] = { Schema.LDAP_OC_TOP, + Schema.LDAP_OC_REQUEST, Schema.LDAP_OC_EXTENSIBLE }; - protected static Hashtable loadExtDataFromRequest(IRequest r) throws EBaseException { + protected static Hashtable loadExtDataFromRequest(IRequest r) + throws EBaseException { Hashtable h = new Hashtable(); Enumeration e = r.getExtDataKeys(); @@ -247,12 +247,12 @@ public class RequestRecord String key = (String) e.nextElement(); Object value = mExtData.get(key); if (value instanceof String) { - r.setExtData(key, (String)value); + r.setExtData(key, (String) value); } else if (value instanceof Hashtable) { - r.setExtData(key, (Hashtable)value); + r.setExtData(key, (Hashtable) value); } else { - throw new EDBException("Illegal data value in RequestRecord: " + - r.toString()); + throw new EDBException("Illegal data value in RequestRecord: " + + r.toString()); } } } @@ -262,40 +262,40 @@ public class RequestRecord static Hashtable mAttrTable = new Hashtable(); /* - * This table contains attribute handlers for attributes - * of the request. These attributes are ones that are stored - * apart from the generic name/value pairs supported by the get/set - * interface plus the hashtable for the name/value pairs themselves. - * - * NOTE: Eventually, all attributes should be done here. Currently - * only the last ones added are implemented this way. + * This table contains attribute handlers for attributes of the request. + * These attributes are ones that are stored apart from the generic + * name/value pairs supported by the get/set interface plus the hashtable + * for the name/value pairs themselves. + * + * NOTE: Eventually, all attributes should be done here. Currently only the + * last ones added are implemented this way. */ static RequestAttr mRequestA[] = { - new RequestAttr(IRequest.ATTR_REQUEST_TYPE, - new StringMapper(Schema.LDAP_ATTR_REQUEST_TYPE)) { - void set(ARequestRecord r, Object o) { - r.mRequestType = (String) o; - } - - Object get(ARequestRecord r) { - return r.mRequestType; - } - - void read(IRequestMod a, IRequest r, ARequestRecord rr) { - r.setRequestType(rr.mRequestType); - } - - void add(IRequest r, ARequestRecord rr) { - rr.mRequestType = r.getRequestType(); - } - - void mod(ModificationSet mods, IRequest r) { - addmod(mods, r.getRequestType()); - } - } + new RequestAttr(IRequest.ATTR_REQUEST_TYPE, new StringMapper( + Schema.LDAP_ATTR_REQUEST_TYPE)) { + void set(ARequestRecord r, Object o) { + r.mRequestType = (String) o; + } + + Object get(ARequestRecord r) { + return r.mRequestType; + } + + void read(IRequestMod a, IRequest r, ARequestRecord rr) { + r.setRequestType(rr.mRequestType); + } + + void add(IRequest r, ARequestRecord rr) { + rr.mRequestType = r.getRequestType(); + } + + void mod(ModificationSet mods, IRequest r) { + addmod(mods, r.getRequestType()); + } + } - }; + }; static { mAttrs.add(IRequestRecord.ATTR_REQUEST_ID); mAttrs.add(IRequestRecord.ATTR_REQUEST_STATE); @@ -315,7 +315,6 @@ public class RequestRecord } - // // A mapper between an request state object and // its LDAP attribute representation @@ -324,8 +323,7 @@ public class RequestRecord // @author thayes // @version $Revision$ $Date$ // -class RequestStateMapper - implements IDBAttrMapper { +class RequestStateMapper implements IDBAttrMapper { // IDBAttrMapper methods // @@ -335,20 +333,20 @@ class RequestStateMapper } // - public void mapObjectToLDAPAttributeSet(IDBObj parent, - String name, Object obj, LDAPAttributeSet attrs) { + public void mapObjectToLDAPAttributeSet(IDBObj parent, String name, + Object obj, LDAPAttributeSet attrs) { RequestStatus rs = (RequestStatus) obj; - attrs.add(new LDAPAttribute(Schema.LDAP_ATTR_REQUEST_STATE, - rs.toString())); + attrs.add(new LDAPAttribute(Schema.LDAP_ATTR_REQUEST_STATE, rs + .toString())); } public void mapLDAPAttributeSetToObject(LDAPAttributeSet attrs, - String name, IDBObj parent) - throws EBaseException { + String name, IDBObj parent) throws EBaseException { LDAPAttribute attr = attrs.getAttribute(Schema.LDAP_ATTR_REQUEST_STATE); - if (attr == null) throw new EBaseException("schema violation"); + if (attr == null) + throw new EBaseException("schema violation"); String value = (String) attr.getStringValues().nextElement(); @@ -366,7 +364,6 @@ class RequestStateMapper } } - // // A mapper between an request id object and // its LDAP attribute representation @@ -375,8 +372,7 @@ class RequestStateMapper // @author thayes // @version $Revision$ $Date$ // -class RequestIdMapper - implements IDBAttrMapper { +class RequestIdMapper implements IDBAttrMapper { // IDBAttrMapper methods // @@ -386,26 +382,27 @@ class RequestIdMapper } // - public void mapObjectToLDAPAttributeSet(IDBObj parent, - String name, Object obj, LDAPAttributeSet attrs) { + public void mapObjectToLDAPAttributeSet(IDBObj parent, String name, + Object obj, LDAPAttributeSet attrs) { RequestId rid = (RequestId) obj; - String v = BigIntegerMapper.BigIntegerToDB(new BigInteger(rid.toString())); + String v = BigIntegerMapper.BigIntegerToDB(new BigInteger(rid + .toString())); attrs.add(new LDAPAttribute(Schema.LDAP_ATTR_REQUEST_ID, v)); } public void mapLDAPAttributeSetToObject(LDAPAttributeSet attrs, - String name, IDBObj parent) - throws EBaseException { + String name, IDBObj parent) throws EBaseException { LDAPAttribute attr = attrs.getAttribute(Schema.LDAP_ATTR_REQUEST_ID); - if (attr == null) throw new EBaseException("schema violation"); + if (attr == null) + throw new EBaseException("schema violation"); String value = (String) attr.getStringValues().nextElement(); - parent.set(name, new RequestId( - BigIntegerMapper.BigIntegerFromDB(value).toString())); + parent.set(name, new RequestId(BigIntegerMapper.BigIntegerFromDB(value) + .toString())); } public String mapSearchFilter(String name, String op, String value) { @@ -426,19 +423,17 @@ class RequestIdMapper } } - /** * A mapper between an request attr set and its LDAP attribute representation. - * - * The attr attribute is no longer used. This class is kept for historical - * and migration purposes. - * + * + * The attr attribute is no longer used. This class is kept for historical and + * migration purposes. + * * @author thayes * @version $Revision$ $Date$ * @deprecated */ -class RequestAttrsMapper - implements IDBAttrMapper { +class RequestAttrsMapper implements IDBAttrMapper { // IDBAttrMapper methods // @@ -448,9 +443,9 @@ class RequestAttrsMapper } // - public void mapObjectToLDAPAttributeSet(IDBObj parent, - String name, Object obj, LDAPAttributeSet attrs) { - Hashtable ht = (Hashtable) obj; + public void mapObjectToLDAPAttributeSet(IDBObj parent, String name, + Object obj, LDAPAttributeSet attrs) { + Hashtable ht = (Hashtable) obj; Enumeration e = ht.keys(); try { @@ -471,14 +466,14 @@ class RequestAttrsMapper os.writeObject(data); } catch (NotSerializableException x) { if (Debug.ON) { - System.err.println("Error: attribute '" + key + "' (" + - x.getMessage() + ") is not serializable"); + System.err.println("Error: attribute '" + key + "' (" + + x.getMessage() + ") is not serializable"); x.printStackTrace(); } } catch (Exception x) { if (Debug.ON) { - System.err.println("Error: attribute '" + key + - "' - error during serialization: " + x); + System.err.println("Error: attribute '" + key + + "' - error during serialization: " + x); x.printStackTrace(); } } @@ -487,19 +482,20 @@ class RequestAttrsMapper os.writeObject(null); os.close(); - attrs.add(new LDAPAttribute(Schema.LDAP_ATTR_REQUEST_ATTRS, - bos.toByteArray())); - } catch (Exception x) { - Debug.trace("Output Mapping Error in requeset ID " + - ((RequestRecord) parent).getRequestId().toString() + " : " + x); - //if (Debug.ON) { + attrs.add(new LDAPAttribute(Schema.LDAP_ATTR_REQUEST_ATTRS, bos + .toByteArray())); + } catch (Exception x) { + Debug.trace("Output Mapping Error in requeset ID " + + ((RequestRecord) parent).getRequestId().toString() + + " : " + x); + // if (Debug.ON) { Debug.printStackTrace(x); - //} + // } } } - private byte[] encode(Object value) - throws NotSerializableException, IOException { + private byte[] encode(Object value) throws NotSerializableException, + IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream os = new ObjectOutputStream(bos); @@ -509,8 +505,8 @@ class RequestAttrsMapper return bos.toByteArray(); } - private Object decode(byte[] data) - throws ObjectStreamException, IOException, ClassNotFoundException { + private Object decode(byte[] data) throws ObjectStreamException, + IOException, ClassNotFoundException { ByteArrayInputStream bis = new ByteArrayInputStream(data); ObjectInputStream is = new ObjectInputStream(bis); @@ -518,7 +514,7 @@ class RequestAttrsMapper } private Hashtable decodeHashtable(byte[] data) - throws ObjectStreamException, IOException, ClassNotFoundException { + throws ObjectStreamException, IOException, ClassNotFoundException { Hashtable ht = new Hashtable(); ByteArrayInputStream bis = new ByteArrayInputStream(data); ObjectInputStream is = new ObjectInputStream(bis); @@ -529,22 +525,23 @@ class RequestAttrsMapper while (true) { key = (String) is.readObject(); - + // end of table is marked with null - if (key == null) break; + if (key == null) + break; byte[] bytes = (byte[]) is.readObject(); ht.put(key, decode(bytes)); } } catch (ObjectStreamException e) { - Debug.trace("Key " + key); // would be nice to know object type. + Debug.trace("Key " + key); // would be nice to know object type. throw e; } catch (IOException e) { - Debug.trace("Key " + key); // would be nice to know object type. + Debug.trace("Key " + key); // would be nice to know object type. throw e; } catch (ClassNotFoundException e) { - Debug.trace("Key " + key); // would be nice to know object type. + Debug.trace("Key " + key); // would be nice to know object type. throw e; } @@ -554,16 +551,16 @@ class RequestAttrsMapper /** * Implements IDBAttrMapper.mapLDAPAttributeSetToObject * <p> + * * @see IDBAttrMapper#mapLDAPAttributeSetToObject */ public void mapLDAPAttributeSetToObject(LDAPAttributeSet attrs, - String name, IDBObj parent) - throws EBaseException { + String name, IDBObj parent) throws EBaseException { Hashtable ht = null; // // Data is stored in a (single valued) binary attribute - // + // byte[] value; LDAPAttribute attr = null; @@ -579,12 +576,13 @@ class RequestAttrsMapper ht = decodeHashtable(value); } } catch (Exception x) { - Debug.trace("Mapping error in request Id " + - ((RequestRecord) parent).getRequestId().toString() + " : " + x); + Debug.trace("Mapping error in request Id " + + ((RequestRecord) parent).getRequestId().toString() + + " : " + x); Debug.trace("Attr " + attr.getName()); - //if (Debug.ON) { + // if (Debug.ON) { Debug.printStackTrace(x); - //} + // } } parent.set(name, ht); @@ -604,48 +602,39 @@ class RequestAttrsMapper /** * Maps dynamic data for the extData- prefix to and from the extData Hashtable * in RequestRecord. - * - * The data in RequestRecord is stored in a Hashtable. It comes in two forms: - * 1. String key1 => String value1 - * String key2 => String value2 - * This is stored in LDAP as: - * extData-key1 => value1 - * extData-key2 => value2 - * - * 2. String key => Hashtable value - * where value stores: - * String key2 => String value2 - * String key3 => String value3 - * This is stored in LDAP as: - * extData-key;key2 => value2 - * extData-key;key3 => value3 - * - * These can be mixed, but each top-level key can only be associated with - * a String value or a Hashtable value. - * + * + * The data in RequestRecord is stored in a Hashtable. It comes in two forms: 1. + * String key1 => String value1 String key2 => String value2 This is stored in + * LDAP as: extData-key1 => value1 extData-key2 => value2 + * + * 2. String key => Hashtable value where value stores: String key2 => String + * value2 String key3 => String value3 This is stored in LDAP as: + * extData-key;key2 => value2 extData-key;key3 => value3 + * + * These can be mixed, but each top-level key can only be associated with a + * String value or a Hashtable value. + * */ class ExtAttrDynMapper implements IDBDynAttrMapper { public boolean supportsLDAPAttributeName(String attrName) { - return (attrName != null) && - attrName.toLowerCase().startsWith(extAttrPrefix); + return (attrName != null) + && attrName.toLowerCase().startsWith(extAttrPrefix); } public Enumeration getSupportedLDAPAttributeNames() { return mAttrs.elements(); } - /** - * Decodes extdata encoded keys. - * -- followed by a 4 digit hexadecimal string is decoded to the character - * representing the hex string. - * - * The routine is written to be highly efficient. It only allocates - * the StringBuffer if needed and copies the pieces in large chunks. - * - * @param key The key to decode - * @return The decoded key. + * Decodes extdata encoded keys. -- followed by a 4 digit hexadecimal string + * is decoded to the character representing the hex string. + * + * The routine is written to be highly efficient. It only allocates the + * StringBuffer if needed and copies the pieces in large chunks. + * + * @param key The key to decode + * @return The decoded key. */ public String decodeKey(String key) { StringBuffer output = null; @@ -655,19 +644,15 @@ class ExtAttrDynMapper implements IDBDynAttrMapper { int index = 0; while (index < input.length) { if (input[index] == '-') { - if ( ((index + 1) < input.length) && - (input[index + 1] == '-')) { + if (((index + 1) < input.length) && (input[index + 1] == '-')) { if (output == null) { output = new StringBuffer(input.length); } output.append(input, startCopyIndex, index - startCopyIndex); index += 2; if ((index + 3) < input.length) { - output.append( - Character.toChars( - Integer.parseInt(new String(input, index, 4), - 16)) - ); + output.append(Character.toChars(Integer.parseInt( + new String(input, index, 4), 16))); } index += 4; startCopyIndex = index; @@ -689,26 +674,23 @@ class ExtAttrDynMapper implements IDBDynAttrMapper { /** * Encoded extdata keys for storage in LDAP. - * - * The rules for encoding are trickier than decoding. We want to allow - * '-' by itself to be stored in the database (for the common case of keys - * like 'Foo-Bar'. Therefore we are using '--' as the encoding character. - * The rules are: - * 1) All characters [^-a-zA-Z0-9] are encoded as --XXXX where XXXX is the - * hex representation of the digit. - * 2) [a-zA-Z0-9] are always passed through unencoded - * 3) [-] is passed through as long as it is preceded and followed - * by [a-zA-Z0-9] (or if it's at the beginning/end of the string) - * 4) If [-] is preceded or followed by [^a-zA-Z0-9] then - * the - as well as all following [^a-zA-Z0-9] characters are encoded - * as --XXXX. - * + * + * The rules for encoding are trickier than decoding. We want to allow '-' + * by itself to be stored in the database (for the common case of keys like + * 'Foo-Bar'. Therefore we are using '--' as the encoding character. The + * rules are: 1) All characters [^-a-zA-Z0-9] are encoded as --XXXX where + * XXXX is the hex representation of the digit. 2) [a-zA-Z0-9] are always + * passed through unencoded 3) [-] is passed through as long as it is + * preceded and followed by [a-zA-Z0-9] (or if it's at the beginning/end of + * the string) 4) If [-] is preceded or followed by [^a-zA-Z0-9] then the - + * as well as all following [^a-zA-Z0-9] characters are encoded as --XXXX. + * * This routine tries to be as efficient as possible with StringBuffer and - * large copies. However, the encoding unfortunately requires several + * large copies. However, the encoding unfortunately requires several * objects to be allocated. - * + * * @param key The key to encode - * @return The encoded key + * @return The encoded key */ public String encodeKey(String key) { StringBuffer output = null; @@ -717,21 +699,20 @@ class ExtAttrDynMapper implements IDBDynAttrMapper { int index = 0; while (index < input.length) { - if (! isAlphaNum(input[index])) { - if ((input[index] == '-') && - ((index + 1) < input.length) && - (isAlphaNum(input[index + 1]))) { + if (!isAlphaNum(input[index])) { + if ((input[index] == '-') && ((index + 1) < input.length) + && (isAlphaNum(input[index + 1]))) { index += 2; - } else if ((input[index] == '-') && - ((index + 1) == input.length)) { + } else if ((input[index] == '-') + && ((index + 1) == input.length)) { index += 1; } else { if (output == null) { output = new StringBuffer(input.length + 5); } output.append(input, startCopyIndex, index - startCopyIndex); - while ( (index < input.length) && - (! isAlphaNum(input[index])) ) { + while ((index < input.length) + && (!isAlphaNum(input[index]))) { output.append("--"); String hexString = Integer.toHexString(input[index]); int padding = 4 - hexString.length(); @@ -771,8 +752,7 @@ class ExtAttrDynMapper implements IDBDynAttrMapper { } public void mapObjectToLDAPAttributeSet(IDBObj parent, String name, - Object obj, LDAPAttributeSet attrs) - throws EBaseException { + Object obj, LDAPAttributeSet attrs) throws EBaseException { Hashtable ht = (Hashtable) obj; Enumeration e = ht.keys(); @@ -781,73 +761,75 @@ class ExtAttrDynMapper implements IDBDynAttrMapper { String key = (String) e.nextElement(); Object value = ht.get(key); if (value instanceof String) { - String stringValue = (String)value; - attrs.add(new LDAPAttribute( - extAttrPrefix + encodeKey(key), + String stringValue = (String) value; + attrs.add(new LDAPAttribute(extAttrPrefix + encodeKey(key), stringValue)); } else if (value instanceof Hashtable) { - Hashtable innerHash = (Hashtable)value; + Hashtable innerHash = (Hashtable) value; Enumeration innerHashEnum = innerHash.keys(); - while (innerHashEnum.hasMoreElements()){ - String innerKey = (String)innerHashEnum.nextElement(); - String innerValue = (String)innerHash.get(innerKey); - attrs.add(new LDAPAttribute( - extAttrPrefix + encodeKey(key) + ";" + encodeKey(innerKey), - innerValue)); + while (innerHashEnum.hasMoreElements()) { + String innerKey = (String) innerHashEnum.nextElement(); + String innerValue = (String) innerHash.get(innerKey); + attrs.add(new LDAPAttribute(extAttrPrefix + + encodeKey(key) + ";" + encodeKey(innerKey), + innerValue)); } } } } catch (Exception x) { - Debug.trace("Output Mapping Error in requeset ID " + - ((IRequestRecord) parent).getRequestId().toString() + " : " + x); - //if (Debug.ON) { + Debug.trace("Output Mapping Error in requeset ID " + + ((IRequestRecord) parent).getRequestId().toString() + + " : " + x); + // if (Debug.ON) { Debug.printStackTrace(x); - //} + // } } } - public void mapLDAPAttributeSetToObject(LDAPAttributeSet attrs, String name, - IDBObj parent) - throws EBaseException { + public void mapLDAPAttributeSetToObject(LDAPAttributeSet attrs, + String name, IDBObj parent) throws EBaseException { Hashtable ht = new Hashtable(); Hashtable valueHashtable; Enumeration attrEnum = attrs.getAttributes(); while (attrEnum.hasMoreElements()) { - LDAPAttribute attr = (LDAPAttribute)attrEnum.nextElement(); + LDAPAttribute attr = (LDAPAttribute) attrEnum.nextElement(); String baseName = attr.getBaseName(); if (baseName.toLowerCase().startsWith(extAttrPrefix)) { - String keyName = decodeKey( - baseName.substring(extAttrPrefix.length())); + String keyName = decodeKey(baseName.substring(extAttrPrefix + .length())); String[] subTypes = attr.getSubtypes(); String[] values = attr.getStringValueArray(); if (values.length != 1) { - String message = "Output Mapping Error in request ID " + - ((IRequestRecord) parent).getRequestId().toString() + " : " + - "more than one value returned for " + - keyName; + String message = "Output Mapping Error in request ID " + + ((IRequestRecord) parent).getRequestId() + .toString() + " : " + + "more than one value returned for " + keyName; Debug.trace(message); throw new EBaseException(message); } if ((subTypes != null) && (subTypes.length > 0)) { if (subTypes.length != 1) { - String message = "Output Mapping Error in request ID " + - ((IRequestRecord) parent).getRequestId().toString() + " : " + - "more than one subType returned for " + - keyName; + String message = "Output Mapping Error in request ID " + + ((IRequestRecord) parent).getRequestId() + .toString() + " : " + + "more than one subType returned for " + + keyName; Debug.trace(message); throw new EBaseException(message); } Object value = ht.get(keyName); - if ((value != null) && (! (value instanceof Hashtable))) { - String message = "Output Mapping Error in request ID " + - ((IRequestRecord) parent).getRequestId().toString() + " : " + - "combined no-subtype and subtype data for key " + - keyName; + if ((value != null) && (!(value instanceof Hashtable))) { + String message = "Output Mapping Error in request ID " + + ((IRequestRecord) parent).getRequestId() + .toString() + + " : " + + "combined no-subtype and subtype data for key " + + keyName; Debug.trace(message); throw new EBaseException(message); } - valueHashtable = (Hashtable)value; + valueHashtable = (Hashtable) value; if (valueHashtable == null) { valueHashtable = new Hashtable(); ht.put(keyName, valueHashtable); @@ -862,7 +844,8 @@ class ExtAttrDynMapper implements IDBDynAttrMapper { parent.set(name, ht); } - public String mapSearchFilter(String name, String op, String value) throws EBaseException { + public String mapSearchFilter(String name, String op, String value) + throws EBaseException { return name + op + value; } diff --git a/pki/base/common/src/com/netscape/cmscore/request/RequestRepository.java b/pki/base/common/src/com/netscape/cmscore/request/RequestRepository.java index 1dafc2a7a..7a580dcc3 100644 --- a/pki/base/common/src/com/netscape/cmscore/request/RequestRepository.java +++ b/pki/base/common/src/com/netscape/cmscore/request/RequestRepository.java @@ -32,30 +32,28 @@ import com.netscape.certsrv.request.IRequestQueue; import com.netscape.cmscore.dbs.Repository; import com.netscape.cmscore.dbs.RepositoryRecord; - /** - * TODO: what does this class provide beyond the Repository - * base class?? + * TODO: what does this class provide beyond the Repository base class?? * <p> + * * @author thayes * @version $Revision$ $Date$ */ -class RequestRepository - extends Repository { +class RequestRepository extends Repository { + + IDBSubsystem mDB = null; + IRequestQueue mRequestQueue = null; - IDBSubsystem mDB = null; - IRequestQueue mRequestQueue = null; /** * Create a request repository that uses the LDAP database * <p> - * @param name - * the name of the repository. This String is used to - * construct the DN for the repository's LDAP entry. - * @param db - * the LDAP database system. + * + * @param name the name of the repository. This String is used to construct + * the DN for the repository's LDAP entry. + * @param db the LDAP database system. */ public RequestRepository(String name, int increment, IDBSubsystem db) - throws EDBException { + throws EDBException { super(db, increment, "ou=" + name + ",ou=requests," + db.getBaseDN()); CMS.debug("RequestRepository: constructor 1"); @@ -67,8 +65,8 @@ class RequestRepository mDB = db; } - public RequestRepository(String name, int increment, IDBSubsystem db,IRequestQueue requestQueue) - throws EDBException { + public RequestRepository(String name, int increment, IDBSubsystem db, + IRequestQueue requestQueue) throws EDBException { super(db, increment, "ou=" + name + ",ou=requests," + db.getBaseDN()); CMS.debug("RequestRepository: constructor2."); @@ -82,12 +80,11 @@ class RequestRepository } /** - * get the LDAP base DN for this repository. This - * value can be used by the request queue to create the - * name for the request records themselves. + * get the LDAP base DN for this repository. This value can be used by the + * request queue to create the name for the request records themselves. * <p> - * @return - * the LDAP base DN. + * + * @return the LDAP base DN. */ public String getBaseDN() { return mBaseDN; @@ -96,61 +93,59 @@ class RequestRepository /** * Resets serial number. */ - public void resetSerialNumber(BigInteger serial) throws EBaseException - { + public void resetSerialNumber(BigInteger serial) throws EBaseException { setTheSerialNumber(serial); } - + /** * Removes all objects with this repository. */ - public void removeAllObjects() throws EBaseException - { + public void removeAllObjects() throws EBaseException { IDBSSession s = mDB.createSession(); try { - Enumeration e = s.search(getBaseDN(), - "(" + RequestRecord.ATTR_REQUEST_ID + "=*)"); + Enumeration e = s.search(getBaseDN(), "(" + + RequestRecord.ATTR_REQUEST_ID + "=*)"); while (e.hasMoreElements()) { - RequestRecord r = (RequestRecord)e.nextElement(); - String name = "cn" + "=" + - r.getRequestId().toString() + "," + getBaseDN(); - s.delete(name); - } + RequestRecord r = (RequestRecord) e.nextElement(); + String name = "cn" + "=" + r.getRequestId().toString() + "," + + getBaseDN(); + s.delete(name); + } } finally { if (s != null) s.close(); } } - public BigInteger getLastSerialNumberInRange(BigInteger min, BigInteger max) - { + public BigInteger getLastSerialNumberInRange(BigInteger min, BigInteger max) { - CMS.debug("RequestRepository: in getLastSerialNumberInRange: min " + min + " max " + max); + CMS.debug("RequestRepository: in getLastSerialNumberInRange: min " + + min + " max " + max); CMS.debug("RequestRepository: mRequestQueue " + mRequestQueue); BigInteger ret = null; - if(mRequestQueue == null) { + if (mRequestQueue == null) { CMS.debug("RequestRepository: mRequestQueue is null."); - } else { - - CMS.debug("RequestRepository: about to call mRequestQueue.getLastRequestIdInRange"); - ret = mRequestQueue.getLastRequestIdInRange(min,max); + } else { + + CMS.debug("RequestRepository: about to call mRequestQueue.getLastRequestIdInRange"); + ret = mRequestQueue.getLastRequestIdInRange(min, max); } return ret; } + /** * the LDAP base DN for this repository */ protected String mBaseDN; - public String getPublishingStatus() { RepositoryRecord record = null; Object obj = null; @@ -160,8 +155,8 @@ class RequestRepository try { dbs = mDB.createSession(); obj = dbs.read(mBaseDN); - } catch (Exception e) { - CMS.debug("RequestRepository: getPublishingStatus: Error: " + e); + } catch (Exception e) { + CMS.debug("RequestRepository: getPublishingStatus: Error: " + e); CMS.debugStackTrace(); } finally { // Close session - ignoring errors (UTIL) @@ -169,7 +164,8 @@ class RequestRepository try { dbs.close(); } catch (Exception ex) { - CMS.debug("RequestRepository: getPublishingStatus: Error: " + ex); + CMS.debug("RequestRepository: getPublishingStatus: Error: " + + ex); } } } @@ -180,8 +176,8 @@ class RequestRepository } else { CMS.debug("RequestRepository: obj is NOT instanceof RepositoryRecord"); } - CMS.debug("RequestRepository: getPublishingStatus mBaseDN: " + mBaseDN + - " status: " + ((status != null)?status:"null")); + CMS.debug("RequestRepository: getPublishingStatus mBaseDN: " + + mBaseDN + " status: " + ((status != null) ? status : "null")); return status; } @@ -189,18 +185,20 @@ class RequestRepository public void setPublishingStatus(String status) { IDBSSession dbs = null; - CMS.debug("RequestRepository: setPublishingStatus mBaseDN: " + mBaseDN + " status: " + status); + CMS.debug("RequestRepository: setPublishingStatus mBaseDN: " + + mBaseDN + " status: " + status); ModificationSet mods = new ModificationSet(); if (status != null && status.length() > 0) { - mods.add(IRepositoryRecord.ATTR_PUB_STATUS, - Modification.MOD_REPLACE, status); + mods.add(IRepositoryRecord.ATTR_PUB_STATUS, + Modification.MOD_REPLACE, status); try { dbs = mDB.createSession(); dbs.modify(mBaseDN, mods); - } catch (Exception e) { - CMS.debug("RequestRepository: setPublishingStatus: Error: " + e); + } catch (Exception e) { + CMS.debug("RequestRepository: setPublishingStatus: Error: " + + e); CMS.debugStackTrace(); } finally { // Close session - ignoring errors (UTIL) @@ -208,7 +206,8 @@ class RequestRepository try { dbs.close(); } catch (Exception ex) { - CMS.debug("RequestRepository: setPublishingStatus: Error: " + ex); + CMS.debug("RequestRepository: setPublishingStatus: Error: " + + ex); } } } diff --git a/pki/base/common/src/com/netscape/cmscore/request/RequestSubsystem.java b/pki/base/common/src/com/netscape/cmscore/request/RequestSubsystem.java index 90df99248..d58196a75 100644 --- a/pki/base/common/src/com/netscape/cmscore/request/RequestSubsystem.java +++ b/pki/base/common/src/com/netscape/cmscore/request/RequestSubsystem.java @@ -17,7 +17,6 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.request; - import com.netscape.certsrv.apps.CMS; import com.netscape.certsrv.base.EBaseException; import com.netscape.certsrv.base.IConfigStore; @@ -32,24 +31,21 @@ import com.netscape.certsrv.request.IRequestSubsystem; import com.netscape.certsrv.request.IService; import com.netscape.cmscore.dbs.DBSubsystem; - /** * RequestSubsystem * <p> - * This class is reponsible for managing storage of request objects - * in the local database. + * This class is reponsible for managing storage of request objects in the local + * database. * <p> - * TODO: review this - * It provides: - * + registration of LDAP/JAVA mapping classes with the DBSubsystem - * + creation of RequestQueue storage in the database - * + retrieval of existing RequestQueue objects from the database + * TODO: review this It provides: + registration of LDAP/JAVA mapping classes + * with the DBSubsystem + creation of RequestQueue storage in the database + + * retrieval of existing RequestQueue objects from the database * <p> + * * @author thayes * @version $Revision$, $Date$ */ -public class RequestSubsystem - implements IRequestSubsystem, ISubsystem { +public class RequestSubsystem implements IRequestSubsystem, ISubsystem { public final static String ID = IRequestSubsystem.SUB_ID; @@ -67,49 +63,49 @@ public class RequestSubsystem // end singleton enforcement. // - // Create a new request queue. The LDAP DN for the entry + // Create a new request queue. The LDAP DN for the entry // in the database is supplied by the caller. // - public void createRequestQueue(String name) - throws EBaseException { + public void createRequestQueue(String name) throws EBaseException { /* - String dbName = makeQueueName(name); - IDBSSession dbs = createDBSSession(); - - // Create Repository record here - - dbs.add(dbName, r); - */ + * String dbName = makeQueueName(name); IDBSSession dbs = + * createDBSSession(); + * + * // Create Repository record here + * + * dbs.add(dbName, r); + */ } - public IRequestQueue - getRequestQueue(String name, int increment, IPolicy p, IService s, INotify n) - throws EBaseException { + public IRequestQueue getRequestQueue(String name, int increment, IPolicy p, + IService s, INotify n) throws EBaseException { return getRequestQueue(name, increment, p, s, n, null); } - public IRequestQueue - getRequestQueue(String name, int increment, IPolicy p, IService s, INotify n, - INotify pendingNotifier) - throws EBaseException { - RequestQueue rq = new RequestQueue(name, increment, p, s, n, pendingNotifier); + public IRequestQueue getRequestQueue(String name, int increment, IPolicy p, + IService s, INotify n, INotify pendingNotifier) + throws EBaseException { + RequestQueue rq = new RequestQueue(name, increment, p, s, n, + pendingNotifier); // can't do this here because the service depends on getting rq - // (to get request) and since this method hasn't returned it's rq is null. - //rq.recover(); + // (to get request) and since this method hasn't returned it's rq is + // null. + // rq.recover(); return rq; } // // ISubsystem methods: - // getId, setId, init, startup, shutdown, getConfigStore + // getId, setId, init, startup, shutdown, getConfigStore // /** * Implements ISubsystem.getId * <p> + * * @see ISubsystem#getId */ public String getId() { @@ -117,8 +113,7 @@ public class RequestSubsystem } // ISubsystem.setId - public void setId(String id) - throws EBaseException { + public void setId(String id) throws EBaseException { mId = id; } @@ -127,18 +122,18 @@ public class RequestSubsystem mParent = parent; mConfig = config; } - + /** * Implements ISubsystem.startup * <p> + * * @see ISubsystem#startup */ - public void startup() - throws EBaseException { + public void startup() throws EBaseException { mLogger = CMS.getLogger(); mLogger.log(ILogger.EV_SYSTEM, ILogger.S_REQQUEUE, ILogger.LL_INFO, - "Request subsystem started"); + "Request subsystem started"); } public void shutdown() { @@ -146,7 +141,7 @@ public class RequestSubsystem if (mLogger != null) { mLogger.log(ILogger.EV_SYSTEM, ILogger.S_REQQUEUE, ILogger.LL_INFO, - "Request subsystem stopped"); + "Request subsystem stopped"); } } @@ -165,8 +160,7 @@ public class RequestSubsystem // Create a database session in the default database // system. // - protected IDBSSession createDBSSession() - throws EBaseException { + protected IDBSSession createDBSSession() throws EBaseException { return getDBSubsystem().createSession(); } @@ -186,6 +180,5 @@ public class RequestSubsystem private String mId = IRequestSubsystem.SUB_ID; private IRequestQueue mRequestQueue; - protected ILogger mLogger; + protected ILogger mLogger; } - diff --git a/pki/base/common/src/com/netscape/cmscore/request/Schema.java b/pki/base/common/src/com/netscape/cmscore/request/Schema.java index 182e3470e..b18b36666 100644 --- a/pki/base/common/src/com/netscape/cmscore/request/Schema.java +++ b/pki/base/common/src/com/netscape/cmscore/request/Schema.java @@ -17,7 +17,6 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.request; - // // The Schema class contains constant string values for // LDAP attribute and object class names used in this package @@ -44,7 +43,7 @@ class Schema { public static final String LDAP_ATTR_EXT_ATTR = "extAttr"; // Indicates a special state that may be searched for exactly - // such as requiresAgentService. The idea is to reduce the space + // such as requiresAgentService. The idea is to reduce the space // used in indexes to optimize common queries. // NOT IMPLEMENTED public static final String LDAP_ATTR_REQUEST_FLAG = "requestFlag"; |