Exemplo n.º 1
0
  @Test
  public void test360AssignToJack() throws Exception {
    final String TEST_NAME = "test360AssignToJack";
    TestUtil.displayTestTile(this, TEST_NAME);

    // GIVEN
    OperationResult result = new OperationResult(DOT_CLASS + TEST_NAME);
    PrismProperty<ScriptingExpressionType> expression = parseAnyData(ASSIGN_TO_JACK_FILE);

    // WHEN
    ExecutionContext output =
        scriptingExpressionEvaluator.evaluateExpression(
            expression.getAnyValue().getValue(), result);

    // THEN
    assertNoOutputData(output);
    IntegrationTestTools.display("stdout", output.getConsoleOutput());
    IntegrationTestTools.display(result);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    // assertEquals("Recomputed user:c0c010c0-d34d-b33f-f00d-111111111111(jack)\n",
    // output.getConsoleOutput());
    PrismObject<UserType> jack = getUser(USER_JACK_OID);
    IntegrationTestTools.display("jack after assignments creation", jack);
    assertAssignedAccount(jack, "10000000-0000-0000-0000-000000000104");
    assertAssignedRole(jack, "12345678-d34d-b33f-f00d-55555555cccc");
  }
Exemplo n.º 2
0
  @Test
  public void test340ModifyJackBack() throws Exception {
    final String TEST_NAME = "test340ModifyJackBack";
    TestUtil.displayTestTile(this, TEST_NAME);

    // GIVEN
    OperationResult result = new OperationResult(DOT_CLASS + TEST_NAME);
    PrismProperty<ScriptingExpressionType> expression = parseAnyData(MODIFY_JACK_BACK_FILE);

    // WHEN
    ExecutionContext output =
        scriptingExpressionEvaluator.evaluateExpression(
            expression.getAnyValue().getValue(), result);

    // THEN
    assertNoOutputData(output);
    IntegrationTestTools.display("stdout", output.getConsoleOutput());
    IntegrationTestTools.display(result);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    assertEquals(
        "Modified user:c0c010c0-d34d-b33f-f00d-111111111111(jack)\n", output.getConsoleOutput());
    assertEquals(
        "Caribbean",
        searchObjectByName(UserType.class, "jack").asObjectable().getLocality().getOrig());
  }
Exemplo n.º 3
0
  @Test
  public void test410TestResource() throws Exception {
    final String TEST_NAME = "test410TestResource";
    TestUtil.displayTestTile(this, TEST_NAME);

    // GIVEN
    OperationResult result = new OperationResult(DOT_CLASS + TEST_NAME);
    PrismProperty<ScriptingExpressionType> expression = parseAnyData(TEST_DUMMY_RESOURCE_FILE);

    // WHEN
    ExecutionContext output =
        scriptingExpressionEvaluator.evaluateExpression(
            expression.getAnyValue().getValue(), result);

    // THEN
    IntegrationTestTools.display("output", output.getFinalOutput());
    IntegrationTestTools.display("stdout", output.getConsoleOutput());
    ResourceType dummy =
        modelService
            .getObject(
                ResourceType.class,
                RESOURCE_DUMMY_OID,
                null,
                taskManager.createTaskInstance(),
                result)
            .asObjectable();
    IntegrationTestTools.display("dummy resource after test connection", dummy.asPrismObject());
    IntegrationTestTools.display(result);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    assertEquals(1, output.getFinalOutput().getData().size());
    assertEquals(
        "Tested resource:10000000-0000-0000-0000-000000000004(Dummy Resource): SUCCESS\n",
        output.getConsoleOutput());
  }
Exemplo n.º 4
0
  @Test
  public void test420NotificationAboutJack() throws Exception {
    final String TEST_NAME = "test420NotificationAboutJack";
    TestUtil.displayTestTile(this, TEST_NAME);

    // GIVEN
    OperationResult result = new OperationResult(DOT_CLASS + TEST_NAME);
    PrismProperty<ScriptingExpressionType> expression = parseAnyData(NOTIFICATION_ABOUT_JACK_FILE);
    prepareNotifications();

    // WHEN
    ExecutionContext output =
        scriptingExpressionEvaluator.evaluateExpression(
            expression.getAnyValue().getValue(), result);

    // THEN
    IntegrationTestTools.display("output", output.getFinalOutput());
    IntegrationTestTools.display("stdout", output.getConsoleOutput());
    result.computeStatus();
    TestUtil.assertSuccess(result);
    assertEquals(0, output.getFinalOutput().getData().size());
    assertEquals("Produced 1 event(s)\n", output.getConsoleOutput());

    IntegrationTestTools.display("Dummy transport", dummyTransport);
    checkDummyTransportMessages("Custom", 1);
    Message m = dummyTransport.getMessages("dummy:Custom").get(0);
    assertEquals("Wrong message body", "jack/" + USER_JACK_OID, m.getBody());
    assertEquals("Wrong message subject", "Ad hoc notification", m.getSubject());
  }
Exemplo n.º 5
0
  @Test
  public void testUserSimpleDiffMultiAdd() throws Exception {
    System.out.println("\n\n===[ testUserSimpleDiffMulti ]===\n");

    // GIVEN
    PrismObjectDefinition<UserType> userDef = getUserTypeDefinition();

    PrismObject<UserType> user1 = userDef.instantiate();
    user1.setOid(USER_JACK_OID);
    PrismProperty<String> anamesProp1 = user1.findOrCreateProperty(UserType.F_ADDITIONAL_NAMES);
    anamesProp1.addRealValue("foo");
    anamesProp1.addRealValue("bar");

    PrismObject<UserType> user2 = userDef.instantiate();
    user2.setOid(USER_JACK_OID);
    PrismProperty<String> anamesProp2 = user2.findOrCreateProperty(UserType.F_ADDITIONAL_NAMES);
    anamesProp2.addRealValue("foo");
    anamesProp2.addRealValue("bar");
    anamesProp2.addRealValue("baz");

    // WHEN
    ObjectDelta<UserType> delta = user1.diff(user2);

    // THEN
    assertNotNull(delta);
    System.out.println(delta.debugDump());
    assertEquals("Unexpected number of midifications", 1, delta.getModifications().size());
    PrismAsserts.assertPropertyAdd(delta, UserType.F_ADDITIONAL_NAMES, "baz");
    assertEquals("Wrong OID", USER_JACK_OID, delta.getOid());
    delta.checkConsistence();
  }
Exemplo n.º 6
0
 private boolean isEnum(PrismProperty property) {
   PrismPropertyDefinition definition = property.getDefinition();
   ////    	Object realValue = property.getAnyRealValue();
   if (definition == null) {
     return property.getValueClass().isEnum();
   }
   //
   //    	QName defName = definition.getName();
   //    	Class clazz =
   // definition.getPrismContext().getSchemaRegistry().determineCompileTimeClass(defName);
   //
   //    	return ((clazz != null && clazz.isEnum()) ||
   // ActivationType.F_ADMINISTRATIVE_STATUS.equals(definition.getName())
   //    	 || ActivationType.F_LOCKOUT_STATUS.equals(definition.getName()) || );
   return (definition.getAllowedValues() != null && definition.getAllowedValues().size() > 0);
 }
