Example #1
0
  public <O extends ObjectType> O resolveObject(ObjectReferenceType ref) {
    Validate.notNull(ref.getOid(), "Object oid must not be null");
    Validate.notNull(ref.getType(), "Object type must not be null");

    Class type = prismContext.getSchemaRegistry().determineCompileTimeClass(ref.getType());
    return resolveObject(type, ref.getOid());
  }
Example #2
0
  public <O extends ObjectType> List<PrismObject<O>> resolveLinkRefs(
      Collection<ObjectReferenceType> refs, Class type) {

    List<PrismObject<O>> objects = new ArrayList<>();

    for (ObjectReferenceType ref : refs) {
      Class clazz = getClassForType(ref.getType());
      if (!clazz.equals(type)) {
        continue;
      }
      Task task = taskManager.createTaskInstance();
      OperationResult parentResult = task.getResult();
      try {
        PrismObject<O> obj =
            model.getObject(
                type,
                ref.getOid(),
                SelectorOptions.createCollection(GetOperationOptions.createResolveNames()),
                task,
                parentResult);
        objects.add(obj);
      } catch (ObjectNotFoundException
          | SchemaException
          | SecurityViolationException
          | CommunicationException
          | ConfigurationException e) {
        // TODO Auto-generated catch block
        LOGGER.error(
            "Could not get object with oid " + ref.getOid() + ". Reason: " + e.getMessage());
      }
    }
    return objects;
  }
Example #3
0
  public String resolveRefName(ObjectReferenceType ref) {
    if (ref == null) {
      return null;
    }
    PrismReferenceValue refValue = ref.asReferenceValue();
    Object name = refValue.getTargetName() != null ? ref.getTargetName().getOrig() : null;
    if (!(name instanceof String)) {
      LOGGER.error("Couldn't resolve object name");
    }

    return (String) name;
  }
Example #4
0
  private AssignmentItemDto createAssignmentItem(
      PrismObject<UserType> user,
      PrismContainerValue assignment,
      Task task,
      OperationResult result) {
    PrismReference targetRef = assignment.findReference(AssignmentType.F_TARGET_REF);
    if (targetRef == null || targetRef.isEmpty()) {
      // account construction
      PrismContainer construction = assignment.findContainer(AssignmentType.F_CONSTRUCTION);
      String name = null;
      String description = null;
      if (construction.getValue().asContainerable() != null && !construction.isEmpty()) {
        ConstructionType constr = (ConstructionType) construction.getValue().asContainerable();
        description =
            (String)
                construction.getPropertyRealValue(ConstructionType.F_DESCRIPTION, String.class);

        if (constr.getResourceRef() != null) {
          ObjectReferenceType resourceRef = constr.getResourceRef();

          PrismObject resource =
              WebModelUtils.loadObject(
                  ResourceType.class, resourceRef.getOid(), this, task, result);
          name = WebMiscUtil.getName(resource);
        }
      }

      return new AssignmentItemDto(
          AssignmentEditorDtoType.ACCOUNT_CONSTRUCTION, name, description, null);
    }

    PrismReferenceValue refValue = targetRef.getValue();
    PrismObject value = refValue.getObject();
    if (value == null) {
      // resolve reference
      value = WebModelUtils.loadObject(ObjectType.class, refValue.getOid(), this, task, result);
    }

    if (value == null) {
      // we couldn't resolve assignment details
      return new AssignmentItemDto(null, null, null, null);
    }

    String name = WebMiscUtil.getName(value);
    AssignmentEditorDtoType type = AssignmentEditorDtoType.getType(value.getCompileTimeClass());
    String relation = refValue.getRelation() != null ? refValue.getRelation().getLocalPart() : null;
    String description = null;
    if (RoleType.class.isAssignableFrom(value.getCompileTimeClass())) {
      description = (String) value.getPropertyRealValue(RoleType.F_DESCRIPTION, String.class);
    }

    return new AssignmentItemDto(type, name, description, relation);
  }
Example #5
0
  // Called from the ObjectResolver.resolve
  public ObjectType resolveRef(
      ObjectReferenceType ref, String contextDescription, OperationResult result)
      throws ObjectNotFoundException, SchemaException {

    Class<? extends ObjectType> type = ObjectType.class;
    if (ref.getType() != null) {
      ObjectTypes objectTypeType = ObjectTypes.getObjectTypeFromTypeQName(ref.getType());
      type = objectTypeType.getClassDefinition();
    }

    return repositoryService.getObject(type, ref.getOid(), null, result).asObjectable();
  }
