diff options
author | Ade Lee <alee@redhat.com> | 2011-12-08 21:15:59 -0500 |
---|---|---|
committer | Ade Lee <alee@redhat.com> | 2011-12-08 21:15:59 -0500 |
commit | 171aaece4f23709d33d180cf36eb3af5e454b0c9 (patch) | |
tree | 1485f9f0a7bd10de4ff25030db575dbb8dafae74 /pki/base/common/src/com/netscape/cmscore/request | |
parent | adad2fcee8a29fdb82376fbce07dedb11fccc182 (diff) | |
download | pki-171aaece4f23709d33d180cf36eb3af5e454b0c9.tar.gz pki-171aaece4f23709d33d180cf36eb3af5e454b0c9.tar.xz pki-171aaece4f23709d33d180cf36eb3af5e454b0c9.zip |
Revert "Formatting"
This reverts commit 32150d3ee32f8ac27118af7c792794b538c78a2f.
Diffstat (limited to 'pki/base/common/src/com/netscape/cmscore/request')
10 files changed, 715 insertions, 661 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 fbc5052de..2da14467e 100644 --- a/pki/base/common/src/com/netscape/cmscore/request/ARequestQueue.java +++ b/pki/base/common/src/com/netscape/cmscore/request/ARequestQueue.java @@ -17,6 +17,7 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.request; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -61,29 +62,31 @@ 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. @@ -93,34 +96,37 @@ public abstract class ARequestQueue implements IRequestQueue { /** * 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 @@ -131,51 +137,56 @@ public abstract class ARequestQueue implements IRequestQueue { /** * 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; @@ -186,9 +197,10 @@ public abstract class ARequestQueue implements IRequestQueue { /** * 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; @@ -199,9 +211,10 @@ public abstract class ARequestQueue implements IRequestQueue { /** * 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; @@ -212,19 +225,20 @@ public abstract class ARequestQueue implements IRequestQueue { /** * 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); @@ -236,15 +250,14 @@ public abstract class ARequestQueue implements IRequestQueue { } /** - * 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); @@ -274,17 +287,16 @@ public abstract class ARequestQueue implements IRequestQueue { /** * 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); @@ -304,10 +316,10 @@ public abstract class ARequestQueue implements IRequestQueue { /** * 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); @@ -315,12 +327,12 @@ public abstract class ARequestQueue implements IRequestQueue { r = readRequest(id); // if (r == null) mTable.unlock(id); - + return r; } private IRequestScheduler mRequestScheduler = null; - + public void setRequestScheduler(IRequestScheduler scheduler) { mRequestScheduler = scheduler; } @@ -332,10 +344,10 @@ public abstract class ARequestQueue implements IRequestQueue { /** * 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(); @@ -348,8 +360,7 @@ public abstract class ARequestQueue implements IRequestQueue { // 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 { @@ -362,20 +373,19 @@ public abstract class ARequestQueue implements IRequestQueue { /** * 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); @@ -385,10 +395,10 @@ public abstract class ARequestQueue implements IRequestQueue { /** * 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); @@ -398,18 +408,17 @@ public abstract class ARequestQueue implements IRequestQueue { /** * 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(); } @@ -417,8 +426,7 @@ public abstract class ARequestQueue implements IRequestQueue { // 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()); @@ -427,7 +435,8 @@ public abstract class ARequestQueue implements IRequestQueue { 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 @@ -440,17 +449,16 @@ public abstract class ARequestQueue implements IRequestQueue { /** * 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); @@ -461,10 +469,10 @@ public abstract class ARequestQueue implements IRequestQueue { /** * 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); @@ -480,8 +488,7 @@ public abstract class ARequestQueue implements IRequestQueue { setRequestStatus(r, RequestStatus.COMPLETE); updateRequest(r); - if (mNotify != null) - mNotify.notify(r); + if (mNotify != null) mNotify.notify(r); return; } @@ -489,10 +496,10 @@ public abstract class ARequestQueue implements IRequestQueue { /** * 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() { @@ -502,10 +509,10 @@ public abstract class ARequestQueue implements IRequestQueue { /** * 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) { @@ -515,7 +522,6 @@ public abstract class ARequestQueue implements IRequestQueue { /** * Implements IRequestQueue.releaseRequest * <p> - * * @see IRequestQueue#releaseRequest */ public final void releaseRequest(IRequest request) { @@ -527,17 +533,17 @@ public abstract class ARequestQueue implements IRequestQueue { 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) { @@ -611,14 +617,14 @@ public abstract class ARequestQueue implements IRequestQueue { // 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 } /** @@ -637,15 +643,15 @@ public abstract class ARequestQueue implements IRequestQueue { */ 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 @@ -658,7 +664,7 @@ public abstract class ARequestQueue implements IRequestQueue { 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) { @@ -678,7 +684,7 @@ public abstract class ARequestQueue implements IRequestQueue { // Constructor protected ARequestQueue(IPolicy policy, IService service, INotify notify, - INotify pendingNotify) { + INotify pendingNotify) { mPolicy = policy; mService = service; mNotify = notify; @@ -698,29 +704,44 @@ public abstract class ARequestQueue implements IRequestQueue { 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; @@ -812,9 +833,9 @@ class Request implements IRequest { 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 { @@ -826,14 +847,15 @@ class Request implements IRequest { /** * 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) { @@ -843,12 +865,13 @@ class Request implements IRequest { 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; } } @@ -857,7 +880,7 @@ class Request implements IRequest { } public boolean setExtData(String key, String value) { - if (!isValidExtDataKey(key)) { + if (! isValidExtDataKey(key)) { return false; } if (value == null) { @@ -869,7 +892,7 @@ class Request implements IRequest { } public boolean setExtData(String key, Hashtable value) { - if (!(isValidExtDataKey(key) && isValidExtDataHashtableValue(value))) { + if ( !(isValidExtDataKey(key) && isValidExtDataHashtableValue(value)) ) { return false; } @@ -886,10 +909,10 @@ class Request implements IRequest { 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) { @@ -897,10 +920,10 @@ class Request implements IRequest { 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() { @@ -912,7 +935,7 @@ class Request implements IRequest { } public boolean setExtData(String key, String subkey, String value) { - if (!(isValidExtDataKey(key) && isValidExtDataKey(subkey))) { + if (! (isValidExtDataKey(key) && isValidExtDataKey(subkey)) ) { return false; } if (isSimpleExtDataValue(key)) { @@ -922,7 +945,7 @@ class Request implements IRequest { return false; } - Hashtable existingValue = (Hashtable) mExtData.get(key); + Hashtable existingValue = (Hashtable)mExtData.get(key); if (existingValue == null) { existingValue = new ExtDataHashtable(); mExtData.put(key, existingValue); @@ -936,7 +959,7 @@ class Request implements IRequest { if (value == null) { return null; } - return (String) value.get(subkey); + return (String)value.get(subkey); } public boolean setExtData(String key, Integer value) { @@ -1099,8 +1122,7 @@ class Request implements IRequest { 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; } @@ -1154,8 +1176,7 @@ class Request implements IRequest { 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; } @@ -1186,8 +1207,7 @@ class Request implements IRequest { 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) { @@ -1203,7 +1223,7 @@ class Request implements IRequest { return false; } try { - stringArray = (String[]) stringVector.toArray(new String[0]); + stringArray = (String[])stringVector.toArray(new String[0]); } catch (ArrayStoreException e) { return false; } @@ -1225,8 +1245,7 @@ class Request implements IRequest { 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; @@ -1319,7 +1338,8 @@ class Request implements IRequest { 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; } @@ -1354,7 +1374,7 @@ class Request implements IRequest { 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) { @@ -1363,9 +1383,10 @@ class Request implements IRequest { 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() { @@ -1404,7 +1425,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()); } @@ -1423,16 +1444,21 @@ 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); } @@ -1475,16 +1501,14 @@ class RequestListByStatus implements IRequestList { 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) { @@ -1494,11 +1518,13 @@ class RequestListByStatus implements IRequestList { 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(); } @@ -1523,9 +1549,10 @@ class RequestList implements IRequestList { 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 14a6cbcfa..f85beca0a 100644 --- a/pki/base/common/src/com/netscape/cmscore/request/ARequestRecord.java +++ b/pki/base/common/src/com/netscape/cmscore/request/ARequestRecord.java @@ -17,19 +17,22 @@ // --- 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 134166f6b..7494b5e48 100644 --- a/pki/base/common/src/com/netscape/cmscore/request/CertRequestConstants.java +++ b/pki/base/common/src/com/netscape/cmscore/request/CertRequestConstants.java @@ -17,13 +17,15 @@ // --- 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"; @@ -49,7 +51,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. @@ -62,7 +64,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 46493005b..415908dc3 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,7 +62,8 @@ 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)); } @@ -70,7 +71,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 d7ac32be6..4583a1fac 100644 --- a/pki/base/common/src/com/netscape/cmscore/request/RequestAttr.java +++ b/pki/base/common/src/com/netscape/cmscore/request/RequestAttr.java @@ -17,24 +17,28 @@ // --- 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 82b906364..b748f23bb 100644 --- a/pki/base/common/src/com/netscape/cmscore/request/RequestQueue.java +++ b/pki/base/common/src/com/netscape/cmscore/request/RequestQueue.java @@ -17,6 +17,7 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.request; + import java.math.BigInteger; import java.util.Date; import java.util.Enumeration; @@ -42,9 +43,13 @@ 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(); @@ -57,7 +62,8 @@ public class RequestQueue extends ARequestQueue implements IRequestMod { 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; @@ -65,29 +71,29 @@ public class RequestQueue extends ARequestQueue implements IRequestMod { 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); } @@ -100,21 +106,21 @@ public class RequestQueue extends ARequestQueue implements IRequestMod { // 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) { } @@ -144,38 +150,39 @@ public class RequestQueue extends ARequestQueue implements IRequestMod { } /* - * // 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) { } @@ -211,35 +218,34 @@ public class RequestQueue extends ARequestQueue implements IRequestMod { /** * 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(); @@ -256,8 +262,7 @@ public class RequestQueue extends ARequestQueue implements IRequestMod { ret = ret.add(new BigInteger("-1")); - CMS.debug("CertificateRepository:getLastCertRecordSerialNo: returning " - + ret); + CMS.debug("CertificateRepository:getLastCertRecordSerialNo: returning " + ret); return ret; } @@ -267,38 +272,38 @@ public class RequestQueue extends ARequestQueue implements IRequestMod { String reqId = null; - for (int i = 0; i < 5; i++) { - curRec = recList.getElementAt(i); + for(int i = 0; i < 5; i++) + { + curRec = recList.getElementAt(i); - if (curRec != null) { + if(curRec != null) { - curId = curRec.getRequestId(); + curId = curRec.getRequestId(); - reqId = curId.toString(); + reqId = curId.toString(); - CMS.debug("RequestQueue: curReqId: " + reqId); + CMS.debug("RequestQueue: curReqId: " + reqId); - BigInteger curIdInt = new BigInteger(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; } @@ -306,14 +311,12 @@ public class RequestQueue extends ARequestQueue implements IRequestMod { /** * 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(); } @@ -321,7 +324,6 @@ public class RequestQueue extends ARequestQueue implements IRequestMod { /** * Implements IRequestQueue.findRequestsBySourceId * <p> - * * @see com.netscape.certsrv.request.IRequestQueue#findRequestsBySourceId */ public IRequestList findRequestsBySourceId(String id) { @@ -341,15 +343,13 @@ public class RequestQueue extends ARequestQueue implements IRequestMod { 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,20 +363,18 @@ public class RequestQueue extends ARequestQueue implements IRequestMod { 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); } @@ -391,20 +389,18 @@ public class RequestQueue extends ARequestQueue implements IRequestMod { 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); } @@ -415,7 +411,7 @@ public class RequestQueue extends ARequestQueue implements IRequestMod { IDBSearchResults results = null; IDBSSession dbs = null; String attrs[] = { IRequestRecord.ATTR_REQUEST_ID }; - + try { dbs = mDB.createSession(); results = dbs.search(mBaseDN, f, maxSize); @@ -424,23 +420,20 @@ public class RequestQueue extends ARequestQueue implements IRequestMod { 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 }; @@ -453,15 +446,13 @@ public class RequestQueue extends ARequestQueue implements IRequestMod { 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); } @@ -482,20 +473,18 @@ public class RequestQueue extends ARequestQueue implements IRequestMod { 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); } @@ -510,18 +499,20 @@ public class RequestQueue extends ARequestQueue implements IRequestMod { /* * 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; @@ -534,26 +525,25 @@ public class RequestQueue extends ARequestQueue implements IRequestMod { 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"; + internalRequestId ="99"; + } else { + if (len > 9) { + internalRequestId = Integer.toString(len) + from.toString(); } else { - if (len > 9) { - internalRequestId = Integer.toString(len) - + from.toString(); - } else { - internalRequestId = "0" + Integer.toString(len) - + from.toString(); - } + 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; @@ -566,7 +556,7 @@ public class RequestQueue extends ARequestQueue implements IRequestMod { try { results.setSortKey(sortKey); - } catch (EBaseException e) {// XXX + } catch (EBaseException e) {//XXX System.out.println(e.toString()); return null; } @@ -574,14 +564,15 @@ public class RequestQueue extends ARequestQueue implements IRequestMod { 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); } @@ -600,8 +591,8 @@ public class RequestQueue extends ARequestQueue implements IRequestMod { } /* - * return request repository - */ + * return request repository + */ public IRepository getRequestRepository() { return (IRepository) mRepository; } @@ -619,14 +610,15 @@ public class RequestQueue extends ARequestQueue implements IRequestMod { 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; @@ -655,8 +647,7 @@ class SearchEnumeration implements IRequestList { obj = mResults.nextElement(); - if (obj == null || !(obj instanceof RequestRecord)) - return null; + if (obj == null || !(obj instanceof RequestRecord)) return null; RequestRecord r = (RequestRecord) obj; @@ -664,7 +655,7 @@ class SearchEnumeration implements IRequestList { } public IRequest nextRequestObject() { - RequestRecord record = (RequestRecord) nextRequest(); + RequestRecord record = (RequestRecord)nextRequest(); if (record != null) return mQueue.makeRequest(record); return null; @@ -674,12 +665,13 @@ class SearchEnumeration implements IRequestList { 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); } @@ -701,7 +693,6 @@ class ListEnumeration implements IRequestVirtualList { 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 e450ef29d..76863ca9a 100644 --- a/pki/base/common/src/com/netscape/cmscore/request/RequestRecord.java +++ b/pki/base/common/src/com/netscape/cmscore/request/RequestRecord.java @@ -17,6 +17,7 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.request; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -52,13 +53,15 @@ 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 { /** * */ @@ -93,8 +96,7 @@ public class RequestRecord extends ARequestRecord implements IRequestRecord, else { RequestAttr ra = (RequestAttr) mAttrTable.get(name); - if (ra != null) - return ra.get(this); + if (ra != null) return ra.get(this); } return null; @@ -117,17 +119,17 @@ public class RequestRecord extends ARequestRecord implements IRequestRecord, 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"); } @@ -173,43 +175,42 @@ public class RequestRecord extends ARequestRecord implements IRequestRecord, 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); @@ -221,11 +222,10 @@ public class RequestRecord extends ARequestRecord implements IRequestRecord, } } - 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 extends ARequestRecord implements IRequestRecord, 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 extends ARequestRecord implements IRequestRecord, 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,6 +315,7 @@ public class RequestRecord extends ARequestRecord implements IRequestRecord, } + // // A mapper between an request state object and // its LDAP attribute representation @@ -323,7 +324,8 @@ public class RequestRecord extends ARequestRecord implements IRequestRecord, // @author thayes // @version $Revision$ $Date$ // -class RequestStateMapper implements IDBAttrMapper { +class RequestStateMapper + implements IDBAttrMapper { // IDBAttrMapper methods // @@ -333,20 +335,20 @@ class RequestStateMapper implements IDBAttrMapper { } // - 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(); @@ -364,6 +366,7 @@ class RequestStateMapper implements IDBAttrMapper { } } + // // A mapper between an request id object and // its LDAP attribute representation @@ -372,7 +375,8 @@ class RequestStateMapper implements IDBAttrMapper { // @author thayes // @version $Revision$ $Date$ // -class RequestIdMapper implements IDBAttrMapper { +class RequestIdMapper + implements IDBAttrMapper { // IDBAttrMapper methods // @@ -382,27 +386,26 @@ class RequestIdMapper implements IDBAttrMapper { } // - 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) { @@ -423,17 +426,19 @@ class RequestIdMapper implements IDBAttrMapper { } } + /** * 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 // @@ -443,9 +448,9 @@ class RequestAttrsMapper implements IDBAttrMapper { } // - 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 { @@ -466,14 +471,14 @@ class RequestAttrsMapper implements IDBAttrMapper { 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(); } } @@ -482,20 +487,19 @@ class RequestAttrsMapper implements IDBAttrMapper { 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); @@ -505,8 +509,8 @@ class RequestAttrsMapper implements IDBAttrMapper { 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); @@ -514,7 +518,7 @@ class RequestAttrsMapper implements IDBAttrMapper { } 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); @@ -525,23 +529,22 @@ class RequestAttrsMapper implements IDBAttrMapper { 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; } @@ -551,16 +554,16 @@ class RequestAttrsMapper implements IDBAttrMapper { /** * 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; @@ -576,13 +579,12 @@ class RequestAttrsMapper implements IDBAttrMapper { 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); @@ -602,39 +604,48 @@ class RequestAttrsMapper implements IDBAttrMapper { /** * 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; @@ -644,15 +655,19 @@ 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; @@ -674,23 +689,26 @@ 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; @@ -699,20 +717,21 @@ 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(); @@ -752,7 +771,8 @@ 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(); @@ -761,75 +781,73 @@ 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); @@ -844,8 +862,7 @@ 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 7a580dcc3..1dafc2a7a 100644 --- a/pki/base/common/src/com/netscape/cmscore/request/RequestRepository.java +++ b/pki/base/common/src/com/netscape/cmscore/request/RequestRepository.java @@ -32,28 +32,30 @@ 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 { - - IDBSubsystem mDB = null; - IRequestQueue mRequestQueue = null; +class RequestRepository + extends Repository { + 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"); @@ -65,8 +67,8 @@ class RequestRepository extends Repository { 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."); @@ -80,11 +82,12 @@ class RequestRepository extends Repository { } /** - * 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; @@ -93,59 +96,61 @@ class RequestRepository extends Repository { /** * 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; @@ -155,8 +160,8 @@ class RequestRepository extends Repository { 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) @@ -164,8 +169,7 @@ class RequestRepository extends Repository { try { dbs.close(); } catch (Exception ex) { - CMS.debug("RequestRepository: getPublishingStatus: Error: " - + ex); + CMS.debug("RequestRepository: getPublishingStatus: Error: " + ex); } } } @@ -176,8 +180,8 @@ class RequestRepository extends Repository { } 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; } @@ -185,20 +189,18 @@ class RequestRepository extends Repository { 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) @@ -206,8 +208,7 @@ class RequestRepository extends Repository { 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 d58196a75..90df99248 100644 --- a/pki/base/common/src/com/netscape/cmscore/request/RequestSubsystem.java +++ b/pki/base/common/src/com/netscape/cmscore/request/RequestSubsystem.java @@ -17,6 +17,7 @@ // --- 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; @@ -31,21 +32,24 @@ 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; @@ -63,49 +67,49 @@ public class RequestSubsystem implements IRequestSubsystem, ISubsystem { // 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() { @@ -113,7 +117,8 @@ public class RequestSubsystem implements IRequestSubsystem, ISubsystem { } // ISubsystem.setId - public void setId(String id) throws EBaseException { + public void setId(String id) + throws EBaseException { mId = id; } @@ -122,18 +127,18 @@ public class RequestSubsystem implements IRequestSubsystem, ISubsystem { 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() { @@ -141,7 +146,7 @@ public class RequestSubsystem implements IRequestSubsystem, ISubsystem { if (mLogger != null) { mLogger.log(ILogger.EV_SYSTEM, ILogger.S_REQQUEUE, ILogger.LL_INFO, - "Request subsystem stopped"); + "Request subsystem stopped"); } } @@ -160,7 +165,8 @@ public class RequestSubsystem implements IRequestSubsystem, ISubsystem { // Create a database session in the default database // system. // - protected IDBSSession createDBSSession() throws EBaseException { + protected IDBSSession createDBSSession() + throws EBaseException { return getDBSubsystem().createSession(); } @@ -180,5 +186,6 @@ public class RequestSubsystem implements IRequestSubsystem, ISubsystem { 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 b18b36666..182e3470e 100644 --- a/pki/base/common/src/com/netscape/cmscore/request/Schema.java +++ b/pki/base/common/src/com/netscape/cmscore/request/Schema.java @@ -17,6 +17,7 @@ // --- 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 @@ -43,7 +44,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"; |