Exemplo n.º 1
0
 @Override
 public CompoundExplainer getExplainer(ExplainContext context) {
   Attributes atts = new Attributes();
   atts.put(Label.NAME, PrimitiveExplainer.getInstance(getName()));
   atts.put(Label.LIMIT, PrimitiveExplainer.getInstance(limit));
   atts.put(Label.INPUT_OPERATOR, inputOperator.getExplainer(context));
   return new CompoundExplainer(Type.LIMIT_OPERATOR, atts);
 }
  @Override
  public CompoundExplainer getExplainer(ExplainContext context) {
    Attributes att = new Attributes();

    att.put(Label.NAME, PrimitiveExplainer.getInstance(getName()));
    att.put(Label.SCAN_OPTION, PrimitiveExplainer.getInstance(cursorCreator.describeRange()));
    TableName rootName = cursorCreator.group().getRoot().getName();
    att.put(Label.TABLE_SCHEMA, PrimitiveExplainer.getInstance(rootName.getSchemaName()));
    att.put(Label.TABLE_NAME, PrimitiveExplainer.getInstance(rootName.getTableName()));
    return new CompoundExplainer(Type.SCAN_OPERATOR, att);
  }
  /**
   * Test the hierachy process. This test verify bug, that caused codes to be badly resolve, is
   * fixed.
   */
  @Test
  public void testHierachyBug() {
    RPClass b = new RPClass("RPClassTest::K");
    b.add(DefinitionClass.ATTRIBUTE, "a", Type.INT, Definition.STANDARD);
    b.add(DefinitionClass.ATTRIBUTE, "b", Type.FLAG, Definition.STANDARD);
    b.add(DefinitionClass.STATIC, "c", "test", Definition.STANDARD);

    RPClass c = new RPClass("RPClassTest::M");
    c.isA(b);
    c.add(DefinitionClass.ATTRIBUTE, "a", Type.STRING, Definition.STANDARD);
    c.add(DefinitionClass.STATIC, "c", "subclass", Definition.STANDARD);

    Attributes attr = new Attributes(c);
    attr.put("a", 10);

    assertTrue(attr.has("a"));
    assertFalse(attr.has("b"));
    assertTrue(attr.has("c"));
    assertEquals("subclass", attr.get("c"));

    Definition def = c.getDefinition(DefinitionClass.ATTRIBUTE, "a");
    assertEquals(Type.STRING, def.getType());
    short code = def.getCode();

    assertEquals("a", c.getName(DefinitionClass.ATTRIBUTE, code));
  }
  /**
   * after a user has successfully logged in we want to build an access object for use in the
   * scheduling system
   *
   * @param String username
   * @param String group a group name to check for username in (via memberUid string)
   * @return boolean yes or no in the group
   * @throws NamingException when the search fails by DN this will be thrown
   */
  private boolean userInGroup(String username, String group) throws NamingException {
    // assume they are not
    boolean inGroup = false;

    // Specify the attributes to match
    Attributes matchAttrs = new BasicAttributes(true); // ignore attribute name case
    // set the common name for the group using defined prefix ie 'cn' or 'ou'
    matchAttrs.put(
        new BasicAttribute(
            this.GROUPS_LOC.substring(0, this.GROUPS_LOC.indexOf("=")),
            group)); // named group for access rights

    // Search for objects that have those matching attributes in the specified group location
    NamingEnumeration answer = ctx.search(this.GROUPS_LOC + this.BASE_DN, matchAttrs);

    // search for that user id in the member list
    while (answer.hasMore()) {
      SearchResult sr = (SearchResult) answer.next();
      if ((sr.getAttributes().get("memberuid").toString()).indexOf(username) >= 0) {
        // this user is in the specified group
        inGroup = true;
      }
    }
    System.err.println(username + " in " + group + ": " + new Boolean(inGroup).toString());
    return inGroup;
  }
