Skip to content

Commit

Permalink
new classes for change password panel
Browse files Browse the repository at this point in the history
  • Loading branch information
Kateryna Honchar committed May 31, 2022
1 parent aa41606 commit 4cae577
Show file tree
Hide file tree
Showing 9 changed files with 637 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.gui.api.factory.wrapper.PrismObjectWrapperFactory;
import com.evolveum.midpoint.gui.api.page.PageAdminLTE;

import com.evolveum.midpoint.gui.api.prism.ItemStatus;
import com.evolveum.midpoint.web.page.admin.users.dto.UserDtoStatus;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.LocaleUtils;
import org.apache.commons.lang3.StringEscapeUtils;
Expand Down Expand Up @@ -5185,6 +5189,88 @@ public static CredentialsPolicyType getPasswordCredentialsPolicy(PrismObject<? e
return credentialsPolicyType;
}

public static <F extends FocusType> List<ShadowWrapper> loadShadowWrapperList(PrismObject<F> focus,
Collection<SelectorOptions<GetOperationOptions>> loadOptions, Task task, PageBase pageBase) {
LOGGER.trace("Loading shadow wrapper");
long start = System.currentTimeMillis();

List<ShadowWrapper> list = new ArrayList<>();
PrismReference prismReference = focus.findReference(UserType.F_LINK_REF);
if (prismReference == null || prismReference.isEmpty()) {
return new ArrayList<>();
}
List<PrismReferenceValue> references = prismReference.getValues();

for (PrismReferenceValue reference : references) {
if (reference == null || (reference.getOid() == null && reference.getTargetType() == null)) {
LOGGER.trace("Skiping reference for shadow with null oid");
continue; // default value
}
long shadowTimestampBefore = System.currentTimeMillis();
OperationResult subResult = task.getResult().createMinorSubresult(task.getTaskIdentifier());
PrismObject<ShadowType> projection = getPrismObjectForShadowWrapper(reference.getOid(),
true, task, subResult, loadOptions, pageBase);

long shadowTimestampAfter = System.currentTimeMillis();
LOGGER.trace("Got shadow: {} in {}", projection, shadowTimestampAfter - shadowTimestampBefore);
if (projection == null) {
LOGGER.error("Couldn't load shadow projection");
continue;
}

long timestampWrapperStart = System.currentTimeMillis();
try {

ShadowWrapper wrapper = loadShadowWrapper(projection, true, task, subResult, pageBase);
wrapper.setLoadWithNoFetch(true);
list.add(wrapper);

} catch (Throwable e) {
pageBase.showResult(subResult, "pageAdminFocus.message.couldntCreateShadowWrapper");
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't create shadow wrapper", e);
}
long timestampWrapperEnd = System.currentTimeMillis();
LOGGER.trace("Load wrapper in {}", timestampWrapperEnd - timestampWrapperStart);
}
long end = System.currentTimeMillis();
LOGGER.trace("Load projctions in {}", end - start);
return list;
}

@NotNull
public static ShadowWrapper loadShadowWrapper(PrismObject<ShadowType> projection, boolean noFetch, Task task,
OperationResult result, PageBase pageBase) throws SchemaException {
PrismObjectWrapperFactory<ShadowType> factory = pageBase.findObjectWrapperFactory(projection.getDefinition());
WrapperContext context = new WrapperContext(task, result);
context.setCreateIfEmpty(noFetch ? false : true);
ShadowWrapper wrapper = (ShadowWrapper) factory.createObjectWrapper(projection, ItemStatus.NOT_CHANGED, context);
wrapper.setProjectionStatus(UserDtoStatus.MODIFY);
return wrapper;
}

private static PrismObject<ShadowType> getPrismObjectForShadowWrapper(String oid, boolean noFetch,
Task task, OperationResult subResult, Collection<SelectorOptions<GetOperationOptions>> loadOptions, PageBase pageBase) {
if (oid == null) {
return null;
}

if (noFetch) {
GetOperationOptions rootOptions = SelectorOptions.findRootOptions(loadOptions);
if (rootOptions == null) {
loadOptions.add(new SelectorOptions<>(GetOperationOptions.createNoFetch()));
} else {
rootOptions.setNoFetch(true);
}
}

PrismObject<ShadowType> projection = WebModelServiceUtils.loadObject(ShadowType.class, oid, loadOptions, pageBase, task, subResult);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Loaded projection {} ({}):\n{}", oid, loadOptions, projection == null ? null : projection.debugDump());
}

return projection;
}

