# This patch file was generated by NetBeans IDE
# Following Index: paths are relative to: C:\Documents and Settings\Aravindan Ranganatha\OpenSSO\opensso\products\amserver
# This patch can be applied using context Tools: Patch action on respective folder.
# It uses platform neutral UTF-8 encoding and \n newlines.
# Above lines and this line are ignored by the patching process.
Index: source/com/sun/identity/jaxrpc/SOAPClient.java
*** C:\Documents and Settings\Aravindan Ranganatha\OpenSSO\opensso\products\amserver\source\com\sun\identity\jaxrpc\SOAPClient.java Base (1.1)
--- C:\Documents and Settings\Aravindan Ranganatha\OpenSSO\opensso\products\amserver\source\com\sun\identity\jaxrpc\SOAPClient.java Locally Modified (Based On 1.1)
***************
*** 37,42 ****
--- 37,43 ----
  import java.util.Collections;
  import java.util.HashMap;
  import java.util.HashSet;
+ import java.util.TreeSet;
  import java.util.Iterator;
  import java.util.LinkedList;
  import java.util.List;
***************
*** 62,67 ****
--- 63,69 ----
  import com.iplanet.sso.SSOException;
  import com.sun.identity.entity.EntityException;
  import com.sun.identity.sm.SMSException;