Exemplo n.º 5
0
  private void put(ClassFormatOutput out) throws IOException {

    /* Write out the header */
    out.putU4(VMDescriptor.JAVA_CLASS_FORMAT_MAGIC);
    out.putU2(minor_version);
    out.putU2(major_version);

    // special case checking that the number of constant
    // pool entries does not exceed the limit of 65535
    // (as it is stored as a U2).
    // Special case to allow somewhat easier debugging
    // of the resulting failure.
    out.putU2("constant_pool", cptEntries.size());
    cptPut(out);

    out.putU2(access_flags);
    out.putU2(this_class);
    out.putU2(super_class);

    if (interfaces != null) {
      int ilen = interfaces.length;
      out.putU2(ilen);
      for (int i = 0; i < ilen; i++) {
        out.putU2(interfaces[i]);
      }
    } else {
      out.putU2(0);
    }

    if (field_info != null) {
      out.putU2(field_info.size());
      field_info.put(out);
    } else {
      out.putU2(0);
    }

    if (method_info != null) {
      out.putU2(method_info.size());
      method_info.put(out);
    } else {
      out.putU2(0);
    }

    if (attribute_info != null) {
      out.putU2(attribute_info.size());
      attribute_info.put(out);
    } else {
      out.putU2(0);
    }
  }
  /**
   * Test the creation of static attributes for Marauroa 2.0. Check they work by creating an
   * attribute object.
   */
  @Test
  public void testStaticAttributes() {
    RPClass b = new RPClass("RPClassTest::J");

    b.add(DefinitionClass.ATTRIBUTE, "a", Type.INT, Definition.STANDARD);
    b.add(DefinitionClass.ATTRIBUTE, "b", Type.FLAG, Definition.STANDARD);
    b.add(DefinitionClass.STATIC, "c", "test", Definition.STANDARD);

    Attributes attr = new Attributes(b);
    attr.put("a", 10);
    assertTrue(attr.has("a"));
    assertFalse(attr.has("b"));
    assertTrue(attr.has("c"));
  }
Exemplo n.º 7
0
 @Override
 public CompoundExplainer getExplainer(ExplainContext context) {
   Attributes atts = new Attributes();
   atts.put(Label.NAME, PrimitiveExplainer.getInstance(getName()));
   atts.put(Label.BINDING_POSITION, PrimitiveExplainer.getInstance(bindingPosition));
   atts.put(Label.INPUT_OPERATOR, input.getExplainer(context));
   atts.put(Label.INPUT_OPERATOR, onPositive.getExplainer(context));
   for (TPreparedExpression field : tFields) {
     atts.put(Label.EXPRESSIONS, field.getExplainer(context));
   }
   atts.put(Label.PIPELINE, PrimitiveExplainer.getInstance(pipeline));
   return new CompoundExplainer(Type.BLOOM_FILTER, atts);
 }
 /**
  * Updates the instance key public-key certificate value of this context from the local truststore
  * of the instance bound by this context. Any current value of the certificate is overwritten. The
  * intent of this method is to retrieve the instance-key public-key certificate when this context
  * is bound to an instance, and cache it for later use in registering the instance into ADS.
  *
  * @param desc The map to update with the instance key-pair public-key certificate.
  * @param ctx The bound server instance.
  * @throws NamingException if unable to retrieve certificate from bound instance.
  */
 private static void updatePublicKeyCertificate(
     ServerDescriptor desc, InitialLdapContext ctx, TopologyCacheFilter filter)
     throws NamingException {
   /* TODO: this DN is declared in some core constants file. Create a constants
   file for the installer and import it into the core. */
   final String dnStr = "ds-cfg-key-id=ads-certificate,cn=ads-truststore";
   final LdapName dn = new LdapName(dnStr);
   for (int i = 0; i < 2; ++i) {
     /* If the entry does not exist in the instance's truststore backend, add
     it (which induces the CryptoManager to create the public-key
     certificate attribute), then repeat the search. */
     try {
       final SearchControls searchControls = new SearchControls();
       searchControls.setSearchScope(SearchControls.OBJECT_SCOPE);
       final String attrIDs[] = {"ds-cfg-public-key-certificate;binary"};
       searchControls.setReturningAttributes(attrIDs);
       final SearchResult certEntry =
           ctx.search(dn, "(objectclass=ds-cfg-instance-key)", searchControls).next();
       final Attribute certAttr = certEntry.getAttributes().get(attrIDs[0]);
       if (null != certAttr) {
         /* attribute ds-cfg-public-key-certificate is a MUST in the schema */
         desc.serverProperties.put(ServerProperty.INSTANCE_PUBLIC_KEY_CERTIFICATE, certAttr.get());
       }
       break;
     } catch (NameNotFoundException x) {
       if (0 == i) {
         /* Poke CryptoManager to initialize truststore. Note the special
         attribute in the request. */
         final Attributes attrs = new BasicAttributes();
         final Attribute oc = new BasicAttribute("objectclass");
         oc.add("top");
         oc.add("ds-cfg-self-signed-cert-request");
         attrs.put(oc);
         ctx.createSubcontext(dn, attrs).close();
       } else {
         throw x;
       }
     }
   }
 }
