/* (non-Javadoc)
   * @see com.evolveum.midpoint.model.sync.Action#handle(com.evolveum.midpoint.model.lens.LensContext, com.evolveum.midpoint.model.sync.SynchronizationSituation, java.util.Map, com.evolveum.midpoint.task.api.Task, com.evolveum.midpoint.schema.result.OperationResult)
   */
  @Override
  public <F extends FocusType> void handle(
      LensContext<F> context,
      SynchronizationSituation<F> situation,
      Map<QName, Object> parameters,
      Task task,
      OperationResult parentResult) {
    ActivationStatusType desiredStatus = ActivationStatusType.DISABLED;

    LensProjectionContext projectionContext = context.getProjectionContextsIterator().next();
    PrismObject<ShadowType> objectCurrent = projectionContext.getObjectCurrent();
    if (objectCurrent != null) {
      PrismProperty<Object> administrativeStatusProp =
          objectCurrent.findProperty(SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS);
      if (administrativeStatusProp != null) {
        if (desiredStatus.equals(administrativeStatusProp.getRealValue())) {
          // Desired status already set, nothing to do
          return;
        }
      }
    }
    ObjectDelta<ShadowType> activationDelta =
        ObjectDelta.createModificationReplaceProperty(
            ShadowType.class,
            projectionContext.getOid(),
            SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS,
            getPrismContext(),
            desiredStatus);
    projectionContext.setPrimaryDelta(activationDelta);
  }
  @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");
  }
  @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());
  }
  private void transformConnectorTimeoutsConfiguration(
      APIConfiguration apiConfig, PrismContainer<?> connectorTimeoutsContainer)
      throws SchemaException {

    if (connectorTimeoutsContainer == null || connectorTimeoutsContainer.getValue() == null) {
      return;
    }

    for (PrismProperty prismProperty : connectorTimeoutsContainer.getValue().getProperties()) {
      QName propertQName = prismProperty.getElementName();

      if (ConnectorFactoryIcfImpl.NS_ICF_CONFIGURATION.equals(propertQName.getNamespaceURI())) {
        String opName = propertQName.getLocalPart();
        Class<? extends APIOperation> apiOpClass =
            ConnectorFactoryIcfImpl.resolveApiOpClass(opName);
        if (apiOpClass != null) {
          apiConfig.setTimeout(apiOpClass, parseInt(prismProperty));
        } else {
          throw new SchemaException(
              "Unknown operation name "
                  + opName
                  + " in "
                  + ConnectorFactoryIcfImpl.CONNECTOR_SCHEMA_TIMEOUTS_XML_ELEMENT_NAME);
        }
      }
    }
  }
  @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());
  }
