예제 #1
0
  /** Adds deltas for iteration and iterationToken to the focus if needed. */
  private <F extends FocusType> void addIterationTokenDeltas(
      LensFocusContext<F> focusContext, int iteration, String iterationToken)
      throws SchemaException {
    PrismObject<F> objectCurrent = focusContext.getObjectCurrent();
    if (objectCurrent != null) {
      Integer iterationOld = objectCurrent.asObjectable().getIteration();
      String iterationTokenOld = objectCurrent.asObjectable().getIterationToken();
      if (iterationOld != null
          && iterationOld == iteration
          && iterationTokenOld != null
          && iterationTokenOld.equals(iterationToken)) {
        // Already stored
        return;
      }
    }
    PrismObjectDefinition<F> objDef = focusContext.getObjectDefinition();

    PrismPropertyValue<Integer> iterationVal = new PrismPropertyValue<Integer>(iteration);
    iterationVal.setOriginType(OriginType.USER_POLICY);
    PropertyDelta<Integer> iterationDelta =
        PropertyDelta.createReplaceDelta(objDef, FocusType.F_ITERATION, iterationVal);
    focusContext.swallowToSecondaryDelta(iterationDelta);

    PrismPropertyValue<String> iterationTokenVal = new PrismPropertyValue<String>(iterationToken);
    iterationTokenVal.setOriginType(OriginType.USER_POLICY);
    PropertyDelta<String> iterationTokenDelta =
        PropertyDelta.createReplaceDelta(objDef, FocusType.F_ITERATION_TOKEN, iterationTokenVal);
    focusContext.swallowToSecondaryDelta(iterationTokenDelta);
  }
예제 #2
0
 private <T> XNode serializePropertyRawValue(PrismPropertyValue<T> value) throws SchemaException {
   Object rawElement = value.getRawElement();
   if (rawElement instanceof XNode) {
     return (XNode) rawElement;
   } else {
     T realValue = value.getValue();
     return createPrimitiveXNode(realValue, DOMUtil.XSD_STRING);
   }
 }
예제 #3
0
  public boolean isRealValueToAdd(PrismPropertyValue<?> value) {
    if (valuesToAdd == null) {
      return false;
    }

    for (PrismPropertyValue valueToAdd : valuesToAdd) {
      if (valueToAdd.equalsRealValue(value)) {
        return true;
      }
    }
    return false;
  }
예제 #4
0
  public boolean evaluateConfirmationExpression(
      UserType user,
      ShadowType shadow,
      ExpressionType expressionType,
      Task task,
      OperationResult result)
      throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
    Validate.notNull(user, "User must not be null.");
    Validate.notNull(shadow, "Resource object shadow must not be null.");
    Validate.notNull(expressionType, "Expression must not be null.");
    Validate.notNull(result, "Operation result must not be null.");

    ResourceType resource = resolveResource(shadow, result);
    ExpressionVariables variables = getDefaultXPathVariables(user, shadow, resource);
    String shortDesc = "confirmation expression for " + resource.asPrismObject();

    PrismPropertyDefinition<Boolean> outputDefinition =
        new PrismPropertyDefinition<>(
            ExpressionConstants.OUTPUT_ELMENT_NAME, DOMUtil.XSD_BOOLEAN, prismContext);
    Expression<PrismPropertyValue<Boolean>, PrismPropertyDefinition<Boolean>> expression =
        expressionFactory.makeExpression(expressionType, outputDefinition, shortDesc, task, result);

    ExpressionEvaluationContext params =
        new ExpressionEvaluationContext(null, variables, shortDesc, task, result);
    PrismValueDeltaSetTriple<PrismPropertyValue<Boolean>> outputTriple =
        ModelExpressionThreadLocalHolder.evaluateExpressionInContext(
            expression, params, task, result);
    Collection<PrismPropertyValue<Boolean>> nonNegativeValues = outputTriple.getNonNegativeValues();
    if (nonNegativeValues == null || nonNegativeValues.isEmpty()) {
      throw new ExpressionEvaluationException(
          "Expression returned no value (" + nonNegativeValues.size() + ") in " + shortDesc);
    }
    if (nonNegativeValues.size() > 1) {
      throw new ExpressionEvaluationException(
          "Expression returned more than one value ("
              + nonNegativeValues.size()
              + ") in "
              + shortDesc);
    }
    PrismPropertyValue<Boolean> resultpval = nonNegativeValues.iterator().next();
    if (resultpval == null) {
      throw new ExpressionEvaluationException(
          "Expression returned no value (" + nonNegativeValues.size() + ") in " + shortDesc);
    }
    Boolean resultVal = resultpval.getValue();
    if (resultVal == null) {
      throw new ExpressionEvaluationException(
          "Expression returned no value (" + nonNegativeValues.size() + ") in " + shortDesc);
    }
    return resultVal;
  }
