Ejemplo n.º 1
0
  /**
   * Test fetching and translating resource schema.
   *
   * @throws Exception
   */
  @Test
  public void test400FetchResourceSchema() throws Exception {
    final String TEST_NAME = "test400FetchResourceSchema";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN

    // WHEN

    // The schema was fetched during test init. Now just check if it was OK.

    // THEN

    AssertJUnit.assertNotNull(resourceSchema);

    System.out.println(resourceSchema.debugDump());

    Document xsdSchema = resourceSchema.serializeToXsd();

    System.out.println(
        "-------------------------------------------------------------------------------------");
    System.out.println(DOMUtil.printDom(xsdSchema));
    System.out.println(
        "-------------------------------------------------------------------------------------");

    ObjectClassComplexTypeDefinition accountDefinition =
        resourceSchema.findObjectClassDefinition(
            new QName(
                ResourceTypeUtil.getResourceNamespace(resourceType),
                ProvisioningTestUtil.OBJECT_CLASS_INETORGPERSON_NAME));
    AssertJUnit.assertNotNull(accountDefinition);

    AssertJUnit.assertFalse(
        "No identifiers for account object class ", accountDefinition.getIdentifiers().isEmpty());

    PrismPropertyDefinition uidDefinition =
        accountDefinition.findAttributeDefinition(
            new QName(
                ResourceTypeUtil.getResourceNamespace(resourceType),
                ProvisioningTestUtil.RESOURCE_OPENDJ_PRIMARY_IDENTIFIER_LOCAL_NAME));
    AssertJUnit.assertNotNull(uidDefinition);

    for (Definition def : resourceSchema.getDefinitions()) {
      if (def instanceof ResourceAttributeContainerDefinition) {
        ResourceAttributeContainerDefinition rdef = (ResourceAttributeContainerDefinition) def;
        assertNotEmpty("No type name in object class", rdef.getTypeName());
        assertNotEmpty(
            "No native object class for " + rdef.getTypeName(), rdef.getNativeObjectClass());

        // This is maybe not that important, but just for a sake of
        // completeness
        assertNotEmpty("No name for " + rdef.getTypeName(), rdef.getName());
      }
    }
  }
 private void serializeAndValidate(PrismObject<UserType> user, PrismContext prismContext)
     throws SchemaException, SAXException, IOException {
   String xmlString = prismContext.serializeObjectToString(user, PrismContext.LANG_XML);
   System.out.println("Serialized XML");
   System.out.println(xmlString);
   Document xmlDocument = DOMUtil.parseDocument(xmlString);
   Schema javaxSchema = prismContext.getSchemaRegistry().getJavaxSchema();
   Validator validator = javaxSchema.newValidator();
   validator.setResourceResolver(prismContext.getEntityResolver());
   validator.validate(new DOMSource(xmlDocument));
 }
Ejemplo n.º 3
0
 public static String dump(QueryType query) throws SchemaException {
   if (query == null) {
     return "null";
   }
   StringBuilder sb = new StringBuilder("Query(");
   sb.append(query.getDescription()).append("):\n");
   if (query.getFilter() != null && query.getFilter().containsFilterClause())
     sb.append(DOMUtil.serializeDOMToString(query.getFilter().getFilterClauseAsElement()));
   else sb.append("(no filter)");
   return sb.toString();
 }
Ejemplo n.º 4
0
 /**
  * Kind of convenience magic. Try few obvious variables and set them as the root node for
  * evaluation. This allow to use "fullName" instead of "$user/fullName".
  */
 private Object determineRootNode(
     XPathVariableResolver variableResolver, String contextDescription) throws SchemaException {
   Object rootNode = variableResolver.resolveVariable(null);
   if (rootNode == null) {
     // Add empty document instead of null so the expressions don't die with exception.
     // This is necessary e.g. on deletes in sync when there may be nothing to evaluate.
     return DOMUtil.getDocument();
   } else {
     return LazyXPathVariableResolver.convertToXml(
         rootNode, null, prismContext, contextDescription);
   }
 }
Ejemplo n.º 5
0
  /**
   * Test fetching and translating resource schema.
   *
   * @throws Exception
   */
  @Test
  public void testFetchResourceSchema() throws CommunicationException, SchemaException {
    TestUtil.displayTestTile("testFetchResourceSchema");
    // GIVEN

    // WHEN

    // The schema was fetched during test init. Now just check if it was OK.

    // THEN

    AssertJUnit.assertNotNull(resourceSchema);

    System.out.println(resourceSchema.debugDump());

    Document xsdSchema = resourceSchema.serializeToXsd();

    System.out.println(
        "-------------------------------------------------------------------------------------");
    System.out.println(DOMUtil.printDom(xsdSchema));
    System.out.println(
        "-------------------------------------------------------------------------------------");

    ObjectClassComplexTypeDefinition accountDefinition =
        resourceSchema.findObjectClassDefinition(
            new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "AccountObjectClass"));
    AssertJUnit.assertNotNull(accountDefinition);

    AssertJUnit.assertFalse(
        "No identifiers for account object class ", accountDefinition.getIdentifiers().isEmpty());

    PrismPropertyDefinition uidDefinition =
        accountDefinition.findPropertyDefinition(ConnectorFactoryIcfImpl.ICFS_UID);
    AssertJUnit.assertNotNull(uidDefinition);

    for (Definition def : resourceSchema.getDefinitions()) {
      if (def instanceof ResourceAttributeContainerDefinition) {
        ResourceAttributeContainerDefinition rdef = (ResourceAttributeContainerDefinition) def;
        assertNotEmpty("No type name in object class", rdef.getTypeName());
        assertNotEmpty(
            "No native object class for " + rdef.getTypeName(), rdef.getNativeObjectClass());

        // This is maybe not that important, but just for a sake of
        // completeness
        assertNotEmpty("No name for " + rdef.getTypeName(), rdef.getName());
      }
    }
  }