Example #6
0
  @Override
  protected void assertStepSyncToken(String syncTaskOid, int step, long tsStart, long tsEnd)
      throws ObjectNotFoundException, SchemaException {
    OperationResult result =
        new OperationResult(AbstractIntegrationTest.class.getName() + ".assertSyncToken");
    Task task = taskManager.getTask(syncTaskOid, result);
    result.computeStatus();
    TestUtil.assertSuccess(result);

    PrismProperty<String> syncTokenProperty = task.getExtensionProperty(SchemaConstants.SYNC_TOKEN);
    assertNotNull("No sync token in " + task, syncTokenProperty);
    String syncToken = syncTokenProperty.getRealValue();
    assertNotNull("No sync token in " + task, syncToken);
    IntegrationTestTools.display("Sync token", syncToken);

    GeneralizedTime syncTokenGt;
    try {
      syncTokenGt = new GeneralizedTime(syncToken);
    } catch (ParseException e) {
      throw new RuntimeException(e.getMessage(), e);
    }
    TestUtil.assertBetween(
        "Wrong time in sync token: " + syncToken,
        roundTsDown(tsStart),
        roundTsUp(tsEnd),
        syncTokenGt.getCalendar().getTimeInMillis());
  }
  @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());
  }
  public static <T> T deserializeValue(
      String value,
      Class clazz,
      QName itemName,
      ItemDefinition itemDef,
      PrismContext prismContext,
      String language)
      throws SchemaException {
    // System.out.println("item value deserialization");

    XNode xnode = prismContext.getParserDom().parse(value);

    //		System.out.println("xnode: " + xnode.debugDump());

    XNode xmap = null;
    if (xnode instanceof RootXNode) {
      xmap = ((RootXNode) xnode).getSubnode();
    }

    //		System.out.println("xmap: " + xmap);
    //		else if (xnode instanceof MapXNode){
    //			xmap = (MapXNode) xnode;
    //		} else if (xnode instanceof PrimitiveXNode){
    //			xmap = new MapXNode();
    //			xmap.put(itemName, xnode);
    //		}

    Item item = prismContext.getXnodeProcessor().parseItem(xmap, itemName, itemDef);

    //		System.out.println("item: " + item.debugDump());

    if (item instanceof PrismProperty) {
      PrismProperty prop = (PrismProperty) item;

      if (prop.isSingleValue()) {
        return (T) prop.getRealValue();
      }
      return (T) prop.getRealValues();
    } else if (item instanceof PrismContainer) {
      PrismContainer cont = (PrismContainer) item;
      return (T) cont.getValue().asContainerable();
    } else if (item instanceof PrismReference) {
      PrismReference ref = (PrismReference) item;
      return (T) ref.getValue();
    }
    if (item != null) {
      return (T) item.getValue(0);
    }
    //		if (prismContext.getBeanConverter().canConvert(clazz)){
    //			prismContext.getBeanConverter().unmarshall(xmap, clazz);
    //		} else{
    //			prismContext.getXnodeProcessor().parseContainer(xnode, clazz);
    //		}

    throw new UnsupportedOperationException("need to be implemented");
  }
  private void transformResultsHandlerConfiguration(
      ResultsHandlerConfiguration resultsHandlerConfiguration,
      PrismContainer<?> resultsHandlerConfigurationContainer)
      throws SchemaException {

    if (resultsHandlerConfigurationContainer == null
        || resultsHandlerConfigurationContainer.getValue() == null) {
      return;
    }

    for (PrismProperty prismProperty :
        resultsHandlerConfigurationContainer.getValue().getProperties()) {
      QName propertyQName = prismProperty.getElementName();
      if (propertyQName.getNamespaceURI().equals(ConnectorFactoryIcfImpl.NS_ICF_CONFIGURATION)) {
        String subelementName = propertyQName.getLocalPart();
        if (ConnectorFactoryIcfImpl
            .CONNECTOR_SCHEMA_RESULTS_HANDLER_CONFIGURATION_ENABLE_NORMALIZING_RESULTS_HANDLER
            .equals(subelementName)) {
          resultsHandlerConfiguration.setEnableNormalizingResultsHandler(
              parseBoolean(prismProperty));
        } else if (ConnectorFactoryIcfImpl
            .CONNECTOR_SCHEMA_RESULTS_HANDLER_CONFIGURATION_ENABLE_FILTERED_RESULTS_HANDLER.equals(
            subelementName)) {
          resultsHandlerConfiguration.setEnableFilteredResultsHandler(parseBoolean(prismProperty));
        } else if (ConnectorFactoryIcfImpl
            .CONNECTOR_SCHEMA_RESULTS_HANDLER_CONFIGURATION_FILTERED_RESULTS_HANDLER_IN_VALIDATION_MODE
            .equals(subelementName)) {
          resultsHandlerConfiguration.setFilteredResultsHandlerInValidationMode(
              parseBoolean(prismProperty));
        } else if (ConnectorFactoryIcfImpl
            .CONNECTOR_SCHEMA_RESULTS_HANDLER_CONFIGURATION_ENABLE_CASE_INSENSITIVE_HANDLER.equals(
            subelementName)) {
          resultsHandlerConfiguration.setEnableCaseInsensitiveFilter(parseBoolean(prismProperty));
        } else if (ConnectorFactoryIcfImpl
            .CONNECTOR_SCHEMA_RESULTS_HANDLER_CONFIGURATION_ENABLE_ATTRIBUTES_TO_GET_SEARCH_RESULTS_HANDLER
            .equals(subelementName)) {
          resultsHandlerConfiguration.setEnableAttributesToGetSearchResultsHandler(
              parseBoolean(prismProperty));
        } else {
          throw new SchemaException(
              "Unexpected element "
                  + propertyQName
                  + " in "
                  + ConnectorFactoryIcfImpl
                      .CONNECTOR_SCHEMA_RESULTS_HANDLER_CONFIGURATION_ELEMENT_LOCAL_NAME);
        }
      } else {
        throw new SchemaException(
            "Unexpected element "
                + propertyQName
                + " in "
                + ConnectorFactoryIcfImpl
                    .CONNECTOR_SCHEMA_RESULTS_HANDLER_CONFIGURATION_ELEMENT_LOCAL_NAME);
      }
    }
  }
 private <O extends ObjectType, T> void checkUserProperty(
     PrismObject<O> object, QName propQName, OperationResult parentResult, T... expectedValues) {
   String propName = propQName.getLocalPart();
   OperationResult result =
       parentResult.createSubresult(parentResult.getOperation() + "." + propName);
   PrismProperty<T> prop = object.findProperty(propQName);
   Collection<T> actualValues = prop.getRealValues();
   result.addArbitraryCollectionAsParam("actualValues", actualValues);
   assertMultivalue("User, property '" + propName + "'", expectedValues, actualValues, result);
   result.recordSuccessIfUnknown();
 }
 private PropertyModificationOperation createDeleteAttributeChange(
     String propertyName, String propertyValue) {
   PrismProperty property = createProperty(propertyName, propertyValue);
   ItemPath propertyPath =
       new ItemPath(
           ShadowType.F_ATTRIBUTES,
           new QName(ResourceTypeUtil.getResourceNamespace(resourceType), propertyName));
   PropertyDelta delta = new PropertyDelta(propertyPath, property.getDefinition(), prismContext);
   delta.addValueToDelete(new PrismPropertyValue(propertyValue));
   PropertyModificationOperation attributeModification = new PropertyModificationOperation(delta);
   return attributeModification;
 }
