use of org.apache.wicket.markup.html.form.PasswordTextField in project midpoint by Evolveum.
the class PasswordPanel method initLayout.
private void initLayout(final IModel<ProtectedStringType> model, final boolean isReadOnly) {
setOutputMarkupId(true);
final WebMarkupContainer inputContainer = new WebMarkupContainer(ID_INPUT_CONTAINER) {
@Override
public boolean isVisible() {
return passwordInputVisble;
}
};
inputContainer.setOutputMarkupId(true);
add(inputContainer);
final PasswordTextField password1 = new PasswordTextField(ID_PASSWORD_ONE, new PasswordModel(model));
password1.setRequired(false);
password1.setResetPassword(false);
password1.setOutputMarkupId(true);
password1.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
inputContainer.add(password1);
final PasswordTextField password2 = new PasswordTextField(ID_PASSWORD_TWO, new Model<String>());
password2.setRequired(false);
password2.setResetPassword(false);
password2.setOutputMarkupId(true);
password2.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
inputContainer.add(password2);
password1.add(new AjaxFormComponentUpdatingBehavior("change") {
@Override
protected void onUpdate(AjaxRequestTarget target) {
boolean required = !StringUtils.isEmpty(password1.getModel().getObject());
password2.setRequired(required);
//fix of MID-2463
// target.add(password2);
// target.appendJavaScript("$(\"#"+ password2.getMarkupId() +"\").focus()");
}
});
password2.add(new PasswordValidator(password1, password2));
final WebMarkupContainer linkContainer = new WebMarkupContainer(ID_LINK_CONTAINER) {
@Override
public boolean isVisible() {
return !passwordInputVisble;
}
};
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 link = new AjaxLink(ID_CHANGE_PASSWORD_LINK) {
@Override
public void onClick(AjaxRequestTarget target) {
onLinkClick(target);
}
@Override
public boolean isVisible() {
return !passwordInputVisble;
}
};
link.add(new VisibleEnableBehaviour() {
@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 removePassword = new AjaxLink(ID_REMOVE_PASSWORD_LINK) {
@Override
public void onClick(AjaxRequestTarget target) {
onRemovePassword(model, target);
}
};
removePassword.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
PageBase pageBase = (PageBase) getPage();
if (pageBase == null) {
return false;
}
if (pageBase instanceof PageSelfProfile) {
return false;
}
if (pageBase instanceof PageUser && model.getObject() != null && !model.getObject().isEmpty()) {
return true;
}
return false;
}
});
removePassword.setBody(new ResourceModel("passwordPanel.passwordRemove"));
removePassword.setOutputMarkupId(true);
removeButtonContainer.add(removePassword);
add(removeButtonContainer);
}
use of org.apache.wicket.markup.html.form.PasswordTextField in project midpoint by Evolveum.
the class ChangePasswordPanel method initLayout.
private void initLayout(final boolean oldPasswordVisible) {
model = (LoadableModel<MyPasswordsDto>) getModel();
Label oldPasswordLabel = new Label(ID_OLD_PASSWORD_LABEL, createStringResource("PageSelfCredentials.oldPasswordLabel"));
add(oldPasswordLabel);
oldPasswordLabel.add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;
@Override
public boolean isVisible() {
return oldPasswordVisible;
}
});
Label passwordLabel = new Label(ID_PASSWORD_LABEL, createStringResource("PageSelfCredentials.passwordLabel1"));
add(passwordLabel);
PasswordTextField oldPasswordField = new PasswordTextField(ID_OLD_PASSWORD_FIELD, new PropertyModel<String>(model, MyPasswordsDto.F_OLD_PASSWORD));
oldPasswordField.setRequired(false);
oldPasswordField.setResetPassword(false);
add(oldPasswordField);
oldPasswordField.add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;
public boolean isVisible() {
return oldPasswordVisible;
}
;
});
PasswordPanel passwordPanel = new PasswordPanel(ID_PASSWORD_PANEL, new PropertyModel<ProtectedStringType>(model, MyPasswordsDto.F_PASSWORD));
passwordPanel.getBaseFormComponent().add(new AttributeModifier("autofocus", ""));
add(passwordPanel);
WebMarkupContainer accountContainer = new WebMarkupContainer(ID_ACCOUNTS_CONTAINER);
List<IColumn<PasswordAccountDto, String>> columns = initColumns();
ListDataProvider<PasswordAccountDto> provider = new ListDataProvider<PasswordAccountDto>(this, new PropertyModel<List<PasswordAccountDto>>(model, MyPasswordsDto.F_ACCOUNTS));
TablePanel accounts = new TablePanel(ID_ACCOUNTS_TABLE, provider, columns);
accounts.setItemsPerPage(30);
accounts.setShowPaging(false);
if (model.getObject().getPropagation() != null && model.getObject().getPropagation().equals(CredentialsPropagationUserControlType.MAPPING)) {
accountContainer.setVisible(false);
}
accountContainer.add(accounts);
AjaxLink help = new AjaxLink(ID_BUTTON_HELP) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
showHelpPerformed(target);
}
};
accountContainer.add(help);
add(accountContainer);
}
use of org.apache.wicket.markup.html.form.PasswordTextField in project midpoint by Evolveum.
the class PageAccountActivation method propagatePassword.
private void propagatePassword(AjaxRequestTarget target, Form<?> form) {
List<ShadowType> shadowsToActivate = getShadowsToActivate();
PasswordTextField passwordPanel = (PasswordTextField) form.get(createComponentPath(ID_PASSWORD));
String value = passwordPanel.getModelObject();
ConnectionEnvironment connEnv = ConnectionEnvironment.create(SchemaConstants.CHANNEL_GUI_USER_URI);
UsernamePasswordAuthenticationToken token;
try {
token = authenticationEvaluator.authenticate(connEnv, new PasswordAuthenticationContext(userModel.getObject().getName().getOrig(), value));
} catch (Exception ex) {
LOGGER.error("Failed to authenticate user, reason ", ex.getMessage());
getSession().error(getString("PageAccountActivation.authentication.failed"));
throw new RestartResponseException(PageAccountActivation.class, getPageParameters());
}
if (token == null) {
LOGGER.error("Failed to authenticate user");
getSession().error(getString("PageAccountActivation.authentication.failed"));
throw new RestartResponseException(PageAccountActivation.class, getPageParameters());
}
ProtectedStringType passwordValue = new ProtectedStringType();
passwordValue.setClearValue(value);
Collection<ObjectDelta<ShadowType>> passwordDeltas = new ArrayList<>(shadowsToActivate.size());
for (ShadowType shadow : shadowsToActivate) {
ObjectDelta<ShadowType> shadowDelta = ObjectDelta.createModificationReplaceProperty(ShadowType.class, shadow.getOid(), SchemaConstants.PATH_PASSWORD_VALUE, getPrismContext(), passwordValue);
shadowDelta.addModificationReplaceProperty(ShadowType.F_LIFECYCLE_STATE, SchemaConstants.LIFECYCLE_PROPOSED);
passwordDeltas.add(shadowDelta);
}
OperationResult result = runPrivileged(new Producer<OperationResult>() {
@Override
public OperationResult run() {
OperationResult result = new OperationResult(OPERATION_ACTIVATE_SHADOWS);
Task task = createAnonymousTask(OPERATION_ACTIVATE_SHADOWS);
WebModelServiceUtils.save((Collection) passwordDeltas, null, result, task, PageAccountActivation.this);
return result;
}
});
result.recomputeStatus();
if (!result.isSuccess()) {
getSession().error(getString("PageAccountActivation.account.activation.failed"));
LOGGER.error("Failed to acitvate accounts, reason: {} ", result.getMessage());
target.add(getFeedbackPanel());
} else {
getSession().success(getString("PageAccountActivation.account.activation.successful"));
target.add(getFeedbackPanel());
activated = true;
}
target.add(PageAccountActivation.this);
}
use of org.apache.wicket.markup.html.form.PasswordTextField in project midpoint by Evolveum.
the class NotificationConfigPanel method initLayout.
@Override
protected void initLayout() {
TextField<String> defaultFromField = WebComponentUtil.createAjaxTextField(ID_DEFAULT_FROM, new PropertyModel<String>(getModel(), "defaultFrom"));
CheckBox debugCheck = WebComponentUtil.createAjaxCheckBox(ID_DEBUG, new PropertyModel<Boolean>(getModel(), "debug"));
DropDownChoice mailServerConfigChooser = new DropDownChoice<>(ID_MAIL_SERVER, new PropertyModel<MailServerConfigurationTypeDto>(getModel(), NotificationConfigurationDto.F_SELECTED_SERVER), new AbstractReadOnlyModel<List<MailServerConfigurationTypeDto>>() {
@Override
public List<MailServerConfigurationTypeDto> getObject() {
return getModel().getObject().getServers();
}
}, new ChoiceableChoiceRenderer<MailServerConfigurationTypeDto>());
mailServerConfigChooser.setNullValid(true);
mailServerConfigChooser.add(new AjaxFormSubmitBehavior("click") {
@Override
protected void onEvent(AjaxRequestTarget target) {
getForm().onFormSubmitted();
}
});
mailServerConfigChooser.add(new OnChangeAjaxBehavior() {
@Override
protected void onUpdate(AjaxRequestTarget target) {
preparePasswordFieldPlaceholder();
target.add(NotificationConfigPanel.this);
}
});
add(mailServerConfigChooser);
Label serverConfigTooltip = new Label(ID_MAIL_SERVER_TOOLTIP);
serverConfigTooltip.add(new InfoTooltipBehavior());
add(serverConfigTooltip);
WebMarkupContainer serverConfigContainer = new WebMarkupContainer(ID_MAIL_SERVER_CONFIG_CONTAINER);
serverConfigContainer.setOutputMarkupId(true);
serverConfigContainer.setOutputMarkupPlaceholderTag(true);
serverConfigContainer.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
if (getModelObject() != null) {
return getModelObject().getSelectedServer() != null;
}
return false;
}
});
add(serverConfigContainer);
TextField<String> hostField = WebComponentUtil.createAjaxTextField(ID_HOST, new PropertyModel<String>(getModel(), "selectedServer.host"));
TextField<Integer> portField = WebComponentUtil.createAjaxTextField(ID_PORT, new PropertyModel<Integer>(getModel(), "selectedServer.port"));
TextField<String> userNameField = WebComponentUtil.createAjaxTextField(ID_USERNAME, new PropertyModel<String>(getModel(), "selectedServer.username"));
PasswordTextField passwordField = new PasswordTextField(ID_PASSWORD, new PropertyModel<String>(getModel(), "selectedServer.password"));
passwordField.setRequired(false);
passwordField.add(new EmptyOnChangeAjaxFormUpdatingBehavior());
TextField<String> redirectToFileField = WebComponentUtil.createAjaxTextField(ID_REDIRECT_TO_FILE, new PropertyModel<String>(getModel(), "redirectToFile"));
DropDownFormGroup transportSecurity = new DropDownFormGroup<>(ID_TRANSPORT_SECURITY, new PropertyModel<MailTransportSecurityType>(getModel(), "selectedServer.mailTransportSecurityType"), WebComponentUtil.createReadonlyModelFromEnum(MailTransportSecurityType.class), new EnumChoiceRenderer<MailTransportSecurityType>(this), createStringResource("SystemConfigPanel.mail.transportSecurity"), ID_LABEL_SIZE, ID_INPUT_SIZE, false);
// transportSecurity.add(new EmptyOnChangeAjaxFormUpdatingBehavior());
serverConfigContainer.add(hostField);
serverConfigContainer.add(portField);
serverConfigContainer.add(userNameField);
serverConfigContainer.add(passwordField);
serverConfigContainer.add(transportSecurity);
add(defaultFromField);
add(debugCheck);
add(redirectToFileField);
AjaxSubmitLink buttonAddNewMailServerConfig = new AjaxSubmitLink(ID_BUTTON_ADD_NEW_MAIL_SERVER_CONFIG) {
@Override
protected void onSubmit(AjaxRequestTarget target, org.apache.wicket.markup.html.form.Form<?> form) {
MailServerConfigurationTypeDto newConfig = new MailServerConfigurationTypeDto();
newConfig.setHost(getString("SystemConfigPanel.mail.config.placeholder"));
if (getModelObject() != null) {
getModelObject().getServers().add(newConfig);
getModelObject().setSelectedServer(newConfig);
}
preparePasswordFieldPlaceholder();
target.add(NotificationConfigPanel.this, getPageBase().getFeedbackPanel());
}
@Override
protected void onError(AjaxRequestTarget target, org.apache.wicket.markup.html.form.Form<?> form) {
target.add(getPageBase().getFeedbackPanel());
}
};
add(buttonAddNewMailServerConfig);
AjaxSubmitLink removeMailServerConfig = new AjaxSubmitLink(ID_BUTTON_REMOVE_MAIL_SERVER_CONFIG) {
@Override
protected void onSubmit(AjaxRequestTarget target, org.apache.wicket.markup.html.form.Form<?> form) {
if (getModelObject() != null) {
NotificationConfigurationDto notificationConfig = getModelObject();
MailServerConfigurationTypeDto selected = notificationConfig.getSelectedServer();
if (notificationConfig.getServers().contains(selected)) {
notificationConfig.getServers().remove(selected);
notificationConfig.setSelectedServer(null);
} else {
warn(getString("SystemConfigPanel.mail.server.remove.warn"));
}
target.add(NotificationConfigPanel.this, getPageBase().getFeedbackPanel());
}
}
@Override
protected void onError(AjaxRequestTarget target, org.apache.wicket.markup.html.form.Form<?> form) {
target.add(getPageBase().getFeedbackPanel());
}
};
removeMailServerConfig.add(new AttributeAppender("class", new AbstractReadOnlyModel<String>() {
@Override
public String getObject() {
if (getModelObject() != null && getModelObject().getSelectedServer() != null) {
return null;
} else {
return " disabled";
}
}
}));
add(removeMailServerConfig);
}
use of org.apache.wicket.markup.html.form.PasswordTextField in project midpoint by Evolveum.
the class PageAccountActivation method initLayout.
private void initLayout() {
WebMarkupContainer activationContainer = new WebMarkupContainer(ID_ACTIVATION_CONTAINER);
activationContainer.setOutputMarkupId(true);
add(activationContainer);
activationContainer.add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;
@Override
public boolean isVisible() {
return !activated;
}
});
Form form = new Form<>(ID_MAIN_FORM);
activationContainer.add(form);
Label usernamePanel = new Label(ID_NAME, createStringResource("PageAccountActivation.activate.accounts.label", new PropertyModel<>(userModel, "name.orig")));
usernamePanel.add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;
@Override
public boolean isEnabled() {
return false;
}
});
form.add(usernamePanel);
PasswordTextField passwordPanel = new PasswordTextField(ID_PASSWORD, Model.of(new String()));
form.add(passwordPanel);
AjaxSubmitButton confirmPasswrod = new AjaxSubmitButton(ID_CONFIRM) {
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
propagatePassword(target, form);
}
@Override
protected void onError(AjaxRequestTarget target, Form<?> form) {
getSession().error(getString("PageAccountActivation.account.activation.failed"));
target.add(getFeedbackPanel());
}
};
form.add(confirmPasswrod);
WebMarkupContainer confirmationContainer = new WebMarkupContainer(ID_CONFIRMATION_CONTAINER);
confirmationContainer.setOutputMarkupId(true);
confirmationContainer.add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;
@Override
public boolean isVisible() {
return activated;
}
});
add(confirmationContainer);
AjaxLink<Void> linkToLogin = new AjaxLink<Void>(ID_LINK_TO_LOGIN) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
setResponsePage(PageLogin.class);
}
};
confirmationContainer.add(linkToLogin);
RepeatingView activatedShadows = new RepeatingView(ID_ACTIVATED_SHADOWS);
confirmationContainer.add(activatedShadows);
List<ShadowType> shadowsToActivate = getShadowsToActivate();
if (shadowsToActivate.isEmpty()) {
LOGGER.error("No accounts to validate for user {}", userModel.getObject());
getSession().warn(getString("PageAccountActivation.nothing.to.activate"));
throw new RestartResponseException(PageLogin.class);
}
for (ShadowType shadow : shadowsToActivate) {
Label shadowDesc = new Label(activatedShadows.newChildId(), WebComponentUtil.getName(shadow) + " on resource " + WebComponentUtil.getName(shadow.getResourceRef()));
activatedShadows.add(shadowDesc);
}
}
Aggregations