cleaning up MIFOSX-1868
This commit is contained in:
@@ -30112,7 +30112,7 @@ GET https://DomainName/api/v1/users
|
||||
"firstname": "App",
|
||||
"lastname": "Administrator",
|
||||
"email": "demomfi@mifos.org",
|
||||
"passwordNeverExpire": false,
|
||||
"passwordNeverExpires": false,
|
||||
"staff": {
|
||||
"id": 1,
|
||||
"firstname": "Test",
|
||||
@@ -30204,7 +30204,7 @@ GET https://DomainName/api/v1/users/{userId}
|
||||
"firstname": "App",
|
||||
"lastname": "Administrator",
|
||||
"email": "demomfi@mifos.org",
|
||||
"passwordNeverExpire": true,
|
||||
"passwordNeverExpires": true,
|
||||
"staff": {
|
||||
"id": 1,
|
||||
"firstname": "Test",
|
||||
@@ -30254,7 +30254,7 @@ GET https://DomainName/api/v1/users/{userId}
|
||||
<td><div class="mifosXHeading2">Optional Fields</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>staffId,passwordNeverExpire</td>
|
||||
<td>staffId,passwordNeverExpires</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
+8
-9
@@ -5,6 +5,11 @@
|
||||
*/
|
||||
package org.mifosplatform.infrastructure.security.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.mifosplatform.commands.domain.CommandWrapper;
|
||||
import org.mifosplatform.commands.service.CommandWrapperBuilder;
|
||||
import org.mifosplatform.infrastructure.configuration.domain.ConfigurationDomainService;
|
||||
@@ -13,19 +18,12 @@ import org.mifosplatform.infrastructure.security.exception.NoAuthorizationExcept
|
||||
import org.mifosplatform.infrastructure.security.exception.ResetPasswordException;
|
||||
import org.mifosplatform.useradministration.domain.AppUser;
|
||||
import org.mifosplatform.useradministration.exception.UnAuthenticatedUserException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContext;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Wrapper around spring security's {@link SecurityContext} for extracted the
|
||||
* current authenticated {@link AppUser}.
|
||||
@@ -34,7 +32,8 @@ import java.util.List;
|
||||
@Service
|
||||
public class SpringSecurityPlatformSecurityContext implements PlatformSecurityContext {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(SpringSecurityPlatformSecurityContext.class);
|
||||
// private final static Logger logger =
|
||||
// LoggerFactory.getLogger(SpringSecurityPlatformSecurityContext.class);
|
||||
|
||||
private final ConfigurationDomainService configurationDomainService;
|
||||
|
||||
@@ -128,7 +127,7 @@ public class SpringSecurityPlatformSecurityContext implements PlatformSecurityCo
|
||||
@Override
|
||||
public boolean doesPasswordHasToBeRenewed(AppUser currentUser) {
|
||||
|
||||
if (this.configurationDomainService.isPasswordForcedResetEnable() && !currentUser.getPasswordNeverExpire()) {
|
||||
if (this.configurationDomainService.isPasswordForcedResetEnable() && !currentUser.getPasswordNeverExpires()) {
|
||||
|
||||
Long passwordDurationDays = this.configurationDomainService.retrievePasswordLiveTime();
|
||||
final Date passWordLastUpdateDate = currentUser.getLastTimePasswordUpdated();
|
||||
|
||||
+13
-11
@@ -5,11 +5,11 @@
|
||||
*/
|
||||
package org.mifosplatform.useradministration.data;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.mifosplatform.organisation.office.data.OfficeData;
|
||||
import org.mifosplatform.organisation.staff.data.StaffData;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Immutable data object for application user data.
|
||||
*/
|
||||
@@ -22,7 +22,7 @@ public class AppUserData {
|
||||
private final String firstname;
|
||||
private final String lastname;
|
||||
private final String email;
|
||||
private final Boolean passwordNeverExpire;
|
||||
private final Boolean passwordNeverExpires;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final Collection<OfficeData> allowedOffices;
|
||||
@@ -32,26 +32,28 @@ public class AppUserData {
|
||||
|
||||
public static AppUserData template(final AppUserData user, final Collection<OfficeData> officesForDropdown) {
|
||||
return new AppUserData(user.id, user.username, user.email, user.officeId, user.officeName, user.firstname, user.lastname,
|
||||
user.availableRoles, user.selectedRoles, officesForDropdown, user.staff,user.passwordNeverExpire);
|
||||
user.availableRoles, user.selectedRoles, officesForDropdown, user.staff, user.passwordNeverExpires);
|
||||
}
|
||||
|
||||
public static AppUserData template(final Collection<OfficeData> offices, final Collection<RoleData> availableRoles) {
|
||||
return new AppUserData(null, null, null, null, null, null, null, availableRoles, null, offices, null,null);
|
||||
return new AppUserData(null, null, null, null, null, null, null, availableRoles, null, offices, null, null);
|
||||
}
|
||||
|
||||
public static AppUserData dropdown(final Long id, final String username) {
|
||||
return new AppUserData(id, username, null, null, null, null, null, null, null, null, null,null);
|
||||
return new AppUserData(id, username, null, null, null, null, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
public static AppUserData instance(final Long id, final String username, final String email, final Long officeId,
|
||||
final String officeName, final String firstname, final String lastname, final Collection<RoleData> availableRoles,
|
||||
final Collection<RoleData> selectedRoles, final StaffData staff,final Boolean passwordNeverExpire) {
|
||||
return new AppUserData(id, username, email, officeId, officeName, firstname, lastname, availableRoles, selectedRoles, null, staff,passwordNeverExpire);
|
||||
final Collection<RoleData> selectedRoles, final StaffData staff, final Boolean passwordNeverExpire) {
|
||||
return new AppUserData(id, username, email, officeId, officeName, firstname, lastname, availableRoles, selectedRoles, null, staff,
|
||||
passwordNeverExpire);
|
||||
}
|
||||
|
||||
private AppUserData(final Long id, final String username, final String email, final Long officeId, final String officeName,
|
||||
final String firstname, final String lastname, final Collection<RoleData> availableRoles,
|
||||
final Collection<RoleData> selectedRoles, final Collection<OfficeData> allowedOffices, final StaffData staff, final Boolean passwordNeverExpire) {
|
||||
final String firstname, final String lastname, final Collection<RoleData> availableRoles,
|
||||
final Collection<RoleData> selectedRoles, final Collection<OfficeData> allowedOffices, final StaffData staff,
|
||||
final Boolean passwordNeverExpire) {
|
||||
this.id = id;
|
||||
this.username = username;
|
||||
this.officeId = officeId;
|
||||
@@ -63,7 +65,7 @@ public class AppUserData {
|
||||
this.availableRoles = availableRoles;
|
||||
this.selectedRoles = selectedRoles;
|
||||
this.staff = staff;
|
||||
this.passwordNeverExpire = passwordNeverExpire;
|
||||
this.passwordNeverExpires = passwordNeverExpire;
|
||||
}
|
||||
|
||||
public boolean hasIdentifyOf(final Long createdById) {
|
||||
|
||||
+11
-10
@@ -35,6 +35,7 @@ import org.mifosplatform.infrastructure.security.service.PlatformPasswordEncoder
|
||||
import org.mifosplatform.infrastructure.security.service.RandomPasswordGenerator;
|
||||
import org.mifosplatform.organisation.office.domain.Office;
|
||||
import org.mifosplatform.organisation.staff.domain.Staff;
|
||||
import org.mifosplatform.useradministration.service.AppUserConstants;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.jpa.domain.AbstractPersistable;
|
||||
@@ -97,8 +98,8 @@ public class AppUser extends AbstractPersistable<Long> implements PlatformUser {
|
||||
@Temporal(TemporalType.DATE)
|
||||
private Date lastTimePasswordUpdated;
|
||||
|
||||
@Column(name = "password_never_expire", nullable = false)
|
||||
private boolean passwordNeverExpire;
|
||||
@Column(name = "password_never_expires", nullable = false)
|
||||
private boolean passwordNeverExpires;
|
||||
|
||||
public static AppUser fromJson(final Office userOffice, final Staff linkedStaff, final Set<Role> allRoles, final JsonCommand command) {
|
||||
|
||||
@@ -112,8 +113,8 @@ public class AppUser extends AbstractPersistable<Long> implements PlatformUser {
|
||||
|
||||
boolean passwordNeverExpire = false;
|
||||
|
||||
if(command.parameterExists("passwordNeverExpire")){
|
||||
passwordNeverExpire = command.booleanPrimitiveValueOfParameterNamed("passwordNeverExpire");
|
||||
if (command.parameterExists(AppUserConstants.PASSWORD_NEVER_EXPIRES)) {
|
||||
passwordNeverExpire = command.booleanPrimitiveValueOfParameterNamed(AppUserConstants.PASSWORD_NEVER_EXPIRES);
|
||||
}
|
||||
|
||||
final boolean userEnabled = true;
|
||||
@@ -131,7 +132,7 @@ public class AppUser extends AbstractPersistable<Long> implements PlatformUser {
|
||||
final String firstname = command.stringValueOfParameterNamed("firstname");
|
||||
final String lastname = command.stringValueOfParameterNamed("lastname");
|
||||
|
||||
return new AppUser(userOffice, user, allRoles, email, firstname, lastname, linkedStaff,passwordNeverExpire);
|
||||
return new AppUser(userOffice, user, allRoles, email, firstname, lastname, linkedStaff, passwordNeverExpire);
|
||||
}
|
||||
|
||||
protected AppUser() {
|
||||
@@ -156,7 +157,7 @@ public class AppUser extends AbstractPersistable<Long> implements PlatformUser {
|
||||
this.firstTimeLoginRemaining = true;
|
||||
this.lastTimePasswordUpdated = DateUtils.getDateOfTenant();
|
||||
this.staff = staff;
|
||||
this.passwordNeverExpire = passwordNeverExpire;
|
||||
this.passwordNeverExpires = passwordNeverExpire;
|
||||
}
|
||||
|
||||
public EnumOptionData organisationalRoleData() {
|
||||
@@ -263,10 +264,10 @@ public class AppUser extends AbstractPersistable<Long> implements PlatformUser {
|
||||
final String passwordNeverExpire = "passwordNeverExpire";
|
||||
|
||||
if (command.hasParameter(passwordNeverExpire)) {
|
||||
if (command.isChangeInBooleanParameterNamed(passwordNeverExpire, this.passwordNeverExpire)) {
|
||||
if (command.isChangeInBooleanParameterNamed(passwordNeverExpire, this.passwordNeverExpires)) {
|
||||
final boolean newValue = command.booleanPrimitiveValueOfParameterNamed(passwordNeverExpire);
|
||||
actualChanges.put(passwordNeverExpire, newValue);
|
||||
this.passwordNeverExpire = newValue;
|
||||
this.passwordNeverExpires = newValue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -371,8 +372,8 @@ public class AppUser extends AbstractPersistable<Long> implements PlatformUser {
|
||||
return this.staff;
|
||||
}
|
||||
|
||||
public boolean getPasswordNeverExpire() {
|
||||
return this.passwordNeverExpire;
|
||||
public boolean getPasswordNeverExpires() {
|
||||
return this.passwordNeverExpires;
|
||||
}
|
||||
|
||||
public Date getLastTimePasswordUpdated() {
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package org.mifosplatform.useradministration.service;
|
||||
|
||||
public class AppUserConstants {
|
||||
|
||||
public static final String PASSWORD_NEVER_EXPIRES = "passwordNeverExpires";
|
||||
|
||||
}
|
||||
+6
-4
@@ -120,7 +120,8 @@ public class AppUserReadPlatformServiceImpl implements AppUserReadPlatformServic
|
||||
}
|
||||
|
||||
return AppUserData.instance(user.getId(), user.getUsername(), user.getEmail(), user.getOffice().getId(),
|
||||
user.getOffice().getName(), user.getFirstname(), user.getLastname(), availableRoles, selectedUserRoles, linkedStaff,user.getPasswordNeverExpire());
|
||||
user.getOffice().getName(), user.getFirstname(), user.getLastname(), availableRoles, selectedUserRoles, linkedStaff,
|
||||
user.getPasswordNeverExpires());
|
||||
}
|
||||
|
||||
private static final class AppUserMapper implements RowMapper<AppUserData> {
|
||||
@@ -144,7 +145,7 @@ public class AppUserReadPlatformServiceImpl implements AppUserReadPlatformServic
|
||||
final Long officeId = JdbcSupport.getLong(rs, "officeId");
|
||||
final String officeName = rs.getString("officeName");
|
||||
final Long staffId = JdbcSupport.getLong(rs, "staffId");
|
||||
final Boolean passwordNeverExpire = rs.getBoolean("passwordNeverExpire");
|
||||
final Boolean passwordNeverExpire = rs.getBoolean("passwordNeverExpires");
|
||||
final Collection<RoleData> selectedRoles = this.roleReadPlatformService.retrieveAppUserRoles(id);
|
||||
|
||||
final StaffData linkedStaff;
|
||||
@@ -153,11 +154,12 @@ public class AppUserReadPlatformServiceImpl implements AppUserReadPlatformServic
|
||||
} else {
|
||||
linkedStaff = null;
|
||||
}
|
||||
return AppUserData.instance(id, username, email, officeId, officeName, firstname, lastname, null, selectedRoles, linkedStaff,passwordNeverExpire);
|
||||
return AppUserData.instance(id, username, email, officeId, officeName, firstname, lastname, null, selectedRoles, linkedStaff,
|
||||
passwordNeverExpire);
|
||||
}
|
||||
|
||||
public String schema() {
|
||||
return " u.id as id, u.username as username, u.firstname as firstname, u.lastname as lastname, u.email as email, u.password_never_expire as passwordNeverExpire, "
|
||||
return " u.id as id, u.username as username, u.firstname as firstname, u.lastname as lastname, u.email as email, u.password_never_expires as passwordNeverExpires, "
|
||||
+ " u.office_id as officeId, o.name as officeName, u.staff_id as staffId from m_appuser u "
|
||||
+ " join m_office o on o.id = u.office_id where o.hierarchy like ? and u.is_deleted=0 order by u.username";
|
||||
}
|
||||
|
||||
+4
-3
@@ -32,7 +32,7 @@ public final class UserDataValidator {
|
||||
* The parameters supported for this command.
|
||||
*/
|
||||
private final Set<String> supportedParameters = new HashSet<>(Arrays.asList("username", "firstname", "lastname", "password",
|
||||
"repeatPassword", "email", "officeId", "notSelectedRoles", "roles", "sendPasswordToEmail", "staffId","passwordNeverExpire"));
|
||||
"repeatPassword", "email", "officeId", "notSelectedRoles", "roles", "sendPasswordToEmail", "staffId", "passwordNeverExpires"));
|
||||
|
||||
private final FromJsonHelper fromApiJsonHelper;
|
||||
|
||||
@@ -86,8 +86,9 @@ public final class UserDataValidator {
|
||||
baseDataValidator.reset().parameter("staffId").value(staffId).notNull().integerGreaterThanZero();
|
||||
}
|
||||
|
||||
if (this.fromApiJsonHelper.parameterExists("passwordNeverExpire", element)) {
|
||||
final boolean passwordNeverExpire = this.fromApiJsonHelper.extractBooleanNamed("passwordNeverExpire", element);
|
||||
if (this.fromApiJsonHelper.parameterExists(AppUserConstants.PASSWORD_NEVER_EXPIRES, element)) {
|
||||
final boolean passwordNeverExpire = this.fromApiJsonHelper
|
||||
.extractBooleanNamed(AppUserConstants.PASSWORD_NEVER_EXPIRES, element);
|
||||
baseDataValidator.reset().parameter("passwordNeverExpire").value(passwordNeverExpire).validateForBooleanValue();
|
||||
}
|
||||
|
||||
|
||||
-1
@@ -1 +0,0 @@
|
||||
ALTER TABLE `m_appuser` ADD `password_never_expire` TINYINT NOT NULL DEFAULT '0' COMMENT 'define if the password, should be check for validity period or not';
|
||||
+1
@@ -0,0 +1 @@
|
||||
ALTER TABLE `m_appuser` ADD `password_never_expires` TINYINT NOT NULL DEFAULT '0' COMMENT 'define if the password, should be check for validity period or not';
|
||||
Reference in New Issue
Block a user