Example #12
0
  public boolean isProtectedAccount() {
    if (object == null || !(ShadowType.class.isAssignableFrom(object.getCompileTimeClass()))) {
      return false;
    }

    PrismProperty<Boolean> protectedObject = object.findProperty(ShadowType.F_PROTECTED_OBJECT);
    if (protectedObject == null) {
      return false;
    }

    return protectedObject.getRealValue() != null ? protectedObject.getRealValue() : false;
  }
Example #13
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);
 }
  @Test
  public void testFetchChanges() throws Exception {
    TestUtil.displayTestTile(this, "testFetchChanges");

    OperationResult result = new OperationResult(this.getClass().getName() + ".testFetchChanges");
    ObjectClassComplexTypeDefinition accountDefinition =
        resourceSchema.findDefaultObjectClassDefinition(ShadowKindType.ACCOUNT);
    PrismProperty lastToken = cc.fetchCurrentToken(accountDefinition, result);

    System.out.println("Property:");
    System.out.println(SchemaDebugUtil.prettyPrint(lastToken));

    System.out.println("token " + lastToken.toString());
    List<Change<ShadowType>> changes = cc.fetchChanges(accountDefinition, lastToken, null, result);
    AssertJUnit.assertEquals(0, changes.size());
  }
 private Object convertToIcfSingle(PrismProperty<?> configProperty, Class<?> expectedType)
     throws ConfigurationException {
   if (configProperty == null) {
     return null;
   }
   PrismPropertyValue<?> pval = configProperty.getValue();
   return convertToIcf(pval, expectedType);
 }
  private void transformConnectorPoolConfiguration(
      ObjectPoolConfiguration connectorPoolConfiguration, PrismContainer<?> connectorPoolContainer)
      throws SchemaException {

    if (connectorPoolContainer == null || connectorPoolContainer.getValue() == null) {
      return;
    }

    for (PrismProperty prismProperty : connectorPoolContainer.getValue().getProperties()) {
      QName propertyQName = prismProperty.getElementName();
      if (propertyQName.getNamespaceURI().equals(ConnectorFactoryIcfImpl.NS_ICF_CONFIGURATION)) {
        String subelementName = propertyQName.getLocalPart();
        if (ConnectorFactoryIcfImpl
            .CONNECTOR_SCHEMA_CONNECTOR_POOL_CONFIGURATION_MIN_EVICTABLE_IDLE_TIME_MILLIS.equals(
            subelementName)) {
          connectorPoolConfiguration.setMinEvictableIdleTimeMillis(parseLong(prismProperty));
        } else if (ConnectorFactoryIcfImpl.CONNECTOR_SCHEMA_CONNECTOR_POOL_CONFIGURATION_MIN_IDLE
            .equals(subelementName)) {
          connectorPoolConfiguration.setMinIdle(parseInt(prismProperty));
        } else if (ConnectorFactoryIcfImpl.CONNECTOR_SCHEMA_CONNECTOR_POOL_CONFIGURATION_MAX_IDLE
            .equals(subelementName)) {
          connectorPoolConfiguration.setMaxIdle(parseInt(prismProperty));
        } else if (ConnectorFactoryIcfImpl.CONNECTOR_SCHEMA_CONNECTOR_POOL_CONFIGURATION_MAX_OBJECTS
            .equals(subelementName)) {
          connectorPoolConfiguration.setMaxObjects(parseInt(prismProperty));
        } else if (ConnectorFactoryIcfImpl.CONNECTOR_SCHEMA_CONNECTOR_POOL_CONFIGURATION_MAX_WAIT
            .equals(subelementName)) {
          connectorPoolConfiguration.setMaxWait(parseLong(prismProperty));
        } else {
          throw new SchemaException(
              "Unexpected element "
                  + propertyQName
                  + " in "
                  + ConnectorFactoryIcfImpl
                      .CONNECTOR_SCHEMA_CONNECTOR_POOL_CONFIGURATION_XML_ELEMENT_NAME);
        }
      } else {
        throw new SchemaException(
            "Unexpected element "
                + propertyQName
                + " in "
                + ConnectorFactoryIcfImpl
                    .CONNECTOR_SCHEMA_CONNECTOR_POOL_CONFIGURATION_XML_ELEMENT_NAME);
      }
    }
  }
