Skip to content

Commit

Permalink
improvements for correlation module - GUI part. a little bit of clean…
Browse files Browse the repository at this point in the history
…up. refactoring for getting processing module
  • Loading branch information
katkav committed Jul 25, 2023
1 parent a58e10c commit e57b3f8
Show file tree
Hide file tree
Showing 13 changed files with 274 additions and 241 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<form method="post" class="form-horizontal" wicket:id="mainForm">
<div wicket:id="csrfField"/>
<input type="hidden" wicket:id="attributeValues"/>
<wicket:child/>
<div wicket:id="attributes" class="d-flex flex-column my-2 justify-content-between login-panel-control">
<label wicket:id="attributeName"></label>
<input type="text" class="form-control form-control-sm" wicket:id="attributeValue"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,7 @@

package com.evolveum.midpoint.gui.impl.page.login;

import com.evolveum.midpoint.authentication.api.util.AuthConstants;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.gui.impl.page.login.dto.VerificationAttributeDto;
import com.evolveum.midpoint.prism.ItemDefinition;
import com.evolveum.midpoint.web.component.form.MidpointForm;
import com.evolveum.midpoint.web.security.util.SecurityUtils;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;

import com.evolveum.prism.xml.ns._public.types_3.ItemPathType;
import java.util.List;

import com.github.openjson.JSONArray;
import com.github.openjson.JSONObject;
Expand All @@ -30,13 +22,21 @@
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.LoadableDetachableModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;

import java.util.List;
import com.evolveum.midpoint.authentication.api.util.AuthConstants;
import com.evolveum.midpoint.gui.api.model.LoadableModel;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.gui.impl.page.login.dto.VerificationAttributeDto;
import com.evolveum.midpoint.prism.ItemDefinition;
import com.evolveum.midpoint.web.component.form.MidpointForm;
import com.evolveum.midpoint.web.security.util.SecurityUtils;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AbstractAuthenticationModuleType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import com.evolveum.prism.xml.ns._public.types_3.ItemPathType;

