Uploaded image for project: 'Sling'
  1. Sling
  2. SLING-7198

Duplicated lookup for mapping without subserviceName

    XMLWordPrintableJSON

Details

    Description

      kpauls If I am not mistaken there is an extra lookup in the following method:

          private Iterable<String> internalGetPrincipalNames(final String serviceName, final String subServiceName) {
              log.debug(
                      "internalGetPrincipalNames: {} active mappings, looking for mapping for {}/{}",
                      new Object[] { this.activeMappings.length, serviceName, subServiceName });
      
              for (final Mapping mapping : this.activeMappings) {
                  final Iterable<String> principalNames = mapping.mapPrincipals(serviceName, subServiceName);
                  if (principalNames != null) {
                      log.debug("Got principalNames [{}] from {}/{}", new Object[] {principalNames, serviceName, subServiceName });
                      return principalNames;
                  }
              }
      
              for (Mapping mapping : this.activeMappings) {
                  final Iterable<String> principalNames = mapping.mapPrincipals(serviceName, null);
                  if (principalNames != null) {
                      log.debug("Got principalNames [{}] from {}/{}", new Object[] {principalNames, serviceName });
                      return principalNames;
                  }
              }
      
              // second round without serviceInfo
              log.debug(
                      "internalGetPrincipalNames: {} active mappings, looking for mapping for {}/<no subServiceName>",
                      this.activeMappings.length, serviceName);
      
              for (Mapping mapping : this.activeMappings) {
                  final Iterable<String> principalNames = mapping.mapPrincipals(serviceName, null);
                  if (principalNames != null) {
                      log.debug("Got principalNames [{}] from {}/<no subServiceName>", principalNames, serviceName);
                      return principalNames;
                  }
              }
      
              log.debug("internalGetPrincipalNames: no mapping found.");
              return null;
          }
      

      If I read the code properly the lookup that is logged by being the 'second round' is actually the third perform once again the lookup without 'subServiceName'. If that is correct I would suggest to remove the following code:

      for (Mapping mapping : this.activeMappings) {
                  final Iterable<String> principalNames = mapping.mapPrincipals(serviceName, null);
                  if (principalNames != null) {
                      log.debug("Got principalNames [{}] from {}/{}", new Object[] {principalNames, serviceName });
                      return principalNames;
                  }
              }
      

      or the third one that is called the second round

      But please double check to make sure I didn't just overlook some subtle diff

      Attachments

        Activity

          People

            karlpauls Karl Pauls
            angela Angela Schreiber
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: