Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed Nov 18, 2021
2 parents ee89048 + e09bd71 commit 2cd1d03
Show file tree
Hide file tree
Showing 75 changed files with 1,494 additions and 931 deletions.
114 changes: 97 additions & 17 deletions dist/src/main/bin/midpoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,18 @@ BASE_DIR=$(cd "${SCRIPT_DIR}/.." && pwd -P)
: "${MIDPOINT_HOME:="${BASE_DIR}/var"}"

if [ "${1}" = "init-native" ] ; then
if [ "${MP_CHECK:-}" != "" ] ; then
touch "${MP_CHECK}"
fi
echo "Initializing native structure of the db..."
if [ "${MP_INIT_DB:-}" = "" -a "${MP_INIT_DB_CONCAT:-}" = "" ] ; then
echo "MP_INIT_DB variable with target for DB init files was not set - skipping db init file processing..."
echo "MP_INIT_DB variable with target for DB init files was not set - skipping db init file processing..." >&2
else
if [ "${MP_INIT_DB_CONCAT:-}" = "" ] ; then
if [ -e "${BASE_DIR}/doc/config/sql/native-new" ] ; then
find "${BASE_DIR}/doc/config/sql/native-new/" -type f -name "postgres-new*.sql" ! -name "postgres-new-upgrade.sql" -exec cp \{\} "${MP_INIT_DB}/" \;
else
echo "Location with sql init structure have not been found..."
echo "Location with sql init structure (source) have not been found..." >&2
exit 1
fi
else
Expand All @@ -58,7 +61,7 @@ if [ "${1}" = "init-native" ] ; then
[ -e "${BASE_DIR}/doc/config/sql/native-new/postgres-new-quartz.sql" ] && \
cat "${BASE_DIR}/doc/config/sql/native-new/postgres-new-quartz.sql" >> "${MP_INIT_DB_CONCAT}"
else
echo "Location with sql init structure have not been found..."
echo "Location with sql init structure (source) have not been found..." >&2
exit 1
fi

