示例#1
0
  public void destroySubcontext(Name name) throws NamingException {
    if (name.size() == 0) throw new NamingException(L.l("can't destroy root subcontext"));

    AbstractModel model = _model;

    int i = 0;
    for (; i + 1 < name.size(); i++) {
      String first = name.get(i);

      Object value = model.lookup(first);

      if (value instanceof AbstractModel) {
        model = (AbstractModel) value;
        continue;
      }

      value = dereference(value, null, model);

      if (value instanceof Context) {
        ((Context) value).destroySubcontext(name.getSuffix(i + 1));
        return;
      } else if (value != null)
        throw new NotContextException(
            L.l("{0}: expected intermediate context at `{1}'", getFullPath(name), value));
      else throw new NameNotFoundException(getFullPath(name));
    }

    String first = name.get(i);

    model.unbind(first);
  }
 @Override
 public boolean endsWith(Name name) {
   if (!(name instanceof CompoundName)) {
     return false;
   }
   return equals(name, size() - name.size(), name.size());
 }
示例#3
0
  private Object lookupImpl(Name name) throws NamingException {
    if (log.isLoggable(Level.FINEST)) log.finest(L.l("JNDI lookup `{0}'", name));

    if (name == null) return create(_model, _env);

    AbstractModel model = _model;

    for (int i = 0; i < name.size(); i++) {
      String first = name.get(i);

      Object value = model.lookup(first);

      if (value instanceof AbstractModel) {
        model = (AbstractModel) value;
        continue;
      }

      value = dereference(value, null, model);

      if (i + 1 == name.size()) {
        return value;
      } else if (value instanceof Context) {
        return ((Context) value).lookup(name.getSuffix(i + 1));
      } else if (value != null)
        throw new NotContextException(
            L.l("{0}: expected intermediate context at `{1}'", getFullPath(name), value));
      else throw new NameNotFoundException(getFullPath(name));
    }

    return create(getFullPath(name), model, _env);
  }
示例#4
0
  /** Looks up an object with the given parsed JNDI name, but don't dereference the final object. */
  public Object lookupLink(Name name) throws NamingException {
    if (name == null) return create(_model, _env);

    AbstractModel model = _model;

    for (int i = 0; i < name.size(); i++) {
      String first = name.get(i);

      Object value = model.lookup(first);

      if (value instanceof AbstractModel) {
        model = (AbstractModel) value;
        continue;
      }

      if (i + 1 == name.size()) {
        if (value == NullValue.NULL) return null;
        else if (value != null) return value;
        else throw new NameNotFoundException(getFullPath(name));
      }

      value = dereference(value, null, model);

      if (value instanceof Context) return ((Context) value).lookupLink(name.getSuffix(i + 1));
      else if (value != null)
        throw new NotContextException(
            L.l("{0}: expected intermediate context at `{1}'", getFullPath(name), value));
      else throw new NameNotFoundException(getFullPath(name));
    }

    return create(getFullPath(name), model, _env);
  }
  public void rename(Name name, Name newName) throws NamingException {
    if (name.size() == 1) {
      if (newName.size() != 1) {
        throw new OperationNotSupportedException(
            "Renaming to a Name with more components not supported: " + newName);
      }
      rename(name.get(0), newName.get(0));
    } else {
      // > 1 component with 1st one being URL
      // URLs must be identical; cannot deal with diff URLs
      if (!urlEquals(name.get(0), newName.get(0))) {
        throw new OperationNotSupportedException(
            "Renaming using different URLs as first components not supported: "
                + name
                + " "
                + newName);
      }

      Context ctx = getContinuationContext(name);
      try {
        ctx.rename(name.getSuffix(1), newName.getSuffix(1));
      } finally {
        ctx.close();
      }
    }
  }