Exemplo n.º 7
0
  @Test
  public void test400PurgeSchema() throws Exception {
    final String TEST_NAME = "test400PurgeSchema";
    TestUtil.displayTestTile(this, TEST_NAME);

    // GIVEN
    OperationResult result = new OperationResult(DOT_CLASS + TEST_NAME);
    Task task = taskManager.createTaskInstance();
    PrismProperty<ScriptingExpressionType> expression = parseAnyData(PURGE_DUMMY_BLACK_SCHEMA_FILE);

    //        ResourceType dummy = modelService.getObject(ResourceType.class,
    // RESOURCE_DUMMY_BLACK_OID, null, task, result).asObjectable();
    //        IntegrationTestTools.display("dummy resource before purge schema",
    // dummy.asPrismObject());
    //        IntegrationTestTools.display("elements: " +
    // dummy.getSchema().getDefinition().getAny().get(0).getElementsByTagName("*").getLength());
    //        IntegrationTestTools.display("schema as XML: " +
    // DOMUtil.printDom(dummy.getSchema().getDefinition().getAny().get(0)));

    // WHEN
    ExecutionContext output =
        scriptingExpressionEvaluator.evaluateExpression(
            expression.getAnyValue().getValue(), result);

    // THEN
    IntegrationTestTools.display("output", output.getFinalOutput());
    IntegrationTestTools.display("stdout", output.getConsoleOutput());
    IntegrationTestTools.display(result);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    assertEquals(1, output.getFinalOutput().getData().size());

    //        dummy = repositoryService.getObject(ResourceType.class, RESOURCE_DUMMY_BLACK_OID,
    // null, result).asObjectable();
    //        IntegrationTestTools.display("dummy resource from repo", dummy.asPrismObject());
    //        IntegrationTestTools.display("elements: " +
    // dummy.getSchema().getDefinition().getAny().get(0).getElementsByTagName("*").getLength());
    //        IntegrationTestTools.display("schema as XML: " +
    // DOMUtil.printDom(dummy.getSchema().getDefinition().getAny().get(0)));

    // AssertJUnit.assertNull("Schema is still present", dummy.getSchema());
    // actually, schema gets downloaded just after purging it
    assertEquals(
        "Purged schema information from resource:10000000-0000-0000-0000-000000000305(Dummy Resource Black)\n",
        output.getConsoleOutput());
  }
  @Override
  public Object getObject() {
    PrismProperty property;
    try {
      property = getPrismObject().findOrCreateProperty(path);
    } catch (SchemaException ex) {
      LoggingUtils.logException(LOGGER, "Couldn't create property in path {}", ex, path);
      // todo show message in page error [lazyman]
      throw new RestartResponseException(PageError.class);
    }

    Object val = getRealValue(property != null ? property.getRealValue() : null);
    if (val == null) {
      return defaultValue;
    } else {
      return val;
    }
  }
  @Override
  public void setObject(Object object) {
    try {
      PrismProperty property = getPrismObject().findOrCreateProperty(path);

      if (object != null) {
        PrismPropertyDefinition def = property.getDefinition();
        if (PolyString.class.equals(def.getTypeClass())) {
          object = new PolyString((String) object);
        }

        property.setValue(new PrismPropertyValue(object, OriginType.USER_ACTION, null));
      } else {
        PrismContainerValue parent = (PrismContainerValue) property.getParent();
        parent.remove(property);
      }
    } catch (Exception ex) {
      LoggingUtils.logException(LOGGER, "Couldn't update prism property model", ex);
    }
  }
Exemplo n.º 10
0
  @Test
  public void test206SearchForRoles() throws Exception {
    final String TEST_NAME = "test206SearchForRoles";
    TestUtil.displayTestTile(this, TEST_NAME);

    // GIVEN
    OperationResult result = new OperationResult(DOT_CLASS + TEST_NAME);
    PrismProperty<SearchExpressionType> expression = parseAnyData(SEARCH_FOR_ROLES_FILE);

    // WHEN
    Data output =
        scriptingExpressionEvaluator
            .evaluateExpression(expression.getAnyValue().getValue(), result)
            .getFinalOutput();

    // THEN
    IntegrationTestTools.display("output", output.getData());
    result.computeStatus();
    TestUtil.assertSuccess(result);
    // assertEquals(9, output.getData().size());
  }
Exemplo n.º 11
0
  // TODO - try to get rid of <br> attributes when creating new lines in association attributes
  // pop-up
  private String createAssociationTooltipText(PrismProperty property) {
    StringBuilder sb = new StringBuilder();
    sb.append(getString("prismValuePanel.message.association.attributes")).append("<br>");

    if (property.getParent() != null && property.getParent().getParent() != null) {
      PrismObject<ShadowType> shadowPrism =
          (PrismObject<ShadowType>) property.getParent().getParent();

      Collection<ResourceAttribute<?>> attributes = ShadowUtil.getAttributes(shadowPrism);
      if (attributes == null || attributes.isEmpty()) {
        return sb.toString();
      }

      // TODO - this is a dirty fix for situation, when attribute value is too long and it is a
      // string without white chars,
      // thus it will not break in tooltip. break-all is also not good, since it can brake in the
      // middle of words. What we
      // are doing here is replacing every, with ,&#8203;, &#8203; (the same with @) is a zero-width
      // space, so the attribute value
      // will break after comma. This dirty fix will be removed when association editor is
      // completed.
      for (ResourceAttribute<?> attr : attributes) {
        for (Object realValue : attr.getRealValues()) {
          sb.append(getAttributeName(attr));
          sb.append(":");
          if (realValue != null) {
            sb.append(
                realValue
                    .toString()
                    .replace(",", ",&#8203;")
                    .replace("@", "@&#8203;")
                    .replace("_", "@&#8203;"));
          }
          sb.append("<br>");
        }
      }
    }

    return sb.toString();
  }
Exemplo n.º 12
0
  @Test
  public void test500ScriptingUsers() throws Exception {
    final String TEST_NAME = "test500ScriptingUsers";
    TestUtil.displayTestTile(this, TEST_NAME);

    // GIVEN
    OperationResult result = new OperationResult(DOT_CLASS + TEST_NAME);
    PrismProperty<ScriptingExpressionType> expression = parseAnyData(SCRIPTING_USERS_FILE);

    // WHEN
    ExecutionContext output =
        scriptingExpressionEvaluator.evaluateExpression(
            expression.getAnyValue().getValue(), result);

    // THEN
    TestUtil.assertSuccess(result);
    Data data = output.getFinalOutput();
    assertEquals("Unexpected # of items in output", 5, data.getData().size());
    Set<String> realOids = new HashSet<>();
    for (PrismValue value : data.getData()) {
      PrismObject<UserType> user = ((PrismObjectValue<UserType>) value).asPrismObject();
      assertEquals("Description not set", "Test", user.asObjectable().getDescription());
      realOids.add(user.getOid());
    }
    assertEquals(
        "Unexpected OIDs in output",
        Sets.newHashSet(
            Arrays.asList(
                USER_ADMINISTRATOR_OID,
                USER_JACK_OID,
                USER_BARBOSSA_OID,
                USER_GUYBRUSH_OID,
                USER_ELAINE_OID)),
        realOids);
    IntegrationTestTools.display("stdout", output.getConsoleOutput());
    IntegrationTestTools.display(result);
    result.computeStatus();
  }
