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
KaterynaHonchar committed Mar 5, 2021
2 parents 8b8bc0a + 3895ba3 commit 56f457b
Show file tree
Hide file tree
Showing 54 changed files with 2,031 additions and 1,407 deletions.
Expand Up @@ -10,6 +10,9 @@
import java.util.ArrayList;
import java.util.List;

import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils;
import com.evolveum.midpoint.prism.Referencable;
import com.evolveum.midpoint.web.component.data.SelectableBeanContainerDataProvider;

import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -83,7 +86,13 @@ public <T> void exportData(IDataProvider<T> dataProvider,
@Override
protected <T> IModel<T> wrapModel(IModel<T> model) {
if (model.getObject() == null) {
return (IModel<T>) () -> (T) "";
return () -> (T) "";
}
if (model.getObject() instanceof Referencable) {
return () -> {
String value = WebModelServiceUtils.resolveReferenceName((Referencable) model.getObject(), getPageBase());
return (T) (value == null ? "" : value);
};
}
return super.wrapModel(model);
}
Expand Down
Expand Up @@ -201,7 +201,7 @@ protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
String s1 = password1.getModelObject();
String s2 = password2.getValue();

if (StringUtils.isEmpty(s1) && StringUtils.isEmpty(s2)) {
if (StringUtils.isEmpty(s1) || StringUtils.isEmpty(s2)) {
return "";
}

Expand Down
Expand Up @@ -4908,4 +4908,20 @@ public static CompiledObjectCollectionView getCollectionViewByObject(AssignmentH
QName type = classToQName(pageBase.getPrismContext(), assignmentHolder.getClass());
return pageBase.getCompiledGuiProfile().findObjectCollectionView(type, null);
}

public static CredentialsPolicyType getPasswordCredentialsPolicy(PrismObject<? extends FocusType> focus, PageBase pagebase, Task task) {
LOGGER.debug("Getting credentials policy");
CredentialsPolicyType credentialsPolicyType = null;
try {
credentialsPolicyType = pagebase.getModelInteractionService().getCredentialsPolicy(focus, task, task.getResult());
task.getResult().recordSuccessIfUnknown();
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load credentials policy", ex);
task.getResult().recordFatalError(
pagebase.createStringResource("PageAbstractSelfCredentials.message.getPasswordCredentialsPolicy.fatalError", ex.getMessage()).getString(), ex);
} finally {
task.getResult().computeStatus();
}
return credentialsPolicyType;
}
}
Expand Up @@ -17,7 +17,7 @@
</div>
</div>

<div wicket:id="popover" class="popover bottom" style="min-width: fit-content;">
<div wicket:id="popover" class="popover bottom" style="min-width: fit-content; max-width: max-content;">
<div wicket:id="popoverPanel"/>
</div>
</wicket:panel>
Expand Down
Expand Up @@ -108,7 +108,20 @@ public boolean equals(Object o) {
SearchItemDefinition property = (SearchItemDefinition) o;

if (isSelected != property.isSelected()) { return false; }
return !(getDef() != null ? !getDef().equals(property.getDef()) : property.getDef() != null);
if (getDef() != null || property.getDef() != null) {
if (getDef() != null) {
return getDef().equals(property.getDef());
}
return false;
}
if (getPredefinedFilter() != null) {
return getPredefinedFilter().equals(property.getPredefinedFilter());
} else {
if (property.getPredefinedFilter() != null) {
return false;
}
}
return true;
}

@Override
Expand Down
Expand Up @@ -6,22 +6,29 @@
*/
package com.evolveum.midpoint.web.page.admin.home.component;

import java.util.Date;

import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.IModel;

import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.gui.api.model.LoadableModel;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
import com.evolveum.midpoint.schema.util.MiscSchemaUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.web.component.DateLabelComponent;
import com.evolveum.midpoint.web.page.admin.home.dto.PersonalInfoDto;
import com.evolveum.midpoint.web.page.self.PageSelfCredentials;
import com.evolveum.midpoint.web.security.util.SecurityUtils;
import com.evolveum.midpoint.xml.ns._public.common.common_3.CredentialsType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AuthenticationBehavioralDataType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.CredentialsPolicyType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.PasswordType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.MetadataType;

import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.IModel;

import javax.xml.datatype.Duration;
import javax.xml.datatype.XMLGregorianCalendar;
import java.util.Date;

/**
* @author lazyman
Expand All @@ -34,6 +41,9 @@ public class PersonalInfoPanel extends BasePanel<PersonalInfoDto> {
private static final String ID_LAST_FAIL_FROM = "lastFailFrom";
private static final String ID_PASSWORD_EXP = "passwordExp";

private static final String DOT_CLASS = PageSelfCredentials.class.getName() + ".";
private static final String OPERATION_GET_CREDENTIALS_POLICY = DOT_CLASS + "getCredentialsPolicy";

public PersonalInfoPanel(String id) {
super(id, null);
}
Expand All @@ -58,27 +68,33 @@ protected PersonalInfoDto load() {
}

private PersonalInfoDto loadPersonalInfo() {
FocusType user = SecurityUtils.getPrincipalUser().getFocus();
CredentialsType credentials = user.getCredentials();
FocusType focus = SecurityUtils.getPrincipalUser().getFocus();
AuthenticationBehavioralDataType behaviour = focus.getBehavior() != null ? focus.getBehavior().getAuthentication() : null;
PersonalInfoDto dto = new PersonalInfoDto();
if (credentials != null) {
PasswordType password = credentials.getPassword();

if (password.getPreviousSuccessfulLogin() != null) {
dto.setLastLoginDate(MiscUtil.asDate(password.getPreviousSuccessfulLogin().getTimestamp()));
dto.setLastLoginFrom(password.getPreviousSuccessfulLogin().getFrom());
if (behaviour != null) {
if (behaviour.getPreviousSuccessfulLogin() != null) {
dto.setLastLoginDate(MiscUtil.asDate(behaviour.getPreviousSuccessfulLogin().getTimestamp()));
dto.setLastLoginFrom(behaviour.getPreviousSuccessfulLogin().getFrom());
}

if (password.getLastFailedLogin() != null) {
dto.setLastFailDate(MiscUtil.asDate(password.getLastFailedLogin().getTimestamp()));
dto.setLastFailFrom(password.getLastFailedLogin().getFrom());
if (behaviour.getLastFailedLogin() != null) {
dto.setLastFailDate(MiscUtil.asDate(behaviour.getLastFailedLogin().getTimestamp()));
dto.setLastFailFrom(behaviour.getLastFailedLogin().getFrom());
}
}
if (user.getActivation() != null) {
//todo fix, this is not password expiration date...
dto.setPasswordExp(MiscUtil.asDate(user.getActivation().getValidTo()));
Task task = getPageBase().createSimpleTask(OPERATION_GET_CREDENTIALS_POLICY);
CredentialsPolicyType credentialsPolicyType = WebComponentUtil.getPasswordCredentialsPolicy(focus.asPrismContainer(), getPageBase(), task);
Duration maxAge = credentialsPolicyType != null && credentialsPolicyType.getPassword() != null ?
credentialsPolicyType.getPassword().getMaxAge() : null;
if (maxAge != null) {
MetadataType credentialMetadata = focus.getCredentials() != null && focus.getCredentials().getPassword() != null ?
focus.getCredentials().getPassword().getMetadata() : null;
XMLGregorianCalendar changeTimestamp = MiscSchemaUtil.getChangeTimestamp(credentialMetadata);
if (changeTimestamp != null) {
XMLGregorianCalendar passwordValidUntil = XmlTypeConverter.addDuration(changeTimestamp, maxAge);
dto.setPasswordExp(MiscUtil.asDate(passwordValidUntil));
}
}

return dto;
}

Expand Down Expand Up @@ -150,21 +166,20 @@ public String getObject() {
});
add(lastFailFrom);

Label passwordExp = new Label(ID_PASSWORD_EXP, new IModel<String>() {

DateLabelComponent passwordExp = new DateLabelComponent(ID_PASSWORD_EXP, new IModel<Date>() {
private static final long serialVersionUID = 1L;

@Override
public String getObject() {
public Date getObject() {

if (getModel() == null) {
return PersonalInfoPanel.this.getString("PersonalInfoPanel.undefined");
return null;
}
PersonalInfoDto dto = getModel().getObject();

return dto.getPasswordExp() != null ? WebComponentUtil.formatDate(dto.getPasswordExp()) :
PersonalInfoPanel.this.getString("PersonalInfoPanel.undefined");
return dto == null ? null : dto.getPasswordExp();
}
});
}, WebComponentUtil.getLongDateTimeFormat(getPageBase()));
passwordExp.setBeforeTextOnDateNull(getPageBase().getString("PersonalInfoPanel.never"));
add(passwordExp);
}
}
Expand Up @@ -412,6 +412,11 @@ protected IModel<String> createLinkModel(IModel<SelectableBean<AuditEventRecordT
return Model.of(WebComponentUtil.formatDate(record.getTimestamp()));
}

@Override
public IModel<String> getDataModel(IModel<SelectableBean<AuditEventRecordType>> rowModel) {
return createLinkModel(rowModel);
}

@Override
public boolean isEnabled(IModel<SelectableBean<AuditEventRecordType>> rowModel) {
return unwrapModel(rowModel) != null;
Expand Down
Expand Up @@ -493,7 +493,8 @@ private MyPasswordsDto loadPageModel() {
private MyPasswordsDto createMyPasswordsDto(PrismObject<? extends FocusType> focus) {
MyPasswordsDto dto = new MyPasswordsDto();
dto.setFocus(focus);
CredentialsPolicyType credentialsPolicyType = getPasswordCredentialsPolicy(focus);
Task task = getPageBase().createSimpleTask(OPERATION_GET_CREDENTIALS_POLICY);
CredentialsPolicyType credentialsPolicyType = WebComponentUtil.getPasswordCredentialsPolicy(focus, getPageBase(), task);
dto.getAccounts().add(createDefaultPasswordAccountDto(focus, getPasswordPolicyOid(credentialsPolicyType)));


Expand All @@ -510,7 +511,7 @@ private MyPasswordsDto createMyPasswordsDto(PrismObject<? extends FocusType> foc
}
ObjectReferenceType valuePolicyRef = passwordCredentialsPolicy.getValuePolicyRef();
if (valuePolicyRef != null && valuePolicyRef.getOid() != null){
Task task = getPageBase().createSimpleTask("load value policy");
task = getPageBase().createSimpleTask("load value policy");
PrismObject<ValuePolicyType> valuePolicy = WebModelServiceUtils.resolveReferenceNoFetch(
valuePolicyRef, getPageBase(), task, task.getResult());
if (valuePolicy != null) {
Expand All @@ -532,24 +533,6 @@ private PasswordAccountDto createDefaultPasswordAccountDto(PrismObject<? extends
return accountDto;
}

private CredentialsPolicyType getPasswordCredentialsPolicy(PrismObject<? extends FocusType> focus) {
LOGGER.debug("Getting credentials policy");
Task task = getPageBase().createSimpleTask(OPERATION_GET_CREDENTIALS_POLICY);
OperationResult result = new OperationResult(OPERATION_GET_CREDENTIALS_POLICY);
CredentialsPolicyType credentialsPolicyType = null;
try {
credentialsPolicyType = getPageBase().getModelInteractionService().getCredentialsPolicy(focus, task, result);
result.recordSuccessIfUnknown();
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load credentials policy", ex);
result.recordFatalError(
getString("PageAbstractSelfCredentials.message.getPasswordCredentialsPolicy.fatalError", ex.getMessage()), ex);
} finally {
result.computeStatus();
}
return credentialsPolicyType;
}

private CredentialsPolicyType getPasswordCredentialsPolicy(RefinedObjectClassDefinition rOCDef) {
LOGGER.debug("Getting credentials policy");
Task task = getPageBase().createSimpleTask(OPERATION_GET_CREDENTIALS_POLICY);
Expand Down
Expand Up @@ -49,6 +49,10 @@ public void onAuthenticationFailure(HttpServletRequest request, HttpServletRespo
String urlSuffix = GuiConstants.DEFAULT_PATH_AFTER_LOGIN;
if (authentication instanceof MidpointAuthentication) {
MidpointAuthentication mpAuthentication = (MidpointAuthentication) authentication;
if (mpAuthentication.isAuthenticated()) {
getRedirectStrategy().sendRedirect(request, response, urlSuffix);
return;
}
ModuleAuthentication moduleAuthentication = mpAuthentication.getProcessingModuleAuthentication();
if (mpAuthentication.getAuthenticationChannel() != null) {
if (mpAuthentication.isLast(moduleAuthentication) && mpAuthentication.getAuthenticationChannel().isDefault()) {
Expand Down
Expand Up @@ -172,6 +172,10 @@ default PrismObject<ShadowType> createBlankShadow(String tag) {

//region Capabilities ========================================================

/**
* Returns configured capabilities for given refined object class definition.
* Returned object is freely modifiable copy of the original information.
*/
CapabilitiesType getCapabilities();

<T extends CapabilityType> T getEffectiveCapability(Class<T> capabilityClass, ResourceType resourceType);
Expand Down

0 comments on commit 56f457b

Please sign in to comment.