protected void setDefaultUserTemplate(String userTemplateOid) throws ObjectNotFoundException, SchemaException, ObjectAlreadyExistsException { PrismObjectDefinition<SystemConfigurationType> objectDefinition = prismContext .getSchemaRegistry() .findObjectDefinitionByCompileTimeClass(SystemConfigurationType.class); Collection<? extends ItemDelta> modifications; if (userTemplateOid == null) { modifications = ReferenceDelta.createModificationReplaceCollection( SystemConfigurationType.F_DEFAULT_USER_TEMPLATE_REF, objectDefinition, null); } else { PrismReferenceValue userTemplateRefVal = new PrismReferenceValue(userTemplateOid); modifications = ReferenceDelta.createModificationReplaceCollection( SystemConfigurationType.F_DEFAULT_USER_TEMPLATE_REF, objectDefinition, userTemplateRefVal); } OperationResult result = new OperationResult("Aplying default user template"); repositoryService.modifyObject( SystemConfigurationType.class, SystemObjectsType.SYSTEM_CONFIGURATION.value(), modifications, result); display("Aplying default user template result", result); result.computeStatus(); TestUtil.assertSuccess("Aplying default user template failed (result)", result); }
private void ownerChangePerformed(AjaxRequestTarget target, UserType user) { AccountOwnerChangeDto dto = ownerChangeModel.getObject(); OperationResult result = new OperationResult(OPERATION_CHANGE_OWNER); try { Task task = createSimpleTask(OPERATION_CHANGE_OWNER); if (StringUtils.isNotEmpty(dto.getOldOwnerOid())) { ObjectDelta delta = new ObjectDelta(UserType.class, ChangeType.MODIFY, getPrismContext()); delta.setOid(dto.getOldOwnerOid()); PrismReferenceValue refValue = new PrismReferenceValue(dto.getAccountOid()); refValue.setTargetType(dto.getAccountType()); delta.addModification( ReferenceDelta.createModificationDelete( UserType.class, UserType.F_LINK_REF, getPrismContext(), refValue)); getModelService() .executeChanges(WebMiscUtil.createDeltaCollection(delta), null, task, result); } if (user != null) { ObjectDelta delta = new ObjectDelta(UserType.class, ChangeType.MODIFY, getPrismContext()); delta.setOid(user.getOid()); PrismReferenceValue refValue = new PrismReferenceValue(dto.getAccountOid()); refValue.setTargetType(dto.getAccountType()); delta.addModification( ReferenceDelta.createModificationAdd( UserType.class, UserType.F_LINK_REF, getPrismContext(), refValue)); getModelService() .executeChanges(WebMiscUtil.createDeltaCollection(delta), null, task, result); } result.recomputeStatus(); } catch (Exception ex) { result.recordFatalError("Couldn't submit user.", ex); LoggingUtils.logException(LOGGER, "Couldn't submit user", ex); } showResult(result); target.add(getFeedbackPanel()); }
private ValuePolicyType determineValuePolicy( ObjectDelta<UserType> userDelta, Task task, OperationResult result) throws SchemaException { ReferenceDelta orgDelta = userDelta.findReferenceModification(UserType.F_PARENT_ORG_REF); ValuePolicyType passwordPolicy = null; LOGGER.trace("Determining password policy from org delta."); if (orgDelta != null) { PrismReferenceValue orgRefValue = orgDelta.getAnyValue(); try { PrismObject<OrgType> org = resolver.resolve(orgRefValue, "resolving parent org ref", null, null, result); OrgType orgType = org.asObjectable(); ObjectReferenceType ref = orgType.getPasswordPolicyRef(); if (ref != null) { LOGGER.trace("Org {} has specified password policy.", orgType); passwordPolicy = resolver.resolve( ref, ValuePolicyType.class, null, "resolving password policy for organization", task, result); LOGGER.trace("Resolved password policy {}", passwordPolicy); } if (passwordPolicy == null) { passwordPolicy = determineValuePolicy(org, task, result); } } catch (ObjectNotFoundException e) { throw new IllegalStateException(e); } } return passwordPolicy; }
public ObjectDelta getObjectDelta() throws SchemaException { if (ContainerStatus.ADDING.equals(getStatus())) { return createAddingObjectDelta(); } ObjectDelta delta = new ObjectDelta(object.getCompileTimeClass(), ChangeType.MODIFY, object.getPrismContext()); delta.setOid(object.getOid()); List<ContainerWrapper> containers = getContainers(); // sort containers by path size Collections.sort(containers, new PathSizeComparator()); for (ContainerWrapper containerWrapper : getContainers()) { // create ContainerDelta for association container // HACK HACK HACK create correct procession for association container data // according to its structure if (containerWrapper.getItemDefinition().getName().equals(ShadowType.F_ASSOCIATION)) { ContainerDelta<ShadowAssociationType> associationDelta = ContainerDelta.createDelta( ShadowType.F_ASSOCIATION, containerWrapper.getItemDefinition()); List<AssociationWrapper> associationItemWrappers = (List<AssociationWrapper>) containerWrapper.getItems(); for (AssociationWrapper associationItemWrapper : associationItemWrappers) { List<ValueWrapper> assocValueWrappers = associationItemWrapper.getValues(); for (ValueWrapper assocValueWrapper : assocValueWrappers) { PrismContainerValue<ShadowAssociationType> assocValue = (PrismContainerValue<ShadowAssociationType>) assocValueWrapper.getValue(); if (assocValueWrapper.getStatus() == ValueStatus.DELETED) { associationDelta.addValueToDelete(assocValue.clone()); } else if (assocValueWrapper.getStatus().equals(ValueStatus.ADDED)) { associationDelta.addValueToAdd(assocValue.clone()); } } } delta.addModification(associationDelta); } else { if (!containerWrapper.hasChanged()) { continue; } for (ItemWrapper itemWrapper : (List<ItemWrapper>) containerWrapper.getItems()) { if (!itemWrapper.hasChanged()) { continue; } ItemPath containerPath = containerWrapper.getPath() != null ? containerWrapper.getPath() : new ItemPath(); if (itemWrapper instanceof PropertyWrapper) { ItemDelta pDelta = computePropertyDeltas((PropertyWrapper) itemWrapper, containerPath); if (!pDelta.isEmpty()) { delta.addModification(pDelta); } } if (itemWrapper instanceof ReferenceWrapper) { ReferenceDelta pDelta = computeReferenceDeltas((ReferenceWrapper) itemWrapper, containerPath); if (!pDelta.isEmpty()) { delta.addModification(pDelta); } } } } } // returning container to previous order Collections.sort(containers, new ItemWrapperComparator()); // Make sure we have all the definitions if (object.getPrismContext() != null) { object.getPrismContext().adopt(delta); } return delta; }