Example #17
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;
    }
  }
 private Object[] convertToIcfArray(PrismProperty prismProperty, Class<?> componentType)
     throws ConfigurationException {
   List<PrismPropertyValue> values = prismProperty.getValues();
   Object valuesArrary = Array.newInstance(componentType, values.size());
   for (int j = 0; j < values.size(); ++j) {
     Object icfValue = convertToIcf(values.get(j), componentType);
     Array.set(valuesArrary, j, icfValue);
   }
   return (Object[]) valuesArrary;
 }
 private long parseLong(PrismProperty<?> prop) {
   Object realValue = prop.getRealValue();
   if (realValue instanceof Long) {
     return (Long) realValue;
   } else if (realValue instanceof Integer) {
     return ((Integer) realValue);
   } else {
     throw new IllegalArgumentException("Cannot convert " + realValue.getClass() + " to long");
   }
 }
  @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);
    }
  }
  @Test
  public void test200FetchChanges() throws Exception {
    final String TEST_NAME = "test200FetchChanges";
    TestUtil.displayTestTile(this, TEST_NAME);

    OperationResult result = new OperationResult(this.getClass().getName() + "." + TEST_NAME);
    ObjectClassComplexTypeDefinition accountDefinition =
        resourceSchema.findObjectClassDefinition(
            ProvisioningTestUtil.OBJECT_CLASS_INETORGPERSON_NAME);
    PrismProperty<Integer> lastToken = cc.fetchCurrentToken(accountDefinition, result);

    System.out.println("Property:");
    System.out.println(SchemaDebugUtil.prettyPrint(lastToken));
    System.out.println("token " + lastToken.toString());

    assertNotNull("No last token", lastToken);
    assertNotNull("No last token value", lastToken.getRealValue());

    List<Change<ShadowType>> changes = cc.fetchChanges(accountDefinition, lastToken, null, result);
    AssertJUnit.assertEquals(0, changes.size());
  }
Example #23
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());
  }
Example #24
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();
  }
Example #25
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();
  }
Example #26
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());
  }
Example #27
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());
  }
Example #28
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());
  }
  // On missing password this returns empty string (""). It is then up to password policy whether it
  // allows empty passwords or not.
  private String determinePasswordValue(PrismProperty<PasswordType> password) {
    if (password == null || password.getValue(ProtectedStringType.class) == null) {
      return null;
    }

    ProtectedStringType passValue = password.getValue(ProtectedStringType.class).getValue();

    if (passValue == null) {
      return null;
    }

    String passwordStr = passValue.getClearValue();

    if (passwordStr == null && passValue.getEncryptedDataType() != null) {
      // TODO: is this appropriate handling???
      try {
        passwordStr = protector.decryptString(passValue);
      } catch (EncryptionException ex) {
        throw new SystemException("Failed to process password for user: ", ex);
      }
    }

    return passwordStr;
  }
Example #30
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");
  }