Ejemplo n.º 1
0
  public String toString() {
    StringBuffer sb = new StringBuffer();
    sb.append("\n----------- START CACHE BLOCK -----------");
    sb.append("\nEntry DN: ").append(entryDN);
    sb.append(" Valid Entry: ").append(isValidEntry);
    sb.append("\nOrganization: ").append(organizationDN);
    sb.append("\nString Attributes: ");
    if ((stringAttributes != null) && (!stringAttributes.isEmpty())) {
      sb.append(MiscUtils.mapSetToString(stringAttributes));
    }
    sb.append("\nByte Attributes: ");
    sb.append(MiscUtils.mapSetToString(byteAttributes));
    sb.append("\nByte Negative Attributes: ");
    if ((byteAttributes != null) && (!byteAttributes.isEmpty())) {
      sb.append(byteAttributes.getNegativeByteAttrClone().toString());
    }
    sb.append("\nCache Entries: ");

    if (cacheEntries != null && !cacheEntries.isEmpty()) {
      Iterator itr = cacheEntries.keySet().iterator();
      while (itr.hasNext()) {
        String principal = (String) itr.next();
        CacheEntry ce = (CacheEntry) cacheEntries.get(principal);
        sb.append("\nPrincipal: ").append(principal);
        sb.append(ce.toString());
      }
    } else {
      sb.append("<empty>");
    }
    sb.append("\n----------- END CACHE BLOCK -----------");
    return sb.toString();
  }
Ejemplo n.º 2
0
  public synchronized Map getAttributes(String principalDN, Set attrNames, boolean byteValues) {
    Map attributes = new AMHashMap(byteValues);

    // Get the cache entry for the principal
    CacheEntry ce = (CacheEntry) cacheEntries.get(principalDN);
    if (ce != null && !hasExpiredAndUpdated()) {
      // Get the names of attributes that this principal can access
      Set accessibleAttrs = null;
      if (attrNames == null) {
        accessibleAttrs = ce.getReadableAttrNames();
      } else {
        accessibleAttrs = ce.getReadableAttrNames(attrNames);
      }
      // Get the attribute values from cache
      if (!byteValues) {
        attributes = stringAttributes.getCopy(accessibleAttrs);
        if (ce.isCompleteSet()
            && !attributes.keySet().containsAll(accessibleAttrs)
            && !byteAttributes.isEmpty()) {
          // Since the flag for complete set does not distingusih
          // between string and binary attributes, check for
          // missing attributes in byteAttributes
          for (Iterator items = accessibleAttrs.iterator(); items.hasNext(); ) {
            Object key = items.next();
            if (!attributes.containsKey(key) && byteAttributes.containsKey(key)) {
              byte[][] values = (byte[][]) byteAttributes.get(key);
              Set valueSet = new HashSet(values.length * 2);
              for (int i = 0; i < values.length; i++) {
                try {
                  valueSet.add(new String(values[i], "UTF8"));
                } catch (UnsupportedEncodingException uee) {
                  // Use default encoding
                  valueSet.add(new String(values[i]));
                }
              }
              attributes.put(key, valueSet);
            }
          }
        }
      } else {
        attributes = byteAttributes.getCopy(accessibleAttrs);
        if (ce.isCompleteSet()
            && !attributes.keySet().containsAll(accessibleAttrs)
            && !stringAttributes.isEmpty()) {
          // Since the flag for complete set does not distingusih
          // between string and binary attributes, check for
          // missing attributes in stringAttributes
          for (Iterator items = accessibleAttrs.iterator(); items.hasNext(); ) {
            Object key = items.next();
            if (!attributes.containsKey(key) && stringAttributes.containsKey(key)) {
              Set valueSet = (Set) stringAttributes.get(key);
              byte[][] values = new byte[valueSet.size()][];
              int item = 0;
              for (Iterator vals = valueSet.iterator(); vals.hasNext(); ) {
                String val = (String) vals.next();
                values[item] = new byte[val.length()];
                byte[] src = null;
                try {
                  src = val.getBytes("UTF8");
                } catch (UnsupportedEncodingException uee) {
                  // Use default encoding
                  src = val.getBytes();
                }
                System.arraycopy(src, 0, values[item], 0, val.length());
                item++;
              }
              attributes.put(key, values);
            }
          }
        }
      }

      // Get the names of attributes that are invalid/not accessible
      Set inAccessibleAttrs = ce.getInaccessibleAttrNames(attrNames);
      ((AMHashMap) attributes).addEmptyValues(inAccessibleAttrs);
    }

    return attributes;
  }