Skip to content

Commit

Permalink
Supporting mustChangePassword for User templates
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgrosso committed Aug 9, 2023
1 parent 6629542 commit ba12ccd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.syncope.client.ui.commons.Constants;
import org.apache.syncope.client.ui.commons.ajax.markup.html.LabelInfo;
import org.apache.syncope.client.ui.commons.markup.html.form.AjaxCheckBoxPanel;
import org.apache.syncope.client.ui.commons.markup.html.form.AjaxTextFieldPanel;
import org.apache.syncope.client.ui.commons.wicket.markup.html.bootstrap.tabs.Accordion;
import org.apache.syncope.client.ui.commons.wizards.any.PasswordPanel;
Expand All @@ -43,25 +44,22 @@ public class UserDetails extends Details<UserTO> {

private static final long serialVersionUID = 6592027822510220463L;

private static final String PASSWORD_CONTENT_PATH = "body:content";

protected final AjaxTextFieldPanel username;

protected final UserTO userTO;

public UserDetails(
final UserWrapper wrapper,
final boolean templateMode,
final boolean includeStatusPanel,
final boolean showPasswordManagement,
final PageReference pageRef) {

super(wrapper, templateMode, includeStatusPanel, pageRef);

userTO = wrapper.getInnerObject();
UserTO userTO = wrapper.getInnerObject();

// ------------------------
// Username
// ------------------------
username = new AjaxTextFieldPanel(Constants.USERNAME_FIELD_NAME, Constants.USERNAME_FIELD_NAME,
AjaxTextFieldPanel username = new AjaxTextFieldPanel(
Constants.USERNAME_FIELD_NAME, Constants.USERNAME_FIELD_NAME,
new PropertyModel<>(userTO, Constants.USERNAME_FIELD_NAME), false);

if (wrapper.getPreviousUserTO() != null && StringUtils.compare(
Expand All @@ -78,6 +76,15 @@ public UserDetails(
add(username);
// ------------------------

// ------------------------
// mustChangePassword
// ------------------------
AjaxCheckBoxPanel mustChangePassword = new AjaxCheckBoxPanel(
"mustChangePassword", "mustChangePassword", new PropertyModel<>(userTO, "mustChangePassword"));

add(mustChangePassword.setOutputMarkupPlaceholderTag(true).setVisible(templateMode));
// ------------------------

// ------------------------
// Password
// ------------------------
Expand Down Expand Up @@ -107,7 +114,7 @@ protected Component newTitle(final String markupId, final ITab tab, final Accord
@Override
public void onClick(final AjaxRequestTarget target) {
model.setObject(model.getObject() == 0 ? -1 : 0);
Component passwordPanel = getParent().get(PASSWORD_CONTENT_PATH);
Component passwordPanel = getParent().get("body:content");
passwordPanel.setEnabled(model.getObject() >= 0);
target.add(passwordPanel);
}
Expand All @@ -118,7 +125,7 @@ public void onClick(final AjaxRequestTarget target) {
accordion.setOutputMarkupId(true);
accordion.setVisible(showPasswordManagement);
add(accordion);
// ------------------------
// ------------------------
}

@Override
Expand All @@ -130,10 +137,7 @@ public static class EditUserPasswordPanel extends Panel {

private static final long serialVersionUID = -8198836979773590078L;

public EditUserPasswordPanel(
final String id,
final UserWrapper wrapper,
final boolean templateMode) {
public EditUserPasswordPanel(final String id, final UserWrapper wrapper, final boolean templateMode) {
super(id);
setOutputMarkupId(true);
add(new Label("warning", new ResourceModel("password.change.warning")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
<span wicket:id="username"/>
</div>

<div class="form-group">
<span wicket:id="mustChangePassword"/>
</div>

<div wicket:id="accordionPanel"></div>
</wicket:extend>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ public void apply(final RealmMember realmMember, final AnyTO template) {
}
}

if (((UserTO) template).isMustChangePassword()) {
if (realmMember instanceof UserTO) {
((UserTO) realmMember).setMustChangePassword(true);
} else if (realmMember instanceof UserCR) {
((UserCR) realmMember).setMustChangePassword(true);
}
}

fillRelationships((GroupableRelatableTO) realmMember, ((GroupableRelatableTO) template));
fillMemberships((GroupableRelatableTO) realmMember, ((GroupableRelatableTO) template));

Expand Down

0 comments on commit ba12ccd

Please sign in to comment.