@Contract("_,true->!null")
public static Long getTimestampAsLong(XMLGregorianCalendar cal, boolean currentIfNull) {
Long calAsLong = MiscUtil.asLong(cal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ private SideBarMenuItem createSelfServiceMenu(boolean experimentalFeaturesEnable
WebComponentUtil.resolveSelfPage(), pageParameters));
menu.addMainMenuItem(createMainMenuItem("PageAdmin.menu.credentials", GuiStyleConstants.CLASS_ICON_CREDENTIALS,
PageSelfCredentials.class));
menu.addMainMenuItem(createMainMenuItem("PageAdmin.menu.credentials", GuiStyleConstants.CLASS_ICON_CREDENTIALS,
com.evolveum.midpoint.gui.impl.page.self.credentials.PageSelfCredentials.class));
if (WebModelServiceUtils.getLoggedInFocus() instanceof UserType) {
menu.addMainMenuItem(createMainMenuItem("PageAdmin.menu.request", GuiStyleConstants.CLASS_ICON_REQUEST,
PageAssignmentShoppingCart.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,53 +74,10 @@ protected ExecuteChangeOptionsDto load() {
}

private List<ShadowWrapper> loadShadowWrappers() {
LOGGER.trace("Loading shadow wrapper");
long start = System.currentTimeMillis();
List<ShadowWrapper> list = new ArrayList<>();

Task task = getModelServiceLocator().createSimpleTask(OPERATION_LOAD_SHADOW);
PrismObjectWrapper<F> focusWrapper = getObjectWrapperModel().getObject();
PrismObject<F> focus = focusWrapper.getObject();
PrismReference prismReference = focus.findReference(UserType.F_LINK_REF);
if (prismReference == null || prismReference.isEmpty()) {
return new ArrayList<>();
}
List<PrismReferenceValue> references = prismReference.getValues();

Task task = getModelServiceLocator().createSimpleTask(OPERATION_LOAD_SHADOW);
for (PrismReferenceValue reference : references) {
if (reference == null || (reference.getOid() == null && reference.getTargetType() == null)) {
LOGGER.trace("Skiping reference for shadow with null oid");
continue; // default value
}
long shadowTimestampBefore = System.currentTimeMillis();
OperationResult subResult = task.getResult().createMinorSubresult(OPERATION_LOAD_SHADOW);
PrismObject<ShadowType> projection = getPrismObjectForShadowWrapper(reference.getOid(),
true, task, subResult, createLoadOptionForShadowWrapper());

long shadowTimestampAfter = System.currentTimeMillis();
LOGGER.trace("Got shadow: {} in {}", projection, shadowTimestampAfter - shadowTimestampBefore);
if (projection == null) {
LOGGER.error("Couldn't load shadow projection");
continue;
}

long timestampWrapperStart = System.currentTimeMillis();
try {

ShadowWrapper wrapper = loadShadowWrapper(projection, true, task, subResult);
wrapper.setLoadWithNoFetch(true);
list.add(wrapper);

} catch (Throwable e) {
getPageBase().showResult(subResult, "pageAdminFocus.message.couldntCreateShadowWrapper");
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't create shadow wrapper", e);
}
long timestampWrapperEnd = System.currentTimeMillis();
LOGGER.trace("Load wrapper in {}", timestampWrapperEnd - timestampWrapperStart);
}
long end = System.currentTimeMillis();
LOGGER.trace("Load projctions in {}", end - start);
return list;
return WebComponentUtil.loadShadowWrapperList(focus, createLoadOptionForShadowWrapper(), task, getPageBase());
}

private Collection<SelectorOptions<GetOperationOptions>> createLoadOptionForShadowWrapper() {
Expand All @@ -129,16 +86,6 @@ private Collection<SelectorOptions<GetOperationOptions>> createLoadOptionForShad
.build();
}

@NotNull
public ShadowWrapper loadShadowWrapper(PrismObject<ShadowType> projection, boolean noFetch, Task task, OperationResult result) throws SchemaException {
PrismObjectWrapperFactory<ShadowType> factory = getPageBase().findObjectWrapperFactory(projection.getDefinition());
WrapperContext context = new WrapperContext(task, result);
context.setCreateIfEmpty(noFetch ? false : true);
ShadowWrapper wrapper = (ShadowWrapper) factory.createObjectWrapper(projection, ItemStatus.NOT_CHANGED, context);
wrapper.setProjectionStatus(UserDtoStatus.MODIFY);
return wrapper;
}

public void setSelfProfile(boolean selfProfile) {
isSelfProfile = selfProfile;
}
Expand All @@ -147,28 +94,6 @@ public boolean isSelfProfile() {
return isSelfProfile;
}

private PrismObject<ShadowType> getPrismObjectForShadowWrapper(String oid, boolean noFetch,
Task task, OperationResult subResult, Collection<SelectorOptions<GetOperationOptions>> loadOptions) {
if (oid == null) {
return null;
}

if (noFetch) {
GetOperationOptions rootOptions = SelectorOptions.findRootOptions(loadOptions);
if (rootOptions == null) {
loadOptions.add(new SelectorOptions<>(GetOperationOptions.createNoFetch()));
} else {
rootOptions.setNoFetch(true);
}
}

PrismObject<ShadowType> projection = WebModelServiceUtils.loadObject(ShadowType.class, oid, loadOptions, getPageBase(), task, subResult);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Loaded projection {} ({}):\n{}", oid, loadOptions, projection == null ? null : projection.debugDump());
}

return projection;
}

public LoadableDetachableModel<List<ShadowWrapper>> getProjectionModel() {
return projectionModel;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!--
~ 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>
<html xmlns:wicket="http://wicket.apache.org">
<wicket:panel>
<div class="d-flex flex-wrap gap-2">
<div class="col-md-5">
<!-- <div class="mb-3 row" wicket:id="oldPasswordContainer">-->
<label class="col-form-label">
<wicket:message key="ChangePasswordPanel.currentPassword"/>
</label>
<div class="">
<div class="password-parent" style="height:30px; position: relative;">
<div class="col-md-12" style="padding: 0px !important;">
<input class="form-control form-control-sm" type="password" autocomplete="new-password" wicket:id="oldPassword" autofocus style="padding-right: 26px;"/>
</div>
<div style="position: absolute; right: 8px; top: 8px; z-index: 5;">
<i class="fa fa-eye" style="float:right;cursor: pointer; color: #555555;" onclick="MidPointTheme.showPassword(this)"></i>
</div>
</div>
</div>
<!-- </div>-->
<!-- <div class="mb-3 row">-->
<label class="col-form-label" wicket:id="passwordLabel"/>
<div class="">
<div class="password-panel" wicket:id="passwordPanel"/>
</div>
<!-- </div>-->
</div>
<div class="col-md-5">
<wicket:message key="ChangePasswordPanel.passwordRequirementsLabel" />
<div wicket:id="passwordValidationPanel"/>
</div>
</div>
</wicket:panel>
</html>

0 comments on commit 4cae577

Please sign in to comment.