Skip to content

Commit

Permalink
small fixes for PageSecurityQuestions
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Dec 6, 2022
1 parent c6a9f29 commit 1f7033a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,13 @@ public void renderHead(IHeaderResponse response) {
@Override
protected void onInitialize() {
super.onInitialize();
initModels();
initLayout();
}

protected void initModels() {
}

private void initLayout() {
String sequenceName = getSequenceName();
Label sequence = new Label(ID_SEQUENCE, createStringResource("AbstractPageLogin.authenticationSequence", sequenceName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,13 @@ public class PageSecurityQuestions extends PageAuthenticationBase {
private static final String ID_BACK_2_BUTTON = "back2";

private IModel<String> answerModel;
private IModel<List<SecurityQuestionDto>> questionsModel;
private LoadableDetachableModel<List<SecurityQuestionDto>> questionsModel;
private LoadableDetachableModel<UserType> userModel;

public PageSecurityQuestions() {
initModels();
}

private void initModels() {
protected void initModels() {
answerModel = Model.of();
userModel = new LoadableDetachableModel<>() {
@Override
Expand All @@ -100,7 +99,12 @@ protected UserType load() {
return principal != null ? (UserType) principal.getFocus() : PageSecurityQuestions.this.searchUser();
}
};
questionsModel = new ListModel<>(createUsersSecurityQuestionsList());
questionsModel = new LoadableDetachableModel<List<SecurityQuestionDto>>() {
@Override
protected List<SecurityQuestionDto> load() {
return createUsersSecurityQuestionsList();
}
};
}

@Override
Expand Down Expand Up @@ -227,18 +231,14 @@ protected void onSubmit(AjaxRequestTarget target) {
private void initStaticLayout(MidpointForm<?> form) {
RequiredTextField<String> visibleUsername = new RequiredTextField<>(ID_USERNAME, new Model<>());
visibleUsername.setOutputMarkupId(true);
visibleUsername.add(new VisibleEnableBehaviour() {

private static final long serialVersionUID = 1L;

@Override
public boolean isVisible() {
return userModel.getObject() == null && !isDynamicForm();
}
});
visibleUsername.add(new VisibleBehaviour(() -> !isUserDefined() && !isDynamicForm()));
form.add(visibleUsername);
}

private boolean isUserDefined() {
return userModel.getObject() != null;
}

private void showQuestions(AjaxRequestTarget target) {
UserType user = userModel.getObject();

Expand All @@ -254,6 +254,10 @@ private void showQuestions(AjaxRequestTarget target) {
private List<SecurityQuestionDto> createUsersSecurityQuestionsList() {
UserType user = userModel.getObject();

if (user == null) {
return new ArrayList<>();
}

SecurityQuestionsCredentialsType credentialsPolicyType = user.getCredentials()
.getSecurityQuestions();
if (credentialsPolicyType == null || credentialsPolicyType.getQuestionAnswer() == null
Expand Down

0 comments on commit 1f7033a

Please sign in to comment.