Skip to content

Commit

Permalink
Merge branch 'master' into temp/MID-9212
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Oct 12, 2023
2 parents df9d866 + 8d60d30 commit 6cc5734
Show file tree
Hide file tree
Showing 16 changed files with 113 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public static List<QName> createSearchableTypeList() {
supportedObjectTypeList.add(AccessCertificationWorkItemType.COMPLEX_TYPE);
supportedObjectTypeList.add(OperationExecutionType.COMPLEX_TYPE);
supportedObjectTypeList.add(SimulationResultProcessedObjectType.COMPLEX_TYPE);
supportedObjectTypeList.add(ObjectReferenceType.COMPLEX_TYPE);
return supportedObjectTypeList;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ private void createShowSimulationResultButton(RepeatingView repeatingView) {

@Override
public void onClick(AjaxRequestTarget target) {
showSimulationResultPerformed();
showSimulationResultPerformed(target);
}
};
download.add(new VisibleBehaviour(this::isSimulationResultAvailable));
Expand All @@ -332,11 +332,23 @@ private ObjectReferenceType getSimulationResultReference() {
}

ActivitySimulationStateType simulation = activityState.getActivity().getSimulation();
return simulation != null ? simulation.getResultRef() : null;
if (simulation == null || simulation.getResultRef() == null) {
return null;
}

ObjectReferenceType ref = simulation.getResultRef();
// this extra check is there because model object (task) can contain empty reference because of
// prism wrappers preparing it for editing (a lot of empty prism items with null values).
return ref.getOid() != null ? ref : null;
}