Exemplo n.º 13
0
  @Test
  public void test350RecomputeJack() throws Exception {
    final String TEST_NAME = "test350RecomputeJack";
    TestUtil.displayTestTile(this, TEST_NAME);

    // GIVEN
    OperationResult result = new OperationResult(DOT_CLASS + TEST_NAME);
    PrismProperty<ScriptingExpressionType> expression = parseAnyData(RECOMPUTE_JACK_FILE);

    // WHEN
    ExecutionContext output =
        scriptingExpressionEvaluator.evaluateExpression(
            expression.getAnyValue().getValue(), result);

    // THEN
    assertNoOutputData(output);
    IntegrationTestTools.display("stdout", output.getConsoleOutput());
    IntegrationTestTools.display(result);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    assertEquals(
        "Recomputed user:c0c010c0-d34d-b33f-f00d-111111111111(jack)\n", output.getConsoleOutput());
  }
Exemplo n.º 14
0
  @Test
  public void test200SearchUser() throws Exception {
    final String TEST_NAME = "test200SearchUser";
    TestUtil.displayTestTile(this, TEST_NAME);

    // GIVEN
    OperationResult result = new OperationResult(DOT_CLASS + TEST_NAME);
    PrismProperty<SearchExpressionType> expression = parseAnyData(SEARCH_FOR_USERS_FILE);

    // WHEN
    Data output =
        scriptingExpressionEvaluator
            .evaluateExpression(expression.getAnyValue().getValue(), result)
            .getFinalOutput();

    // THEN
    IntegrationTestTools.display("output", output.getData());
    result.computeStatus();
    TestUtil.assertSuccess(result);
    assertEquals(2, output.getData().size());
    // assertEquals("administrator", ((PrismObject<UserType>)
    // output.getData().get(0)).asObjectable().getName().getOrig());
  }
Exemplo n.º 15
0
  @Test
  public void test225SearchForUsersAccountsNoFetch() throws Exception {
    final String TEST_NAME = "test225SearchForUsersAccountsNoFetch";
    TestUtil.displayTestTile(this, TEST_NAME);

    // GIVEN
    OperationResult result = new OperationResult(DOT_CLASS + TEST_NAME);
    PrismProperty<SearchExpressionType> expression =
        parseAnyData(SEARCH_FOR_USERS_ACCOUNTS_NOFETCH_FILE);

    // WHEN
    Data output =
        scriptingExpressionEvaluator
            .evaluateExpression(expression.getAnyValue().getValue(), result)
            .getFinalOutput();

    // THEN
    IntegrationTestTools.display("output", output.getData());
    result.computeStatus();
    TestUtil.assertSuccess(result);
    assertEquals(4, output.getData().size());
    assertAttributesNotFetched(output.getData());
  }
Exemplo n.º 16
0
  @Test
  public void test370AssignToJackInBackground() throws Exception {
    final String TEST_NAME = "test370AssignToJackInBackground";
    TestUtil.displayTestTile(this, TEST_NAME);

    // GIVEN
    OperationResult result = new OperationResult(DOT_CLASS + TEST_NAME);
    PrismProperty<ScriptingExpressionType> expression = parseAnyData(ASSIGN_TO_JACK_2_FILE);

    // WHEN
    Task task = taskManager.createTaskInstance();
    task.setOwner(getUser(USER_ADMINISTRATOR_OID));
    scriptingExpressionEvaluator.evaluateExpressionInBackground(
        expression.getAnyValue().getValue(), task, result);
    waitForTaskFinish(task.getOid(), false);
    task.refresh(result);

    // THEN
    IntegrationTestTools.display(task.getResult());
    TestUtil.assertSuccess(task.getResult());
    PrismObject<UserType> jack = getUser(USER_JACK_OID);
    IntegrationTestTools.display("jack after assignment creation", jack);
    assertAssignedRole(jack, "12345678-d34d-b33f-f00d-555555556677");
  }
Exemplo n.º 17
0
  @Test
  public void test120Log() throws Exception {
    final String TEST_NAME = "test120Log";
    TestUtil.displayTestTile(this, TEST_NAME);

    // GIVEN
    OperationResult result = new OperationResult(DOT_CLASS + TEST_NAME);
    PrismProperty<ScriptingExpressionType> logAction = parseAnyData(LOG_FILE);

    LogfileTestTailer tailer = new LogfileTestTailer(LoggingConfigurationManager.AUDIT_LOGGER_NAME);
    tailer.tail();
    tailer.setExpecteMessage("Custom message:");

    // WHEN
    ExecutionContext output =
        scriptingExpressionEvaluator.evaluateExpression(logAction.getAnyValue().getValue(), result);

    // THEN
    assertNoOutputData(output);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    tailer.tail();
    tailer.assertExpectedMessage();
  }
Exemplo n.º 18
0
  @Test
  public void test320DeleteAndAddJack() throws Exception {
    final String TEST_NAME = "test320DeleteAndAddJack";
    TestUtil.displayTestTile(this, TEST_NAME);

    // GIVEN
    OperationResult result = new OperationResult(DOT_CLASS + TEST_NAME);
    PrismProperty<ScriptingExpressionType> expression = parseAnyData(DELETE_AND_ADD_JACK_FILE);

    // WHEN
    ExecutionContext output =
        scriptingExpressionEvaluator.evaluateExpression(
            expression.getAnyValue().getValue(), result);

    // THEN
    assertNoOutputData(output);
    IntegrationTestTools.display("stdout", output.getConsoleOutput());
    result.computeStatus();
    TestUtil.assertSuccess(result);
    assertEquals(
        "Deleted user:c0c010c0-d34d-b33f-f00d-111111111111(jack)\nAdded user:c0c010c0-d34d-b33f-f00d-111111111111(jack)\n",
        output.getConsoleOutput());
    assertAdministrativeStatusEnabled(searchObjectByName(UserType.class, "jack"));
  }
