Beispiel #1
0
 public synchronized boolean hasCompleteSet(String principalDN) {
   CacheEntry ce = (CacheEntry) cacheEntries.get(principalDN);
   boolean completeSet = false;
   if (ce != null && !hasExpiredAndUpdated()) {
     completeSet = ce.isCompleteSet();
   }
   return completeSet;
 }
Beispiel #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;
  }