Example #6
0
  private AccountCallableResult<List<SimpleAccountDto>> loadAccounts() throws Exception {
    LOGGER.debug("Loading accounts.");

    AccountCallableResult callableResult = new AccountCallableResult();
    List<SimpleAccountDto> list = new ArrayList<SimpleAccountDto>();
    callableResult.setValue(list);
    PrismObject<UserType> user = principalModel.getObject();
    if (user == null) {
      return callableResult;
    }

    Task task = createSimpleTask(OPERATION_LOAD_ACCOUNTS);
    OperationResult result = task.getResult();
    callableResult.setResult(result);
    Collection<SelectorOptions<GetOperationOptions>> options =
        SelectorOptions.createCollection(
            ShadowType.F_RESOURCE, GetOperationOptions.createResolve());

    List<ObjectReferenceType> references = user.asObjectable().getLinkRef();
    for (ObjectReferenceType reference : references) {
      PrismObject<ShadowType> account =
          WebModelUtils.loadObject(
              ShadowType.class, reference.getOid(), options, this, task, result);
      if (account == null) {
        continue;
      }

      ShadowType accountType = account.asObjectable();

      OperationResultType fetchResult = accountType.getFetchResult();

      if (fetchResult != null) {
        callableResult.getFetchResults().add(OperationResult.createOperationResult(fetchResult));
      }

      ResourceType resource = accountType.getResource();
      String resourceName = WebMiscUtil.getName(resource);
      list.add(
          new SimpleAccountDto(
              WebMiscUtil.getOrigStringFromPoly(accountType.getName()), resourceName));
    }
    result.recordSuccessIfUnknown();
    result.recomputeStatus();

    LOGGER.debug("Finished accounts loading.");

    return callableResult;
  }
  public ObjectPolicyConfigurationTypeDto preparePolicyConfig() {
    ObjectPolicyConfigurationTypeDto newConfig = new ObjectPolicyConfigurationTypeDto();

    newConfig.setConstraints(propertyConstraintsList);
    newConfig.setType(type);

    ObjectReferenceType ref = new ObjectReferenceType();
    if (templateRef != null) {
      ref.setOid(templateRef.getOid());
      ref.setType(ObjectTemplateType.COMPLEX_TYPE);
    }

    newConfig.setTemplateRef(ref);

    return newConfig;
  }
  public ObjectPolicyDialogDto(ObjectPolicyConfigurationTypeDto config, PageBase page) {
    this.config = config;
    type = config.getType();

    propertyConstraintsList = new ArrayList<>();

    if (config != null && config.getConstraints() != null) {
      propertyConstraintsList.addAll(config.getConstraints());
    } else {
      propertyConstraintsList.add(new PropertyConstraintTypeDto(null));
    }

    if (config.getTemplateRef() != null) {
      ObjectReferenceType ref = config.getTemplateRef();
      templateRef =
          new ObjectTemplateConfigTypeReferenceDto(
              ref.getOid(), getObjectTemplateName(ref.getOid(), page));
    }
  }