Exemplo n.º 19
0
  // normally this method returns an InputPanel;
  // however, for some special readonly types (like ObjectDeltaType) it will return a Panel
  private Panel createTypedInputComponent(String id) {
    //        ValueWrapper valueWrapper = model.getObject();
    //        ItemWrapper itemWrapper =
    final Item item = valueWrapperModel.getObject().getItem().getItem();

    Panel panel = null;
    if (item instanceof PrismProperty) {
      final PrismProperty property = (PrismProperty) item;
      PrismPropertyDefinition definition = property.getDefinition();
      final QName valueType = definition.getTypeName();

      final String baseExpression = "value.value"; // pointing to prism property real value

      // fixing MID-1230, will be improved with some kind of annotation or something like that
      // now it works only in description
      if (ObjectType.F_DESCRIPTION.equals(definition.getName())) {
        return new TextAreaPanel(id, new PropertyModel(valueWrapperModel, baseExpression), null);
      }

      if (ActivationType.F_ADMINISTRATIVE_STATUS.equals(definition.getName())) {
        return WebComponentUtil.createEnumPanel(
            ActivationStatusType.class,
            id,
            new PropertyModel<ActivationStatusType>(valueWrapperModel, baseExpression),
            this);
      } else if (ActivationType.F_LOCKOUT_STATUS.equals(definition.getName())) {
        return new LockoutStatusPanel(
            id, new PropertyModel<LockoutStatusType>(valueWrapperModel, baseExpression));
      } else {
        // nothing to do
      }

      if (DOMUtil.XSD_DATETIME.equals(valueType)) {
        panel =
            new DatePanel(
                id, new PropertyModel<XMLGregorianCalendar>(valueWrapperModel, baseExpression));

      } else if (ProtectedStringType.COMPLEX_TYPE.equals(valueType)) {
        boolean showRemovePasswordButton = true;
        if (pageBase instanceof PageUser
            && ((PageUser) pageBase).getObjectWrapper().getObject() != null
            && ((PageUser) pageBase).getObjectWrapper().getObject().getOid() != null
            && ((PageUser) pageBase)
                .getObjectWrapper()
                .getObject()
                .getOid()
                .equals(SecurityUtils.getPrincipalUser().getOid())) {
          showRemovePasswordButton = false;
        }
        panel =
            new PasswordPanel(
                id,
                new PropertyModel<ProtectedStringType>(valueWrapperModel, baseExpression),
                valueWrapperModel.getObject().isReadonly(),
                showRemovePasswordButton);
      } else if (DOMUtil.XSD_BOOLEAN.equals(valueType)) {
        panel =
            new TriStateComboPanel(
                id, new PropertyModel<Boolean>(valueWrapperModel, baseExpression));

      } else if (SchemaConstants.T_POLY_STRING_TYPE.equals(valueType)) {
        InputPanel inputPanel;
        PrismPropertyDefinition def = property.getDefinition();

        if (def.getValueEnumerationRef() != null) {
          PrismReferenceValue valueEnumerationRef = def.getValueEnumerationRef();
          String lookupTableUid = valueEnumerationRef.getOid();
          Task task = pageBase.createSimpleTask("loadLookupTable");
          OperationResult result = task.getResult();

          Collection<SelectorOptions<GetOperationOptions>> options =
              SelectorOptions.createCollection(
                  LookupTableType.F_ROW,
                  GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE));
          final PrismObject<LookupTableType> lookupTable =
              WebModelServiceUtils.loadObject(
                  LookupTableType.class, lookupTableUid, options, pageBase, task, result);

          if (lookupTable != null) {

            inputPanel =
                new AutoCompleteTextPanel<String>(
                    id,
                    new LookupPropertyModel<String>(
                        valueWrapperModel, baseExpression + ".orig", lookupTable.asObjectable()),
                    String.class) {

                  @Override
                  public Iterator<String> getIterator(String input) {
                    return prepareAutoCompleteList(input, lookupTable).iterator();
                  }
                };

          } else {
            inputPanel =
                new TextPanel<>(
                    id,
                    new PropertyModel<String>(valueWrapperModel, baseExpression + ".orig"),
                    String.class);
          }

        } else {

          inputPanel =
              new TextPanel<>(
                  id,
                  new PropertyModel<String>(valueWrapperModel, baseExpression + ".orig"),
                  String.class);
        }

        if (ObjectType.F_NAME.equals(def.getName()) || UserType.F_FULL_NAME.equals(def.getName())) {
          inputPanel.getBaseFormComponent().setRequired(true);
        }
        panel = inputPanel;

      } else if (DOMUtil.XSD_BASE64BINARY.equals(valueType)) {
        panel =
            new UploadDownloadPanel(id, valueWrapperModel.getObject().isReadonly()) {

              @Override
              public InputStream getStream() {
                Object object =
                    ((PrismPropertyValue) valueWrapperModel.getObject().getValue()).getValue();
                return object != null
                    ? new ByteArrayInputStream((byte[]) object)
                    : new ByteArrayInputStream(new byte[0]);
                //                		return super.getStream();
              }

              @Override
              public void updateValue(byte[] file) {
                ((PrismPropertyValue) valueWrapperModel.getObject().getValue()).setValue(file);
              }

              @Override
              public void uploadFilePerformed(AjaxRequestTarget target) {
                super.uploadFilePerformed(target);
                target.add(PrismValuePanel.this.get(ID_FEEDBACK));
              }

              @Override
              public void removeFilePerformed(AjaxRequestTarget target) {
                super.removeFilePerformed(target);
                target.add(PrismValuePanel.this.get(ID_FEEDBACK));
              }

              @Override
              public void uploadFileFailed(AjaxRequestTarget target) {
                super.uploadFileFailed(target);
                target.add(PrismValuePanel.this.get(ID_FEEDBACK));
                target.add(((PageBase) getPage()).getFeedbackPanel());
              }
            };

      } else if (ObjectDeltaType.COMPLEX_TYPE.equals(valueType)) {
        panel =
            new ModificationsPanel(
                id,
                new AbstractReadOnlyModel<DeltaDto>() {
                  @Override
                  public DeltaDto getObject() {
                    if (valueWrapperModel.getObject() == null
                        || valueWrapperModel.getObject().getValue() == null
                        || ((PrismPropertyValue) valueWrapperModel.getObject().getValue())
                                .getValue()
                            == null) {
                      return null;
                    }
                    PrismContext prismContext = ((PageBase) getPage()).getPrismContext();
                    ObjectDeltaType objectDeltaType =
                        (ObjectDeltaType)
                            ((PrismPropertyValue) valueWrapperModel.getObject().getValue())
                                .getValue();
                    try {
                      ObjectDelta delta =
                          DeltaConvertor.createObjectDelta(objectDeltaType, prismContext);
                      return new DeltaDto(delta);
                    } catch (SchemaException e) {
                      throw new IllegalStateException(
                          "Couldn't convert object delta: " + objectDeltaType);
                    }
                  }
                });
      } else if (QueryType.COMPLEX_TYPE.equals(valueType)
          || CleanupPoliciesType.COMPLEX_TYPE.equals(valueType)) {
        return new TextAreaPanel(
            id,
            new AbstractReadOnlyModel() {
              @Override
              public Object getObject() {
                if (valueWrapperModel.getObject() == null
                    || valueWrapperModel.getObject().getValue() == null) {
                  return null;
                }
                PrismPropertyValue ppv =
                    (PrismPropertyValue) valueWrapperModel.getObject().getValue();
                if (ppv == null || ppv.getValue() == null) {
                  return null;
                }
                QName name = property.getElementName();
                if (name == null && property.getDefinition() != null) {
                  name = property.getDefinition().getName();
                }
                if (name == null) {
                  name = SchemaConstants.C_VALUE;
                }
                PrismContext prismContext = ((PageBase) getPage()).getPrismContext();
                try {
                  return prismContext.serializeAnyData(ppv.getValue(), name, PrismContext.LANG_XML);
                } catch (SchemaException e) {
                  throw new SystemException(
                      "Couldn't serialize property value of type: "
                          + valueType
                          + ": "
                          + e.getMessage(),
                      e);
                }
              }
            },
            10);
      } else {
        Class type = XsdTypeMapper.getXsdToJavaMapping(valueType);
        if (type != null && type.isPrimitive()) {
          type = ClassUtils.primitiveToWrapper(type);
        }

        if (isEnum(property)) {
          return WebComponentUtil.createEnumPanel(
              definition, id, new PropertyModel<>(valueWrapperModel, baseExpression), this);
        }
        //                  // default QName validation is a bit weird, so let's treat QNames as
        // strings [TODO finish this - at the parsing side]
        //                  if (type == QName.class) {
        //                      type = String.class;
        //                  }

        PrismPropertyDefinition def = property.getDefinition();

        if (def.getValueEnumerationRef() != null) {
          PrismReferenceValue valueEnumerationRef = def.getValueEnumerationRef();
          String lookupTableUid = valueEnumerationRef.getOid();
          Task task = pageBase.createSimpleTask("loadLookupTable");
          OperationResult result = task.getResult();

          Collection<SelectorOptions<GetOperationOptions>> options =
              SelectorOptions.createCollection(
                  LookupTableType.F_ROW,
                  GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE));
          final PrismObject<LookupTableType> lookupTable =
              WebModelServiceUtils.loadObject(
                  LookupTableType.class, lookupTableUid, options, pageBase, task, result);

          if (lookupTable != null) {

            panel =
                new AutoCompleteTextPanel<String>(
                    id,
                    new LookupPropertyModel<String>(
                        valueWrapperModel,
                        baseExpression,
                        lookupTable == null ? null : lookupTable.asObjectable()),
                    type) {

                  @Override
                  public Iterator<String> getIterator(String input) {
                    return prepareAutoCompleteList(input, lookupTable).iterator();
                  }

                  @Override
                  public void checkInputValue(
                      AutoCompleteTextField input,
                      AjaxRequestTarget target,
                      LookupPropertyModel model) {
                    Iterator<String> lookupTableValuesIterator =
                        prepareAutoCompleteList("", lookupTable).iterator();

                    String value = input.getInput();
                    boolean isValueExist = false;
                    if (value != null) {
                      if (value.trim().equals("")) {
                        isValueExist = true;
                      } else {
                        while (lookupTableValuesIterator.hasNext()) {
                          String lookupTableValue = lookupTableValuesIterator.next();
                          if (value.trim().equals(lookupTableValue)) {
                            isValueExist = true;
                            break;
                          }
                        }
                      }
                    }
                    if (isValueExist) {
                      input.setModelValue(new String[] {value});
                      target.add(PrismValuePanel.this.get(ID_FEEDBACK));
                    } else {
                      input.error(
                          "Entered value doesn't match any of available values and will not be saved.");
                      target.add(PrismValuePanel.this.get(ID_FEEDBACK));
                    }
                  }
                };

          } else {

            panel =
                new TextPanel<>(
                    id, new PropertyModel<String>(valueWrapperModel, baseExpression), type);
          }

        } else {
          panel =
              new TextPanel<>(
                  id, new PropertyModel<String>(valueWrapperModel, baseExpression), type);
        }
      }
    } else if (item instanceof PrismReference) {
      PrismContext prismContext = item.getPrismContext();
      if (prismContext == null) {
        prismContext = pageBase.getPrismContext();
      }
      QName targetTypeName = ((PrismReferenceDefinition) item.getDefinition()).getTargetTypeName();
      Class targetClass = null;
      if (targetTypeName != null && prismContext != null) {
        targetClass = prismContext.getSchemaRegistry().determineCompileTimeClass(targetTypeName);
      }
      final Class typeClass =
          targetClass != null
              ? targetClass
              : (item.getDefinition().getTypeClassIfKnown() != null
                  ? item.getDefinition().getTypeClassIfKnown()
                  : FocusType.class);
      Collection typeClasses = new ArrayList();

      // HACK HACK MID-3201 MID-3231
      if (isUserOrgItem(item, typeClass)) {
        typeClasses.add(UserType.class);
        typeClasses.add(OrgType.class);
      } else {
        typeClasses.add(typeClass);
      }

      panel =
          new ValueChoosePanel(
              id,
              new PropertyModel<>(valueWrapperModel, "value"),
              item.getValues(),
              false,
              typeClasses);

    } else if (item instanceof PrismContainer<?>) {
      AssociationWrapper itemWrapper = (AssociationWrapper) valueWrapperModel.getObject().getItem();
      final PrismContainer container = (PrismContainer) item;
      PrismContainerDefinition definition = container.getDefinition();
      QName valueType = definition.getTypeName();

      if (ShadowAssociationType.COMPLEX_TYPE.equals(valueType)) {

        PrismContext prismContext = item.getPrismContext();
        if (prismContext == null) {
          prismContext = pageBase.getPrismContext();
        }

        ShadowType shadowType =
            ((ShadowType) itemWrapper.getContainer().getObject().getObject().asObjectable());
        PrismObject<ResourceType> resource = shadowType.getResource().asPrismObject();
        // HACK. The revive should not be here. Revive is no good. The next use of the resource will
        // cause parsing of resource schema. We need some centralized place to maintain live cached
        // copies
        // of resources.
        try {
          resource.revive(prismContext);
        } catch (SchemaException e) {
          throw new SystemException(e.getMessage(), e);
        }
        RefinedResourceSchema refinedSchema;
        CompositeRefinedObjectClassDefinition rOcDef;
        try {
          refinedSchema = RefinedResourceSchema.getRefinedSchema(resource);
          rOcDef =
              refinedSchema.determineCompositeObjectClassDefinition(shadowType.asPrismObject());
        } catch (SchemaException e) {
          throw new SystemException(e.getMessage(), e);
        }
        RefinedAssociationDefinition assocDef = itemWrapper.getRefinedAssociationDefinition();
        RefinedObjectClassDefinition assocTargetDef = assocDef.getAssociationTarget();

        ObjectQuery query =
            getAssociationsSearchQuery(
                prismContext,
                resource,
                assocTargetDef.getTypeName(),
                assocTargetDef.getKind(),
                assocTargetDef.getIntent());

        List values = item.getValues();
        return new AssociationValueChoicePanel(
            id, valueWrapperModel, values, false, ShadowType.class, query, assocTargetDef);
      }
    }

    return panel;
  }