Expand All @@ -67,32 +70,103 @@ if [ "${1}" = "init-native" ] ; then
if [ "${MP_INIT_CFG:-}" = "" ] ; then
echo "MP_INIT_CFG variable with target for config.xml was not set - skipping config.xml file processing..."
else
if [ -e "${BASE_DIR}/doc/config/config-native.xml" ] ; then
cp "${BASE_DIR}/doc/config/config-native.xml" ${MP_INIT_CFG}/config.xml
if [ -e "${BASE_DIR}/doc/config/config-native.xml" ]; then
if [ ! -e ${MP_INIT_CFG}/config.xml ] ; then
cp "${BASE_DIR}/doc/config/config-native.xml" ${MP_INIT_CFG}/config.xml
else
echo "File already exists... Skipping"
fi
else
echo "Location with config.xml have not been found..."
echo "Source location with config.xml have not been found..." >&2
exit 1
fi
fi
if [ "${MP_DB_PW:-}" != "" ] ; then
dd if=/dev/random bs=8 count=3 |base64 | tr -d -c [:alnum:] > ${MP_DB_PW}
echo "DB Password generated..."
if [ ! -e ${MP_DB_PW} ] ; then
base64 /dev/random | tr -d -c [:alnum:] | head -c 24 2>/dev/null > ${MP_DB_PW}
echo "DB Password generated..."
else
echo "Destination file with DB Password already exists... Skipping" >&2
fi
fi
if [ "${MP_PW:-}" != "" ] ; then
dd if=/dev/random bs=8 count=3 |base64 | tr -d -c [:alnum:] > ${MP_PW}
echo "MP Password generated..."
if [ ! -e ${MP_PW} ] ; then
base64 /dev/random | tr -d -c [:alnum:] | head -c 24 2>/dev/null > ${MP_PW}
echo "MP Password generated..."
else
echo "Destination file with the generated MP Password already exists... Skipping" >&2
fi
fi
if [ "${MP_PW_DEF:-}" != "" ] ; then
echo -n "changeit" > ${MP_PW_DEF}
echo "Default MP Password stored..."
if [ ! -e ${MP_PW_DEF} ] ; then
echo -n "changeit" > ${MP_PW_DEF}
echo "Default MP Password stored..."
else
echo "Destination file with the default MP Password already exists... Skipping" >&2
fi
fi
if [ "${MP_INIT_LOOP:-}" = "" ] ; then
echo "All requested operation has been done - init files are ready on requested location..."
else
echo "All requested operation has been done - init files are ready on requested location..."
echo "Looping to keep kontainer UP"
if [ "${MP_CERT:-}" != "" ] ; then
if [ "${MP_KEYSTORE:-}" = "" ] ; then
echo "Keystore path has not been set..." >&2
exit 1
fi
keystorepw="${MP_PW:-${MP_PW_DEF:-}}"
if [ "${keystorepw}" = "" ] ; then
echo "Keystore password file path has not been set..." >&2
exit 1
fi
if [ ! -e "${MP_KEYSTORE:-}" ] ; then
keytool -genseckey -alias default -keystore "${MP_KEYSTORE}" -storetype jceks -keypass midpoint -storepass:file ${keystorepw} -keyalg AES -keysize 128 2>/dev/null
fi
echo "${MP_CERT}" > "${MP_KEYSTORE}_"
while [ -s "${MP_KEYSTORE}_" ]
do
sed -n '0,/-----END CERTIFICATE-----/p' "${MP_KEYSTORE}_" > "${MP_KEYSTORE}__"
echo "- - - - -" >&2
subject="$(keytool -printcert -file "${MP_KEYSTORE}__" 2>/dev/null | grep "Owner: " | sed "s/[^:]*: \(.*\)/\1/")"
echo "${subject}"
keytool -printcert -file "${MP_KEYSTORE}__" 2>/dev/null | \
sed -n "/Certificate fingerprints:/,/^[A-Z]/p" | \
grep -v "^[A-Z]" | \
sed "s/[[:space:]][^:]*: //" | while read line
do
touch "${MP_KEYSTORE}__.exists"
if $(keytool -list -keystore ${MP_KEYSTORE} -storetype jceks -storepass:file ${keystorepw} 2>/dev/null | grep -q " ${line}$") ; then
echo "${line} .:. Found" >&2
touch "${MP_KEYSTORE}__.found"
else
echo "${line} .:. Not Found" >&2
fi
done
if [ -e "${MP_KEYSTORE}__.exists" ] ; then
rm "${MP_KEYSTORE}__.exists"
if [ -e "${MP_KEYSTORE}__.found" ] ; then
echo "Fingerprint found in the certstore - certificate exists..." >&2
rm "${MP_KEYSTORE}__.found"
else
echo "Adding cert to certstore..." >&2
keytool -importcert -noprompt -trustcacerts -alias "${subject}" -file "${MP_KEYSTORE}__" -keystore "${MP_KEYSTORE}" -storetype jceks -storepass:file "${keystorepw}" 2>/dev/null
sleep 1
fi
rm "${MP_KEYSTORE}__"
else
echo "Certificate did not found in the file..." >&2
fi
sed -i '0,/-----END CERTIFICATE-----/d' ${MP_KEYSTORE}_
done
[ -e "${MP_KEYSTORE}_" ] && rm -f "${MP_KEYSTORE}_"
echo "- - - - -"
keytool -list -keystore ${MP_KEYSTORE} -storetype jceks -storepass:file ${keystorepw} 2>/dev/null
echo "- - - - -"
fi
echo "All requested operation has been done - init files are ready on requested location..."
if [ "${MP_INIT_LOOP:-}" != "" ] ; then
echo "Looping to keep container UP"
tail -f /dev/null
fi
if [ "${MP_CHECK:-}" != "" ] ; then
rm "${MP_CHECK}"
fi
exit 0
fi

Expand Down Expand Up @@ -356,6 +430,12 @@ fi

#############################################################

if [ "${MP_CHECK:-}" != "" ] ; then
while [ -e "${MP_CHECK}" ] ; do
sleep 1
done
fi