Example #9
0
  // TODO: refactor - this method is also in SchemaHandlerImpl
  private ResourceType resolveResource(ShadowType shadow, OperationResult result)
      throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
    if (shadow.getResource() != null) {
      return shadow.getResource();
    }

    ObjectReferenceType ref = shadow.getResourceRef();
    if (ref == null) {
      throw new ExpressionEvaluationException(
          "Resource shadow object " + shadow + " doesn't have defined resource.");
    }
    if (ref.getOid() == null) {
      throw new ExpressionEvaluationException(
          "Resource shadow object " + shadow + " defines null resource OID.");
    }

    return modelObjectResolver.getObjectSimple(
        ResourceType.class, ref.getOid(), null, null, result);
  }
  private List<ObjectReferenceType> createResourceList() {
    resourceMap.clear();
    OperationResult result = new OperationResult(OPERATION_LOAD_RESOURCES);
    Task task = getPageBase().createSimpleTask(OPERATION_LOAD_RESOURCES);
    List<PrismObject<ResourceType>> resources = null;
    List<ObjectReferenceType> references = new ArrayList<>();

    try {
      resources =
          getPageBase()
              .getModelService()
              .searchObjects(ResourceType.class, new ObjectQuery(), null, task, result);
      result.recomputeStatus();
    } catch (Exception e) {
      result.recordFatalError("Couldn't get resource list.", e);
      LoggingUtils.logException(LOGGER, "Couldn't get resource list.", e);
    }

    // TODO - show error somehow
    // if(!result.isSuccess()){
    //    getPageBase().showResult(result);
    // }

    if (resources != null) {
      ObjectReferenceType ref;
      for (PrismObject<ResourceType> r : resources) {
        resourceMap.put(r.getOid(), WebMiscUtil.getName(r));
        ref = new ObjectReferenceType();
        ref.setType(ResourceType.COMPLEX_TYPE);
        ref.setOid(r.getOid());
        references.add(ref);
      }
    }

    return references;
  }
Example #11
0
  public static RObjectReference jaxbRefToRepo(
      ObjectReferenceType reference,
      PrismContext prismContext,
      RObject owner,
      RReferenceOwner refOwner) {
    if (reference == null) {
      return null;
    }
    Validate.notNull(owner, "Owner of reference must not be null.");
    Validate.notNull(refOwner, "Reference owner of reference must not be null.");
    Validate.notEmpty(reference.getOid(), "Target oid reference must not be null.");

    RObjectReference repoRef = RReferenceOwner.createObjectReference(refOwner);
    repoRef.setOwner(owner);
    RObjectReference.copyFromJAXB(reference, repoRef, prismContext);

    return repoRef;
  }
 private String createResourceReadLabel(ObjectReferenceType ref) {
   return resourceMap.get(ref.getOid());
 }
Example #13
0
 private ExpressionVariables processInnerVariables(
     ExpressionVariables variables, String contextDescription, Task task, OperationResult result)
     throws SchemaException, ObjectNotFoundException {
   if (expressionType == null
       || expressionType.getVariable() == null
       || expressionType.getVariable().isEmpty()) {
     // shortcut
     return variables;
   }
   ExpressionVariables newVariables = new ExpressionVariables();
   for (Entry<QName, Object> entry : variables.entrySet()) {
     newVariables.addVariableDefinition(entry.getKey(), entry.getValue());
   }
   for (ExpressionVariableDefinitionType variableDefType : expressionType.getVariable()) {
     QName varName = variableDefType.getName();
     if (varName == null) {
       throw new SchemaException("No variable name in expression in " + contextDescription);
     }
     if (variableDefType.getObjectRef() != null) {
       ObjectReferenceType ref = variableDefType.getObjectRef();
       ref.setType(prismContext.getSchemaRegistry().qualifyTypeName(ref.getType()));
       ObjectType varObject =
           objectResolver.resolve(
               ref,
               ObjectType.class,
               null,
               "variable " + varName + " in " + contextDescription,
               task,
               result);
       newVariables.addVariableDefinition(varName, varObject);
     } else if (variableDefType.getValue() != null) {
       // Only string is supported now
       Object valueObject = variableDefType.getValue();
       if (valueObject instanceof String) {
         newVariables.addVariableDefinition(varName, valueObject);
       } else if (valueObject instanceof Element) {
         newVariables.addVariableDefinition(varName, ((Element) valueObject).getTextContent());
       } else if (valueObject instanceof RawType) {
         newVariables.addVariableDefinition(
             varName, ((RawType) valueObject).getParsedValue(null, varName));
       } else {
         throw new SchemaException(
             "Unexpected type "
                 + valueObject.getClass()
                 + " in variable definition "
                 + varName
                 + " in "
                 + contextDescription);
       }
     } else if (variableDefType.getPath() != null) {
       ItemPath itemPath = variableDefType.getPath().getItemPath();
       Object resolvedValue =
           ExpressionUtil.resolvePath(
               itemPath, variables, null, objectResolver, contextDescription, task, result);
       newVariables.addVariableDefinition(varName, resolvedValue);
     } else {
       throw new SchemaException("No value for variable " + varName + " in " + contextDescription);
     }
   }
   return newVariables;
 }