Add client IDs for selfservice user in auth credentials (FINERACT-1340)

This commit is contained in:
Joseph Makara
2021-04-15 22:00:29 +08:00
committed by Petri Tuomola
parent 619419dd35
commit c9f843d0d7
4 changed files with 22 additions and 4 deletions
@@ -41,6 +41,7 @@ import org.apache.fineract.infrastructure.security.constants.TwoFactorConstants;
import org.apache.fineract.infrastructure.security.data.AuthenticatedUserData; import org.apache.fineract.infrastructure.security.data.AuthenticatedUserData;
import org.apache.fineract.infrastructure.security.service.SpringSecurityPlatformSecurityContext; import org.apache.fineract.infrastructure.security.service.SpringSecurityPlatformSecurityContext;
import org.apache.fineract.infrastructure.security.service.TwoFactorUtils; import org.apache.fineract.infrastructure.security.service.TwoFactorUtils;
import org.apache.fineract.portfolio.client.service.ClientReadPlatformService;
import org.apache.fineract.useradministration.data.RoleData; import org.apache.fineract.useradministration.data.RoleData;
import org.apache.fineract.useradministration.domain.AppUser; import org.apache.fineract.useradministration.domain.AppUser;
import org.apache.fineract.useradministration.domain.Role; import org.apache.fineract.useradministration.domain.Role;
@@ -71,16 +72,19 @@ public class AuthenticationApiResource {
private final ToApiJsonSerializer<AuthenticatedUserData> apiJsonSerializerService; private final ToApiJsonSerializer<AuthenticatedUserData> apiJsonSerializerService;
private final SpringSecurityPlatformSecurityContext springSecurityPlatformSecurityContext; private final SpringSecurityPlatformSecurityContext springSecurityPlatformSecurityContext;
private final TwoFactorUtils twoFactorUtils; private final TwoFactorUtils twoFactorUtils;
private final ClientReadPlatformService clientReadPlatformService;
@Autowired @Autowired
public AuthenticationApiResource( public AuthenticationApiResource(
@Qualifier("customAuthenticationProvider") final DaoAuthenticationProvider customAuthenticationProvider, @Qualifier("customAuthenticationProvider") final DaoAuthenticationProvider customAuthenticationProvider,
final ToApiJsonSerializer<AuthenticatedUserData> apiJsonSerializerService, final ToApiJsonSerializer<AuthenticatedUserData> apiJsonSerializerService,
final SpringSecurityPlatformSecurityContext springSecurityPlatformSecurityContext, TwoFactorUtils twoFactorUtils) { final SpringSecurityPlatformSecurityContext springSecurityPlatformSecurityContext, TwoFactorUtils twoFactorUtils,
ClientReadPlatformService aClientReadPlatformService) {
this.customAuthenticationProvider = customAuthenticationProvider; this.customAuthenticationProvider = customAuthenticationProvider;
this.apiJsonSerializerService = apiJsonSerializerService; this.apiJsonSerializerService = apiJsonSerializerService;
this.springSecurityPlatformSecurityContext = springSecurityPlatformSecurityContext; this.springSecurityPlatformSecurityContext = springSecurityPlatformSecurityContext;
this.twoFactorUtils = twoFactorUtils; this.twoFactorUtils = twoFactorUtils;
clientReadPlatformService = aClientReadPlatformService;
} }
@POST @POST
@@ -134,14 +138,16 @@ public class AuthenticationApiResource {
boolean isTwoFactorRequired = twoFactorUtils.isTwoFactorAuthEnabled() boolean isTwoFactorRequired = twoFactorUtils.isTwoFactorAuthEnabled()
&& !principal.hasSpecificPermissionTo(TwoFactorConstants.BYPASS_TWO_FACTOR_PERMISSION); && !principal.hasSpecificPermissionTo(TwoFactorConstants.BYPASS_TWO_FACTOR_PERMISSION);
Long userId = principal.getId();
if (this.springSecurityPlatformSecurityContext.doesPasswordHasToBeRenewed(principal)) { if (this.springSecurityPlatformSecurityContext.doesPasswordHasToBeRenewed(principal)) {
authenticatedUserData = new AuthenticatedUserData(request.username, principal.getId(), authenticatedUserData = new AuthenticatedUserData(request.username, userId,
new String(base64EncodedAuthenticationKey, StandardCharsets.UTF_8), isTwoFactorRequired); new String(base64EncodedAuthenticationKey, StandardCharsets.UTF_8), isTwoFactorRequired);
} else { } else {
authenticatedUserData = new AuthenticatedUserData(request.username, officeId, officeName, staffId, staffDisplayName, authenticatedUserData = new AuthenticatedUserData(request.username, officeId, officeName, staffId, staffDisplayName,
organisationalRole, roles, permissions, principal.getId(), organisationalRole, roles, permissions, principal.getId(),
new String(base64EncodedAuthenticationKey, StandardCharsets.UTF_8), isTwoFactorRequired); new String(base64EncodedAuthenticationKey, StandardCharsets.UTF_8), isTwoFactorRequired,
principal.isSelfServiceUser() ? clientReadPlatformService.retrieveUserClients(userId) : null);
} }
} }
@@ -50,6 +50,8 @@ public class AuthenticatedUserData {
@SuppressWarnings("unused") @SuppressWarnings("unused")
private final Collection<String> permissions; private final Collection<String> permissions;
private final Collection<Long> clients;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private final boolean shouldRenewPassword; private final boolean shouldRenewPassword;
@@ -70,12 +72,13 @@ public class AuthenticatedUserData {
this.permissions = permissions; this.permissions = permissions;
this.shouldRenewPassword = false; this.shouldRenewPassword = false;
this.isTwoFactorAuthenticationRequired = false; this.isTwoFactorAuthenticationRequired = false;
clients = null;
} }
public AuthenticatedUserData(final String username, final Long officeId, final String officeName, final Long staffId, public AuthenticatedUserData(final String username, final Long officeId, final String officeName, final Long staffId,
final String staffDisplayName, final EnumOptionData organisationalRole, final Collection<RoleData> roles, final String staffDisplayName, final EnumOptionData organisationalRole, final Collection<RoleData> roles,
final Collection<String> permissions, final Long userId, final String base64EncodedAuthenticationKey, final Collection<String> permissions, final Long userId, final String base64EncodedAuthenticationKey,
final boolean isTwoFactorAuthenticationRequired) { final boolean isTwoFactorAuthenticationRequired, Collection<Long> aListOfClientIDs) {
this.username = username; this.username = username;
this.officeId = officeId; this.officeId = officeId;
this.officeName = officeName; this.officeName = officeName;
@@ -89,6 +92,7 @@ public class AuthenticatedUserData {
this.permissions = permissions; this.permissions = permissions;
this.shouldRenewPassword = false; this.shouldRenewPassword = false;
this.isTwoFactorAuthenticationRequired = isTwoFactorAuthenticationRequired; this.isTwoFactorAuthenticationRequired = isTwoFactorAuthenticationRequired;
clients = aListOfClientIDs;
} }
public AuthenticatedUserData(final String username, final Long userId, final String base64EncodedAuthenticationKey, public AuthenticatedUserData(final String username, final Long userId, final String base64EncodedAuthenticationKey,
@@ -106,5 +110,6 @@ public class AuthenticatedUserData {
this.permissions = null; this.permissions = null;
this.shouldRenewPassword = true; this.shouldRenewPassword = true;
this.isTwoFactorAuthenticationRequired = isTwoFactorAuthenticationRequired; this.isTwoFactorAuthenticationRequired = isTwoFactorAuthenticationRequired;
clients = null;
} }
} }
@@ -46,6 +46,8 @@ public interface ClientReadPlatformService {
ClientData retrieveAllNarrations(String clientNarrations); ClientData retrieveAllNarrations(String clientNarrations);
Collection<Long> retrieveUserClients(Long aUserID);
Date retrieveClientTransferProposalDate(Long clientId); Date retrieveClientTransferProposalDate(Long clientId);
void validateClient(Long clientId); void validateClient(Long clientId);
@@ -865,4 +865,9 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService
} }
} }
@Override
public Collection<Long> retrieveUserClients(Long aUserID) {
String sql = "SELECT m.client_id FROM m_selfservice_user_client_mapping m INNER JOIN m_client c ON c.id = m.client_id WHERE m.appuser_id = ?";
return jdbcTemplate.queryForList(sql, Long.class, new Object[] { aUserID });
}
} }