if [[ "$1" == "container" ]]; then
if ! which "${_RUNJAVA}" &>/dev/null; then
echo "${_RUNJAVA} not found (or not executable). Start aborted."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package com.evolveum.midpoint.gui.api.util;

import static com.evolveum.midpoint.gui.api.page.PageBase.createStringResourceStatic;
import static com.evolveum.midpoint.model.api.ModelExecuteOptions.toModelExecutionOptionsBean;

import java.io.PrintWriter;
import java.io.StringWriter;
Expand Down Expand Up @@ -677,8 +678,8 @@ public static <T extends Containerable> QName containerClassToQName(PrismContext
return prismContext.getSchemaRegistry().findComplexTypeDefinitionByCompileTimeClass(clazz).getTypeName();
}

public static TaskType createSingleRecurrenceTask(String taskName, QName applicableType, ObjectQuery query,
ObjectDelta delta, ModelExecuteOptions options, String handlerUri, PageBase pageBase) throws SchemaException {
public static TaskType createIterativeChangeExecutionTask(String taskName, QName applicableType, ObjectQuery query,
@Nullable ObjectDelta<? extends ObjectType> delta, ModelExecuteOptions options, PageBase pageBase) throws SchemaException {

TaskType task = new TaskType(pageBase.getPrismContext());

Expand All @@ -693,30 +694,30 @@ public static TaskType createSingleRecurrenceTask(String taskName, QName applica
task.setExecutionState(TaskExecutionStateType.RUNNABLE);
task.setSchedulingState(TaskSchedulingStateType.READY);
task.setThreadStopAction(ThreadStopActionType.RESTART);
task.setHandlerUri(handlerUri);

ScheduleType schedule = new ScheduleType();
schedule.setMisfireAction(MisfireActionType.EXECUTE_IMMEDIATELY);
task.setSchedule(schedule);

task.setName(WebComponentUtil.createPolyFromOrigString(taskName));

PrismObject<TaskType> prismTask = task.asPrismObject();
QueryType queryType = pageBase.getQueryConverter().createQueryType(query);
prismTask.findOrCreateProperty(SchemaConstants.PATH_MODEL_EXTENSION_OBJECT_QUERY).addRealValue(queryType);

if (applicableType != null) {
prismTask.findOrCreateProperty(SchemaConstants.PATH_MODEL_EXTENSION_OBJECT_TYPE).setRealValue(applicableType);
}

if (delta != null) {
ObjectDeltaType deltaBean = DeltaConvertor.toObjectDeltaType(delta);
prismTask.findOrCreateProperty(SchemaConstants.PATH_MODEL_EXTENSION_OBJECT_DELTA).setRealValue(deltaBean);
}
IterativeChangeExecutionWorkDefinitionType workDef =
new IterativeChangeExecutionWorkDefinitionType(PrismContext.get())
.beginObjects()
.type(applicableType)
.query(pageBase.getQueryConverter().createQueryType(query))
.<IterativeChangeExecutionWorkDefinitionType>end()
.delta(DeltaConvertor.toObjectDeltaType(delta))
.executionOptions(toModelExecutionOptionsBean(options));

// @formatter:off
task.setActivity(
new ActivityDefinitionType(PrismContext.get())
.beginWork()
.iterativeChangeExecution(workDef)
.end());
// @formatter:on

if (options != null) {
prismTask.findOrCreateContainer(SchemaConstants.PATH_MODEL_EXTENSION_EXECUTE_OPTIONS)
.setRealValue(options.toModelExecutionOptionsType());
}
return task;
}

Expand Down Expand Up @@ -3361,6 +3362,8 @@ public void onClick(AjaxRequestTarget target) {
* Extension values are task-dependent. Therefore, in the future we will probably make
* this behaviour configurable. For the time being we assume that the task template will be
* of "iterative task handler" type and so it will expect mext:objectQuery extension property.
*
* FIXME
*/

@NotNull
Expand Down Expand Up @@ -4159,6 +4162,7 @@ public static IModel<String> getIconUrlModel(IconType icon) {

}

// FIXME this uses old-style token processing
public static void deleteSyncTokenPerformed(AjaxRequestTarget target, ResourceType resourceType, PageBase pageBase) {
String resourceOid = resourceType.getOid();
String handlerUri = "http://midpoint.evolveum.com/xml/ns/public/model/synchronization/task/live-sync/handler-3";
Expand Down Expand Up @@ -4325,7 +4329,8 @@ public static boolean assignmentObjectRelationAlreadyExists(List<AssignmentObjec
return true;
}

public static void saveTask(PrismObject<TaskType> oldTask, OperationResult result, PageBase pageBase) {
// FIXME this uses old-style token processing
private static void saveTask(PrismObject<TaskType> oldTask, OperationResult result, PageBase pageBase) {
Task task = pageBase.createSimpleTask(pageBase.getClass().getName() + "." + "saveSyncTask");

PrismProperty<?> property = oldTask.findProperty(ItemPath.create(TaskType.F_EXTENSION, SchemaConstants.SYNC_TOKEN));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,19 @@
import com.evolveum.midpoint.web.application.AsyncWebProcessModel;
import com.evolveum.midpoint.web.component.SecurityContextAwareCallable;

import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import org.apache.wicket.RestartResponseException;
import org.apache.wicket.ajax.AjaxRequestTarget;

import com.evolveum.midpoint.gui.impl.page.admin.component.ProgressPanel;
import com.evolveum.midpoint.gui.impl.page.admin.component.ProgressReportingAwarePage;
import com.evolveum.midpoint.model.api.ModelExecuteOptions;
import com.evolveum.midpoint.model.api.ModelInteractionService;
import com.evolveum.midpoint.model.api.ModelPublicConstants;
import com.evolveum.midpoint.model.api.ModelService;
import com.evolveum.midpoint.model.api.context.ModelContext;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.schema.SchemaRegistry;
import com.evolveum.midpoint.schema.DeltaConvertor;
import com.evolveum.midpoint.schema.ObjectDeltaOperation;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
Expand All @@ -49,15 +48,13 @@
import com.evolveum.midpoint.web.page.login.PageLogin;
import com.evolveum.midpoint.web.security.MidPointApplication;
import com.evolveum.midpoint.web.security.util.SecurityUtils;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ModelExecuteOptionsType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.PartialProcessingTypeType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SystemObjectsType;
import com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

import static com.evolveum.midpoint.model.api.ModelExecuteOptions.toModelExecutionOptionsBean;
import static com.evolveum.midpoint.schema.util.task.work.SpecificWorkDefinitionUtil.createNonIterativeChangeExecutionDef;

public class ProgressAwareChangesExecutorImpl implements ObjectChangeExecutor {

private static final Trace LOGGER = TraceManager.getTrace(ProgressAwareChangesExecutorImpl.class);
Expand Down Expand Up @@ -205,7 +202,7 @@ public Collection<ObjectDeltaOperation<? extends ObjectType>> executeChangesInBa

try {

configureTask(deltas, options, progressAwarePage.getPrismContext().getSchemaRegistry(), task);
configureTask(deltas, options, task);

TaskManager taskManager = progressAwarePage.getTaskManager();
taskManager.switchToBackground(task, result);
Expand All @@ -220,35 +217,21 @@ public Collection<ObjectDeltaOperation<? extends ObjectType>> executeChangesInBa
return null;
}

private void configureTask(Collection<ObjectDelta<? extends ObjectType>> deltas, ModelExecuteOptions options, SchemaRegistry schemaRegistry, Task task) throws SchemaException {
private void configureTask(Collection<ObjectDelta<? extends ObjectType>> deltas, ModelExecuteOptions options, Task task)
throws SchemaException {
MidPointPrincipal user = SecurityUtils.getPrincipalUser();
if (user == null) {
throw new RestartResponseException(PageLogin.class);
} else {
task.setOwner(user.getFocus().asPrismObject());
}

List<ObjectDeltaType> deltasBeans = new ArrayList<>();
for (ObjectDelta<?> delta : deltas) {
deltasBeans.add(DeltaConvertor.toObjectDeltaType((ObjectDelta<? extends com.evolveum.prism.xml.ns._public.types_3.ObjectType>) delta));
}
PrismPropertyDefinition<ObjectDeltaType> deltasDefinition = schemaRegistry
.findPropertyDefinitionByElementName(SchemaConstants.MODEL_EXTENSION_OBJECT_DELTAS);
PrismProperty<ObjectDeltaType> deltasProperty = deltasDefinition.instantiate();
deltasProperty.setRealValues(deltasBeans.toArray(new ObjectDeltaType[0]));
task.addExtensionProperty(deltasProperty);
if (options != null) {
PrismContainerDefinition<ModelExecuteOptionsType> optionsDefinition = schemaRegistry
.findContainerDefinitionByElementName(SchemaConstants.MODEL_EXTENSION_EXECUTE_OPTIONS);
PrismContainer<ModelExecuteOptionsType> optionsContainer = optionsDefinition.instantiate();
optionsContainer.setRealValue(options.toModelExecutionOptionsType());
task.setExtensionContainer(optionsContainer);
}
task.setRootActivityDefinition(
createNonIterativeChangeExecutionDef(deltas, toModelExecutionOptionsBean(options)));

task.setChannel(SchemaConstants.CHANNEL_USER_URI);
task.setHandlerUri(ModelPublicConstants.EXECUTE_DELTAS_TASK_HANDLER_URI);
task.setName("Execute changes");
task.setInitiallyRunnable();
task.addArchetypeInformation(SystemObjectsType.ARCHETYPE_UTILITY_TASK.value());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -442,21 +442,21 @@ private List<TaskType> getTaskFor(List<PrismObject<TaskType>> tasks,
List<TaskType> syncTasks = new ArrayList<>();
for (PrismObject<TaskType> task : tasks) {
PrismProperty<ShadowKindType> taskKind = task
.findProperty(ItemPath.create(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_KIND));
.findProperty(ItemPath.create(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_KIND)); // FIXME
ShadowKindType taskKindValue = null;
if (taskKind != null) {
taskKindValue = taskKind.getRealValue();
}

PrismProperty<String> taskIntent = task
.findProperty(ItemPath.create(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_INTENT));
.findProperty(ItemPath.create(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_INTENT)); // FIXME
String taskIntentValue = null;
if (taskIntent != null) {
taskIntentValue = taskIntent.getRealValue();
}

PrismProperty<QName> taskObjectClass = task.findProperty(
ItemPath.create(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_OBJECTCLASS));
ItemPath.create(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_OBJECTCLASS)); // FIXME
QName taskObjectClassValue = null;
if (taskObjectClass != null) {
taskObjectClassValue = taskObjectClass.getRealValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public void populateItem(Item<ICellPopulator<SelectableBean<T>>> cellItem,
pKind = findPropertyInResourceSet(object.getValue(), ResourceObjectSetType.F_KIND);
if (pKind == null) {
pKind = object.getValue().asPrismObject().findProperty(
ItemPath.create(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_KIND));
ItemPath.create(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_KIND)); // FIXME
}
} else {
pKind = null;
Expand Down Expand Up @@ -336,7 +336,7 @@ public void populateItem(Item<ICellPopulator<SelectableBean<T>>> cellItem,
pIntent = findPropertyInResourceSet(object.getValue(), ResourceObjectSetType.F_INTENT);
if (pIntent == null) {
pIntent = object.getValue().asPrismObject().findProperty(
ItemPath.create(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_INTENT));
ItemPath.create(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_INTENT)); // FIXME
}
} else {
pIntent = null;
Expand All @@ -363,7 +363,7 @@ public void populateItem(Item<ICellPopulator<SelectableBean<T>>> cellItem,
pObjectClass = findPropertyInResourceSet(object.getValue(), ResourceObjectSetType.F_OBJECTCLASS);
if (pObjectClass == null) {
pObjectClass = object.getValue().asPrismObject().findProperty(
ItemPath.create(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_OBJECTCLASS));
ItemPath.create(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_OBJECTCLASS)); // FIXME
}
} else {
pObjectClass = null;
Expand Down

0 comments on commit 2cd1d03

Please sign in to comment.