Ejemplo n.º 1
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;
  }
Ejemplo n.º 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);
   }
 }
  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;
    }
  }
Ejemplo n.º 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;
  }
Ejemplo n.º 5
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);
   }
 }
  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());
  }
Ejemplo n.º 7
0
 public T getAnyRealValue() {
   PrismPropertyValue<T> anyValue = getAnyValue();
   return anyValue.getValue();
 }