Ejemplo n.º 6
0
 private String dumpEntry(int indent, Serializable value) {
   if (value instanceof Element) {
     Element element = (Element) value;
     if (SchemaConstants.C_VALUE.equals(DOMUtil.getQName(element))) {
       try {
         String cvalue = null;
         if (value == null) {
           cvalue = "null";
         } else if (value instanceof Element) {
           cvalue = SchemaDebugUtil.prettyPrint(XmlTypeConverter.toJavaValue((Element) value));
         } else {
           cvalue = SchemaDebugUtil.prettyPrint(value);
         }
         return DebugUtil.fixIndentInMultiline(indent, INDENT_STRING, cvalue);
       } catch (Exception e) {
         return DebugUtil.fixIndentInMultiline(
             indent, INDENT_STRING, "value: " + element.getTextContent());
       }
     }
   }
   return DebugUtil.fixIndentInMultiline(
       indent, INDENT_STRING, SchemaDebugUtil.prettyPrint(value));
 }
Ejemplo n.º 7
0
 public static Element createFakeParentElement() {
   return DOMUtil.createElement(DOMUtil.getDocument(), CUSTOM_OBJECT);
 }
Ejemplo n.º 8
0
  @Test
  public void test610ChangePassword() throws Exception {
    final String TEST_NAME = "test610ChangePassword";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    ResourceAttributeContainer resourceObject =
        createResourceObject("uid=drake,ou=People,dc=example,dc=com", "Sir Francis Drake", "Drake");
    PrismObject<ShadowType> shadow = wrapInShadow(ShadowType.class, resourceObject);

    OperationResult addResult = new OperationResult(this.getClass().getName() + "." + TEST_NAME);

    // Add a testing object
    cc.addObject(shadow, null, addResult);

    String entryUuid = (String) resourceObject.getIdentifier().getValue().getValue();
    SearchResultEntry entry = openDJController.searchAndAssertByEntryUuid(entryUuid);
    display("Entry before change", entry);
    String passwordBefore = OpenDJController.getAttributeValue(entry, "userPassword");
    // We have set no password during create, therefore the password should
    // be empty
    assertNull(passwordBefore);

    ObjectClassComplexTypeDefinition accountDefinition =
        resourceObject.getDefinition().getComplexTypeDefinition();

    Collection<ResourceAttribute<?>> identifiers = resourceObject.getIdentifiers();
    // Determine object class from the schema

    OperationResult result = new OperationResult(this.getClass().getName() + ".testFetchObject");

    // WHEN

    Set<Operation> changes = new HashSet<Operation>();
    ProtectedStringType passPs = protector.encryptString("salalala");

    ItemDeltaType propMod = new ItemDeltaType();
    // create modification path
    Document doc = DOMUtil.getDocument();
    ItemPathType path = new ItemPathType("credentials/password/value");
    //		PropertyPath propPath = new PropertyPath(new
    // PropertyPath(ResourceObjectShadowType.F_CREDENTIALS), CredentialsType.F_PASSWORD);
    propMod.setPath(path);

    // set the replace value
    MapXNode passPsXnode = prismContext.getBeanConverter().marshalProtectedDataType(passPs);
    RawType value = new RawType(passPsXnode, prismContext);
    propMod.getValue().add(value);

    // set the modificaion type
    propMod.setModificationType(ModificationTypeType.REPLACE);

    PropertyDelta passDelta =
        (PropertyDelta) DeltaConvertor.createItemDelta(propMod, shadow.getDefinition());
    PropertyModificationOperation passwordModification =
        new PropertyModificationOperation(passDelta);
    changes.add(passwordModification);

    //		PasswordChangeOperation passwordChange = new PasswordChangeOperation(passPs);
    //		changes.add(passwordChange);
    cc.modifyObject(accountDefinition, identifiers, changes, result);

    // THEN

    entry = openDJController.searchAndAssertByEntryUuid(entryUuid);
    display("Entry after change", entry);

    String passwordAfter = OpenDJController.getAttributeValue(entry, "userPassword");
    assertNotNull(passwordAfter);

    System.out.println("Account password: " + passwordAfter);
  }