use of com.evolveum.midpoint.prism.PrismReference in project midpoint by Evolveum.
the class PageResourceEdit method updateConnectorRef.
/**
* Method which attempts to resolve connector reference filter to actual connector (if necessary).
*
* @param resource {@link PrismObject} resource
*/
private void updateConnectorRef(PrismObject<ResourceType> resource, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
if (resource == null) {
return;
}
PrismReference resourceRef = resource.findReference(ResourceType.F_CONNECTOR_REF);
if (resourceRef == null || resourceRef.getValue() == null) {
return;
}
PrismReferenceValue refValue = resourceRef.getValue();
if (StringUtils.isNotEmpty(refValue.getOid())) {
return;
}
if (refValue.getFilter() == null) {
return;
}
SchemaRegistry registry = getPrismContext().getSchemaRegistry();
PrismObjectDefinition objDef = registry.findObjectDefinitionByCompileTimeClass(ConnectorType.class);
ObjectFilter filter = QueryConvertor.parseFilter(refValue.getFilter(), objDef);
List<PrismObject<ConnectorType>> connectors = getModelService().searchObjects(ConnectorType.class, ObjectQuery.createObjectQuery(filter), null, task, result);
if (connectors.size() != 1) {
return;
}
PrismObject<ConnectorType> connector = connectors.get(0);
refValue.setOid(connector.getOid());
refValue.setTargetType(ConnectorType.COMPLEX_TYPE);
refValue.setFilter(null);
}
use of com.evolveum.midpoint.prism.PrismReference in project midpoint by Evolveum.
the class PageAbstractSelfCredentials method loadPageModel.
private MyPasswordsDto loadPageModel() {
LOGGER.debug("Loading user and accounts.");
MyPasswordsDto dto = new MyPasswordsDto();
OperationResult result = new OperationResult(OPERATION_LOAD_USER_WITH_ACCOUNTS);
try {
String userOid = SecurityUtils.getPrincipalUser().getOid();
Task task = createSimpleTask(OPERATION_LOAD_USER);
OperationResult subResult = result.createSubresult(OPERATION_LOAD_USER);
user = getModelService().getObject(UserType.class, userOid, null, task, subResult);
subResult.recordSuccessIfUnknown();
dto.getAccounts().add(createDefaultPasswordAccountDto(user));
CredentialsPolicyType credentialsPolicyType = getPasswordCredentialsPolicy();
if (credentialsPolicyType != null) {
PasswordCredentialsPolicyType passwordCredentialsPolicy = credentialsPolicyType.getPassword();
if (passwordCredentialsPolicy != null) {
CredentialsPropagationUserControlType propagationUserControl = passwordCredentialsPolicy.getPropagationUserControl();
if (propagationUserControl != null) {
dto.setPropagation(propagationUserControl);
}
PasswordChangeSecurityType passwordChangeSecurity = passwordCredentialsPolicy.getPasswordChangeSecurity();
if (passwordChangeSecurity != null) {
dto.setPasswordChangeSecurity(passwordChangeSecurity);
}
}
}
if (dto.getPropagation() == null || dto.getPropagation().equals(CredentialsPropagationUserControlType.USER_CHOICE)) {
PrismReference reference = user.findReference(UserType.F_LINK_REF);
if (reference == null || reference.getValues() == null) {
LOGGER.debug("No accounts found for user {}.", new Object[] { userOid });
return dto;
}
final Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(ShadowType.F_RESOURCE, GetOperationOptions.createResolve());
List<PrismReferenceValue> values = reference.getValues();
for (PrismReferenceValue value : values) {
subResult = result.createSubresult(OPERATION_LOAD_ACCOUNT);
try {
String accountOid = value.getOid();
task = createSimpleTask(OPERATION_LOAD_ACCOUNT);
PrismObject<ShadowType> account = getModelService().getObject(ShadowType.class, accountOid, options, task, subResult);
dto.getAccounts().add(createPasswordAccountDto(account));
subResult.recordSuccessIfUnknown();
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load account", ex);
subResult.recordFatalError("Couldn't load account.", ex);
}
}
}
result.recordSuccessIfUnknown();
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load accounts", ex);
result.recordFatalError("Couldn't load accounts", ex);
} finally {
result.recomputeStatus();
}
Collections.sort(dto.getAccounts());
if (!result.isSuccess() && !result.isHandledError()) {
showResult(result);
}
return dto;
}
use of com.evolveum.midpoint.prism.PrismReference in project midpoint by Evolveum.
the class PageAbstractSelfCredentials method createPasswordAccountDto.
private PasswordAccountDto createPasswordAccountDto(PrismObject<ShadowType> account) {
PrismReference resourceRef = account.findReference(ShadowType.F_RESOURCE_REF);
String resourceName;
if (resourceRef == null || resourceRef.getValue() == null || resourceRef.getValue().getObject() == null) {
resourceName = getString("PageSelfCredentials.couldntResolve");
} else {
resourceName = WebComponentUtil.getName(resourceRef.getValue().getObject());
}
PasswordAccountDto passwordAccountDto = new PasswordAccountDto(account.getOid(), WebComponentUtil.getName(account), resourceName, WebComponentUtil.isActivationEnabled(account));
passwordAccountDto.setPasswordOutbound(getPasswordOutbound(account));
return passwordAccountDto;
}
use of com.evolveum.midpoint.prism.PrismReference in project midpoint by Evolveum.
the class AssignmentProcessor method setReferences.
private <F extends ObjectType> void setReferences(LensFocusContext<F> focusContext, QName itemName, Collection<PrismReferenceValue> targetState) throws SchemaException {
PrismObject<F> focusOld = focusContext.getObjectOld();
if (focusOld == null) {
if (targetState.isEmpty()) {
return;
}
} else {
PrismReference existingState = focusOld.findReference(itemName);
if (existingState == null || existingState.isEmpty()) {
if (targetState.isEmpty()) {
return;
}
} else {
// we don't use QNameUtil.match here, because we want to ensure we store qualified values there
// (and newValues are all qualified)
Comparator<PrismReferenceValue> comparator = (a, b) -> 2 * a.getOid().compareTo(b.getOid()) + (Objects.equals(a.getRelation(), b.getRelation()) ? 0 : 1);
if (MiscUtil.unorderedCollectionCompare(targetState, existingState.getValues(), comparator)) {
return;
}
}
}
PrismReferenceDefinition itemDef = focusContext.getObjectDefinition().findItemDefinition(itemName, PrismReferenceDefinition.class);
ReferenceDelta itemDelta = new ReferenceDelta(itemName, itemDef, focusContext.getObjectDefinition().getPrismContext());
itemDelta.setValuesToReplace(targetState);
focusContext.swallowToSecondaryDelta(itemDelta);
}
use of com.evolveum.midpoint.prism.PrismReference in project midpoint by Evolveum.
the class TestStrings method ref.
protected PrismReference ref(List<ObjectReferenceType> orts) {
PrismReference rv = new PrismReference(new QName("dummy"));
orts.forEach(ort -> rv.add(ort.asReferenceValue().clone()));
return rv;
}
Aggregations