use of com.evolveum.midpoint.gui.api.page.PageBase in project midpoint by Evolveum.
the class OperationResultPanel method createMessage.
private Label createMessage() {
Label message = new Label(ID_MESSAGE_LABEL, (IModel<String>) () -> {
OpResult result = OperationResultPanel.this.getModel().getObject();
PageBase page = getPageBase();
String msg = null;
if (result.getUserFriendlyMessage() != null) {
// TODO: unify with WebModelServiceUtil.translateMessage()
LocalizationService service = page.getLocalizationService();
Locale locale = page.getSession().getLocale();
msg = service.translate(result.getUserFriendlyMessage(), locale);
}
if (StringUtils.isNotBlank(msg)) {
return msg;
}
msg = result.getMessage();
if (StringUtils.isNotBlank(msg)) {
return msg;
}
String resourceKey = OPERATION_RESOURCE_KEY_PREFIX + result.getOperation();
return page.getString(resourceKey, null, result.getOperation());
});
message.setOutputMarkupId(true);
return message;
}
use of com.evolveum.midpoint.gui.api.page.PageBase in project midpoint by Evolveum.
the class PasswordPanel method initLayout.
private <F extends FocusType> void initLayout(final boolean isReadOnly, PrismObject<F> object) {
setOutputMarkupId(true);
final WebMarkupContainer inputContainer = new WebMarkupContainer(ID_INPUT_CONTAINER) {
private static final long serialVersionUID = 1L;
@Override
public boolean isVisible() {
return passwordInputVisible;
}
};
inputContainer.setOutputMarkupId(true);
add(inputContainer);
ValuePolicyType valuePolicy = getValuePolicy(object);
LoadableModel<List<StringLimitationResult>> limitationsModel = new LoadableModel<>() {
@Override
protected List<StringLimitationResult> load() {
return getLimitationsForActualPassword(valuePolicy, object);
}
};
final PasswordLimitationsPanel validationPanel = new PasswordLimitationsPanel(ID_VALIDATION_PANEL, limitationsModel);
validationPanel.setOutputMarkupId(true);
inputContainer.add(validationPanel);
final PasswordTextField password1 = new SecureModelPasswordTextField(ID_PASSWORD_ONE, new PasswordModel(model)) {
private static final long serialVersionUID = 1L;
@Override
protected void onComponentTag(ComponentTag tag) {
super.onComponentTag(tag);
if (clearPasswordInput) {
tag.remove("value");
}
}
};
password1.add(AttributeAppender.append("onfocus", "initPasswordValidation({\n" + "container: $('#progress-bar-container'),\n" + "hierarchy: {\n" + " '0': ['progress-bar-danger', '" + PageBase.createStringResourceStatic(null, "PasswordPanel.strength.veryWeak").getString() + "'],\n" + " '25': ['progress-bar-danger', '" + PageBase.createStringResourceStatic(null, "PasswordPanel.strength.weak").getString() + "'],\n" + " '50': ['progress-bar-warning', '" + PageBase.createStringResourceStatic(null, "PasswordPanel.strength.good").getString() + "'],\n" + " '75': ['progress-bar-success', '" + PageBase.createStringResourceStatic(null, "PasswordPanel.strength.strong").getString() + "'],\n" + " '100': ['progress-bar-success', '" + PageBase.createStringResourceStatic(null, "PasswordPanel.strength.veryStrong").getString() + "']\n" + "}\n" + "})"));
password1.setRequired(false);
password1.setOutputMarkupId(true);
password1.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
inputContainer.add(password1);
final PasswordTextField password2 = new SecureModelPasswordTextField(ID_PASSWORD_TWO, new PasswordModel(Model.of(new ProtectedStringType())));
password2.setRequired(false);
password2.setOutputMarkupId(true);
inputContainer.add(password2);
password1.add(new AjaxFormComponentUpdatingBehavior("change") {
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
boolean required = !StringUtils.isEmpty(password1.getModelObject());
password2.setRequired(required);
changePasswordPerformed();
}
});
IModel<String> password2ValidationModel = (IModel<String>) () -> {
String s1 = password1.getModelObject();
String s2 = password2.getValue();
if (StringUtils.isEmpty(s1) || StringUtils.isEmpty(s2)) {
return "";
}
if (!Objects.equals(s1, s2)) {
return PageBase.createStringResourceStatic(null, "passwordPanel.error").getString();
}
return "";
};
Label password2ValidationMessage = new Label(ID_PASSWORD_TWO_VALIDATION_MESSAGE, password2ValidationModel);
password2ValidationMessage.setOutputMarkupId(true);
inputContainer.add(password2ValidationMessage);
password1.add(new AjaxFormComponentUpdatingBehavior("keyup input") {
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
limitationsModel.reset();
validationPanel.refreshItems(target);
updatePasswordValidation(target);
target.add(password2ValidationMessage);
}
@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
super.updateAjaxAttributes(attributes);
attributes.setThrottlingSettings(new ThrottlingSettings(Duration.ofMillis(500), true));
attributes.setChannel(new AjaxChannel("Drop", AjaxChannel.Type.DROP));
}
});
PasswordValidator pass2Validator = new PasswordValidator(password1);
password2.add(pass2Validator);
password2.add(new AjaxFormComponentUpdatingBehavior("keyup input") {
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
target.add(password2ValidationMessage);
}
@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
super.updateAjaxAttributes(attributes);
attributes.setThrottlingSettings(new ThrottlingSettings(Duration.ofMillis(500), true));
attributes.setChannel(new AjaxChannel("Drop", AjaxChannel.Type.DROP));
}
});
final WebMarkupContainer linkContainer = new WebMarkupContainer(ID_LINK_CONTAINER) {
private static final long serialVersionUID = 1L;
@Override
public boolean isVisible() {
return !passwordInputVisible;
}
};
inputContainer.setOutputMarkupId(true);
linkContainer.setOutputMarkupId(true);
add(linkContainer);
final Label passwordSetLabel = new Label(ID_PASSWORD_SET, new ResourceModel("passwordPanel.passwordSet"));
linkContainer.add(passwordSetLabel);
final Label passwordRemoveLabel = new Label(ID_PASSWORD_REMOVE, new ResourceModel("passwordPanel.passwordRemoveLabel"));
passwordRemoveLabel.setVisible(false);
linkContainer.add(passwordRemoveLabel);
AjaxLink<Void> link = new AjaxLink<Void>(ID_CHANGE_PASSWORD_LINK) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
clearPasswordInput = true;
setPasswordInput = false;
onLinkClick(target);
}
@Override
public boolean isVisible() {
return !passwordInputVisible && model != null && model.getObject() != null;
}
};
link.add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;
@Override
public boolean isVisible() {
return !isReadOnly;
}
});
link.setBody(new ResourceModel("passwordPanel.passwordChange"));
link.setOutputMarkupId(true);
linkContainer.add(link);
final WebMarkupContainer removeButtonContainer = new WebMarkupContainer(ID_REMOVE_BUTTON_CONTAINER);
AjaxLink<Void> removePassword = new AjaxLink<Void>(ID_REMOVE_PASSWORD_LINK) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
onRemovePassword(model, target);
}
};
removePassword.add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;
@Override
public boolean isVisible() {
PageBase pageBase = getPageBase();
if (pageBase == null) {
return false;
}
if (pageBase instanceof PageUserSelfProfile || pageBase instanceof PageOrgSelfProfile || pageBase instanceof PageRoleSelfProfile || pageBase instanceof PageServiceSelfProfile) {
return false;
}
if (pageBase instanceof PageAdminFocus && !((PageAdminFocus) pageBase).isLoggedInFocusPage() && model.getObject() != null) {
return true;
}
return false;
}
});
removePassword.setBody(new ResourceModel("passwordPanel.passwordRemove"));
removePassword.setOutputMarkupId(true);
removeButtonContainer.add(removePassword);
add(removeButtonContainer);
}
use of com.evolveum.midpoint.gui.api.page.PageBase in project midpoint by Evolveum.
the class TreeTablePanel method deleteNodeConfirmedPerformed.
private void deleteNodeConfirmedPerformed(SelectableBeanImpl<OrgType> orgToDelete, AjaxRequestTarget target) {
OperationResult result = new OperationResult(OPERATION_DELETE_OBJECT);
PageBase page = getPageBase();
if (orgToDelete == null) {
orgToDelete = getTreePanel().getRootFromProvider();
}
if (orgToDelete.getValue() == null) {
return;
}
if (CollectionUtils.isEmpty(orgToDelete.getValue().getParentOrgRef())) {
OrgTreeStateStorage storage = getTreePanel().getOrgTreeStateStorage();
if (storage != null) {
storage.setSelectedTabId(-1);
}
getTreePanel().setSelectedItem(null, storage);
}
String oidToDelete = orgToDelete.getValue().getOid();
WebModelServiceUtils.deleteObject(OrgType.class, oidToDelete, result, page);
result.computeStatusIfUnknown();
page.showResult(result);
target.add(getPageBase().getFeedbackPanel());
// TODO is this ok? [pmed]
throw new RestartResponseException(getPage().getClass());
}
use of com.evolveum.midpoint.gui.api.page.PageBase in project midpoint by Evolveum.
the class PageSecurityQuestions method resetPassword.
private void resetPassword(UserType user, AjaxRequestTarget target) {
Task task = createAnonymousTask(OPERATION_RESET_PASSWORD);
OperationResult result = task.getResult();
LOGGER.debug("Resetting password for {}", user);
ProtectedStringType password = new ProtectedStringType();
PrismObject<SystemConfigurationType> systemConfig = null;
String newPassword = "";
PageBase page = (PageBase) getPage();
ModelService modelService = page.getModelService();
try {
systemConfig = modelService.getObject(SystemConfigurationType.class, SystemObjectsType.SYSTEM_CONFIGURATION.value(), null, task, result);
LOGGER.trace("system config {}", systemConfig);
CredentialsPolicyType credentialsPolicy = getModelInteractionService().getCredentialsPolicy(user.asPrismObject(), task, result);
String policyOid = null;
if (credentialsPolicy != null && credentialsPolicy.getPassword() != null) {
if (credentialsPolicy.getPassword().getValuePolicyRef() != null) {
policyOid = credentialsPolicy.getPassword().getValuePolicyRef().getOid();
}
}
if (policyOid == null) {
warn(getString("pageSecurityQuestions.message.noPolicySet"));
target.add(getFeedbackPanel());
return;
}
PrismObject<ValuePolicyType> valPolicy = modelService.getObject(ValuePolicyType.class, policyOid, null, task, result);
LOGGER.trace("password value policy {}", valPolicy);
newPassword = getModelInteractionService().generateValue(valPolicy.asObjectable(), valPolicy.asObjectable().getStringPolicy().getLimitations().getMinLength(), false, user.asPrismObject(), "security questions password generation", task, result);
} catch (CommonException e1) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't reset password", e1);
}
password.setClearValue(newPassword);
WebComponentUtil.encryptProtectedString(password, true, getMidpointApplication());
final ItemPath valuePath = ItemPath.create(SchemaConstantsGenerated.C_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_VALUE);
SchemaRegistry registry = getPrismContext().getSchemaRegistry();
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<>();
PrismObjectDefinition objDef = registry.findObjectDefinitionByCompileTimeClass(UserType.class);
PropertyDelta delta = getPrismContext().deltaFactory().property().createModificationReplaceProperty(valuePath, objDef, password);
Class<? extends ObjectType> type = UserType.class;
deltas.add(getPrismContext().deltaFactory().object().createModifyDelta(user.getOid(), delta, type));
try {
modelService.executeChanges(deltas, null, task, result);
OperationResult parentResult = new OperationResult(OPERATION_LOAD_RESET_PASSWORD_POLICY);
try {
// TODO should we really ignore user-specific security policy?
CredentialsPolicyType globalCredentialsPolicy = getModelInteractionService().getCredentialsPolicy(null, null, parentResult);
CredentialsResetTypeType resetType = globalCredentialsPolicy != null && globalCredentialsPolicy.getSecurityQuestions() != null && globalCredentialsPolicy.getSecurityQuestions().getResetMethod() != null ? globalCredentialsPolicy.getSecurityQuestions().getResetMethod().getResetType() : null;
if (resetType == null || resetType == CredentialsResetTypeType.SECURITY_QUESTIONS) {
getSession().setAttribute("pwdReset", newPassword);
setResponsePage(PageShowPassword.class);
} else if (resetType == CredentialsResetTypeType.SECURITY_QUESTIONS_EMAIL) {
// not checked
if (systemConfig.asObjectable().getNotificationConfiguration() != null && systemConfig.asObjectable().getNotificationConfiguration().getMail() != null) {
MailConfigurationType mailConfig = systemConfig.asObjectable().getNotificationConfiguration().getMail();
if (mailConfig.getServer() != null) {
List serverList = mailConfig.getServer();
if (serverList.size() > 0) {
MailServerConfigurationType mailServerType = mailConfig.getServer().get(0);
sendMailToUser(mailServerType.getUsername(), getMidpointApplication().getProtector().decryptString(mailServerType.getPassword()), newPassword, mailServerType.getHost(), mailServerType.getPort().toString(), mailConfig.getDefaultFrom(), user.getEmailAddress());
} else {
getSession().error(getString("pageLogin.message.ForgetPasswordSettingsWrong"));
throw new RestartResponseException(PageLogin.class);
}
} else {
getSession().error(getString("pageLogin.message.ForgetPasswordSettingsWrong"));
throw new RestartResponseException(PageLogin.class);
}
} else {
getSession().error(getString("pageLogin.message.ForgetPasswordSettingsWrong"));
throw new RestartResponseException(PageLogin.class);
}
}
} catch (ObjectNotFoundException | SchemaException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// TODO ASAP a message should be shown as the result of the process
// MailMessage mailMessage=new MailMessage(, port);
// mailTransport.send(mailMessage, transportName, task,
// parentResult);
} catch (ObjectAlreadyExistsException | ObjectNotFoundException | SchemaException | ExpressionEvaluationException | CommunicationException | ConfigurationException | PolicyViolationException | SecurityViolationException | EncryptionException e) {
LoggingUtils.logUnexpectedException(LOGGER, "reset password exception", e);
}
}
use of com.evolveum.midpoint.gui.api.page.PageBase in project midpoint by Evolveum.
the class ResourceDetailsTabPanel method taskDetailsPerformed.
private void taskDetailsPerformed(AjaxRequestTarget target, String taskOid) {
PageParameters parameters = new PageParameters();
parameters.add(OnePageParameterEncoder.PARAMETER, taskOid);
((PageBase) getPage()).navigateToNext(PageTask.class, parameters);
}
Aggregations