예제 #5
0
  private PrismValue clone(PrismValue value) {
    if (value == null) {
      return null;
    }
    PrismValue cloned = value.clone();
    cloned.setOriginType(OriginType.USER_ACTION);
    if (value instanceof PrismPropertyValue) {
      PrismPropertyValue ppValue = (PrismPropertyValue) value;
      if (ppValue.getValue() instanceof ProtectedStringType) {
        ((PrismPropertyValue) cloned).setValue(((ProtectedStringType) ppValue.getValue()).clone());
      }
      if (ppValue.getValue() instanceof PolyString) {
        PolyString poly = (PolyString) ppValue.getValue();
        if (StringUtils.isEmpty(poly.getOrig())) {
          return null;
        }
        ((PrismPropertyValue) cloned).setValue(new PolyString(poly.getOrig(), poly.getNorm()));
      }
    } else if (value instanceof PrismReferenceValue) {
      if (cloned == null) {
        return null;
      }
      if (cloned.isEmpty()) {
        return null;
      }
    }

    return cloned;
  }
  private Object convertToIcf(PrismPropertyValue<?> pval, Class<?> expectedType)
      throws ConfigurationException {
    Object midPointRealValue = pval.getValue();
    if (expectedType.equals(GuardedString.class)) {
      // Guarded string is a special ICF beast
      // The value must be ProtectedStringType
      if (midPointRealValue instanceof ProtectedStringType) {
        ProtectedStringType ps = (ProtectedStringType) pval.getValue();
        return IcfUtil.toGuardedString(
            ps, pval.getParent().getElementName().getLocalPart(), protector);
      } else {
        throw new ConfigurationException(
            "Expected protected string as value of configuration property "
                + pval.getParent().getElementName().getLocalPart()
                + " but got "
                + midPointRealValue.getClass());
      }

    } else if (expectedType.equals(GuardedByteArray.class)) {
      // Guarded string is a special ICF beast
      // TODO
      //			return new GuardedByteArray(Base64.decodeBase64((ProtectedByteArrayType)
      // pval.getValue()));
      return new GuardedByteArray(((ProtectedByteArrayType) pval.getValue()).getClearBytes());
    } else if (midPointRealValue instanceof PolyString) {
      return ((PolyString) midPointRealValue).getOrig();
    } else if (midPointRealValue instanceof PolyStringType) {
      return ((PolyStringType) midPointRealValue).getOrig();
    } else if (expectedType.equals(File.class) && midPointRealValue instanceof String) {
      return new File((String) midPointRealValue);
    } else if (expectedType.equals(String.class)
        && midPointRealValue instanceof ProtectedStringType) {
      try {
        return protector.decryptString((ProtectedStringType) midPointRealValue);
      } catch (EncryptionException e) {
        throw new ConfigurationException(e);
      }
    } else {
      return midPointRealValue;
    }
  }
  private void assertTask(PrismObject<TaskType> task) {

    task.checkConsistence();

    assertEquals("Wrong oid", "44444444-4444-4444-4444-000000001111", task.getOid());
    PrismObjectDefinition<TaskType> usedDefinition = task.getDefinition();
    assertNotNull("No task definition", usedDefinition);
    PrismAsserts.assertObjectDefinition(
        usedDefinition,
        new QName(SchemaConstantsGenerated.NS_COMMON, "task"),
        TaskType.COMPLEX_TYPE,
        TaskType.class);
    assertEquals("Wrong class in task", TaskType.class, task.getCompileTimeClass());
    TaskType taskType = task.asObjectable();
    assertNotNull("asObjectable resulted in null", taskType);

    assertPropertyValue(task, "name", PrismTestUtil.createPolyString("Task2"));
    assertPropertyDefinition(task, "name", PolyStringType.COMPLEX_TYPE, 0, 1);

    assertPropertyValue(task, "taskIdentifier", "44444444-4444-4444-4444-000000001111");
    assertPropertyDefinition(task, "taskIdentifier", DOMUtil.XSD_STRING, 0, 1);

    assertPropertyDefinition(
        task, "executionStatus", JAXBUtil.getTypeQName(TaskExecutionStatusType.class), 1, 1);
    PrismProperty<TaskExecutionStatusType> executionStatusProperty =
        task.findProperty(TaskType.F_EXECUTION_STATUS);
    PrismPropertyValue<TaskExecutionStatusType> executionStatusValue =
        executionStatusProperty.getValue();
    TaskExecutionStatusType executionStatus = executionStatusValue.getValue();
    assertEquals("Wrong execution status", TaskExecutionStatusType.RUNNABLE, executionStatus);

    PrismContainer extension = task.getExtension();
    PrismContainerValue extensionValue = extension.getValue();
    assertTrue("Extension parent", extensionValue.getParent() == extension);
    assertNull("Extension ID", extensionValue.getId());
  }
예제 #8
0
 // region Serializing properties - specific functionality
 private <T> XNode serializePropertyValue(
     PrismPropertyValue<T> value, PrismPropertyDefinition<T> definition) throws SchemaException {
   QName typeQName = definition.getTypeName();
   T realValue = value.getValue();
   if (realValue instanceof PolyString) {
     return serializePolyString((PolyString) realValue);
   } else if (beanConverter.canProcess(typeQName)) {
     XNode xnode = beanConverter.marshall(realValue);
     if (realValue instanceof ProtectedDataType<?> && definition.isDynamic()) { // why is this?
       xnode.setExplicitTypeDeclaration(true);
       xnode.setTypeQName(definition.getTypeName());
     }
     return xnode;
   } else {
     // primitive value
     return createPrimitiveXNode(realValue, typeQName);
   }
 }
예제 #9
0
 public T getAnyRealValue() {
   PrismPropertyValue<T> anyValue = getAnyValue();
   return anyValue.getValue();
 }