public abstract class PageAbstractAttributeVerification extends PageAuthenticationBase {
public abstract class PageAbstractAttributeVerification<AM extends AbstractAuthenticationModuleType> extends PageAuthenticationBase<AM> {
private static final long serialVersionUID = 1L;

private static final String ID_MAIN_FORM = "mainForm";
Expand All @@ -48,16 +48,17 @@ public abstract class PageAbstractAttributeVerification extends PageAuthenticati
private static final String ID_CSRF_FIELD = "csrfField";


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

public PageAbstractAttributeVerification() {
}

protected void initModels() {
attributePathModel = new LoadableDetachableModel<List<VerificationAttributeDto>>() {
attributePathModel = new LoadableModel<>(false) {
private static final long serialVersionUID = 1L;

@Override
protected List<VerificationAttributeDto> load() {
return loadAttrbuteVerificationDtoList();
Expand Down Expand Up @@ -149,5 +150,4 @@ private String generateAttributeValuesString() {
return attrValues.toString();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,28 @@
*/
package com.evolveum.midpoint.gui.impl.page.login;

import static com.evolveum.midpoint.gui.api.GuiStyleConstants.CLASS_TEST_CONNECTION_MENU_ITEM;

import java.util.ArrayList;
import java.util.List;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.WebMarkupContainer;
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.LoadableDetachableModel;
import org.apache.wicket.model.Model;

import com.evolveum.midpoint.authentication.api.authorization.PageDescriptor;
import com.evolveum.midpoint.authentication.api.authorization.Url;
import com.evolveum.midpoint.authentication.api.util.AuthenticationModuleNameConstants;
import com.evolveum.midpoint.gui.api.model.LoadableModel;
import com.evolveum.midpoint.gui.api.util.*;
import com.evolveum.midpoint.gui.api.util.GuiDisplayTypeUtil;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.gui.impl.component.tile.Tile;
import com.evolveum.midpoint.gui.impl.component.tile.TilePanel;
import com.evolveum.midpoint.prism.query.ObjectQuery;
Expand All @@ -19,34 +36,16 @@
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.AjaxButton;
import com.evolveum.midpoint.web.component.form.MidpointForm;

import com.evolveum.midpoint.web.component.prism.DynamicFormPanel;
import com.evolveum.midpoint.web.security.util.SecurityUtils;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.WebMarkupContainer;
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.LoadableDetachableModel;
import org.apache.wicket.model.Model;

import java.util.ArrayList;
import java.util.List;

import static com.evolveum.midpoint.gui.api.GuiStyleConstants.CLASS_TEST_CONNECTION_MENU_ITEM;

@PageDescriptor(urls = {
@Url(mountUrl = "/archetypeSelection", matchUrlForSecurity = "/archetypeSelection")
}, permitAll = true, loginPage = true, authModule = AuthenticationModuleNameConstants.ARCHETYPE_SELECTION)
public class PageArchetypeSelection extends PageAuthenticationBase {
public class PageArchetypeSelection extends PageAuthenticationBase<ArchetypeSelectionModuleType> {

private static final long serialVersionUID = 1L;
private static final Trace LOGGER = TraceManager.getTrace(PageArchetypeSelection.class);
Expand Down Expand Up @@ -89,16 +88,19 @@ protected String getModuleTypeName() {
return AuthenticationModuleNameConstants.ARCHETYPE_SELECTION;
}

@Override
protected List<ArchetypeSelectionModuleType> getAuthetcationModules(AuthenticationModulesType modules) {
return modules.getArchetypeSelection();
}

@Override
protected void initModels() {
archetypeSelectionModuleModel = new LoadableDetachableModel<>() {
private static final long serialVersionUID = 1L;

@Override
protected ArchetypeSelectionModuleType load() {
var securityPolicy = resolveSecurityPolicy(null);

return ConfigurationLoadUtil.loadArchetypeSelectionModuleForLoginRecovery(PageArchetypeSelection.this, securityPolicy);
return getAutheticationModuleConfiguration();
}
};
allowUndefinedArchetype = loadAllowUndefinedArchetypeConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,9 @@
import org.apache.wicket.RestartResponseException;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

import com.evolveum.midpoint.authentication.api.authorization.PageDescriptor;
import com.evolveum.midpoint.authentication.api.authorization.Url;
import com.evolveum.midpoint.authentication.api.config.MidpointAuthentication;
import com.evolveum.midpoint.authentication.api.config.ModuleAuthentication;
import com.evolveum.midpoint.authentication.api.util.AuthUtil;
import com.evolveum.midpoint.authentication.api.util.AuthenticationModuleNameConstants;
import com.evolveum.midpoint.gui.impl.page.login.dto.VerificationAttributeDto;
Expand All @@ -28,14 +24,15 @@
import com.evolveum.midpoint.web.component.prism.DynamicFormPanel;
import com.evolveum.midpoint.web.page.error.PageError;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AttributeVerificationAuthenticationModuleType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AuthenticationModulesType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityPolicyType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import com.evolveum.prism.xml.ns._public.types_3.ItemPathType;

@PageDescriptor(urls = {
@Url(mountUrl = "/attributeVerification", matchUrlForSecurity = "/attributeVerification")
}, permitAll = true, loginPage = true, authModule = AuthenticationModuleNameConstants.ATTRIBUTE_VERIFICATION)
public class PageAttributeVerification extends PageAbstractAttributeVerification {
public class PageAttributeVerification extends PageAbstractAttributeVerification<AttributeVerificationAuthenticationModuleType> {
private static final long serialVersionUID = 1L;
private LoadableDetachableModel<UserType> userModel;

Expand All @@ -57,28 +54,8 @@ protected UserType load() {

@Override
protected List<VerificationAttributeDto> loadAttrbuteVerificationDtoList() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (!(authentication instanceof MidpointAuthentication)) {
getSession().error(getString("No midPoint authentication is found"));
throw new RestartResponseException(PageError.class);
}
MidpointAuthentication mpAuthentication = (MidpointAuthentication) authentication;
ModuleAuthentication moduleAuthentication = mpAuthentication.getProcessingModuleAuthentication();
if (moduleAuthentication == null
&& !AuthenticationModuleNameConstants.ATTRIBUTE_VERIFICATION.equals(moduleAuthentication.getModuleTypeName())) {
getSession().error(getString("No authentication module is found"));
throw new RestartResponseException(PageError.class);
}
if (StringUtils.isEmpty(moduleAuthentication.getModuleIdentifier())) {
getSession().error(getString("No module identifier is defined"));
throw new RestartResponseException(PageError.class);
}
AttributeVerificationAuthenticationModuleType module = getModuleByIdentifier(moduleAuthentication.getModuleIdentifier());
if (module == null) {
getSession().error(getString("No module with identifier \"" + moduleAuthentication.getModuleIdentifier() + "\" is found"));
throw new RestartResponseException(PageError.class);
}
List<ItemPathType> moduleAttributes = module.getPath();
AttributeVerificationAuthenticationModuleType module = getAutheticationModuleConfiguration();
List<ItemPathType> moduleAttributes = module.getPath();
return moduleAttributes.stream()
.map(attr -> new VerificationAttributeDto(attr))
.collect(Collectors.toList());
Expand Down Expand Up @@ -122,6 +99,11 @@ protected String getModuleTypeName() {
return AuthenticationModuleNameConstants.ATTRIBUTE_VERIFICATION;
}

@Override
protected List<AttributeVerificationAuthenticationModuleType> getAuthetcationModules(AuthenticationModulesType modules) {
return modules.getAttributeVerification();
}

@Override
protected IModel<String> getLoginPanelTitleModel() {
return createStringResource("PageAttributeVerification.attributeVerificationLabel");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
import com.evolveum.midpoint.model.api.authentication.GuiProfiledPrincipal;
import com.evolveum.midpoint.web.component.util.VisibleBehaviour;

import com.evolveum.midpoint.web.page.error.PageError;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.RestartResponseException;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.WebMarkupContainer;
Expand Down Expand Up @@ -43,12 +47,8 @@
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.AjaxButton;
import com.evolveum.midpoint.web.component.prism.DynamicFormPanel;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityPolicyType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;

public abstract class PageAuthenticationBase extends AbstractPageLogin {
public abstract class PageAuthenticationBase<AM extends AbstractAuthenticationModuleType> extends AbstractPageLogin {

private static final long serialVersionUID = 1L;
private static final String DOT_CLASS = PageAuthenticationBase.class.getName() + ".";
Expand Down Expand Up @@ -258,4 +258,51 @@ && getModuleTypeName().equals(moduleAuthentication.getModuleTypeName())){
}

protected abstract String getModuleTypeName();

protected AM getAutheticationModuleConfiguration() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (!(authentication instanceof MidpointAuthentication)) {
getSession().error(getString("No midPoint authentication is found"));
throw new RestartResponseException(PageError.class);
}
MidpointAuthentication mpAuthentication = (MidpointAuthentication) authentication;
ModuleAuthentication moduleAuthentication = mpAuthentication.getProcessingModuleAuthentication();
if (moduleAuthentication == null
|| !getModuleTypeName().equals(moduleAuthentication.getModuleTypeName())) {
getSession().error(getString("No authentication module is found"));
throw new RestartResponseException(PageError.class);
}
if (StringUtils.isEmpty(moduleAuthentication.getModuleIdentifier())) {
getSession().error(getString("No module identifier is defined"));
throw new RestartResponseException(PageError.class);
}
AM module = getModuleByIdentifier(moduleAuthentication.getModuleIdentifier());
if (module == null) {
getSession().error(getString("No module with identifier \"" + moduleAuthentication.getModuleIdentifier() + "\" is found"));
throw new RestartResponseException(PageError.class);
}

return module;
}

protected abstract List<AM> getAuthetcationModules(AuthenticationModulesType modules);

private AM getModuleByIdentifier(String moduleIdentifier) {
if (StringUtils.isEmpty(moduleIdentifier)) {
return null;
}

//TODO security policy defined for archetype? e.g. not null user but empty focus with archetype. but wouldn't it be hack?
SecurityPolicyType securityPolicy = resolveSecurityPolicy(null);
if (securityPolicy == null || securityPolicy.getAuthentication() == null) {
getSession().error(getString("Security policy not found"));
throw new RestartResponseException(PageError.class);
}
return getAuthetcationModules(securityPolicy.getAuthentication().getModules())
.stream()
.filter(m -> moduleIdentifier.equals(m.getIdentifier()) || moduleIdentifier.equals(m.getName()))
.findFirst()
.orElse(null);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2022 Evolveum
~
~ This work is dual-licensed under the Apache License 2.0
~ and European Union Public License. See LICENSE file for details.
-->

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns:wicket="http://wicket.apache.org">
<wicket:extend>
<input type="hidden" wicket:id="correlatorName"/>

</wicket:extend>

</html>

0 comments on commit e57b3f8

Please sign in to comment.