Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed Feb 28, 2019
2 parents a44164a + a330353 commit 7e885c1
Show file tree
Hide file tree
Showing 24 changed files with 544 additions and 101 deletions.
2 changes: 1 addition & 1 deletion config/initial-objects/070-task-validity.xml
Expand Up @@ -23,7 +23,7 @@
<executionStatus>runnable</executionStatus>

<category>System</category>
<handlerUri>http://midpoint.evolveum.com/xml/ns/public/model/synchronization/task/focus-validation-scanner/handler-3</handlerUri>
<handlerUri>http://midpoint.evolveum.com/xml/ns/public/model/focus-validity-scanner/handler-3</handlerUri>
<recurrence>recurring</recurrence>
<binding>loose</binding>
<schedule>
Expand Down
Expand Up @@ -244,7 +244,7 @@ public boolean isOrderingDisabled() {
}
// TODO: Default list view setting should never be needed. Always check setting for specific object type (and archetype).
CompiledObjectCollectionView def = WebComponentUtil.getDefaultGuiObjectListType((PageBase) component.getPage());
return def != null && def.isDisableSorting();
return def != null && def.isDisableSorting() != null && def.isDisableSorting();
}

protected ObjectPaging createPaging(long offset, long pageSize) {
Expand Down
Expand Up @@ -88,7 +88,7 @@ public <C extends Containerable> ContainerWrapper createContainerWrapper( Object

result = new OperationResult(CREATE_PROPERTIES);

ContainerWrapper<C> cWrapper = new ContainerWrapper(objectWrapper, container, objectWrapper.getStatus(), status, path);
ContainerWrapper<C> cWrapper = new ContainerWrapper(objectWrapper, container, objectWrapper != null ? objectWrapper.getStatus() : status, status, path);

List<ContainerValueWrapper<C>> containerValues = createContainerValues(cWrapper, path, task);
cWrapper.setProperties(containerValues);
Expand Down
Expand Up @@ -26,6 +26,7 @@
import com.evolveum.midpoint.model.api.context.ModelContext;
import com.evolveum.midpoint.model.api.util.ModelContextUtil;
import com.evolveum.midpoint.model.api.visualizer.Scene;
import com.evolveum.midpoint.prism.Item;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.PrismProperty;
import com.evolveum.midpoint.prism.path.ItemPath;
Expand Down Expand Up @@ -945,8 +946,12 @@ public OperationResult getTaskOperationResult() {
return taskOperationResult;
}

public PrismProperty getExtensionProperty(QName propertyName) {
return taskType.asPrismObject().findProperty(ItemPath.create(TaskType.F_EXTENSION, propertyName));
public Item getExtensionItem(QName itemName) {
return taskType.asPrismObject().findItem(ItemPath.create(TaskType.F_EXTENSION, itemName));
}

public PrismProperty getExtensionProperty(QName itemName) {
return taskType.asPrismObject().findProperty(ItemPath.create(TaskType.F_EXTENSION, itemName));
}

public <T> T getExtensionPropertyRealValue(QName propertyName, Class<T> clazz) {
Expand Down Expand Up @@ -1205,7 +1210,8 @@ public boolean isShadowIntegrityCheck() {
}

public boolean isFocusValidityScanner() {
return getHandlerUriList().contains(ModelPublicConstants.FOCUS_VALIDITY_SCANNER_TASK_HANDLER_URI);
return getHandlerUriList().contains(ModelPublicConstants.FOCUS_VALIDITY_SCANNER_TASK_HANDLER_URI)
|| getHandlerUriList().contains(ModelPublicConstants.DEPRECATED_FOCUS_VALIDITY_SCANNER_TASK_HANDLER_URI);
}

public boolean isJdbcPing() {
Expand Down
Expand Up @@ -29,7 +29,7 @@
import java.util.Collections;

import static com.evolveum.midpoint.schema.constants.SchemaConstants.*;
import static com.evolveum.midpoint.web.page.admin.server.handlers.dto.GenericHandlerDto.item;
import static com.evolveum.midpoint.web.page.admin.server.handlers.dto.GenericHandlerDto.extensionItem;

/**
* @author mederly
Expand Down Expand Up @@ -58,30 +58,30 @@ public HandlerDto createDtoForTask(TaskDto taskDto, PageBase pageBase, Task opTa
return new ExecuteChangesHandlerDto(taskDto);
} else if (taskDto.isShadowIntegrityCheck()) {
return new GenericHandlerDto(taskDto, Arrays.asList(
item(MODEL_EXTENSION_OBJECT_QUERY, QueryType.class),
item(MODEL_EXTENSION_DIAGNOSE, String.class),
item(MODEL_EXTENSION_FIX, String.class),
item(MODEL_EXTENSION_DRY_RUN, Boolean.class),
item(MODEL_EXTENSION_DUPLICATE_SHADOWS_RESOLVER, String.class),
item(MODEL_EXTENSION_CHECK_DUPLICATES_ON_PRIMARY_IDENTIFIERS_ONLY, Boolean.class)), pageBase);
extensionItem(MODEL_EXTENSION_OBJECT_QUERY, QueryType.class),
extensionItem(MODEL_EXTENSION_DIAGNOSE, String.class),
extensionItem(MODEL_EXTENSION_FIX, String.class),
extensionItem(MODEL_EXTENSION_DRY_RUN, Boolean.class),
extensionItem(MODEL_EXTENSION_DUPLICATE_SHADOWS_RESOLVER, String.class),
extensionItem(MODEL_EXTENSION_CHECK_DUPLICATES_ON_PRIMARY_IDENTIFIERS_ONLY, Boolean.class)), pageBase);
} else if (taskDto.isCleanup()) {
return new GenericHandlerDto(taskDto, Collections.singletonList(
item(MODEL_EXTENSION_CLEANUP_POLICIES, CleanupPoliciesType.class)), pageBase);
extensionItem(MODEL_EXTENSION_CLEANUP_POLICIES, CleanupPoliciesType.class)), pageBase);
} else if (taskDto.isNoOp()) {
return new GenericHandlerDto(taskDto, Arrays.asList(
item(SchemaConstants.NOOP_STEPS_QNAME, Integer.class),
item(SchemaConstants.NOOP_DELAY_QNAME, Integer.class)), pageBase);
extensionItem(SchemaConstants.NOOP_STEPS_QNAME, Integer.class),
extensionItem(SchemaConstants.NOOP_DELAY_QNAME, Integer.class)), pageBase);
} else if (taskDto.isReportCreate()) {
return new ReportCreateHandlerDto(taskDto);
} else if (taskDto.isJdbcPing()) {
return new GenericHandlerDto(taskDto, Arrays.asList(
item(SchemaConstants.JDBC_PING_TESTS_QNAME, Integer.class),
item(SchemaConstants.JDBC_PING_INTERVAL_QNAME, Integer.class),
item(SchemaConstants.JDBC_PING_TEST_QUERY_QNAME, String.class),
item(SchemaConstants.JDBC_PING_JDBC_URL_QNAME, String.class),
item(SchemaConstants.JDBC_PING_JDBC_USERNAME_QNAME, String.class),
extensionItem(SchemaConstants.JDBC_PING_TESTS_QNAME, Integer.class),
extensionItem(SchemaConstants.JDBC_PING_INTERVAL_QNAME, Integer.class),
extensionItem(SchemaConstants.JDBC_PING_TEST_QUERY_QNAME, String.class),
extensionItem(SchemaConstants.JDBC_PING_JDBC_URL_QNAME, String.class),
extensionItem(SchemaConstants.JDBC_PING_JDBC_USERNAME_QNAME, String.class),
//item(SchemaConstants.JDBC_PING_JDBC_PASSWORD_QNAME, String.class),
item(SchemaConstants.JDBC_PING_LOG_ON_INFO_LEVEL_QNAME, Boolean.class)
extensionItem(SchemaConstants.JDBC_PING_LOG_ON_INFO_LEVEL_QNAME, Boolean.class)
), pageBase);
} else {
return new HandlerDto(taskDto);
Expand Down
Expand Up @@ -23,78 +23,74 @@
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SystemException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.prism.*;
import com.evolveum.midpoint.web.page.admin.server.dto.TaskDto;
import org.jetbrains.annotations.NotNull;

import javax.xml.namespace.QName;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
* @author mederly
*/
public class GenericHandlerDto extends HandlerDto {

private static final Trace LOGGER = TraceManager.getTrace(GenericHandlerDto.class);

public static final String F_CONTAINER = "container";

public static class Item implements Serializable {
@NotNull private QName name;
@NotNull private Class<?> type;
public static class ExtensionItem implements Serializable {
@NotNull private final QName name;
@NotNull private final Class<?> type;

public Item(@NotNull QName name, @NotNull Class<?> type) {
public ExtensionItem(@NotNull QName name, @NotNull Class<?> type) {
this.name = name;
this.type = type;
}
}

public static Item item(QName name, Class<?> type) {
return new Item(name, type);
public static ExtensionItem extensionItem(QName name, Class<?> type) {
return new ExtensionItem(name, type);
}

@NotNull private List<Item> items;
private final List<ItemWrapper> propertyWrappers = new ArrayList<>();
private final ContainerWrapper containerWrapper;

public GenericHandlerDto(TaskDto taskDto, @NotNull List<Item> items, PageBase pageBase) {
public GenericHandlerDto(TaskDto taskDto, @NotNull List<ExtensionItem> extensionItems, PageBase pageBase) {
super(taskDto);
this.items = items;
for (Item item : items) {
PrismProperty<?> property = taskDto.getExtensionProperty(item.name);
if (property != null) {
PropertyWrapper propertyWrapper = new PropertyWrapper<>(null, property, true, ValueStatus.NOT_CHANGED, pageBase.getPrismContext());
propertyWrappers.add(propertyWrapper);
} else {
// TODO create empty property?
}
}
PrismContext prismContext = pageBase.getPrismContext();
ContainerWrapperFactory cwf = new ContainerWrapperFactory(pageBase);

final PrismContext prismContext = pageBase.getPrismContext();
PrismContainer container = prismContext.itemFactory().createContainer(new QName("test"));
ComplexTypeDefinition ctd = prismContext.definitionFactory().createComplexTypeDefinition(new QName("Test"));
int displayOrder = 1;
for (Item item : items) {
PrismProperty<?> property = taskDto.getExtensionProperty(item.name);
MutablePrismPropertyDefinition<?> clonedDefinition = null;
if (property != null) {
for (ExtensionItem extensionItem : extensionItems) {
Item<?,?> item = taskDto.getExtensionItem(extensionItem.name);
MutableItemDefinition<?> clonedDefinition = null;
if (item != null) {
try {
PrismProperty<?> clonedProperty = property.clone();
container.add(clonedProperty);
if (clonedProperty.getDefinition() != null) {
clonedDefinition = clonedProperty.getDefinition().clone().toMutable();
clonedProperty.setDefinition((PrismPropertyDefinition) clonedDefinition);
Item<?,?> clonedItem = item.clone();
//noinspection unchecked
container.add(clonedItem);
if (clonedItem.getDefinition() != null) {
clonedDefinition = clonedItem.getDefinition().clone().toMutable();
//noinspection unchecked
((Item) clonedItem).setDefinition(clonedDefinition);
}
} catch (SchemaException e) {
throw new SystemException(e);
}
}
if (clonedDefinition == null) {
clonedDefinition = CloneUtil.clone(prismContext.getSchemaRegistry().findPropertyDefinitionByElementName(item.name)).toMutable();
ItemDefinition definition = prismContext.getSchemaRegistry().findItemDefinitionByElementName(extensionItem.name);
if (definition != null) {
clonedDefinition = CloneUtil.clone(definition).toMutable();
}
}
if (clonedDefinition == null) {
System.out.println("Definition-less property " + item.name); // TODO
LOGGER.warn("Extension item without definition: {} of {}", extensionItem.name, extensionItem.type);
} else {
clonedDefinition.setCanAdd(false);
clonedDefinition.setCanModify(false);
Expand All @@ -104,8 +100,10 @@ public GenericHandlerDto(TaskDto taskDto, @NotNull List<Item> items, PageBase pa
displayOrder++;
}
MutablePrismContainerDefinition<?> containerDefinition = prismContext.definitionFactory().createContainerDefinition(new QName("Handler data"), ctd);
//noinspection unchecked
container.setDefinition(containerDefinition);
Task task = pageBase.createSimpleTask("Adding new container wrapper");
//noinspection unchecked
containerWrapper = cwf.createContainerWrapper(null, container, ContainerStatus.MODIFYING, ItemPath.EMPTY_PATH, true, task);
}

Expand Down
Expand Up @@ -23,7 +23,7 @@
<executionStatus>runnable</executionStatus>

<category>System</category>
<handlerUri>http://midpoint.evolveum.com/xml/ns/public/model/synchronization/task/focus-validation-scanner/handler-3</handlerUri>
<handlerUri>http://midpoint.evolveum.com/xml/ns/public/model/focus-validity-scanner/handler-3</handlerUri>
<recurrence>recurring</recurrence>
<binding>loose</binding>
<schedule>
Expand Down
Expand Up @@ -200,7 +200,7 @@ private static void checkEncrypted(PrismPropertyValue<?> pval) {
@SuppressWarnings("unchecked")
PrismPropertyValue<ProtectedStringType> psPval = (PrismPropertyValue<ProtectedStringType>)pval;
ProtectedStringType ps = psPval.getValue();
if (ps.getClearValue() != null) {
if (ps != null && ps.getClearValue() != null) {
throw new IllegalStateException("Unencrypted value in field " + propName);
}
} else if (itemDef.getTypeName().equals(MailConfigurationType.COMPLEX_TYPE)) {
Expand Down
Expand Up @@ -113,6 +113,21 @@ public static <F extends FocusType> void assertNotAssigned(PrismObject<F> user,
}
}
}

public static <F extends FocusType> void assertNotAssigned(PrismObject<F> user, String targetOid, QName refType, QName relation) {
F userType = user.asObjectable();
for (AssignmentType assignmentType: userType.getAssignment()) {
ObjectReferenceType targetRef = assignmentType.getTargetRef();
if (targetRef != null) {
if (QNameUtil.match(refType, targetRef.getType())) {
if (targetOid.equals(targetRef.getOid()) &&
getPrismContext().relationMatches(targetRef.getRelation(), relation)) {
AssertJUnit.fail(user + " does have assigned "+refType.getLocalPart()+" "+targetOid+", relation "+relation+"while not expecting it");
}
}
}
}
}

public static <F extends AssignmentHolderType> void assertAssignments(PrismObject<F> user, int expectedNumber) {
F userType = user.asObjectable();
Expand Down
Expand Up @@ -102,9 +102,9 @@ public Response getSchema(@PathParam("name") String name) {
.entity("Name not defined").build();
}

if (!name.toLowerCase().endsWith("\\.xsd")) {
if (!name.toLowerCase().endsWith(".xsd") && name.length() > 4) {
return Response.status(Response.Status.BAD_REQUEST).type(MediaType.TEXT_PLAIN_TYPE)
.entity("Name must be and xsd schema (.xsd extension expected)").build();
.entity("Name must be an xsd schema (.xsd extension expected)").build();
}

SchemaRegistry registry = prismContext.getSchemaRegistry();
Expand Down
Expand Up @@ -25,7 +25,10 @@
import com.evolveum.midpoint.prism.PrismObjectValue;
import com.evolveum.midpoint.prism.PrismValue;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.schema.constants.RelationTypes;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.exception.CommonException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.logging.Trace;
Expand All @@ -37,7 +40,12 @@
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.xml.namespace.QName;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
*
Expand Down Expand Up @@ -129,8 +137,55 @@ public PipelineData execute(ActionExpressionType expression, PipelineData input,
return input; // TODO updated objects?
}

private ObjectDelta<? extends ObjectType> createDelta(ObjectType object, Collection<ObjectReferenceType> resources, Collection<ObjectReferenceType> roles, Collection<String> relations) throws ScriptExecutionException {
// TODO implement delta creation
return null;
private ObjectDelta<? extends ObjectType> createDelta(AssignmentHolderType object, Collection<ObjectReferenceType> resources, Collection<ObjectReferenceType> roles, Collection<String> relations) throws ScriptExecutionException {
if (relations == null || relations.isEmpty()) {
QName defaultRelation = prismContext.getDefaultRelation() != null ?
prismContext.getDefaultRelation() : RelationTypes.MEMBER.getRelation();
relations = Collections.singletonList(QNameUtil.qNameToUri(defaultRelation));
}
List<AssignmentType> assignmentsForDelete = new ArrayList<>();

List<AssignmentType> oldAssignments = object.getAssignment();
for (AssignmentType oldAssignment : oldAssignments) {
ObjectReferenceType targetRef = oldAssignment.getTargetRef();
if (targetRef != null) {
if (roles != null) {
outerloop:
for (ObjectReferenceType roleRef : roles) {
if (targetRef.getOid() != null && targetRef.getOid().equals(roleRef.getOid())) {
for (String relationQuery : relations) {
if (prismContext.relationMatches(QNameUtil.uriToQName(relationQuery, true), targetRef.getRelation())) {
assignmentsForDelete.add(oldAssignment.clone());
break outerloop;
}
}
}
}
}
} else if (oldAssignment.getConstruction() != null) {
if (resources != null) {
for (ObjectReferenceType resourceRef : resources) {
if (oldAssignment.getConstruction().getResourceRef() != null &&
oldAssignment.getConstruction().getResourceRef().getOid() != null &&
oldAssignment.getConstruction().getResourceRef().getOid().equals(resourceRef.getOid())) {
assignmentsForDelete.add(oldAssignment.clone());
break;
}
}
}
}
}

ObjectDelta<? extends ObjectType> delta;

try {
delta = prismContext.deltaFor(object.getClass())
.item(ItemPath.create(AssignmentHolderType.F_ASSIGNMENT))
.deleteRealValues(assignmentsForDelete)
.asObjectDelta(object.getOid());
} catch (SchemaException e) {
throw new ScriptExecutionException("Couldn't prepare modification to delete resource/role assignments", e);
}
return delta;
}
}
Expand Up @@ -322,6 +322,9 @@ public class AbstractConfiguredModelIntegrationTest extends AbstractModelIntegra
protected static final String USER_GUYBRUSH_GIVEN_NAME = "Guybrush";
protected static final String USER_GUYBRUSH_FAMILY_NAME = "Threepwood";
protected static final String USER_GUYBRUSH_LOCALITY = "Melee Island";

public static final File USER_WILL_FILE = new File(COMMON_DIR, "user-will.xml");
public static final String USER_WILL_OID = "c0c010c0-d34d-b33f-f00d-111111145118";

// Largo does not have a full name set, employeeType=PIRATE
protected static final File USER_LARGO_FILE = new File(COMMON_DIR, "user-largo.xml");
Expand Down
Expand Up @@ -82,6 +82,7 @@ public class AbstractInitializedModelIntegrationTest extends AbstractConfiguredM
protected UserType userTypeBarbossa;
protected UserType userTypeGuybrush;
protected UserType userTypeElaine;
protected UserType userTypeWill;

protected DummyResourceContoller dummyResourceCtl;

Expand Down Expand Up @@ -230,6 +231,7 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
userTypeBarbossa = repoAddObjectFromFile(USER_BARBOSSA_FILE, UserType.class, initResult).asObjectable();
userTypeGuybrush = repoAddObjectFromFile(USER_GUYBRUSH_FILE, UserType.class, initResult).asObjectable();
userTypeElaine = repoAddObjectFromFile(USER_ELAINE_FILE, UserType.class, initResult).asObjectable();
userTypeWill = repoAddObjectFromFile(USER_WILL_FILE, UserType.class, true, initResult).asObjectable();

// Roles
repoAddObjectFromFile(ROLE_PIRATE_FILE, initResult);
Expand Down

0 comments on commit 7e885c1

Please sign in to comment.