Exemplo n.º 9
0
 /** Exctract specified attributes from the ldapMatchingRule */
 Attributes extractAttributeIds(String[] attrIds) throws NamingException {
   Attributes attrs = new BasicAttributes();
   String val = null;
   for (int i = 0; i < attrIds.length; i++) {
     if (attrIds[i].equals(NUMERICOID)) {
       val = m_ldapMatchingRule.getID();
       if (val != null) {
         attrs.put(new BasicAttribute(NUMERICOID, val));
       }
     } else if (attrIds[i].equals(NAME)) {
       val = m_ldapMatchingRule.getName();
       if (val != null) {
         attrs.put(new BasicAttribute(NAME, val));
       }
     } else if (attrIds[i].equals(DESC)) {
       val = m_ldapMatchingRule.getDescription();
       if (val != null) {
         attrs.put(new BasicAttribute(DESC, val));
       }
     } else if (attrIds[i].equals(SYNTAX)) {
       val = m_ldapMatchingRule.getSyntaxString();
       if (val != null) {
         attrs.put(new BasicAttribute(SYNTAX, val));
       }
     } else if (attrIds[i].equals(APPLIES)) {
       String[] appliesToAttrs = m_ldapMatchingRule.getAttributes();
       if (appliesToAttrs != null && appliesToAttrs.length > 0) {
         BasicAttribute applies = new BasicAttribute(APPLIES);
         for (int a = 0; a < appliesToAttrs.length; a++) {
           applies.add(appliesToAttrs[a]);
         }
         attrs.put(applies);
       }
     } else if (attrIds[i].equals(OBSOLETE)) {
       if (m_ldapMatchingRule.getQualifier(OBSOLETE) != null) {
         attrs.put(new BasicAttribute(OBSOLETE, "true"));
       }
     } else {
       throw new NamingException(
           "Invalid schema attribute type for matching rule definition " + attrIds[i]);
     }
   }
   return attrs;
 }
Exemplo n.º 10
0
  /**
   * Returns a pair consisting of a MarshalledObject and attributes to be bound with the stub.
   *
   * @param obj The non-null object to store.
   * @param inAttrs The possible null attributes to store with object.
   * @return A non-null Result consisting of the MarshalledObject and attributes.
   */
  private static DirStateFactory.Result jrmpObject(Object obj, Attributes inAttrs)
      throws NamingException {
    try {
      Object mobj = new MarshalledObject(obj);

      Attributes outAttrs = null;
      Attribute cname = null;
      Attribute tnames = null;
      Attribute objectClass = null;

      if (inAttrs != null) {
        // Get existing objectclass attribute
        objectClass = (Attribute) inAttrs.get("objectClass");
        if (objectClass == null && !inAttrs.isCaseIgnored()) {
          // %%% workaround
          objectClass = (Attribute) inAttrs.get("objectclass");
        }

        // No objectclasses supplied, use "top" to start
        if (objectClass == null) {
          objectClass = new BasicAttribute("objectClass", "top");
        } else {
          objectClass = (Attribute) objectClass.clone();
        }

        cname = inAttrs.get(CLASSNAME_ATTRID);
        tnames = inAttrs.get(CLASSNAMES_ATTRID);

        outAttrs = (Attributes) inAttrs.clone();
      } else {
        outAttrs = new BasicAttributes(true);
        objectClass = new BasicAttribute("objectClass", "top");
      }

      if (cname == null) {
        outAttrs.put(CLASSNAME_ATTRID, obj.getClass().getName());
      }
      if (tnames == null) {
        Attribute tAttr = LdapCtxFactory.createTypeNameAttr(obj.getClass());
        if (tAttr != null) {
          outAttrs.put(tAttr);
        }
      }

      boolean structural =
          (objectClass.size() == 0 || (objectClass.size() == 1 && objectClass.contains("top")));

      if (structural) {
        objectClass.add(STRUCTURAL_OCID);
      }
      objectClass.add(MARSHALLED_OCID);
      outAttrs.put(objectClass);

      return new DirStateFactory.Result(mobj, outAttrs);

    } catch (java.io.IOException e) {
      NamingException ne = new NamingException("Cannot create MarshallObject for " + obj);
      ne.setRootCause(e);
      throw ne;
    }
  }
Exemplo n.º 11
0
  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;
  }