private <O extends ObjectType> List<ShadowType> getProjections(PrismObject<O> objectRight, Task task, OperationResult result) throws ObjectNotFoundException, CommunicationException, SchemaException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException { if (!objectRight.canRepresent(FocusType.class)) { return new ArrayList<>(0); } List<ObjectReferenceType> linkRefs = ((FocusType)objectRight.asObjectable()).getLinkRef(); List<ShadowType> projections = new ArrayList<>(linkRefs.size()); for (ObjectReferenceType linkRef: linkRefs) { projections.add(getProjection(linkRef, task, result)); } return projections; }
private <O extends ObjectType> AbstractValuePolicyOriginResolver<O> createOriginResolver(PrismObject<O> object, OperationResult result) throws SchemaException { if (object == null) { return null; } if (object.canRepresent(UserType.class)) { return (AbstractValuePolicyOriginResolver<O>) new UserValuePolicyOriginResolver((PrismObject<UserType>) object, objectResolver); } if (object.canRepresent(ShadowType.class)) { return (AbstractValuePolicyOriginResolver<O>) new ShadowValuePolicyOriginResolver((PrismObject<ShadowType>) object, objectResolver); } SchemaException e = new SchemaException("Unsupport object type "+object); result.recordFatalError(e); throw e; }
@NotNull // to eliminate the need for extensive NPE avoidance public static <O extends ObjectType> List<String> determineSubTypes(PrismObject<O> object) { if (object == null) { return emptyList(); } List<String> subtypes = object.asObjectable().getSubtype(); if (!subtypes.isEmpty()) { return subtypes; } if (object.canRepresent(UserType.class)) { return (((UserType)object.asObjectable()).getEmployeeType()); } if (object.canRepresent(OrgType.class)) { return (((OrgType)object.asObjectable()).getOrgType()); } if (object.canRepresent(RoleType.class)) { // TODO why not return simply .getRoleType() [pmed] List<String> roleTypes = new ArrayList<>(1); roleTypes.add((((RoleType)object.asObjectable()).getRoleType())); return roleTypes; } if (object.canRepresent(ServiceType.class)) { return (((ServiceType)object.asObjectable()).getServiceType()); } return emptyList(); }
return null; if (object.canRepresent(ShadowType.class)) { PrismObject<ShadowType> shadow = (PrismObject<ShadowType>)object; Collection<ResourceAttribute<?>> identifiers = ShadowUtil.getPrimaryIdentifiers(shadow);
private <F extends ObjectType, T extends ObjectType> String addProvisioningObject(PrismObject<T> object, LensContext<F> context, LensElementContext<T> objectContext, ProvisioningOperationOptions options, ResourceType resource, Task task, OperationResult result) throws ObjectNotFoundException, ObjectAlreadyExistsException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException, PolicyViolationException { if (object.canRepresent(ShadowType.class)) { ShadowType shadow = (ShadowType) object.asObjectable(); String resourceOid = ShadowUtil.getResourceOid(shadow); if (resourceOid == null) { throw new IllegalArgumentException("Resource OID is null in shadow"); } } OperationProvisioningScriptsType scripts = null; if (object.canRepresent(ShadowType.class)) { scripts = prepareScripts(object, context, objectContext, ProvisioningOperationTypeType.ADD, resource, task, result); } ModelImplUtils.setRequestee(task, context); String oid = provisioning.addObject(object, scripts, options, task, result); ModelImplUtils.clearRequestee(task); return oid; }
private <T extends ObjectType> void generateIdentifiers(PrismObject<T> object, RepositoryService repository, OperationResult objectResult) { if (object.canRepresent(TaskType.class)) { TaskType task = (TaskType)object.asObjectable(); if (task.getTaskIdentifier() == null || task.getTaskIdentifier().isEmpty()) { task.setTaskIdentifier(lightweightIdentifierGenerator.generate().toString()); } } }
private <O extends ObjectType> boolean isDelegationToNonDelegableTarget(AssignmentType assignmentType, @NotNull PrismObject<O> target, EvaluationContext ctx) { AssignmentPathSegment previousSegment = ctx.assignmentPath.beforeLast(1); if (previousSegment == null || !previousSegment.isDelegation() || !target.canRepresent(AbstractRoleType.class)) { return false; } if (!Boolean.TRUE.equals(((AbstractRoleType)target.asObjectable()).isDelegable())) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("Skipping evaluation of {} because it delegates to a non-delegable target {}", FocusTypeUtil.dumpAssignment(assignmentType), target); } return true; } else { return false; } }
private <O extends AssignmentHolderType> PrismObject<ArchetypeType> determineArchetype(PrismObject<O> assignmentHolder, OperationResult result) throws SchemaException, ConfigurationException { if (assignmentHolder == null) { return null; } if (!assignmentHolder.canRepresent(AssignmentHolderType.class)) { return null; } List<ObjectReferenceType> archetypeRefs = ((AssignmentHolderType)assignmentHolder.asObjectable()).getArchetypeRef(); if (archetypeRefs == null || archetypeRefs.isEmpty()) { return null; } if (archetypeRefs.size() > 1) { throw new SchemaException("Only a single archetype for an object is supported: "+assignmentHolder); } ObjectReferenceType archetypeRef = archetypeRefs.get(0); PrismObject<ArchetypeType> archetype; try { archetype = systemObjectCache.getArchetype(archetypeRef.getOid(), result); } catch (ObjectNotFoundException e) { LOGGER.warn("Archetype {} for object {} cannot be found", archetypeRef.getOid(), assignmentHolder); return null; } return archetype; }
protected void add(PrismObject<? extends ObjectType> object, OperationResult result) throws ObjectAlreadyExistsException, SchemaException { if (object.canRepresent(TaskType.class)) { taskManager.addTask((PrismObject)object, result); } else { repositoryService.addObject(object, null, result); } }
public <T extends ObjectType, F extends ObjectType> void applyMetadataAdd(LensContext<F> context, PrismObject<T> objectToAdd, XMLGregorianCalendar now, Task task, OperationResult result) throws SchemaException { T objectType = objectToAdd.asObjectable(); MetadataType metadataType = objectType.getMetadata(); if (metadataType == null) { metadataType = new MetadataType(); objectType.setMetadata(metadataType); } transplantRequestMetadata(context, metadataType); applyCreateMetadata(context, metadataType, now, task); if (workflowManager != null) { metadataType.getCreateApproverRef().addAll(workflowManager.getApprovedBy(task, result)); metadataType.getCreateApprovalComment().addAll(workflowManager.getApproverComments(task, result)); } if (objectToAdd.canRepresent(FocusType.class)) { applyAssignmentMetadataObject((LensContext<? extends FocusType>) context, objectToAdd, now, task, result); } }
private <P extends ObjectType> void handlePersonas(ResultHandler<P> handler, String contextDescription, Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException { PrismObject<O> object = getObject(); if (!object.canRepresent(UserType.class)) { return; } for (ObjectReferenceType personaRef: ((UserType)object.asObjectable()).getPersonaRef()) { UserType persona = objectResolver.resolve(personaRef, UserType.class, SelectorOptions.createCollection(GetOperationOptions.createReadOnly()), "resolving persona in " + contextDescription, task, result); handler.handle((PrismObject<P>) persona.asPrismObject(), result); } }
@Override public boolean handle(PrismObject<ShadowType> shadow, OperationResult parentResult) { foundObjects.add(shadow); XMLGregorianCalendar endTs = clock.currentTimeXMLGregorianCalendar(); assertTrue(shadow.canRepresent(ShadowType.class)); try { checkAccountShadow(shadow, parentResult, true, startTs, endTs); } catch (SchemaException e) { throw new SystemException(e.getMessage(), e); } return true; } };
@Override public boolean handle(PrismObject<ShadowType> shadow, OperationResult parentResult) { foundObjects.add(shadow); XMLGregorianCalendar endTs = clock.currentTimeXMLGregorianCalendar(); assertTrue(shadow.canRepresent(ShadowType.class)); if (!useRepo) { try { checkAccountShadow(shadow, parentResult, fullShadow, startTs, endTs); } catch (SchemaException e) { throw new SystemException(e.getMessage(), e); } } return true; } };
protected void delete(PrismObject<? extends ObjectType> object, OperationResult result) throws ObjectNotFoundException, SchemaException { if (object.canRepresent(TaskType.class)) { taskManager.deleteTask(object.getOid(), result); } else { repositoryService.deleteObject(ObjectType.class, object.getOid(), result); // correct? } }
protected <T extends ObjectType> void repoAddObject(PrismObject<T> object, String contextDesc, OperationResult result) throws SchemaException, ObjectAlreadyExistsException, EncryptionException { if (object.canRepresent(TaskType.class)) { Assert.assertNotNull(taskManager, "Task manager is not initialized"); try {
private <O extends ObjectType> boolean matchesRoleRelation(PrismObject<O> object, ObjectReferenceType subjectRoleMembershipRef, RoleRelationObjectSpecificationType specRoleRelation, String autzHumanReadableDesc, String desc) throws SchemaException { if (!prismContext.relationMatches(specRoleRelation.getSubjectRelation(), subjectRoleMembershipRef.getRelation())) { return false; } if (BooleanUtils.isTrue(specRoleRelation.isIncludeReferenceRole()) && subjectRoleMembershipRef.getOid().equals(object.getOid())) { return true; } if (!BooleanUtils.isFalse(specRoleRelation.isIncludeMembers())) { if (!object.canRepresent(FocusType.class)) { return false; } for (ObjectReferenceType objectRoleMembershipRef: ((FocusType)object.asObjectable()).getRoleMembershipRef()) { if (!subjectRoleMembershipRef.getOid().equals(objectRoleMembershipRef.getOid())) { continue; } if (!prismContext.relationMatches(specRoleRelation.getObjectRelation(), objectRoleMembershipRef.getRelation())) { continue; } return true; } } return false; }
public static <O extends ObjectType> void addDefaultExpressionVariables(ExpressionVariables variables, PrismObject<? extends ObjectType> focus, PrismObject<? extends ShadowType> shadow, ResourceShadowDiscriminator discr, PrismObject<ResourceType> resource, PrismObject<SystemConfigurationType> configuration, LensElementContext<O> affectedElementContext) { // Legacy. And convenience/understandability. if (focus == null || focus.canRepresent(UserType.class) || (discr != null && discr.getKind() == ShadowKindType.ACCOUNT)) { variables.addVariableDefinition(ExpressionConstants.VAR_USER, focus); variables.addVariableDefinition(ExpressionConstants.VAR_ACCOUNT, shadow); } variables.addVariableDefinition(ExpressionConstants.VAR_FOCUS, focus); variables.addVariableDefinition(ExpressionConstants.VAR_SHADOW, shadow); variables.addVariableDefinition(ExpressionConstants.VAR_PROJECTION, shadow); variables.addVariableDefinition(ExpressionConstants.VAR_RESOURCE, resource); variables.addVariableDefinition(ExpressionConstants.VAR_CONFIGURATION, configuration); if (affectedElementContext != null) { variables.addVariableDefinition(ExpressionConstants.VAR_OPERATION, affectedElementContext.getOperation().getValue()); // We do not want to add delta to all expressions. The delta may be tricky. Is it focus delta? projection delta? Primary? Secondary? // It is better to leave delta to be accessed from the model context. And in cases when it is clear which delta is meant // (e.g. provisioning scripts) we can still add the delta explicitly. } }
if (objectNew.canRepresent(OrgType.class) && BooleanUtils.isTrue(((OrgType)objectNew.asObjectable()).isTenant())) {
@Override public <F extends FocusType, O extends ObjectType> PrismObject<F> resolveOwner(PrismObject<O> object) { if (object == null || object.getOid() == null) { return null; } PrismObject<F> owner = null; if (object.canRepresent(ShadowType.class)) { owner = repositoryService.searchShadowOwner(object.getOid(), null, new OperationResult(MidPointPrincipalManagerMock.class+".resolveOwner")); } else if (object.canRepresent(AbstractRoleType.class)) { ObjectReferenceType ownerRef = ((AbstractRoleType)(object.asObjectable())).getOwnerRef(); if (ownerRef != null && ownerRef.getOid() != null && ownerRef.getType() != null) { OperationResult result = new OperationResult(MidPointPrincipalManager.class.getName() + ".resolveOwner"); try { owner = (PrismObject<F>) repositoryService.getObject(ObjectTypes.getObjectTypeFromTypeQName(ownerRef.getType()).getClassDefinition(), ownerRef.getOid(), null, result); } catch (ObjectNotFoundException | SchemaException e) { LOGGER.warn("Cannot resolve owner of {}: {}", object, e.getMessage(), e); } } } if (owner == null) { return null; } return owner; }
@Override public boolean handle(PrismObject<ShadowType> object, OperationResult parentResult) { foundObjects.add(object); display("Found", object); XMLGregorianCalendar endTs = clock.currentTimeXMLGregorianCalendar(); assertTrue(object.canRepresent(ShadowType.class)); try { checkAccountShadow(object, parentResult, true, startTs, endTs); } catch (SchemaException e) { throw new SystemException(e.getMessage(), e); } assertCachingMetadata(object, false, startTs, endTs); if (object.asObjectable().getName().getOrig().equals("meathook")) { meathookAccountOid = object.getOid(); seenMeathookHolder.setValue(true); try { Integer loot = ShadowUtil.getAttributeValue(object, dummyResourceCtl.getAttributeQName(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOOT_NAME)); assertEquals("Wrong meathook's loot", 666, (int) loot); } catch (SchemaException e) { throw new SystemException(e.getMessage(), e); } } return true; } };