示例#6
0
  public void rebind(Name name, Object obj) throws NamingException {
    if (name.size() == 0) throw new NamingException(L.l("can't bind root"));

    AbstractModel model = _model;

    int i = 0;
    for (; i + 1 < name.size(); i++) {
      String first = name.get(i);

      Object value = model.lookup(first);

      if (value instanceof AbstractModel) {
        model = (AbstractModel) value;
        continue;
      }

      value = dereference(value, null, model);

      if (value instanceof Context) {
        ((Context) value).bind(name.getSuffix(i + 1), obj);
        return;
      } else if (value != null)
        throw new NotContextException(
            L.l("{0}: expected intermediate context at `{1}'", getFullPath(name), value));
      else throw new NameNotFoundException(getFullPath(name));
    }

    String first = name.get(i);

    if (obj == null) obj = NullValue.NULL;

    model.bind(first, getReference(model, obj));
  }
示例#7
0
 /**
  * Determines whether a compound name is a suffix of this compound name. A compound name 'n' is a
  * suffix if it it is equal to getSuffix(size()-n.size())--in other words, this compound name ends
  * with 'n'. If n is null or not a compound name, false is returned.
  *
  * <p>Implementation note: Currently the syntax properties of n are not used when doing the
  * comparison. They might be in the future.
  *
  * @param n The possibly null compound name to check.
  * @return true if n is a CompoundName and is a suffix of this compound name, false otherwise.
  */
 public boolean endsWith(Name n) {
   if (n instanceof CompoundName) {
     return (impl.endsWith(n.size(), n.getAll()));
   } else {
     return false;
   }
 }
示例#8
0
  /** Lists the names for the context. */
  public NamingEnumeration list(Name name) throws NamingException {
    AbstractModel model = _model;

    if (name == null) {
      return new QNameClassEnumeration(create(model, _env), model.list());
    }

    for (int i = 0; i < name.size(); i++) {
      String first = name.get(i);

      Object value = model.lookup(first);

      if (value instanceof AbstractModel) {
        model = (AbstractModel) value;
        continue;
      }

      value = dereference(value, null, model);

      if (value instanceof Context) return ((Context) value).list(name.getSuffix(i + 1));
      else if (value != null)
        throw new NotContextException(
            L.l("{0}: expected intermediate context at `{1}'", getFullPath(name), value));
      else throw new NameNotFoundException(getFullPath(name));
    }

    return new QNameClassEnumeration(create(model, _env), model.list());
  }
示例#9
0
  /** Returns the full name for the context. */
  protected String getFullPath(Name name) {
    if (_name == null || _name.equals("")) return name.toString();
    else if (name == null || name.size() == 0) return _name;

    String sep = getSeparatorString();

    return _name + sep + name;
  }
