Skip to content

Commit

Permalink
Pasword Reset enchancements
Browse files Browse the repository at this point in the history
  • Loading branch information
Sabria committed Apr 15, 2015
1 parent ab57b8a commit ca69c8d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
Expand Up @@ -7,6 +7,7 @@ PageBase.button.save=Save
PageBase.button.saveAndRun=Save & Run
PageBase.button.search=Search
PageBase.button.update=Update
PageBase.button.send=Send
PageBase.clearCssCache=Clear less/js cache
WorkItemsPanel.assigned=Assigned to
WorkItemsPanel.created=Created
Expand Down
Expand Up @@ -436,7 +436,7 @@ private void savePerformed(AjaxRequestTarget target) {
}

if(questionNumber==correctAnswers){
resetPassword(principalModel.getObject().asObjectable());
resetPassword(principalModel.getObject().asObjectable(),target);

}
else{
Expand Down Expand Up @@ -525,7 +525,7 @@ public PageBase getPageBase() {
return (PageBase) getPage();
}

private void resetPassword(UserType user){
private void resetPassword(UserType user,AjaxRequestTarget target){


Task task = createSimpleTask(OPERATION_RESET_PASSWORD);
Expand All @@ -539,14 +539,27 @@ private void resetPassword(UserType user){
String newPassword="";
PageBase page = (PageBase) getPage();

ModelService model = page.getModelService();
ModelService modelService = page.getModelService();
try {

systemConfig = model.getObject(SystemConfigurationType.class,
systemConfig = modelService.getObject(SystemConfigurationType.class,
SystemObjectsType.SYSTEM_CONFIGURATION.value(), options, task, result);
if(systemConfig.asObjectable().getNotificationConfiguration()!=null){
PrismObject<ValuePolicyType> valPolicy =model.getObject(ValuePolicyType.class, systemConfig.asObjectable().getGlobalPasswordPolicyRef().getOid(), options, task, result);
newPassword=ValuePolicyGenerator.generate(valPolicy.asObjectable().getStringPolicy(), valPolicy.asObjectable().getStringPolicy().getLimitations().getMinLength(), result);
//New password is automatically reset according to the global Security policy with the minumum number of chars
if (systemConfig.asObjectable().getGlobalPasswordPolicyRef()!=null)
{
PrismObject<ValuePolicyType> valPolicy =modelService.getObject(ValuePolicyType.class, systemConfig.asObjectable().getGlobalPasswordPolicyRef().getOid(), options, task, result);
newPassword=ValuePolicyGenerator.generate(valPolicy.asObjectable().getStringPolicy(), valPolicy.asObjectable().getStringPolicy().getLimitations().getMinLength(), result);
}
else{
//TODO What if there is no policy? What should be done to provide a new automatic password
warn(getString("pageSecurityQuestions.message.noPolicySet"));
target.add(getFeedbackPanel());
setAuthenticationNull();
return;
}



}else{
//TODO localization
Expand Down
Expand Up @@ -16,14 +16,18 @@

package com.evolveum.midpoint.web.page.login;

import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.security.api.AuthorizationConstants;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.web.application.AuthorizationAction;
import com.evolveum.midpoint.web.application.PageDescriptor;
import com.evolveum.midpoint.web.component.menu.top.LocalePanel;
import com.evolveum.midpoint.web.component.menu.top.TopMenuBar;
import com.evolveum.midpoint.web.page.PageBase;
import com.evolveum.midpoint.web.page.admin.home.PageDashboard;
import com.evolveum.midpoint.web.security.MidPointAuthWebSession;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SystemObjectsType;

import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.PasswordTextField;
Expand All @@ -42,12 +46,24 @@ public class PageLogin extends PageBase {
private static final String ID_USERNAME = "username";
private static final String ID_PASSWORD = "password";

protected static final String OPERATION_LOAD_RESET_PASSWORD_POLICY = "LOAD PASSWORD RESET POLICY";


public PageLogin() {
TopMenuBar menuBar = getTopMenuBar();
menuBar.addOrReplace(new LocalePanel(TopMenuBar.ID_RIGHT_PANEL));


Task task = getPageBase().createSimpleTask(OPERATION_LOAD_RESET_PASSWORD_POLICY);
OperationResult subResult = result.createSubresult(OPERATION_LOAD_RESET_PASSWORD_POLICY);
getMidpointApplication().getModel().getObject(SystemConfigurationType.class, SystemObjectsType.SYSTEM_CONFIGURATION.value(), null,
task, result);


Form form = new Form(ID_LOGIN_FORM) {


ge


@Override
protected void onSubmit() {
MidPointAuthWebSession session = MidPointAuthWebSession.getSession();
Expand All @@ -56,17 +72,24 @@ protected void onSubmit() {
PasswordTextField password = (PasswordTextField) get(ID_PASSWORD);
if (session.authenticate(username.getModelObject(), password.getModelObject())) {
setResponsePage(PageDashboard.class);


}
}
};

form.add(new RequiredTextField(ID_USERNAME, new Model<String>()));
form.add(new PasswordTextField(ID_PASSWORD, new Model<String>()));

add(form);
}

@Override
protected IModel<String> createPageTitleModel() {
return new Model<>("");
}

public PageBase getPageBase() {
return (PageBase) getPage();
}
}

0 comments on commit ca69c8d

Please sign in to comment.