Exemplo n.º 20
0
  private List<ItemWrapper> createProperties(PageBase pageBase) {
    result = new OperationResult(CREATE_PROPERTIES);

    List<ItemWrapper> properties = new ArrayList<ItemWrapper>();

    PrismContainerDefinition definition = null;
    PrismObject parent = getObject().getObject();
    Class clazz = parent.getCompileTimeClass();
    if (ShadowType.class.isAssignableFrom(clazz)) {
      QName name = containerDefinition.getName();

      if (ShadowType.F_ATTRIBUTES.equals(name)) {
        try {
          definition = objectWrapper.getRefinedAttributeDefinition();

          if (definition == null) {
            PrismReference resourceRef = parent.findReference(ShadowType.F_RESOURCE_REF);
            PrismObject<ResourceType> resource = resourceRef.getValue().getObject();

            definition =
                pageBase
                    .getModelInteractionService()
                    .getEditObjectClassDefinition(
                        (PrismObject<ShadowType>) objectWrapper.getObject(),
                        resource,
                        AuthorizationPhaseType.REQUEST)
                    .toResourceAttributeContainerDefinition();

            if (LOGGER.isTraceEnabled()) {
              LOGGER.trace("Refined account def:\n{}", definition.debugDump());
            }
          }
        } catch (Exception ex) {
          LoggingUtils.logException(
              LOGGER, "Couldn't load definitions from refined schema for shadow", ex);
          result.recordFatalError(
              "Couldn't load definitions from refined schema for shadow, reason: "
                  + ex.getMessage(),
              ex);

          return properties;
        }
      } else {
        definition = containerDefinition;
      }
    } else if (ResourceType.class.isAssignableFrom(clazz)) {
      if (containerDefinition != null) {
        definition = containerDefinition;
      } else {
        definition = container.getDefinition();
      }
    } else {
      definition = containerDefinition;
    }

    if (definition == null) {
      LOGGER.error(
          "Couldn't get property list from null definition {}",
          new Object[] {container.getElementName()});
      return properties;
    }

    // assignments are treated in a special way -- we display names of
    // org.units and roles
    // (but only if ObjectWrapper.isShowAssignments() is true; otherwise
    // they are filtered out by ObjectWrapper)
    if (container.getCompileTimeClass() != null
        && AssignmentType.class.isAssignableFrom(container.getCompileTimeClass())) {

      for (Object o : container.getValues()) {
        PrismContainerValue<AssignmentType> pcv = (PrismContainerValue<AssignmentType>) o;

        AssignmentType assignmentType = pcv.asContainerable();

        if (assignmentType.getTargetRef() == null) {
          continue;
        }

        // hack... we want to create a definition for Name
        // PrismPropertyDefinition def = ((PrismContainerValue)
        // pcv.getContainer().getParent()).getContainer().findProperty(ObjectType.F_NAME).getDefinition();
        PrismPropertyDefinition def =
            new PrismPropertyDefinition(
                ObjectType.F_NAME, DOMUtil.XSD_STRING, pcv.getPrismContext());

        if (OrgType.COMPLEX_TYPE.equals(assignmentType.getTargetRef().getType())) {
          def.setDisplayName("Org.Unit");
          def.setDisplayOrder(100);
        } else if (RoleType.COMPLEX_TYPE.equals(assignmentType.getTargetRef().getType())) {
          def.setDisplayName("Role");
          def.setDisplayOrder(200);
        } else {
          continue;
        }

        PrismProperty<Object> temp = def.instantiate();

        String value = formatAssignmentBrief(assignmentType);

        temp.setValue(new PrismPropertyValue<Object>(value));
        // TODO: do this.isReadOnly() - is that OK? (originally it was the default behavior for all
        // cases)
        properties.add(new PropertyWrapper(this, temp, this.isReadonly(), ValueStatus.NOT_CHANGED));
      }

    } else if (isShadowAssociation()) {
      PrismContext prismContext = objectWrapper.getObject().getPrismContext();
      Map<QName, PrismContainer<ShadowAssociationType>> assocMap = new HashMap<>();
      if (objectWrapper.getAssociations() != null) {
        for (PrismContainerValue<ShadowAssociationType> cval : objectWrapper.getAssociations()) {
          ShadowAssociationType associationType = cval.asContainerable();
          QName assocName = associationType.getName();
          PrismContainer<ShadowAssociationType> fractionalContainer = assocMap.get(assocName);
          if (fractionalContainer == null) {
            fractionalContainer =
                new PrismContainer<>(
                    ShadowType.F_ASSOCIATION, ShadowAssociationType.class, cval.getPrismContext());
            fractionalContainer.setDefinition(cval.getParent().getDefinition());
            // HACK: set the name of the association as the element name so wrapper.getName() will
            // return correct data.
            fractionalContainer.setElementName(assocName);
            assocMap.put(assocName, fractionalContainer);
          }
          try {
            fractionalContainer.add(cval.clone());
          } catch (SchemaException e) {
            // Should not happen
            throw new SystemException("Unexpected error: " + e.getMessage(), e);
          }
        }
      }

      PrismReference resourceRef = parent.findReference(ShadowType.F_RESOURCE_REF);
      PrismObject<ResourceType> resource = resourceRef.getValue().getObject();

      // HACK. The revive should not be here. Revive is no good. The next use of the resource will
      // cause parsing of resource schema. We need some centralized place to maintain live cached
      // copies
      // of resources.
      try {
        resource.revive(prismContext);
      } catch (SchemaException e) {
        throw new SystemException(e.getMessage(), e);
      }
      RefinedResourceSchema refinedSchema;
      CompositeRefinedObjectClassDefinition rOcDef;
      try {
        refinedSchema = RefinedResourceSchema.getRefinedSchema(resource);
        rOcDef = refinedSchema.determineCompositeObjectClassDefinition(parent);
      } catch (SchemaException e) {
        throw new SystemException(e.getMessage(), e);
      }
      // Make sure even empty associations have their wrappers so they can be displayed and edited
      for (RefinedAssociationDefinition assocDef : rOcDef.getAssociations()) {
        QName name = assocDef.getName();
        if (!assocMap.containsKey(name)) {
          PrismContainer<ShadowAssociationType> fractionalContainer =
              new PrismContainer<>(
                  ShadowType.F_ASSOCIATION, ShadowAssociationType.class, prismContext);
          fractionalContainer.setDefinition(getItemDefinition());
          // HACK: set the name of the association as the element name so wrapper.getName() will
          // return correct data.
          fractionalContainer.setElementName(name);
          assocMap.put(name, fractionalContainer);
        }
      }

      for (Entry<QName, PrismContainer<ShadowAssociationType>> assocEntry : assocMap.entrySet()) {
        // HACK HACK HACK, the container wrapper should not parse itself. This code should not be
        // here.
        AssociationWrapper assocWrapper =
            new AssociationWrapper(
                this, assocEntry.getValue(), this.isReadonly(), ValueStatus.NOT_CHANGED);
        properties.add(assocWrapper);
      }

    } else { // if not an assignment

      if ((container.getValues().size() == 1 || container.getValues().isEmpty())
          && (containerDefinition == null || containerDefinition.isSingleValue())) {

        // there's no point in showing properties for non-single-valued
        // parent containers,
        // so we continue only if the parent is single-valued

        Collection<ItemDefinition> propertyDefinitions = definition.getDefinitions();
        for (ItemDefinition itemDef : propertyDefinitions) {
          if (itemDef instanceof PrismPropertyDefinition) {

            PrismPropertyDefinition def = (PrismPropertyDefinition) itemDef;
            if (def.isIgnored() || skipProperty(def)) {
              continue;
            }
            if (!showInheritedObjectAttributes
                && INHERITED_OBJECT_ATTRIBUTES.contains(def.getName())) {
              continue;
            }

            // capability handling for activation properties
            if (isShadowActivation() && !hasCapability(def)) {
              continue;
            }

            if (isShadowAssociation()) {
              continue;
            }

            PrismProperty property = container.findProperty(def.getName());
            boolean propertyIsReadOnly;
            // decision is based on parent object status, not this
            // container's one (because container can be added also
            // to an existing object)
            if (objectWrapper.getStatus() == ContainerStatus.MODIFYING) {

              propertyIsReadOnly = !def.canModify();
            } else {
              propertyIsReadOnly = !def.canAdd();
            }
            if (property == null) {
              properties.add(
                  new PropertyWrapper(
                      this, def.instantiate(), propertyIsReadOnly, ValueStatus.ADDED));
            } else {
              properties.add(
                  new PropertyWrapper(this, property, propertyIsReadOnly, ValueStatus.NOT_CHANGED));
            }
          } else if (itemDef instanceof PrismReferenceDefinition) {
            PrismReferenceDefinition def = (PrismReferenceDefinition) itemDef;

            if (INHERITED_OBJECT_ATTRIBUTES.contains(def.getName())) {
              continue;
            }

            PrismReference reference = container.findReference(def.getName());
            boolean propertyIsReadOnly;
            // decision is based on parent object status, not this
            // container's one (because container can be added also
            // to an existing object)
            if (objectWrapper.getStatus() == ContainerStatus.MODIFYING) {

              propertyIsReadOnly = !def.canModify();
            } else {
              propertyIsReadOnly = !def.canAdd();
            }
            if (reference == null) {
              properties.add(
                  new ReferenceWrapper(
                      this, def.instantiate(), propertyIsReadOnly, ValueStatus.ADDED));
            } else {
              properties.add(
                  new ReferenceWrapper(
                      this, reference, propertyIsReadOnly, ValueStatus.NOT_CHANGED));
            }
          }
        }
      }
    }

    Collections.sort(properties, new ItemWrapperComparator());

    result.recomputeStatus();

    return properties;
  }
  private void fillInUserDrake(PrismObject<UserType> user, boolean assertDefinitions)
      throws SchemaException {
    user.setOid(USER_OID);

    // fullName
    PrismProperty<String> fullNameProperty = user.findOrCreateProperty(USER_FULLNAME_QNAME);
    assertEquals(USER_FULLNAME_QNAME, fullNameProperty.getElementName());
    PrismAsserts.assertParentConsistency(user);
    if (assertDefinitions)
      PrismAsserts.assertDefinition(fullNameProperty, DOMUtil.XSD_STRING, 1, 1);
    fullNameProperty.setValue(new PrismPropertyValue<String>("Sir Fancis Drake"));
    PrismProperty<String> fullNamePropertyAgain = user.findOrCreateProperty(USER_FULLNAME_QNAME);
    // The "==" is there by purpose. We really want to make sure that is the same *instance*, that
    // is was not created again
    assertTrue("Property not the same", fullNameProperty == fullNamePropertyAgain);

    // activation
    PrismContainer<ActivationType> activationContainer =
        user.findOrCreateContainer(USER_ACTIVATION_QNAME);
    assertEquals(USER_ACTIVATION_QNAME, activationContainer.getElementName());
    PrismAsserts.assertParentConsistency(user);
    if (assertDefinitions)
      PrismAsserts.assertDefinition(activationContainer, ACTIVATION_TYPE_QNAME, 0, 1);
    PrismContainer<ActivationType> activationContainerAgain =
        user.findOrCreateContainer(USER_ACTIVATION_QNAME);
    // The "==" is there by purpose. We really want to make sure that is the same *instance*, that
    // is was not created again
    assertTrue("Property not the same", activationContainer == activationContainerAgain);

    // activation/enabled
    PrismProperty<Boolean> enabledProperty = user.findOrCreateProperty(USER_ENABLED_PATH);
    assertEquals(USER_ENABLED_QNAME, enabledProperty.getElementName());
    PrismAsserts.assertParentConsistency(user);
    if (assertDefinitions)
      PrismAsserts.assertDefinition(enabledProperty, DOMUtil.XSD_BOOLEAN, 0, 1);
    enabledProperty.setValue(new PrismPropertyValue<Boolean>(true));
    PrismProperty<Boolean> enabledPropertyAgain =
        activationContainer.findOrCreateProperty(USER_ENABLED_QNAME);
    // The "==" is there by purpose. We really want to make sure that is the same *instance*, that
    // is was not created again
    assertTrue("Property not the same", enabledProperty == enabledPropertyAgain);

    // assignment
    // Try to create this one from the value. It should work the same, but let's test a different
    // code path
    PrismContainer<AssignmentType> assignmentContainer =
        user.getValue().findOrCreateContainer(USER_ASSIGNMENT_QNAME);
    assertEquals(USER_ASSIGNMENT_QNAME, assignmentContainer.getElementName());
    PrismAsserts.assertParentConsistency(user);
    if (assertDefinitions)
      PrismAsserts.assertDefinition(assignmentContainer, ASSIGNMENT_TYPE_QNAME, 0, -1);
    PrismContainer<AssignmentType> assignmentContainerAgain =
        user.findOrCreateContainer(USER_ASSIGNMENT_QNAME);
    // The "==" is there by purpose. We really want to make sure that is the same *instance*, that
    // is was not created again
    assertTrue("Property not the same", assignmentContainer == assignmentContainerAgain);
    assertEquals(
        "Wrong number of assignment values (empty)", 0, assignmentContainer.getValues().size());

    // assignment values: construct assignment value as a new container "out of the blue" and then
    // add it.
    PrismContainer<AssignmentType> assBlueContainer =
        new PrismContainer<AssignmentType>(USER_ASSIGNMENT_QNAME);
    PrismProperty<String> assBlueDescriptionProperty =
        assBlueContainer.findOrCreateProperty(USER_DESCRIPTION_QNAME);
    assBlueDescriptionProperty.addValue(
        new PrismPropertyValue<String>("Assignment created out of the blue"));
    PrismAsserts.assertParentConsistency(user);
    assignmentContainer.mergeValues(assBlueContainer);
    assertEquals(
        "Wrong number of assignment values (after blue)",
        1,
        assignmentContainer.getValues().size());
    PrismAsserts.assertParentConsistency(user);

    // assignment values: construct assignment value as a new container value "out of the blue" and
    // then add it.
    PrismContainerValue<AssignmentType> assCyanContainerValue =
        new PrismContainerValue<AssignmentType>();
    PrismProperty<String> assCyanDescriptionProperty =
        assCyanContainerValue.findOrCreateProperty(USER_DESCRIPTION_QNAME);
    assCyanDescriptionProperty.addValue(
        new PrismPropertyValue<String>("Assignment created out of the cyan"));
    assignmentContainer.mergeValue(assCyanContainerValue);
    assertEquals(
        "Wrong number of assignment values (after cyan)",
        2,
        assignmentContainer.getValues().size());
    PrismAsserts.assertParentConsistency(user);

    // assignment values: construct assignment value from existing container
    PrismContainerValue<AssignmentType> assRedContainerValue = assignmentContainer.createNewValue();
    PrismProperty<String> assRedDescriptionProperty =
        assRedContainerValue.findOrCreateProperty(USER_DESCRIPTION_QNAME);
    assRedDescriptionProperty.addValue(
        new PrismPropertyValue<String>("Assignment created out of the red"));
    assertEquals(
        "Wrong number of assignment values (after red)", 3, assignmentContainer.getValues().size());
    PrismAsserts.assertParentConsistency(user);

    // accountRef
    PrismReference accountRef = user.findOrCreateReference(USER_ACCOUNTREF_QNAME);
    assertEquals(USER_ACCOUNTREF_QNAME, accountRef.getElementName());
    if (assertDefinitions)
      PrismAsserts.assertDefinition(accountRef, OBJECT_REFERENCE_TYPE_QNAME, 0, -1);
    accountRef.add(new PrismReferenceValue(ACCOUNT1_OID));
    accountRef.add(new PrismReferenceValue(ACCOUNT2_OID));
    PrismReference accountRefAgain = user.findOrCreateReference(USER_ACCOUNTREF_QNAME);
    // The "==" is there by purpose. We really want to make sure that is the same *instance*, that
    // is was not created again
    assertTrue("Property not the same", accountRef == accountRefAgain);
    assertEquals("accountRef size", 2, accountRef.getValues().size());
    PrismAsserts.assertParentConsistency(user);

    // extension
    PrismContainer<?> extensionContainer = user.findOrCreateContainer(USER_EXTENSION_QNAME);
    assertEquals(USER_EXTENSION_QNAME, extensionContainer.getElementName());
    PrismAsserts.assertParentConsistency(user);
    if (assertDefinitions) PrismAsserts.assertDefinition(extensionContainer, DOMUtil.XSD_ANY, 0, 1);
    PrismContainer<AssignmentType> extensionContainerAgain =
        user.findOrCreateContainer(USER_EXTENSION_QNAME);
    // The "==" is there by purpose. We really want to make sure that is the same *instance*, that
    // is was not created again
    assertTrue("Extension not the same", extensionContainer == extensionContainerAgain);
    assertEquals(
        "Wrong number of extension values (empty)", 0, extensionContainer.getValues().size());

    // extension / stringType
    PrismProperty<String> stringTypeProperty =
        extensionContainer.findOrCreateProperty(EXTENSION_STRING_TYPE_ELEMENT);
    assertEquals(EXTENSION_STRING_TYPE_ELEMENT, stringTypeProperty.getElementName());
    PrismAsserts.assertParentConsistency(user);
    if (assertDefinitions)
      PrismAsserts.assertDefinition(stringTypeProperty, DOMUtil.XSD_STRING, 0, -1);

    // TODO

  }
 private void assertUserDrakeContent(PrismObject<UserType> user, boolean assertDefinitions) {
   // fullName
   PrismProperty fullNameProperty = user.findProperty(USER_FULLNAME_QNAME);
   if (assertDefinitions)
     PrismAsserts.assertDefinition(fullNameProperty, DOMUtil.XSD_STRING, 1, 1);
   assertEquals("Wrong fullname", "Sir Fancis Drake", fullNameProperty.getValue().getValue());
   // activation
   PrismContainer activationContainer = user.findContainer(USER_ACTIVATION_QNAME);
   assertEquals(USER_ACTIVATION_QNAME, activationContainer.getElementName());
   if (assertDefinitions)
     PrismAsserts.assertDefinition(activationContainer, ACTIVATION_TYPE_QNAME, 0, 1);
   // activation/enabled
   PrismProperty enabledProperty = user.findProperty(USER_ENABLED_PATH);
   assertEquals(USER_ENABLED_QNAME, enabledProperty.getElementName());
   if (assertDefinitions)
     PrismAsserts.assertDefinition(enabledProperty, DOMUtil.XSD_BOOLEAN, 0, 1);
   assertEquals("Wrong enabled", true, enabledProperty.getValue().getValue());
   // assignment
   PrismContainer assignmentContainer = user.findContainer(USER_ASSIGNMENT_QNAME);
   assertEquals(USER_ASSIGNMENT_QNAME, assignmentContainer.getElementName());
   if (assertDefinitions)
     PrismAsserts.assertDefinition(assignmentContainer, ASSIGNMENT_TYPE_QNAME, 0, -1);
   // assignment values
   List<PrismContainerValue> assValues = assignmentContainer.getValues();
   assertEquals("Wrong number of assignment values", 3, assValues.size());
   // assignment values: blue
   PrismContainerValue assBlueValue = assValues.get(0);
   PrismProperty assBlueDescriptionProperty = assBlueValue.findProperty(USER_DESCRIPTION_QNAME);
   if (assertDefinitions)
     PrismAsserts.assertDefinition(assBlueDescriptionProperty, DOMUtil.XSD_STRING, 0, 1);
   assertEquals(
       "Wrong blue assignment description",
       "Assignment created out of the blue",
       assBlueDescriptionProperty.getValue().getValue());
   // assignment values: cyan
   PrismContainerValue assCyanValue = assValues.get(1);
   PrismProperty assCyanDescriptionProperty = assCyanValue.findProperty(USER_DESCRIPTION_QNAME);
   if (assertDefinitions)
     PrismAsserts.assertDefinition(assCyanDescriptionProperty, DOMUtil.XSD_STRING, 0, 1);
   assertEquals(
       "Wrong cyan assignment description",
       "Assignment created out of the cyan",
       assCyanDescriptionProperty.getValue().getValue());
   // assignment values: red
   PrismContainerValue assRedValue = assValues.get(2);
   PrismProperty assRedDescriptionProperty = assRedValue.findProperty(USER_DESCRIPTION_QNAME);
   if (assertDefinitions)
     PrismAsserts.assertDefinition(assRedDescriptionProperty, DOMUtil.XSD_STRING, 0, 1);
   assertEquals(
       "Wrong red assignment description",
       "Assignment created out of the red",
       assRedDescriptionProperty.getValue().getValue());
   // accountRef
   PrismReference accountRef = user.findReference(USER_ACCOUNTREF_QNAME);
   if (assertDefinitions)
     PrismAsserts.assertDefinition(accountRef, OBJECT_REFERENCE_TYPE_QNAME, 0, -1);
   PrismAsserts.assertReferenceValue(accountRef, ACCOUNT1_OID);
   PrismAsserts.assertReferenceValue(accountRef, ACCOUNT2_OID);
   assertEquals("accountRef size", 2, accountRef.getValues().size());
   PrismAsserts.assertParentConsistency(user);
 }