+ import com.sun.identity.idm.IdRepoException;
  import com.sun.identity.sm.SMSSchema;
  
  /**
***************
*** 567,572 ****
--- 569,576 ----
                      type = currentType = attrs.getValue(attrs.getIndex(TYPE));
                      if (type.equalsIgnoreCase(SET)) {
                          set = currentSet = new OrderedSet();
+                     } else if (type.equalsIgnoreCase(TREESET)) {
+                         set = currentSet = new TreeSet();
                      } else if (type.equalsIgnoreCase(MAP)) {
                          map = new HashMap();
                          maps.add(0, map);
***************
*** 620,626 ****
                      }
                      currentType = (String) types.remove(0);
                  } else if (localName.equalsIgnoreCase(VALUE)) {
!                     if (currentType.equalsIgnoreCase(SET)) {
                          Map map1 = (Map) maps.get(0);
                          map1.put(keys.remove(0), currentSet);
                      } else if (currentType.equalsIgnoreCase(MAP)) {
--- 624,631 ----
                      }
                      currentType = (String) types.remove(0);
                  } else if (localName.equalsIgnoreCase(VALUE)) {
!                     if (currentType.equalsIgnoreCase(SET) ||
!                         currentType.equalsIgnoreCase(TREESET)) {
                          Map map1 = (Map) maps.get(0);
                          map1.put(keys.remove(0), currentSet);
                      } else if (currentType.equalsIgnoreCase(MAP)) {
***************
*** 641,647 ****
                      keys.add(0, currentString.toString());
                  } else if (localName.equalsIgnoreCase(RESULT)) {
                      // End of results
!                     if (type.equalsIgnoreCase(SET)) {
                          answer = set;
                      } else if (type.equalsIgnoreCase(MAP)) {
                          answer = map;
--- 646,653 ----
                      keys.add(0, currentString.toString());
                  } else if (localName.equalsIgnoreCase(RESULT)) {
                      // End of results
!                     if (type.equalsIgnoreCase(SET) ||
!                         type.equalsIgnoreCase(TREESET)) {
                          answer = set;
                      } else if (type.equalsIgnoreCase(MAP)) {
                          answer = map;
***************
*** 738,743 ****
--- 744,764 ----
                          // Throw generic SMSException
                          exception = new SMSException();
                      }
+                 } else if (exceptionClassName.equals(IDREPOEXCEPTION)) {
+                     if (resourceBundleName != null) {
+                         exception = new IdRepoException(
+                             resourceBundleName, exceptionCode,
+                             (messageArgs == null) ? null :
+                                 messageArgs.toArray());
+                     } else if (exceptionCode != null) {
+                         exception = new IdRepoException(exceptionMessage,
+                             exceptionCode);
+                     } else if (exceptionMessage != null) {
+                         exception = new IdRepoException(exceptionMessage);
+                     } else {
+                         // Throw generic SMSException
+                         exception = new SMSException();
+                     }
                  } else if (exceptionClassName.equals(AMREMOTEEXCEPTION)) {
                      exception = new AMRemoteException(exceptionMessage,
                          exceptionCode, ldapErrorCode,
***************
*** 758,766 ****
                      } else {
                          exception = new SOAPClientException(exceptionClassName);
                      }
!                 }
!                 else if (exceptionClassName.indexOf(RMIREMOTEEXCEPTION) != -1)
!                 {
                      exception = new RemoteException(exceptionClassName);
                  } else {
                      // Catch all for remaing exception
--- 779,785 ----
                      } else {
                          exception = new SOAPClientException(exceptionClassName);
                      }
!                 } else if (exceptionClassName.indexOf(RMIREMOTEEXCEPTION) != -1) {
                      exception = new RemoteException(exceptionClassName);
                  } else {
                      // Catch all for remaing exception
***************
*** 798,805 ****
  
      class SOAPErrorHandler implements ErrorHandler {
  
-         private Debug debug = Debug.getInstance("amJAXRPC-XML");
- 
          SOAPErrorHandler() {
              // do nothing
          }
--- 817,822 ----
***************
*** 809,818 ****
          }
  
          public void error(SAXParseException spe) throws SAXParseException {
!             if (debug.warningEnabled()) {
!                 debug.warning("SOAPClient:PARSER:error", spe);
              }
-         }
  
          public void warning(SAXParseException spe) throws SAXParseException {
              // Parser warning can be ignored
--- 826,836 ----
          }
          
          public void error(SAXParseException spe) throws SAXParseException {
!             // do nothing, error can be ignored
          }
          
          public void warning(SAXParseException spe) throws SAXParseException {
***************
*** 852,857 ****
--- 867,874 ----
      
      static final String SET = "ns1:hashSet";
      
+     static final String TREESET = "ns1:treeSet";
+     
      static final String MAP = "ns1:hashMap";
      
      static final String LIST = "ns1:linkedList";
***************
*** 885,890 ****
--- 902,910 ----
      
      static final String SMSEXCEPTION = "com.sun.identity.sm.SMSException";
      
+     static final String IDREPOEXCEPTION =
+         "com.sun.identity.sm.IdRepoException";
+     
      static final String ENTITYEXCEPTION =
          "com.sun.identity.entity.EntityException";
      
Index: source/com/sun/identity/idm/remote/IdRemoteServicesImpl.java
*** C:\Documents and Settings\Aravindan Ranganatha\OpenSSO\opensso\products\amserver\source\com\sun\identity\idm\remote\IdRemoteServicesImpl.java Base (1.2)
--- C:\Documents and Settings\Aravindan Ranganatha\OpenSSO\opensso\products\amserver\source\com\sun\identity\idm\remote\IdRemoteServicesImpl.java Locally Modified (Based On 1.2)
***************
*** 128,133 ****
--- 128,135 ----
                      "IdRemoteServicesImpl.create_idrepo: caught exception=",
                      rex);
              throw new IdRepoException(AMSDKBundle.getString("1000"), "1000");
+         } catch (IdRepoException ide) {
+             throw (ide);
          } catch (Exception ex) {
              getDebug().error(
                      "IdRemoteServicesImpl.create_idrepo: caught exception=",
***************
*** 149,154 ****
--- 151,158 ----
                      "IdRemoteServicesImpl.create_idrepo: caught exception=",
                      rex);
              throw new IdRepoException(AMSDKBundle.getString("1000"), "1000");
+         } catch (IdRepoException ide) {
+             throw (ide);
          } catch (Exception ex) {
              getDebug().error(
                      "IdRemoteServicesImpl.create_idrepo: caught exception=",
***************
*** 179,184 ****
--- 183,190 ----
              getDebug().error("IdRemoteServicesImpl.getAttributes1_idrepo: " 
                      + "caught exception=", rex);
              throw new IdRepoException(AMSDKBundle.getString("1000"), "1000");
+         } catch (IdRepoException ide) {
+             throw (ide);
          } catch (Exception ex) {
              getDebug().error("IdRemoteServicesImpl.getAttributes1_idrepo: " 
                      + "caught exception=", ex);
***************
*** 208,213 ****
--- 214,221 ----
              getDebug().error("IdRemoteServicesImpl.getAttributes2_idrepo: " 
                      + "caught exception=", rex);
              throw new IdRepoException(AMSDKBundle.getString("1000"), "1000");
+         } catch (IdRepoException ide) {
+             throw (ide);
          } catch (Exception ex) {
              getDebug().error("IdRemoteServicesImpl.getAttributes2_idrepo: " 
                      + "caught exception=", ex);
***************
*** 227,232 ****
--- 235,242 ----
              getDebug().error("IdRemoteServicesImpl.removeAttributes_idrepo: " 
                      + "caught exception=", rex);
              throw new IdRepoException(AMSDKBundle.getString("1000"), "1000");
+         } catch (IdRepoException ide) {
+             throw (ide);
          } catch (Exception ex) {
              getDebug().error(
                      "IdRemoteServicesImpl.removeAttributes_idrepo: caught "
***************
*** 262,267 ****
--- 272,279 ----
                      "IdRemoteServicesImpl.search2_idrepo: caught exception=",
                      rex);
              throw new IdRepoException(AMSDKBundle.getString("1000"), "1000");
+         } catch (IdRepoException ide) {
+             throw (ide);
          } catch (Exception ex) {
              getDebug().error(
                      "IdRemoteServicesImpl.search2_idrepo: caught exception=",
***************
*** 285,290 ****
--- 297,304 ----
              getDebug().error("IdRemoteServicesImpl.setAttributes_idrepo: " 
                      + "caught exception=", rex);
              throw new IdRepoException(AMSDKBundle.getString("1000"), "1000");
+         } catch (IdRepoException ide) {
+             throw (ide);
          } catch (Exception ex) {
              getDebug().error("IdRemoteServicesImpl.setAttributes_idrepo: " 
                      + "caught exception=", ex);
***************
*** 307,312 ****
--- 321,328 ----
              getDebug().error("IdRemoteServicesImpl.assignService_idrepo: " 
                      + "caught exception=", rex);
              throw new IdRepoException(AMSDKBundle.getString("1000"), "1000");
+         } catch (IdRepoException ide) {
+             throw (ide);
          } catch (Exception ex) {
              getDebug().error("IdRemoteServicesImpl.assignService_idrepo: " 
                      + "caught exception=", ex);
***************
*** 329,334 ****
--- 345,352 ----
                      "IdRemoteServicesImpl.getAssignedServices_idrepo: caught "
                              + "exception=", rex);
              throw new IdRepoException(AMSDKBundle.getString("1000"), "1000");
+         } catch (IdRepoException ide) {
+             throw (ide);
          } catch (Exception ex) {
              getDebug().error(
                      "IdRemoteServicesImpl.getAssignedServices_idrepo: caught "
***************
*** 351,356 ****
--- 369,376 ----
                      "IdRemoteServicesImpl.getServiceAttributes_idrepo: caught "
                              + "exception=", rex);
              throw new IdRepoException(AMSDKBundle.getString("1000"), "1000");
+         } catch (IdRepoException ide) {
+             throw (ide);
          } catch (Exception ex) {
              getDebug().error(
                      "IdRemoteServicesImpl.getServiceAttributes_idrepo: caught "
***************
*** 372,377 ****
--- 392,399 ----
              getDebug().error("IdRemoteServicesImpl.unassignService_idrepo: "
                      + "caught exception=", rex);
              throw new IdRepoException(AMSDKBundle.getString("1000"), "1000");
+         } catch (IdRepoException ide) {
+             throw (ide);
          } catch (Exception ex) {
              getDebug().error("IdRemoteServicesImpl.unassignService_idrepo: " 
                      + "caught exception=", ex);
***************
*** 395,400 ****
--- 417,424 ----
              getDebug().error("IdRemoteServicesImpl.modifyService_idrepo: " +
                      "caught exception=", rex);
              throw new IdRepoException(AMSDKBundle.getString("1000"), "1000");
+         } catch (IdRepoException ide) {
+             throw (ide);
          } catch (Exception ex) {
              getDebug().error("IdRemoteServicesImpl.modifyService_idrepo: " +
                      "caught exception=", ex);
***************
*** 425,430 ****
--- 449,456 ----
              getDebug().error("IdRemoteServicesImpl.getMembers_idrepo: " 
                      + "caught exception=", rex);
              throw new IdRepoException(AMSDKBundle.getString("1000"), "1000");
+         } catch (IdRepoException ide) {
+             throw (ide);
          } catch (Exception ex) {
              getDebug().error("IdRemoteServicesImpl.getMembers_idrepo: " 
                      + "caught exception=", ex);
***************
*** 455,460 ****
--- 481,488 ----
              getDebug().error("IdRemoteServicesImpl.getMemberships_idrepo: " 
                      + "caught exception=", rex);
              throw new IdRepoException(AMSDKBundle.getString("1000"), "1000");
+         } catch (IdRepoException ide) {
+             throw (ide);
          } catch (Exception ex) {
              getDebug().error("IdRemoteServicesImpl.getMemberships_idrepo: " +
                      "caught exception=", ex);
***************
*** 477,482 ****
--- 505,512 ----
                      "IdRemoteServicesImpl.modifyMemberShip_idrepo: caught "
                              + "exception=", rex);
              throw new IdRepoException(AMSDKBundle.getString("1000"), "1000");
+         } catch (IdRepoException ide) {
+             throw (ide);
          } catch (Exception ex) {
              getDebug().error(
                      "IdRemoteServicesImpl.modifyMemberShip_idrepo: caught "
***************
*** 508,513 ****
--- 538,545 ----
                      + "getSupportedOperations_idrepo: caught "
                      + "exception=", rex);
              throw new IdRepoException(AMSDKBundle.getString("1000"), "1000");
+         } catch (IdRepoException ide) {
+             throw (ide);
          } catch (Exception ex) {
              getDebug().error(
                      "IdRemoteServicesImpl.getSupportedOperations_idrepo: " +
***************
*** 537,542 ****
--- 569,576 ----
                      "IdRemoteServicesImpl.getSupportedTypes_idrepo: caught "
                              + "exception=", rex);
              throw new IdRepoException(AMSDKBundle.getString("1000"), "1000");
+         } catch (IdRepoException ide) {
+             throw (ide);
          } catch (Exception ex) {
              getDebug().error(
                      "IdRemoteServicesImpl.getSupportedTypes_idrepo: caught "
Index: source/com/sun/identity/sm/CachedSMSEntry.java
*** C:\Documents and Settings\Aravindan Ranganatha\OpenSSO\opensso\products\amserver\source\com\sun\identity\sm\CachedSMSEntry.java Base (1.2)
--- C:\Documents and Settings\Aravindan Ranganatha\OpenSSO\opensso\products\amserver\source\com\sun\identity\sm\CachedSMSEntry.java Locally Modified (Based On 1.2)
***************
*** 300,314 ****
          String cacheEntry = (new DN(dn)).toRFCString().toLowerCase();
          CachedSMSEntry answer = null;
          synchronized (cachedSMSEntriesMutex) {
!             if ((answer = (CachedSMSEntry) smsEntries.get(cacheEntry)) == null){
                  // Construct the SMS entry
                  answer = new CachedSMSEntry(new SMSEntry(t, dn));
                  smsEntries.put(cacheEntry, answer);
              }
          }
          // Check if user has permissions
          if (!answer.checkPrincipal(t)) {
--- 300,322 ----
          String cacheEntry = (new DN(dn)).toRFCString().toLowerCase();
          CachedSMSEntry answer = null;
          synchronized (cachedSMSEntriesMutex) {
!             answer = (CachedSMSEntry) smsEntries.get(cacheEntry);
!         }
!         if (answer == null) {
              // Construct the SMS entry
              answer = new CachedSMSEntry(new SMSEntry(t, dn));
+             // Check and add it to cache
+             CachedSMSEntry tmp;
+             synchronized (cachedSMSEntriesMutex) {
+                 if ((tmp = (CachedSMSEntry) smsEntries.get(
+                     cacheEntry)) == null) {
                      smsEntries.put(cacheEntry, answer);
+                 } else {
+                     answer = tmp;
                  }
              }
+         }
+         
          // Check if user has permissions
          if (!answer.checkPrincipal(t)) {
              // Read the SMS entry as that user, and ignore the results
Index: source/com/sun/identity/idm/server/IdCachedServicesImpl.java
*** C:\Documents and Settings\Aravindan Ranganatha\OpenSSO\opensso\products\amserver\source\com\sun\identity\idm\server\IdCachedServicesImpl.java Base (1.2)
--- C:\Documents and Settings\Aravindan Ranganatha\OpenSSO\opensso\products\amserver\source\com\sun\identity\idm\server\IdCachedServicesImpl.java Locally Modified (Based On 1.2)
***************
*** 497,515 ****
          if ((pattern.indexOf('*') == -1) &&
              (ctrl.getSearchModifierMap() == null)) {
              // Search is for a specific user, look in the cache
              Map attributes;
!             if (ctrl.isGetAllReturnAttributesEnabled()) {
!                 attributes = getAttributes(token, type, pattern,
                      orgName, null);
              } else {
!                 Set attrNames = ctrl.getReturnAttributes();
!                 attributes = getAttributes(token, type, pattern,
                      attrNames, orgName, null, true);
              }
              // Construct IdSearchResults
!             AMIdentity id = new AMIdentity(token, pattern, type, orgName, null);
!             answer = new IdSearchResults(type, orgName);
!             answer.addResult(id, attributes);
          } else {
              answer = super.search(token, type, pattern, ctrl, orgName);
          }
--- 497,524 ----
          if ((pattern.indexOf('*') == -1) &&
              (ctrl.getSearchModifierMap() == null)) {
              // Search is for a specific user, look in the cache
+             answer = new IdSearchResults(type, orgName);
              Map attributes;
!             try {
!                 if (ctrl.isGetAllReturnAttributesEnabled ()) {
!                     attributes = getAttributes (token, type, pattern,
                          orgName, null);
                  } else {
!                     Set attrNames = ctrl.getReturnAttributes ();
!                     attributes = getAttributes (token, type, pattern,
                          attrNames, orgName, null, true);
                  }
                  // Construct IdSearchResults
!                 AMIdentity id = new AMIdentity (token, pattern,
!                     type, orgName, null);
!                 answer.addResult (id, attributes);
!             }  catch (IdRepoException ide) {
!                 // Check if the exception is name not found
!                 if (!ide.getErrorCode ().equals ("220")) {
!                     // Throw the exception
!                     throw (ide);
!                 }
!             }
          } else {
              answer = super.search(token, type, pattern, ctrl, orgName);
          }
Index: source/com/sun/identity/idm/remote/IdRemoteCachedServicesImpl.java
*** C:\Documents and Settings\Aravindan Ranganatha\OpenSSO\opensso\products\amserver\source\com\sun\identity\idm\remote\IdRemoteCachedServicesImpl.java Base (1.2)
--- C:\Documents and Settings\Aravindan Ranganatha\OpenSSO\opensso\products\amserver\source\com\sun\identity\idm\remote\IdRemoteCachedServicesImpl.java Locally Modified (Based On 1.2)
***************
*** 463,468 ****
--- 463,532 ----
          }
      }
  
+     public void delete (SSOToken token, IdType type, String name,
+         String orgName, String amsdkDN) throws IdRepoException,
+         SSOException {
+         // Call parent to delete the entry
+         super.delete (token, type, name, orgName, amsdkDN);
+         
+         // Clear the cache, get identity DN
+         AMIdentity id = new AMIdentity (token, name, type, orgName, amsdkDN);
+         String dn = id.getUniversalId ();
+         idRepoCache.remove (dn);
+     }
+     
+     public void removeAttributes (SSOToken token, IdType type, String name,
+         Set attrNames, String orgName, String amsdkDN)
+         throws IdRepoException, SSOException {
+         // Call parent to remove the attributes
+         super.removeAttributes (token, type, name, attrNames, orgName, amsdkDN);
+         
+         // Update the cache
+         AMIdentity id = new AMIdentity (token, name, type, orgName, amsdkDN);
+         String dn = id.getUniversalId ();
+         IdCacheBlock cb = (IdCacheBlock) idRepoCache.get (dn);
+         if ((cb != null) && !cb.hasExpiredAndUpdated () && cb.isExists ()) {
+             // Remove the attributes
+             cb.removeAttributes (attrNames);
+         }
+     }
+     
+     public IdSearchResults search (SSOToken token, IdType type, String pattern,
+         IdSearchControl ctrl, String orgName)
+         throws IdRepoException, SSOException {
+         IdSearchResults answer;
+         // Check if search is for a specific identity
+         if ((pattern.indexOf ('*') == -1) &&
+             (ctrl.getSearchModifierMap () == null)) {
+             // Search is for a specific user, look in the cache
+             answer = new IdSearchResults(type, orgName);
+             try {
+                 Map attributes;
+                 if (ctrl.isGetAllReturnAttributesEnabled ()) {
+                     attributes = getAttributes (token, type, pattern,
+                         orgName, null);
+                 } else {
+                     Set attrNames = ctrl.getReturnAttributes ();
+                     attributes = getAttributes (token, type, pattern,
+                         attrNames, orgName, null, true);
+                 }
+                 // Construct IdSearchResults
+                 AMIdentity id = new AMIdentity (token, pattern,
+                     type, orgName, null);
+                 answer.addResult (id, attributes);
+             } catch (IdRepoException ide) {
+                 // Check if the exception is name not found
+                 if (!ide.getErrorCode ().equals ("220")) {
+                     // Throw the exception
+                     throw (ide);
+                 }
+             }
+         } else {
+             answer = super.search (token, type, pattern, ctrl, orgName);
+         }
+         return (answer);
+     }
+ 
      private IdCacheBlock getFromCache(String dn) {
          IdCacheBlock cb = (IdCacheBlock) idRepoCache.get(dn);
          if ((cb == null)) {
Index: source/com/sun/identity/idm/plugins/files/FilesRepo.java
*** C:\Documents and Settings\Aravindan Ranganatha\OpenSSO\opensso\products\amserver\source\com\sun\identity\idm\plugins\files\FilesRepo.java Base (1.5)
--- C:\Documents and Settings\Aravindan Ranganatha\OpenSSO\opensso\products\amserver\source\com\sun\identity\idm\plugins\files\FilesRepo.java Locally Modified (Based On 1.5)
***************
*** 1292,1298 ****
                                  ioe);
              }
              String[] args = { NAME, fileName };
!             throw (new IdRepoException(ioe.getMessage(), "220", args));
          } finally {
              if (pw != null) {
                  pw.close();
--- 1292,1298 ----
                                  ioe);
              }
              String[] args = { NAME, fileName };
!             throw (new IdRepoException(IdRepoBundle.BUNDLE_NAME, "220", args));
          } finally {
              if (pw != null) {
                  pw.close();
***************
*** 1344,1350 ****
                                  ioe);
              }
              String[] args = { NAME, fileName };
!             throw (new IdRepoException(ioe.getMessage(), "220", args));
          } finally {
              if (br != null) {
                  try {
--- 1344,1350 ----
                                  ioe);
              }
              String[] args = { NAME, fileName };
!             throw (new IdRepoException(IdRepoBundle.BUNDLE_NAME, "220", args));
          } finally {
              if (br != null) {
                  try {
Index: source/com/sun/identity/idm/server/IdServicesImpl.java
*** C:\Documents and Settings\Aravindan Ranganatha\OpenSSO\opensso\products\amserver\source\com\sun\identity\idm\server\IdServicesImpl.java Base (1.2)
--- C:\Documents and Settings\Aravindan Ranganatha\OpenSSO\opensso\products\amserver\source\com\sun\identity\idm\server\IdServicesImpl.java Locally Modified (Based On 1.2)
***************
*** 1342,1348 ****
  
          // Check permission first. If allowed then proceed, else the
          // checkPermission method throws an "402" exception.
!         checkPermission(token, amOrgName, name, null, IdOperation.READ, type);
          // First get the list of plugins that support the create operation.
          Set plugIns = getIdRepoPlugins(token, amOrgName);
          Set configuredPluginClasses = new HashSet();
--- 1342,1349 ----
  
          // Check permission first. If allowed then proceed, else the
          // checkPermission method throws an "402" exception.
!         checkPermission(token, amOrgName, name, null,
!             IdOperation.SERVICE, type);
          // First get the list of plugins that support the create operation.
          Set plugIns = getIdRepoPlugins(token, amOrgName);
          Set configuredPluginClasses = new HashSet();