示例#10
0
  public NameParser getNameParser(Name name) throws NamingException {
    if (name.size() == 0) return new QNameParser(this);

    Object obj = lookupSingleObject(name.get(0));

    if (obj instanceof Context) return ((Context) obj).getNameParser(name.getSuffix(1));
    else return new QNameParser(this);
  }
 protected final String getAtom(String dn) {
   // need to strip off all but lowest component of dn
   // so that is relative to current context (currentDN)
   try {
     Name parsed = new LdapName(dn);
     return parsed.get(parsed.size() - 1);
   } catch (NamingException e) {
     return dn;
   }
 }
 public NamingEnumeration listBindings(Name name) throws NamingException {
   if (name.size() == 1) {
     return listBindings(name.get(0));
   } else {
     Context ctx = getContinuationContext(name);
     try {
       return ctx.listBindings(name.getSuffix(1));
     } finally {
       ctx.close();
     }
   }
 }
 public void bind(Name name, Object obj, Attributes attrs) throws NamingException {
   if (name.size() == 1) {
     bind(name.get(0), obj, attrs);
   } else {
     DirContext ctx = getContinuationDirContext(name);
     try {
       ctx.bind(name.getSuffix(1), obj, attrs);
     } finally {
       ctx.close();
     }
   }
 }
 public DirContext createSubcontext(Name name, Attributes attrs) throws NamingException {
   if (name.size() == 1) {
     return createSubcontext(name.get(0), attrs);
   } else {
     DirContext ctx = getContinuationDirContext(name);
     try {
       return ctx.createSubcontext(name.getSuffix(1), attrs);
     } finally {
       ctx.close();
     }
   }
 }
 public DirContext getSchemaClassDefinition(Name name) throws NamingException {
   if (name.size() == 1) {
     return getSchemaClassDefinition(name.get(0));
   } else {
     DirContext ctx = getContinuationDirContext(name);
     try {
       return ctx.getSchemaClassDefinition(name.getSuffix(1));
     } finally {
       ctx.close();
     }
   }
 }
 public NameParser getNameParser(Name name) throws NamingException {
   if (name.size() == 1) {
     return getNameParser(name.get(0));
   } else {
     Context ctx = getContinuationContext(name);
     try {
       return ctx.getNameParser(name.getSuffix(1));
     } finally {
       ctx.close();
     }
   }
 }
 public void modifyAttributes(Name name, ModificationItem[] mods) throws NamingException {
   if (name.size() == 1) {
     modifyAttributes(name.get(0), mods);
   } else {
     DirContext ctx = getContinuationDirContext(name);
     try {
       ctx.modifyAttributes(name.getSuffix(1), mods);
     } finally {
       ctx.close();
     }
   }
 }
 public Context createSubcontext(Name name) throws NamingException {
   if (name.size() == 1) {
     return createSubcontext(name.get(0));
   } else {
     Context ctx = getContinuationContext(name);
     try {
       return ctx.createSubcontext(name.getSuffix(1));
     } finally {
       ctx.close();
     }
   }
 }
 public void destroySubcontext(Name name) throws NamingException {
   if (name.size() == 1) {
     destroySubcontext(name.get(0));
   } else {
     Context ctx = getContinuationContext(name);
     try {
       ctx.destroySubcontext(name.getSuffix(1));
     } finally {
       ctx.close();
     }
   }
 }
 public void rebind(Name name, Object obj) throws NamingException {
   if (name.size() == 1) {
     rebind(name.get(0), obj);
   } else {
     Context ctx = getContinuationContext(name);
     try {
       ctx.rebind(name.getSuffix(1), obj);
     } finally {
       ctx.close();
     }
   }
 }
 public Attributes getAttributes(Name name, String[] attrIds) throws NamingException {
   if (name.size() == 1) {
     return getAttributes(name.get(0), attrIds);
   } else {
     DirContext ctx = getContinuationDirContext(name);
     try {
       return ctx.getAttributes(name.getSuffix(1), attrIds);
     } finally {
       ctx.close();
     }
   }
 }
 public Object lookupLink(Name name) throws NamingException {
   if (name.size() == 1) {
     return lookupLink(name.get(0));
   } else {
     Context ctx = getContinuationContext(name);
     try {
       return ctx.lookupLink(name.getSuffix(1));
     } finally {
       ctx.close();
     }
   }
 }
 public NamingEnumeration<SearchResult> search(Name name, String filter, SearchControls cons)
     throws NamingException {
   if (name.size() == 1) {
     return search(name.get(0), filter, cons);
   } else {
     DirContext ctx = getContinuationDirContext(name);
     try {
       return ctx.search(name.getSuffix(1), filter, cons);
     } finally {
       ctx.close();
     }
   }
 }
 public NamingEnumeration<SearchResult> search(Name name, Attributes matchingAttributes)
     throws NamingException {
   if (name.size() == 1) {
     return search(name.get(0), matchingAttributes);
   } else {
     DirContext ctx = getContinuationDirContext(name);
     try {
       return ctx.search(name.getSuffix(1), matchingAttributes);
     } finally {
       ctx.close();
     }
   }
 }
 @Override
 public Name addAll(int index, Name name) throws InvalidNameException {
   if (name == null) {
     // jndi.00=name must not be null
     throw new NullPointerException(Messages.getString("jndi.00")); // $NON-NLS-1$
   }
   if (!(name instanceof CompoundName)) {
     // jndi.09={0} is not a compound name.
     throw new InvalidNameException(Messages.getString("jndi.09", name.toString())); // $NON-NLS-1$
   }
   if (FLAT.equals(direction) && (size() + name.size() > 1)) {
     // jndi.0A=A flat name can only have a single component
     throw new InvalidNameException(Messages.getString("jndi.0A")); // $NON-NLS-1$
   }
   validateIndex(index, true);
   final Enumeration<String> enumeration = name.getAll();
   while (enumeration.hasMoreElements()) {
     elems.add(index++, enumeration.nextElement());
   }
   return this;
 }
  protected NameClassPair createItem(String dn, Attributes attrs, Vector respCtls)
      throws NamingException {

    Object obj = null;

    String relStart; // name relative to starting search context
    String relHome; // name relative to homeCtx.currentDN
    boolean relative = true; // whether relative to currentDN

    // need to strip off all but lowest component of dn
    // so that is relative to current context (currentDN)

    try {
      Name parsed = new LdapName(dn);
      // System.err.println("dn string: " + dn);
      // System.err.println("dn name: " + parsed);

      if (startName != null && parsed.startsWith(startName)) {
        relStart = parsed.getSuffix(startName.size()).toString();
        relHome = parsed.getSuffix(homeCtx.currentParsedDN.size()).toString();
      } else {
        relative = false;
        relHome =
            relStart =
                LdapURL.toUrlString(
                    homeCtx.hostname, homeCtx.port_number, dn, homeCtx.hasLdapsScheme);
      }
    } catch (NamingException e) {
      // could not parse name
      relative = false;
      relHome =
          relStart =
              LdapURL.toUrlString(
                  homeCtx.hostname, homeCtx.port_number, dn, homeCtx.hasLdapsScheme);
    }

    // Name relative to search context
    CompositeName cn = new CompositeName();
    if (!relStart.equals("")) {
      cn.add(relStart);
    }

    // Name relative to homeCtx
    CompositeName rcn = new CompositeName();
    if (!relHome.equals("")) {
      rcn.add(relHome);
    }
    // System.err.println("relStart: " + cn);
    // System.err.println("relHome: " + rcn);

    // Fix attributes to be able to get schema
    homeCtx.setParents(attrs, rcn);

    // only generate object when requested
    if (searchArgs.cons.getReturningObjFlag()) {

      if (attrs.get(Obj.JAVA_ATTRIBUTES[Obj.CLASSNAME]) != null) {
        // Entry contains Java-object attributes (ser/ref object)
        // serialized object or object reference
        obj = Obj.decodeObject(attrs);
      }
      if (obj == null) {
        obj = new LdapCtx(homeCtx, dn);
      }

      // Call getObjectInstance before removing unrequested attributes
      try {
        // rcn is either relative to homeCtx or a fully qualified DN
        obj =
            DirectoryManager.getObjectInstance(
                obj, rcn, (relative ? homeCtx : null), homeCtx.envprops, attrs);
      } catch (NamingException e) {
        throw e;
      } catch (Exception e) {
        NamingException ne = new NamingException("problem generating object using object factory");
        ne.setRootCause(e);
        throw ne;
      }

      // remove Java attributes from result, if necessary
      // Even if CLASSNAME attr not there, there might be some
      // residual attributes

      String[] reqAttrs;
      if ((reqAttrs = searchArgs.reqAttrs) != null) {
        // create an attribute set for those requested
        Attributes rattrs = new BasicAttributes(true); // caseignore
        for (int i = 0; i < reqAttrs.length; i++) {
          rattrs.put(reqAttrs[i], null);
        }
        for (int i = 0; i < Obj.JAVA_ATTRIBUTES.length; i++) {
          // Remove Java-object attributes if not requested
          if (rattrs.get(Obj.JAVA_ATTRIBUTES[i]) == null) {
            attrs.remove(Obj.JAVA_ATTRIBUTES[i]);
          }
        }
      }
    }

    /*
     * name in search result is either the stringified composite name
     * relative to the search context that can be passed directly to
     * methods of the search context, or the fully qualified DN
     * which can be used with the initial context.
     */
    SearchResult sr;
    if (respCtls != null) {
      sr =
          new SearchResultWithControls(
              (relative ? cn.toString() : relStart),
              obj,
              attrs,
              relative,
              homeCtx.convertControls(respCtls));
    } else {
      sr = new SearchResult((relative ? cn.toString() : relStart), obj, attrs, relative);
    }
    sr.setNameInNamespace(dn);
    return sr;
  }