private void showSimulationResultPerformed() {
private void showSimulationResultPerformed(AjaxRequestTarget target) {
ObjectReferenceType resultRef = getSimulationResultReference();
if (resultRef == null) {
getPageBase().warn(getString("TaskOperationalButtonsPanel.noResultAvailable"));
target.add(getPageBase().getFeedbackPanel());
return;
}

PageParameters params = new PageParameters();
params.set(SimulationPage.PAGE_PARAMETER_RESULT_OID, resultRef.getOid());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.io.Serial;

import com.evolveum.midpoint.gui.api.component.result.Toast;
import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.web.page.error.PageError;

import org.apache.wicket.RestartResponseException;
Expand Down Expand Up @@ -128,8 +129,13 @@ private void generateAndSendNonce(AjaxRequestTarget target) {

private void validateUserNotNullOrFail(UserType user) {
if (user == null) {
LOGGER.error("Couldn't find principal user, you probably use wrong configuration. "
+ "Please confirm order of authentication modules "
+ "and add module for identification of user before 'mailNonce' module, "
+ "for example 'focusIdentification' module.",
new IllegalArgumentException("principal user is null"));
getSession().error(getString("pageForgetPassword.message.user.not.found"));
throw new RestartResponseException(PageError.class);
throw new RestartResponseException(PageBase.class);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import javax.xml.namespace.QName;

import com.evolveum.midpoint.gui.impl.util.DetailsPageUtil;
import com.evolveum.midpoint.prism.Containerable;
import com.evolveum.midpoint.schema.query.TypedQuery;

import org.apache.commons.io.IOUtils;
Expand Down Expand Up @@ -122,7 +123,8 @@ public class QueryPlaygroundPanel extends BasePanel<RepoQueryDto> {
"ObjectType_AllObjectsInASubtree",
"ObjectType_AllObjectsInAnOrg",
"ShadowType_ShadowsOnGivenResource",
"UserType_UsersWithShadowOnGivenResource"
"UserType_UsersWithShadowOnGivenResource",
"ObjectReferenceType_RoleMembershipRefsTargetingSuperuser"
);
private static final Set<QName> USE_IN_OBJECT_LIST_AVAILABLE_FOR = new HashSet<>(Arrays.asList(
UserType.COMPLEX_TYPE,
Expand Down Expand Up @@ -383,19 +385,12 @@ private void useInObjectListPerformed(AjaxRequestTarget target) {
Task task = getPageBase().createSimpleTask(OPERATION_CHECK_QUERY);
OperationResult result = task.getResult();
try {
updateRequestWithMidpointQuery(request, dto.getObjectType(), queryText, dto.isDistinct(), dto.getMidPointQueryScript(), task, result); // just to parse the query

ObjectFilter parsedFilter = request.getQuery().getFilter();
String filterAsString;
if (parsedFilter != null) {
SearchFilterType filterType = getPageBase().getQueryConverter().createSearchFilterType(parsedFilter);
filterAsString = getPrismContext().xmlSerializer().serializeRealValue(filterType, SchemaConstantsGenerated.Q_FILTER);
// TODO remove extra xmlns from serialized value
} else {
filterAsString = "";
}

// TODO add containerable option too (or split the code sooner?)
ExpressionType scriptQuery = null;
if (dto.isScriptEnabled()) {
scriptQuery = dto.getMidPointQueryScript();
}
updateRequestWithMidpointQuery(request, dto.getObjectType(), dto.getMidPointQuery(), dto.isDistinct(), scriptQuery, task, result);
//noinspection unchecked
Class<? extends PageBase> listPageClass = DetailsPageUtil.getObjectListPage((Class<? extends ObjectType>) request.getType());
String storageKey = listPageClass != null ? WebComponentUtil.getObjectListPageStorageKey(dto.getObjectType().getLocalPart()) : null;
Expand All @@ -411,11 +406,11 @@ private void useInObjectListPerformed(AjaxRequestTarget target) {
if (storage == null) {
storage = sessionStorage.initPageStorage(storageKey);
}
// TODO add containerable option too
Search search = storage.getSearch() != null ? storage.getSearch() : new SearchBuilder(request.getType()).modelServiceLocator(getPageBase()).build();
search.addAllowedModelType(SearchBoxModeType.ADVANCED);
search.setSearchMode(SearchBoxModeType.ADVANCED);
search.setAdvancedQuery(filterAsString);
search.addAllowedModelType(SearchBoxModeType.AXIOM_QUERY);
search.setSearchMode(SearchBoxModeType.AXIOM_QUERY);
// Use query from model object, call of updateRequestWithMidpointQuery may updated it with new Query Language text.
search.setDslQuery(getModelObject().getMidPointQuery());

if (!search.isAdvancedQueryValid(getPageBase())) {
// shouldn't occur because the query was already parsed
Expand Down Expand Up @@ -478,10 +473,9 @@ private void queryPerformed(QueryPlaygroundPanel.Action action, AjaxRequestTarge

if (action != Action.TRANSLATE_ONLY) {
// not an admin, so have to fetch objects via model
// TODO add containerable option too
queryResult = performModelSearch(request, task, result);
//noinspection unchecked
queryResult = getPageBase().getModelService().searchObjects((Class<? extends ObjectType>) request.getType(), request.getQuery(),
createRawCollection(), task, result);

} else {
queryResult = null;
}
Expand Down Expand Up @@ -515,6 +509,21 @@ private void queryPerformed(QueryPlaygroundPanel.Action action, AjaxRequestTarge
target.add(this);
}

private List<?> performModelSearch(RepositoryQueryDiagRequest request, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, SecurityViolationException, CommunicationException, ConfigurationException, ObjectNotFoundException {
if (ObjectType.class.isAssignableFrom(request.getType())) {
return getPageBase().getModelService().searchObjects((Class<? extends ObjectType>) request.getType(), request.getQuery(),
createRawCollection(), task, result);
}
if (Containerable.class.isAssignableFrom(request.getType())) {
return getPageBase().getModelService().searchContainers((Class<? extends Containerable>) request.getType(), request.getQuery(),
createRawCollection(), task, result);
}
if (ObjectReferenceType.class.isAssignableFrom(request.getType())) {
return getPageBase().getModelService().searchReferences(request.getQuery(), createRawCollection(), task, result);
}
throw new SchemaException("Unknown type " + request.getType() + "for search.");
}

private void warnNoQuery(AjaxRequestTarget target) {
warn(getString("PageRepositoryQuery.message.emptyString"));
target.add(getFeedbackPanel());
Expand All @@ -532,9 +541,8 @@ private void updateRequestWithMidpointQuery(
objectType = ObjectType.COMPLEX_TYPE;
}
@SuppressWarnings("unchecked")
Class<? extends ObjectType> clazz = (Class<? extends ObjectType>)
prismContext.getSchemaRegistry().getCompileTimeClassForObjectTypeRequired(objectType);

Class<? extends Containerable> clazz =
prismContext.getSchemaRegistry().determineClassForTypeRequired(objectType);
ObjectQuery queryWithExprEvaluated = null;
if (midPointQueryScript != null) {
PrismPropertyValue<?> filterValue = ExpressionUtil.evaluateExpression(new VariablesMap(), null, midPointQueryScript,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<query>
<filter>
<text>. ownedBy (@type = UserType and @path = roleMembershipRef ) and @/name = "Superuser"</text>
</filter>
</query>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<query>
<filter>
<text>(costCenter > '100000' and costCenter < '999999') or (costCenter >= 'X100' and costCenter <= 'X999')</text>
<text>(costCenter &gt; '100000' and costCenter &lt; '999999') or (costCenter &gt;= 'X100' and costCenter &lt;= 'X999')</text>
</filter>
</query>
Original file line number Diff line number Diff line change
Expand Up @@ -3183,7 +3183,7 @@
</xsd:documentation>
<xsd:appinfo>
<a:composite>true</a:composite>
<a:objectReferenceTargetType>FocusType</a:objectReferenceTargetType>
<a:objectReferenceTargetType>tns:FocusType</a:objectReferenceTargetType>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
Expand Down Expand Up @@ -3233,7 +3233,7 @@
</xsd:documentation>
<xsd:appinfo>
<a:composite>true</a:composite>
<a:objectReferenceTargetType>ObjectType</a:objectReferenceTargetType>
<a:objectReferenceTargetType>tns:ObjectType</a:objectReferenceTargetType>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ public boolean isEmptyCorrelatorsList() {
return CollectionUtils.isEmpty(correlators);
}

public void addCandidateOwners(CandidateOwnersMap map) {
public void rewriteCandidateOwners(CandidateOwnersMap map) {
candidateOwners.clear();
candidateOwners.mergeWith(map);
}

Expand All @@ -85,8 +86,18 @@ public Set<String> getCandidateOids() {
}

public void rewriteOwner(ObjectType owner) {
rewriteOwners(Collections.singletonList(owner));
}

public void rewriteOwners(List<ObjectType> owners) {
clearOwners();
if (owners != null) {
owners.forEach(this::addOwnerIfNotExist);
}
}

public void clearOwners() {
owners.clear();
owners.add(owner);
}

public void addOwnerIfNotExist(ObjectType owner) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ public Authentication doAuthenticate(
focusType);
ObjectType owner = correlationResult.getOwner();

if (owner == null && !candidateOwnerExist(correlationResult)) {
throw new AuthenticationServiceException("No identity is found.");
}

correlationModuleAuthentication.addAttributes(correlationVerificationToken.getDetails());

correlationModuleAuthentication.setPreFocus(correlationVerificationToken.getPreFocus(focusType,
Expand All @@ -82,7 +86,9 @@ public Authentication doAuthenticate(
return authentication;
} else if (correlationModuleAuthentication.isLastCorrelator()) {
if (candidateOwnerExist(correlationResult)) {
writeCandidatesToOwners(correlationResult.getCandidateOwnersMap(), correlationModuleAuthentication);
rewriteCandidatesToOwners(correlationResult.getCandidateOwnersMap(), correlationModuleAuthentication);
} else {
correlationModuleAuthentication.clearOwners();
}

isOwnersNumberUnderRestriction(correlationModuleAuthentication);
Expand All @@ -91,7 +97,7 @@ public Authentication doAuthenticate(
}

CandidateOwnersMap ownersMap = correlationResult.getCandidateOwnersMap();
correlationModuleAuthentication.addCandidateOwners(ownersMap);
correlationModuleAuthentication.rewriteCandidateOwners(ownersMap);

return authentication;
} catch (Exception e) {
Expand All @@ -113,8 +119,9 @@ private boolean candidateOwnerExist(CompleteCorrelationResult correlationResult)
return correlationResult.getCandidateOwnersMap() != null && !correlationResult.getCandidateOwnersMap().isEmpty();
}

private void writeCandidatesToOwners(@NotNull CandidateOwnersMap candidateOwnersMap,
private void rewriteCandidatesToOwners(@NotNull CandidateOwnersMap candidateOwnersMap,
CorrelationModuleAuthenticationImpl correlationModuleAuthentication) {
correlationModuleAuthentication.clearOwners();
candidateOwnersMap.values()
.forEach(c -> correlationModuleAuthentication.addOwnerIfNotExist(c.getObject()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,8 @@ public void mergeWith(CandidateOwnersMap other) {
}
}
}

public void clear() {
map.clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2122,9 +2122,15 @@ public RepositoryQueryDiagResponse executeQueryDiagnostics(
// Modified code from SqlQueryExecutor.list()
SimulatedSqlQuery<Object> simulatedQuery = new SimulatedSqlQuery<>(
sqlRepoContext.getQuerydslConfiguration(), jdbcSession.connection(), request.isTranslateOnly());
SqaleQueryContext<S, Q, R> context =
SqaleQueryContext.from(type, sqlRepoContext, simulatedQuery, null);

// Special handling for references?
SqaleQueryContext<S, Q, R> context;
if (ObjectReferenceType.class.isAssignableFrom(type)) {
SqaleTableMapping mapping = determineMapping(request.getQuery().getFilter());
context = SqaleQueryContext.from(mapping, sqlRepoContext, simulatedQuery, null);
} else {
context = SqaleQueryContext.from(type, sqlRepoContext, simulatedQuery, null);
}
ObjectQuery query = request.getQuery();
if (query != null) {
context.processFilter(query.getFilter());
Expand All @@ -2139,7 +2145,11 @@ public RepositoryQueryDiagResponse executeQueryDiagnostics(
result = context.executeQuery(jdbcSession);
PageOf<S> transformedResult = context.transformToSchemaType(result, jdbcSession);
//noinspection unchecked
resultList = transformedResult.map(o -> (PrismContainerValue<S>) o.asPrismContainerValue()).content();
if (ObjectReferenceType.class.isAssignableFrom(type)) {
resultList = transformedResult.content();
} else {
resultList = transformedResult.map(o -> (PrismContainerValue<S>) o.asPrismContainerValue()).content();
}
} catch (RuntimeException e) {
if (e != SimulatedSqlQuery.SIMULATION_EXCEPTION) {
throw e; // OK, this was unexpected, so rethrow it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ public ExtensionItemFilterProcessor(
@Override
public Predicate process(ValueFilter<?, ?> filter) throws RepositoryException {
ItemDefinition<?> definition = filter.getDefinition();
Objects.requireNonNull(definition,
"Item '" + filter.getPath() + "' without definition used in query.");
if (definition == null) {
throw new QueryException("Item '" + filter.getPath() + "' without definition used in query. Path probably does not exists.");
}
MExtItem extItem = new ExtensionProcessor((SqaleRepoContext) context.repositoryContext())
.resolveExtensionItem(definition, holderType);
assert definition != null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;

import static com.evolveum.midpoint.schema.result.OperationResultStatus.SUCCESS;

/**
* Initializes the task manager and brings it down.
*/
@DependsOn("midpointConfiguration")
@Component
public class UpAndDown implements BeanFactoryAware {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.jetbrains.annotations.Nullable;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;

import com.evolveum.midpoint.schema.result.OperationResult;
Expand All @@ -37,6 +38,7 @@
* - SHOULD NOT update task objects themselves.
* - Even it SHOULD NOT query task state. All of this has to be done by callers.
*/
@DependsOn("quartzInitializationHelper")
@Component
public class LocalScheduler {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.quartz.impl.StdSchedulerFactory;
import org.quartz.listeners.SchedulerListenerSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;

import com.evolveum.midpoint.schema.result.OperationResult;
Expand All @@ -36,6 +37,7 @@
/**
* Helps with Quartz starting and stopping.
*/
@DependsOn("taskManagerConfiguration")
@Component
class QuartzInitializationHelper {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class LogBeanPostProcessor implements BeanPostProcessor {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName)
throws BeansException {
LOGGER.info("Bean before initialization with name {} and class {}", beanName, bean.getClass().getSimpleName());
LOGGER.info("{}: {} before initialization", beanName, bean.getClass().getSimpleName());

return bean;

Expand All @@ -31,7 +31,7 @@ public Object postProcessBeforeInitialization(Object bean, String beanName)
@Override
public Object postProcessAfterInitialization(Object bean, String beanName)
throws BeansException {
LOGGER.info("Bean after initialization with name {} and class {}", beanName, bean.getClass().getSimpleName());
LOGGER.info("{}: {} after initialization", beanName, bean.getClass().getSimpleName());

return bean;
}
Expand Down

0 comments on commit 6cc5734

Please sign in to comment.