Merge pull request #1382 from chandrikamohith/MIFOSX-2022
MIFOSX-2022 To enable force-password reset, the value of no of days s…
This commit is contained in:
+84
@@ -11,6 +11,7 @@ import java.util.HashMap;
|
|||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.mifosplatform.integrationtests.common.CommonConstants;
|
||||||
import org.mifosplatform.integrationtests.common.Utils;
|
import org.mifosplatform.integrationtests.common.Utils;
|
||||||
import org.mifosplatform.integrationtests.common.GlobalConfigurationHelper;
|
import org.mifosplatform.integrationtests.common.GlobalConfigurationHelper;
|
||||||
|
|
||||||
@@ -26,6 +27,7 @@ public class GlobalConfigurationTest {
|
|||||||
private ResponseSpecification responseSpec;
|
private ResponseSpecification responseSpec;
|
||||||
private RequestSpecification requestSpec;
|
private RequestSpecification requestSpec;
|
||||||
private GlobalConfigurationHelper globalConfigurationHelper;
|
private GlobalConfigurationHelper globalConfigurationHelper;
|
||||||
|
private ResponseSpecification httpStatusForidden;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
@@ -33,6 +35,7 @@ public class GlobalConfigurationTest {
|
|||||||
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
|
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
|
||||||
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
|
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
|
||||||
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||||
|
this.httpStatusForidden = new ResponseSpecBuilder().expectStatusCode(403).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -121,4 +124,85 @@ public class GlobalConfigurationTest {
|
|||||||
Assert.assertEquals("Verifying Is Cache Enabled Global Config after Updation", cacheTypeId, changes.get("cacheType"));
|
Assert.assertEquals("Verifying Is Cache Enabled Global Config after Updation", cacheTypeId, changes.get("cacheType"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGlobalConfigForcePasswordResetDays() {
|
||||||
|
|
||||||
|
// Retrieving All Global Configuration details
|
||||||
|
final ArrayList<HashMap> globalConfig = this.globalConfigurationHelper
|
||||||
|
.getAllGlobalConfigurations(this.requestSpec, this.responseSpec);
|
||||||
|
Assert.assertNotNull(globalConfig);
|
||||||
|
|
||||||
|
String configName = "force-password-reset-days";
|
||||||
|
String newValue = "0";
|
||||||
|
String newBooleanValue = "true";
|
||||||
|
|
||||||
|
for (Integer configIndex = 0; configIndex < (globalConfig.size() - 1); configIndex++) {
|
||||||
|
if (globalConfig.get(configIndex).get("name").equals(configName)) {
|
||||||
|
Integer configId = (Integer) globalConfig.get(configIndex).get(
|
||||||
|
"id");
|
||||||
|
Assert.assertNotNull(configId);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Update force-password-reset-days with value as 0 and Enable
|
||||||
|
* as true - failure case
|
||||||
|
*/
|
||||||
|
ArrayList error = (ArrayList) this.globalConfigurationHelper
|
||||||
|
.updatePasswordResetDaysForGlobalConfiguration(
|
||||||
|
this.requestSpec, this.httpStatusForidden,
|
||||||
|
configId, newValue, newBooleanValue,
|
||||||
|
CommonConstants.RESPONSE_ERROR);
|
||||||
|
HashMap hash = (HashMap) error.get(0);
|
||||||
|
|
||||||
|
Assert.assertEquals(
|
||||||
|
"Force Password Reset days value must be greater than zero.",
|
||||||
|
"error.msg.password.reset.days.value.must.be.greater.than.zero",
|
||||||
|
hash.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Update force-password-reset-days with value as 50 and Enable
|
||||||
|
* as true - success case
|
||||||
|
*/
|
||||||
|
final HashMap updateSuccess = (HashMap) this.globalConfigurationHelper
|
||||||
|
.updatePasswordResetDaysForGlobalConfiguration(
|
||||||
|
this.requestSpec, this.responseSpec, configId,
|
||||||
|
"50", newBooleanValue, "changes");
|
||||||
|
Assert.assertNotNull(updateSuccess);
|
||||||
|
|
||||||
|
/* Update with value as 0 and Enable as false - success case */
|
||||||
|
final HashMap updateSuccess1 = (HashMap) this.globalConfigurationHelper
|
||||||
|
.updatePasswordResetDaysForGlobalConfiguration(
|
||||||
|
this.requestSpec, this.responseSpec, configId,
|
||||||
|
newValue, "false", "changes");
|
||||||
|
Assert.assertNotNull(updateSuccess1);
|
||||||
|
|
||||||
|
/* Update without sending value and Enable as true - failure case*/
|
||||||
|
ArrayList failure = (ArrayList) this.globalConfigurationHelper
|
||||||
|
.updatePasswordResetDaysForGlobalConfiguration(
|
||||||
|
this.requestSpec, this.httpStatusForidden, configId,
|
||||||
|
null, newBooleanValue, CommonConstants.RESPONSE_ERROR);
|
||||||
|
HashMap failureHash = (HashMap) failure.get(0);
|
||||||
|
Assert.assertEquals(
|
||||||
|
"Force Password Reset days value must be greater than zero.",
|
||||||
|
"error.msg.password.reset.days.value.must.be.greater.than.zero",
|
||||||
|
failureHash.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Update other global configuration property */
|
||||||
|
String otherConfigName = "maker-checker";
|
||||||
|
for (Integer configIndex = 0; configIndex < (globalConfig.size() - 1); configIndex++) {
|
||||||
|
if (globalConfig.get(configIndex).get("name")
|
||||||
|
.equals(otherConfigName)) {
|
||||||
|
String configId = (globalConfig.get(configIndex).get("id"))
|
||||||
|
.toString();
|
||||||
|
Integer updateConfigId = this.globalConfigurationHelper
|
||||||
|
.updateValueForGlobalConfiguration(this.requestSpec,
|
||||||
|
this.responseSpec, configId, newValue);
|
||||||
|
Assert.assertNotNull(updateConfigId);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+19
@@ -7,6 +7,7 @@ package org.mifosplatform.integrationtests.common;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
@@ -70,6 +71,14 @@ public class GlobalConfigurationHelper {
|
|||||||
return Utils.performServerPut(requestSpec, responseSpec, IS_CACHE_GLOBAL_CONFIG_UPDATE_URL,
|
return Utils.performServerPut(requestSpec, responseSpec, IS_CACHE_GLOBAL_CONFIG_UPDATE_URL,
|
||||||
updateIsCacheEnabledGlobalConfigUpdateAsJSON(cacheType), "changes");
|
updateIsCacheEnabledGlobalConfigUpdateAsJSON(cacheType), "changes");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Object updatePasswordResetDaysForGlobalConfiguration(final RequestSpecification requestSpec,
|
||||||
|
final ResponseSpecification responseSpec, final Integer configId, final String value, final String enabled, final String jsonAttributeToGetBack) {
|
||||||
|
final String UPDATE_URL = "/mifosng-provider/api/v1/configurations/" + configId + "?" + Utils.TENANT_IDENTIFIER;
|
||||||
|
System.out.println("------------------UPDATE GLOBAL CONFIG FOR FORCE PASSWORD RESET DAYS----------------------");
|
||||||
|
return Utils.performServerPut(requestSpec, responseSpec, UPDATE_URL,
|
||||||
|
updatePasswordResetDaysGlobalConfigAsJSON(value, enabled), jsonAttributeToGetBack);
|
||||||
|
}
|
||||||
|
|
||||||
public static String updateGlobalConfigUpdateValueAsJSON(final String value) {
|
public static String updateGlobalConfigUpdateValueAsJSON(final String value) {
|
||||||
final HashMap<String, String> map = new HashMap<>();
|
final HashMap<String, String> map = new HashMap<>();
|
||||||
@@ -77,6 +86,16 @@ public class GlobalConfigurationHelper {
|
|||||||
System.out.println("map : " + map);
|
System.out.println("map : " + map);
|
||||||
return new Gson().toJson(map);
|
return new Gson().toJson(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String updatePasswordResetDaysGlobalConfigAsJSON(final String value, final String enabled) {
|
||||||
|
final HashMap<String, String> map = new HashMap<>();
|
||||||
|
if(value != null){
|
||||||
|
map.put("value", value);
|
||||||
|
}
|
||||||
|
map.put("enabled", enabled);
|
||||||
|
System.out.println("map : " + map);
|
||||||
|
return new Gson().toJson(map);
|
||||||
|
}
|
||||||
|
|
||||||
public static String updateGlobalConfigUpdateEnabledFlagAsJSON(final Boolean enabled) {
|
public static String updateGlobalConfigUpdateEnabledFlagAsJSON(final Boolean enabled) {
|
||||||
final HashMap<String, Boolean> map = new HashMap<String, Boolean>();
|
final HashMap<String, Boolean> map = new HashMap<String, Boolean>();
|
||||||
|
|||||||
+11
-1
@@ -13,6 +13,7 @@ import javax.persistence.Entity;
|
|||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||||
|
import org.mifosplatform.infrastructure.security.exception.ForcePasswordResetException;
|
||||||
import org.springframework.data.jpa.domain.AbstractPersistable;
|
import org.springframework.data.jpa.domain.AbstractPersistable;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@@ -72,12 +73,21 @@ public class GlobalConfigurationProperty extends AbstractPersistable<Long> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final String valueParamName = "value";
|
final String valueParamName = "value";
|
||||||
|
final Long previousValue = this.value;
|
||||||
if (command.isChangeInLongParameterNamed(valueParamName, this.value)) {
|
if (command.isChangeInLongParameterNamed(valueParamName, this.value)) {
|
||||||
final Long newValue = command.longValueOfParameterNamed(valueParamName);
|
final Long newValue = command.longValueOfParameterNamed(valueParamName);
|
||||||
actualChanges.put(valueParamName, newValue);
|
actualChanges.put(valueParamName, newValue);
|
||||||
this.value = newValue;
|
this.value = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final String passwordPropertyName = "force-password-reset-days";
|
||||||
|
if(this.name.equalsIgnoreCase(passwordPropertyName)){
|
||||||
|
if(this.enabled == true && command.hasParameter(valueParamName) && this.value == 0 ||
|
||||||
|
this.enabled == true && !command.hasParameter(valueParamName) && previousValue == 0){
|
||||||
|
throw new ForcePasswordResetException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return actualChanges;
|
return actualChanges;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
/**
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||||
|
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.mifosplatform.infrastructure.security.exception;
|
||||||
|
|
||||||
|
import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRuleException;
|
||||||
|
|
||||||
|
public class ForcePasswordResetException extends AbstractPlatformDomainRuleException {
|
||||||
|
|
||||||
|
public ForcePasswordResetException(){
|
||||||
|
super("error.msg.password.reset.days.value.must.be.greater.than.zero" , "For enabling 'Force Password Reset Days' configuration , the value (number of days after which a user is forced to reset his password) must be set to a number greater than 0.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user