Skip to content

Commit

Permalink
replaced polystring panel by text panel for correlation flow; fix for…
Browse files Browse the repository at this point in the history
… last correlator index (MID-9215)
  • Loading branch information
KaterynaHonchar committed Oct 12, 2023
1 parent 6cc5734 commit d1b5a4f
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ public void configure(PrismPropertyPanelContext<T> panelCtx, Component component
if (formComponent instanceof TextField) {
formComponent.add(new AttributeModifier("size", "42"));
}
formComponent.add(panelCtx.getAjaxEventBehavior());
if (panelCtx.getAjaxEventBehavior() != null) {
formComponent.add(panelCtx.getAjaxEventBehavior());
}
formComponent.add(panelCtx.getVisibleEnableBehavior());
if (panelCtx.getAttributeValuesMap() != null) {
panelCtx.getAttributeValuesMap().keySet().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@
public class CorrelatorConfigDto implements Serializable {

public static final String CORRELATOR_IDENTIFIER = "correlatorIdentifier";
public static final String CORRELATOR_INDEX = "correlatorIndex";

private String correlatorIdentifier;
private List<VerificationAttributeDto> attributeDtoList;
private String archetypeOid;
private int correlatorIndex;

public CorrelatorConfigDto(String correlatorIdentifier, String archetypeOid, List<VerificationAttributeDto> attributeDtoList) {
public CorrelatorConfigDto(String correlatorIdentifier, String archetypeOid, List<VerificationAttributeDto> attributeDtoList,
int correlatorIndex) {
this.correlatorIdentifier = correlatorIdentifier;
this.archetypeOid = archetypeOid;
this.attributeDtoList = attributeDtoList;
this.correlatorIndex = correlatorIndex;
}

public List<VerificationAttributeDto> getAttributeDtoList() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
<wicket:extend>
<form method="post" class="form-horizontal" wicket:id="form">
<div wicket:id="csrfField"/>
<!-- <input type="hidden" wicket:id="attributeValues"/>-->
<wicket:child class="mt-4"/>
<div wicket:id="attributes" class="d-flex flex-column my-2 justify-content-between login-panel-control">
<!-- <div wicket:id="attributePanel"></div>-->
<label wicket:id="attributeName"></label>
<div wicket:id="attributeValue"/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,24 @@
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.DOMUtil;
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;
import com.evolveum.midpoint.util.logging.TraceManager;

import com.evolveum.midpoint.web.component.input.TextPanel;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;

import com.github.openjson.JSONArray;
import com.github.openjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxEventBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.HiddenField;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

import com.evolveum.midpoint.authentication.api.config.ModuleAuthentication;
import com.evolveum.midpoint.authentication.api.util.AuthConstants;
Expand All @@ -61,14 +58,11 @@ public abstract class PageAbstractAttributeVerification<MA extends ModuleAuthent
private static final Trace LOGGER = TraceManager.getTrace(PageAbstractAttributeVerification.class);
private static final String DOT_CLASS = PageAbstractAttributeVerification.class.getName() + ".";
protected static final String OPERATION_CREATE_ITEM_WRAPPER = DOT_CLASS + "createItemWrapper";
// private static final String ID_ATTRIBUTE_VALUES = "attributeValues";
private static final String ID_ATTRIBUTES = "attributes";
private static final String ID_ATTRIBUTE_NAME = "attributeName";
private static final String ID_ATTRIBUTE_PANEL = "attributePanel";
private static final String ID_ATTRIBUTE_VALUE = "attributeValue";

private LoadableModel<List<VerificationAttributeDto>> attributePathModel;
private final IModel<String> attrValuesModel = Model.of();

public PageAbstractAttributeVerification() {
super();
Expand All @@ -90,10 +84,6 @@ protected List<VerificationAttributeDto> load() {

@Override
protected void initModuleLayout(MidpointForm form) {
// HiddenField<String> verified = new HiddenField<>(ID_ATTRIBUTE_VALUES, attrValuesModel);
// verified.setOutputMarkupId(true);
// form.add(verified);

initAttributesLayout(form);
}

Expand All @@ -116,30 +106,24 @@ private void createAttributePanel(ListItem<VerificationAttributeDto> item) {
item.add(attributeNameLabel);

PrismPropertyWrapper<?> itemWrapper = item.getModelObject().getItemWrapper();
if (QNameUtil.match(DOMUtil.XSD_STRING, itemWrapper.getTypeName()) ||
QNameUtil.match(PolyStringType.COMPLEX_TYPE, itemWrapper.getTypeName())) {
TextPanel<String> valuePanel = new TextPanel<>(ID_ATTRIBUTE_VALUE, new PropertyModel<>(itemWrapper, "value.realValue"));
valuePanel.getBaseFormComponent().add(AttributeAppender.replace("name", AuthConstants.ATTR_VERIFICATION_PARAMETER_START
+ item.getModelObject().getItemPath()));
item.add(valuePanel);
return;
}
var valuePanel = new PrismPropertyValuePanel(ID_ATTRIBUTE_VALUE,
new PropertyModel<PrismPropertyValueWrapper>(itemWrapper, "value"),
new ItemPanelSettingsBuilder().build()) {

@Serial private static final long serialVersionUID = 1L;

// @Override
// protected AjaxEventBehavior createEventBehavior() {
// return new AjaxFormComponentUpdatingBehavior("blur") {
//
// @Serial private static final long serialVersionUID = 1L;
//
// @Override
// protected void onUpdate(AjaxRequestTarget target) {
// attrValuesModel.setObject(generateAttributeValuesString());
// target.add(getVerifiedField());
// }
//
// @Override
// protected void onError(AjaxRequestTarget target, RuntimeException e) {
// target.add(getFeedback());
// }
// };
// }
@Override
protected AjaxEventBehavior createEventBehavior() {
return null;
}

@Override
protected Map<String, String> getAttributeValuesMap() {
Expand Down Expand Up @@ -207,25 +191,4 @@ private WrapperContext createWrapperContext() {
return ctx;
}

// private String generateAttributeValuesString() {
// JSONArray attrValues = new JSONArray();
// attributePathModel.getObject().forEach(entry -> {
// PrismPropertyValueWrapper value = (PrismPropertyValueWrapper) entry.getValue();
// if (value == null || value.getRealValue() == null) {
// return;
// }
// JSONObject json = new JSONObject();
// json.put(AuthConstants.ATTR_VERIFICATION_J_PATH, entry.getItemPath());
// json.put(AuthConstants.ATTR_VERIFICATION_J_VALUE, value.getRealValue());
// attrValues.put(json);
// });
// if (attrValues.length() == 0) {
// return null;
// }
// return attrValues.toString();
// }

// private Component getVerifiedField() {
// return getForm().get(ID_ATTRIBUTE_VALUES);
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<html xmlns:wicket="http://wicket.apache.org">
<wicket:extend>
<input type="hidden" wicket:id="correlatorName"/>
<input type="hidden" wicket:id="correlatorIndex"/>
</wicket:extend>

</html>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.util.List;
import java.util.stream.Collectors;

import com.evolveum.midpoint.authentication.api.util.AuthConstants;

import org.apache.wicket.markup.html.form.HiddenField;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;
Expand Down Expand Up @@ -45,8 +47,6 @@ public class PageCorrelation extends PageAbstractAttributeVerification<Correlati
private static final Trace LOGGER = TraceManager.getTrace(PageCorrelation.class);
private static final String OPERATION_DETERMINE_CORRELATOR_SETTINGS = DOT_CLASS + "determineCorrelatorSettings";

private static final String ID_CORRELATOR_NAME = "correlatorName";

private LoadableModel<CorrelatorConfigDto> correlatorModel;

public PageCorrelation() {
Expand Down Expand Up @@ -74,7 +74,8 @@ protected CorrelatorConfigDto load() {
archetypeOid = mpAuthentication.getArchetypeOid();
}

return new CorrelatorConfigDto(correlatorName, archetypeOid, getCorrelationAttributePaths(correlatorName, archetypeOid));
return new CorrelatorConfigDto(correlatorName, archetypeOid, getCorrelationAttributePaths(correlatorName, archetypeOid),
module.getCurrentCorrelatorIndex());
}
};
super.initModels();
Expand All @@ -101,9 +102,13 @@ private List<VerificationAttributeDto> getCorrelationAttributePaths(String corre
protected void initModuleLayout(MidpointForm form) {
super.initModuleLayout(form);

HiddenField<String> verified = new HiddenField<>(ID_CORRELATOR_NAME, new PropertyModel<>(correlatorModel, CorrelatorConfigDto.CORRELATOR_IDENTIFIER));
HiddenField<String> verified = new HiddenField<>(AuthConstants.ATTR_VERIFICATION_CORRELATOR_NAME, new PropertyModel<>(correlatorModel, CorrelatorConfigDto.CORRELATOR_IDENTIFIER));
verified.setOutputMarkupId(true);
form.add(verified);

HiddenField<String> index = new HiddenField<>(AuthConstants.ATTR_VERIFICATION_CORRELATOR_INDEX, new PropertyModel<>(correlatorModel, CorrelatorConfigDto.CORRELATOR_INDEX));
index.setOutputMarkupId(true);
form.add(index);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ public interface CorrelationModuleAuthentication extends ModuleAuthentication {

FocusType getPreFocus();

int getCurrentCorrelatorIndex();
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ public class AuthConstants {
public static final String ATTR_VERIFICATION_J_VALUE = "value";

public static final String ATTR_VERIFICATION_PARAMETER_START = "attributeValue.";
public static final String ATTR_VERIFICATION_CORRELATOR_NAME = "correlatorName";
public static final String ATTR_VERIFICATION_CORRELATOR_INDEX = "correlatorIndex";
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@

import java.util.Map;

import com.evolveum.midpoint.authentication.api.util.AuthConstants;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.core.Authentication;
Expand All @@ -32,17 +35,25 @@ public CorrelationAuthenticationFilter(AuthenticationManager authenticationManag
}

protected AbstractAuthenticationToken createAuthenticationToken(Map<ItemPath, String> attributeValues) {
return new CorrelationVerificationToken(attributeValues, null); //TDO refactor
return new CorrelationVerificationToken(attributeValues, null, 0); //TDO refactor
}

@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException {
validateRequest(request);

Map<ItemPath, String> attributeValues = obtainAttributeValues(request);
String correlatorName = request.getParameter("correlatorName");
AbstractAuthenticationToken authRequest = new CorrelationVerificationToken(attributeValues, correlatorName);

String correlatorName = request.getParameter(AuthConstants.ATTR_VERIFICATION_CORRELATOR_NAME);
String correlatorIndex = request.getParameter(AuthConstants.ATTR_VERIFICATION_CORRELATOR_INDEX);
int correlatorIndexVal = 0;
if (StringUtils.isNotEmpty(correlatorIndex)) {
try {
correlatorIndexVal = Integer.parseInt(correlatorIndex);
} catch (Exception e) {
//nothing to do here
}
}
CorrelationVerificationToken authRequest = new CorrelationVerificationToken(attributeValues, correlatorName, correlatorIndexVal);
return this.getAuthenticationManager().authenticate(authRequest);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ public boolean isLastCorrelator() {
return currentProcessingCorrelator == correlators.size() - 1;
}

public boolean currentCorrelatorIndexEquals(int expectedValue) {
return currentProcessingCorrelator == expectedValue;
}

public void setNextCorrelator() {
currentProcessingCorrelator++;
}
Expand Down Expand Up @@ -134,6 +138,10 @@ public FocusType getPreFocus() {
return preFocus;
}

public int getCurrentCorrelatorIndex() {
return currentProcessingCorrelator;
}

public boolean isCorrelationMaxUsersNumberSet() {
return correlationMaxUsersNumber != null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ public class CorrelationVerificationToken extends AbstractAuthenticationToken {

private String correlatorName;
private Map<ItemPath, String> attributes;
private int currentCorrelatorIndex;

public CorrelationVerificationToken(Map<ItemPath, String> attributes, String correlatorName) {
public CorrelationVerificationToken(Map<ItemPath, String> attributes, String correlatorName, int currentCorrelatorIndex) {
super(null);
this.attributes = attributes;
this.correlatorName = correlatorName;
this.currentCorrelatorIndex = currentCorrelatorIndex;
}

@Override
Expand Down Expand Up @@ -90,4 +92,8 @@ private Object convertValueIfNecessary(PrismPropertyDefinition def, String value
}
return value;
}

public int getCurrentCorrelatorIndex() {
return currentCorrelatorIndex;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public Authentication doAuthenticate(
if (owner != null) {
correlationModuleAuthentication.rewriteOwner(owner);
return authentication;
} else if (correlationModuleAuthentication.isLastCorrelator()) {
} else if (isLastCorrelatorProcessing(correlationModuleAuthentication, correlationVerificationToken)) {
if (candidateOwnerExist(correlationResult)) {
rewriteCandidatesToOwners(correlationResult.getCandidateOwnersMap(), correlationModuleAuthentication);
} else {
Expand All @@ -107,6 +107,12 @@ public Authentication doAuthenticate(

}

private boolean isLastCorrelatorProcessing(CorrelationModuleAuthenticationImpl correlationModuleAuthentication,
CorrelationVerificationToken token) {
return correlationModuleAuthentication.isLastCorrelator()
&& correlationModuleAuthentication.currentCorrelatorIndexEquals(token.getCurrentCorrelatorIndex());
}

private String determineArchetypeOid() {
Authentication processingAuthentication = SecurityUtil.getAuthentication();
if (processingAuthentication instanceof MidpointAuthentication mpAuthentication) {
Expand Down

0 comments on commit d1b5a4f

Please sign in to comment.