diff --git a/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/AppUserReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/AppUserReadPlatformServiceImpl.java index 12d2949d0b0..b621d8f32db 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/AppUserReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/AppUserReadPlatformServiceImpl.java @@ -24,6 +24,7 @@ import java.util.Collection; import java.util.HashSet; import java.util.Set; +import lombok.RequiredArgsConstructor; import org.apache.fineract.infrastructure.core.domain.JdbcSupport; import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; import org.apache.fineract.organisation.office.data.OfficeData; @@ -39,34 +40,20 @@ import org.apache.fineract.useradministration.domain.AppUserRepository; import org.apache.fineract.useradministration.domain.Role; import org.apache.fineract.useradministration.exception.UserNotFoundException; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.Cacheable; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; -import org.springframework.stereotype.Service; -@Service +@RequiredArgsConstructor public class AppUserReadPlatformServiceImpl implements AppUserReadPlatformService { - private final JdbcTemplate jdbcTemplate; private final PlatformSecurityContext context; + private final JdbcTemplate jdbcTemplate; private final OfficeReadPlatformService officeReadPlatformService; private final RoleReadPlatformService roleReadPlatformService; private final AppUserRepository appUserRepository; private final StaffReadPlatformService staffReadPlatformService; - @Autowired - public AppUserReadPlatformServiceImpl(final PlatformSecurityContext context, final JdbcTemplate jdbcTemplate, - final OfficeReadPlatformService officeReadPlatformService, final RoleReadPlatformService roleReadPlatformService, - final AppUserRepository appUserRepository, final StaffReadPlatformService staffReadPlatformService) { - this.context = context; - this.officeReadPlatformService = officeReadPlatformService; - this.roleReadPlatformService = roleReadPlatformService; - this.appUserRepository = appUserRepository; - this.jdbcTemplate = jdbcTemplate; - this.staffReadPlatformService = staffReadPlatformService; - } - /* * used for caching in spring expression language. */ diff --git a/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/AppUserWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/AppUserWritePlatformServiceJpaRepositoryImpl.java index a03efcdc436..11d18eef9eb 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/AppUserWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/AppUserWritePlatformServiceJpaRepositoryImpl.java @@ -63,11 +63,9 @@ import org.springframework.data.domain.Sort; import org.springframework.orm.jpa.JpaSystemException; import org.springframework.security.authentication.AuthenticationServiceException; -import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.ObjectUtils; -@Service @Slf4j @RequiredArgsConstructor public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWritePlatformService { diff --git a/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/PasswordPreferencesWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/PasswordPreferencesWritePlatformServiceJpaRepositoryImpl.java index 4d39267630f..3efebab5b2c 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/PasswordPreferencesWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/PasswordPreferencesWritePlatformServiceJpaRepositoryImpl.java @@ -21,6 +21,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; @@ -30,29 +32,17 @@ import org.apache.fineract.useradministration.domain.PasswordValidationPolicy; import org.apache.fineract.useradministration.domain.PasswordValidationPolicyRepository; import org.apache.fineract.useradministration.exception.PasswordValidationPolicyNotFoundException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.orm.jpa.JpaSystemException; -import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -@Service +@Slf4j +@RequiredArgsConstructor public class PasswordPreferencesWritePlatformServiceJpaRepositoryImpl implements PasswordPreferencesWritePlatformService { - private static final Logger LOG = LoggerFactory.getLogger(PasswordPreferencesWritePlatformServiceJpaRepositoryImpl.class); private final PasswordValidationPolicyRepository validationRepository; private final PasswordPreferencesDataValidator dataValidator; - @Autowired - public PasswordPreferencesWritePlatformServiceJpaRepositoryImpl(final PasswordValidationPolicyRepository validationPolicyRepository, - final PasswordPreferencesDataValidator dataValidator) { - this.validationRepository = validationPolicyRepository; - this.dataValidator = dataValidator; - - } - @Transactional @Override public CommandProcessingResult updatePreferences(final JsonCommand command) { @@ -91,7 +81,7 @@ public CommandProcessingResult updatePreferences(final JsonCommand command) { .with(changes) // .build(); } catch (final JpaSystemException | DataIntegrityViolationException dve) { - LOG.error("Error occured.", dve); + log.error("Error occured.", dve); throw new PlatformDataIntegrityException("error.msg.password.validation.policy.unknown.data.integrity.issue", "Unknown data integrity issue with resource.", dve); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/PasswordValidationPolicyReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/PasswordValidationPolicyReadPlatformServiceImpl.java index c4b23bfc80d..662594bb605 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/PasswordValidationPolicyReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/PasswordValidationPolicyReadPlatformServiceImpl.java @@ -25,20 +25,16 @@ import org.apache.fineract.infrastructure.core.service.database.DatabaseSpecificSQLGenerator; import org.apache.fineract.useradministration.data.PasswordValidationPolicyData; import org.apache.fineract.useradministration.exception.PasswordValidationPolicyNotFoundException; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; -import org.springframework.stereotype.Service; -@Service public class PasswordValidationPolicyReadPlatformServiceImpl implements PasswordValidationPolicyReadPlatformService { private final JdbcTemplate jdbcTemplate; private final DatabaseSpecificSQLGenerator sqlGenerator; private final PasswordValidationPolicyMapper passwordValidationPolicyMapper; - @Autowired public PasswordValidationPolicyReadPlatformServiceImpl(final JdbcTemplate jdbcTemplate, DatabaseSpecificSQLGenerator sqlGenerator) { this.jdbcTemplate = jdbcTemplate; this.sqlGenerator = sqlGenerator; diff --git a/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/PermissionReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/PermissionReadPlatformServiceImpl.java index b08f0c669f9..9554f8cdb73 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/PermissionReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/PermissionReadPlatformServiceImpl.java @@ -21,32 +21,21 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.Collection; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.apache.fineract.infrastructure.core.service.database.DatabaseSpecificSQLGenerator; import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; import org.apache.fineract.useradministration.data.PermissionData; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; -import org.springframework.stereotype.Service; -@Service +@Slf4j +@RequiredArgsConstructor public class PermissionReadPlatformServiceImpl implements PermissionReadPlatformService { - private static final Logger LOG = LoggerFactory.getLogger(PermissionReadPlatformServiceImpl.class); - + private final PlatformSecurityContext context; private final JdbcTemplate jdbcTemplate; private final DatabaseSpecificSQLGenerator sqlGenerator; - private final PlatformSecurityContext context; - - @Autowired - public PermissionReadPlatformServiceImpl(final PlatformSecurityContext context, final JdbcTemplate jdbcTemplate, - DatabaseSpecificSQLGenerator sqlGenerator) { - this.context = context; - this.jdbcTemplate = jdbcTemplate; - this.sqlGenerator = sqlGenerator; - } @Override public Collection retrieveAllPermissions() { @@ -55,7 +44,7 @@ public Collection retrieveAllPermissions() { final PermissionUsageDataMapper mapper = new PermissionUsageDataMapper(sqlGenerator); final String sql = mapper.permissionSchema(); - LOG.debug("retrieveAllPermissions: {}", sql); + log.debug("retrieveAllPermissions: {}", sql); return this.jdbcTemplate.query(sql, mapper, new Object[] {}); } @@ -66,7 +55,7 @@ public Collection retrieveAllMakerCheckerablePermissions() { final PermissionUsageDataMapper mapper = new PermissionUsageDataMapper(sqlGenerator); final String sql = mapper.makerCheckerablePermissionSchema(); - LOG.debug("retrieveAllMakerCheckerablePermissions: {}", sql); + log.debug("retrieveAllMakerCheckerablePermissions: {}", sql); return this.jdbcTemplate.query(sql, mapper, new Object[] {}); } @@ -76,7 +65,7 @@ public Collection retrieveAllRolePermissions(final Long roleId) final PermissionUsageDataMapper mapper = new PermissionUsageDataMapper(sqlGenerator); final String sql = mapper.rolePermissionSchema(); - LOG.debug("retrieveAllRolePermissions: {}", sql); + log.debug("retrieveAllRolePermissions: {}", sql); return this.jdbcTemplate.query(sql, mapper, new Object[] { roleId }); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/PermissionWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/PermissionWritePlatformServiceJpaRepositoryImpl.java index 10552b830b8..193ea27c6b4 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/PermissionWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/PermissionWritePlatformServiceJpaRepositoryImpl.java @@ -21,6 +21,7 @@ import java.util.Collection; import java.util.HashMap; import java.util.Map; +import lombok.RequiredArgsConstructor; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; @@ -30,27 +31,17 @@ import org.apache.fineract.useradministration.domain.PermissionRepository; import org.apache.fineract.useradministration.exception.PermissionNotFoundException; import org.apache.fineract.useradministration.serialization.PermissionsCommandFromApiJsonDeserializer; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Caching; -import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -@Service +@RequiredArgsConstructor public class PermissionWritePlatformServiceJpaRepositoryImpl implements PermissionWritePlatformService { private final PlatformSecurityContext context; private final PermissionRepository permissionRepository; private final PermissionsCommandFromApiJsonDeserializer fromApiJsonDeserializer; - @Autowired - public PermissionWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, - final PermissionRepository permissionRepository, final PermissionsCommandFromApiJsonDeserializer fromApiJsonDeserializer) { - this.context = context; - this.permissionRepository = permissionRepository; - this.fromApiJsonDeserializer = fromApiJsonDeserializer; - } - @Caching(evict = { @CacheEvict(value = "users", allEntries = true), @CacheEvict(value = "usersByUsername", allEntries = true) }) @Transactional @Override diff --git a/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/RoleReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/RoleReadPlatformServiceImpl.java index 67be81272e0..a884933e7f2 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/RoleReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/RoleReadPlatformServiceImpl.java @@ -25,19 +25,15 @@ import org.apache.fineract.portfolio.self.registration.SelfServiceApiConstants; import org.apache.fineract.useradministration.data.RoleData; import org.apache.fineract.useradministration.exception.RoleNotFoundException; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; -import org.springframework.stereotype.Service; -@Service public class RoleReadPlatformServiceImpl implements RoleReadPlatformService { private final JdbcTemplate jdbcTemplate; private final RoleMapper roleRowMapper; - @Autowired public RoleReadPlatformServiceImpl(final JdbcTemplate jdbcTemplate) { this.jdbcTemplate = jdbcTemplate; this.roleRowMapper = new RoleMapper(); diff --git a/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/RoleWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/RoleWritePlatformServiceJpaRepositoryImpl.java index 062ca98a400..2d505aa1fac 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/RoleWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/RoleWritePlatformServiceJpaRepositoryImpl.java @@ -43,10 +43,8 @@ import org.springframework.cache.annotation.Caching; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.orm.jpa.JpaSystemException; -import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -@Service @Slf4j @RequiredArgsConstructor public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatformService { diff --git a/fineract-provider/src/main/java/org/apache/fineract/useradministration/starter/UserAdministrationConfiguration.java b/fineract-provider/src/main/java/org/apache/fineract/useradministration/starter/UserAdministrationConfiguration.java new file mode 100644 index 00000000000..f092ee0e385 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/useradministration/starter/UserAdministrationConfiguration.java @@ -0,0 +1,126 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.useradministration.starter; + +import org.apache.fineract.infrastructure.core.service.database.DatabaseSpecificSQLGenerator; +import org.apache.fineract.infrastructure.security.service.PlatformPasswordEncoder; +import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; +import org.apache.fineract.organisation.office.domain.OfficeRepositoryWrapper; +import org.apache.fineract.organisation.office.service.OfficeReadPlatformService; +import org.apache.fineract.organisation.staff.domain.StaffRepositoryWrapper; +import org.apache.fineract.organisation.staff.service.StaffReadPlatformService; +import org.apache.fineract.portfolio.client.domain.ClientRepositoryWrapper; +import org.apache.fineract.useradministration.data.PasswordPreferencesDataValidator; +import org.apache.fineract.useradministration.domain.AppUserPreviousPasswordRepository; +import org.apache.fineract.useradministration.domain.AppUserRepository; +import org.apache.fineract.useradministration.domain.PasswordValidationPolicyRepository; +import org.apache.fineract.useradministration.domain.PermissionRepository; +import org.apache.fineract.useradministration.domain.RoleRepository; +import org.apache.fineract.useradministration.domain.UserDomainService; +import org.apache.fineract.useradministration.serialization.PermissionsCommandFromApiJsonDeserializer; +import org.apache.fineract.useradministration.service.AppUserReadPlatformService; +import org.apache.fineract.useradministration.service.AppUserReadPlatformServiceImpl; +import org.apache.fineract.useradministration.service.AppUserWritePlatformService; +import org.apache.fineract.useradministration.service.AppUserWritePlatformServiceJpaRepositoryImpl; +import org.apache.fineract.useradministration.service.PasswordPreferencesWritePlatformService; +import org.apache.fineract.useradministration.service.PasswordPreferencesWritePlatformServiceJpaRepositoryImpl; +import org.apache.fineract.useradministration.service.PasswordValidationPolicyReadPlatformService; +import org.apache.fineract.useradministration.service.PasswordValidationPolicyReadPlatformServiceImpl; +import org.apache.fineract.useradministration.service.PermissionReadPlatformService; +import org.apache.fineract.useradministration.service.PermissionReadPlatformServiceImpl; +import org.apache.fineract.useradministration.service.PermissionWritePlatformService; +import org.apache.fineract.useradministration.service.PermissionWritePlatformServiceJpaRepositoryImpl; +import org.apache.fineract.useradministration.service.RoleDataValidator; +import org.apache.fineract.useradministration.service.RoleReadPlatformService; +import org.apache.fineract.useradministration.service.RoleReadPlatformServiceImpl; +import org.apache.fineract.useradministration.service.RoleWritePlatformService; +import org.apache.fineract.useradministration.service.RoleWritePlatformServiceJpaRepositoryImpl; +import org.apache.fineract.useradministration.service.UserDataValidator; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.jdbc.core.JdbcTemplate; + +@Configuration +public class UserAdministrationConfiguration { + + @Bean + @ConditionalOnMissingBean(AppUserReadPlatformService.class) + public AppUserReadPlatformService appUserReadPlatformService(PlatformSecurityContext context, JdbcTemplate jdbcTemplate, + OfficeReadPlatformService officeReadPlatformService, RoleReadPlatformService roleReadPlatformService, + AppUserRepository appUserRepository, StaffReadPlatformService staffReadPlatformService) { + return new AppUserReadPlatformServiceImpl(context, jdbcTemplate, officeReadPlatformService, roleReadPlatformService, + appUserRepository, staffReadPlatformService); + } + + @Bean + @ConditionalOnMissingBean(AppUserWritePlatformService.class) + public AppUserWritePlatformService appUserWritePlatformService(PlatformSecurityContext context, UserDomainService userDomainService, + PlatformPasswordEncoder platformPasswordEncoder, AppUserRepository appUserRepository, + OfficeRepositoryWrapper officeRepositoryWrapper, RoleRepository roleRepository, UserDataValidator fromApiJsonDeserializer, + AppUserPreviousPasswordRepository appUserPreviewPasswordRepository, StaffRepositoryWrapper staffRepositoryWrapper, + ClientRepositoryWrapper clientRepositoryWrapper) { + return new AppUserWritePlatformServiceJpaRepositoryImpl(context, userDomainService, platformPasswordEncoder, appUserRepository, + officeRepositoryWrapper, roleRepository, fromApiJsonDeserializer, appUserPreviewPasswordRepository, staffRepositoryWrapper, + clientRepositoryWrapper); + } + + @Bean + @ConditionalOnMissingBean(PasswordPreferencesWritePlatformService.class) + public PasswordPreferencesWritePlatformService passwordPreferencesWritePlatformService( + PasswordValidationPolicyRepository validationPolicyRepository, PasswordPreferencesDataValidator dataValidator) { + return new PasswordPreferencesWritePlatformServiceJpaRepositoryImpl(validationPolicyRepository, dataValidator); + } + + @Bean + @ConditionalOnMissingBean(PasswordValidationPolicyReadPlatformService.class) + public PasswordValidationPolicyReadPlatformService passwordValidationPolicyReadPlatformService(JdbcTemplate jdbcTemplate, + DatabaseSpecificSQLGenerator sqlGenerator) { + return new PasswordValidationPolicyReadPlatformServiceImpl(jdbcTemplate, sqlGenerator); + } + + @Bean + @ConditionalOnMissingBean(PermissionReadPlatformService.class) + public PermissionReadPlatformService permissionReadPlatformService(PlatformSecurityContext context, JdbcTemplate jdbcTemplate, + DatabaseSpecificSQLGenerator sqlGenerator) { + return new PermissionReadPlatformServiceImpl(context, jdbcTemplate, sqlGenerator); + } + + @Bean + @ConditionalOnMissingBean(PermissionWritePlatformService.class) + public PermissionWritePlatformService permissionWritePlatformService(PlatformSecurityContext context, + PermissionRepository permissionRepository, PermissionsCommandFromApiJsonDeserializer fromApiJsonDeserializer) { + return new PermissionWritePlatformServiceJpaRepositoryImpl(context, permissionRepository, fromApiJsonDeserializer); + } + + @Bean + @ConditionalOnMissingBean(RoleReadPlatformService.class) + public RoleReadPlatformService roleReadPlatformService(JdbcTemplate jdbcTemplate) { + return new RoleReadPlatformServiceImpl(jdbcTemplate); + } + + @Bean + @ConditionalOnMissingBean(RoleWritePlatformService.class) + public RoleWritePlatformService roleWritePlatformService(PlatformSecurityContext context, RoleRepository roleRepository, + PermissionRepository permissionRepository, RoleDataValidator roleCommandFromApiJsonDeserializer, + PermissionsCommandFromApiJsonDeserializer permissionsFromApiJsonDeserializer) { + return new RoleWritePlatformServiceJpaRepositoryImpl(context, roleRepository, permissionRepository, + roleCommandFromApiJsonDeserializer, permissionsFromApiJsonDeserializer); + } +}