Merge branch 'develop' into feature/GEPAFINBE-64

This commit is contained in:
nishainnogent
2024-10-16 17:37:54 +05:30
committed by GitHub
11 changed files with 65 additions and 9 deletions

View File

@@ -106,6 +106,8 @@ public class SecurityConfig {
.requestMatchers("/saml2/**").permitAll() // SAML login initiation
.requestMatchers("/swagger-ui/**").permitAll() // Swagger docs
.requestMatchers("/v1/api-docs/**").permitAll() // API docs
.requestMatchers("/v1/user/reset-password/initiate").permitAll()
.requestMatchers("/v1/user/reset-password").permitAll()
.anyRequest().authenticated())
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED))
.exceptionHandling(exceptionHandling -> exceptionHandling

View File

@@ -231,5 +231,7 @@ public class GepafinConstant {
public static final String LOGIN_ATTEMPTED_CREATED_SUCCESSFULLY="login_attempt_successfully_created";
public static final String GET_LOGIN_ATTEMPT_MSG="get_login_attempt_se_msg";
public static final String CANNOT_DELETE_COMPANY_WITH_APPLICATION_SUBMITT = "application.in.submit.status.cannot.delete.company";
public static final String GET_USERS_SUCCESS_MSG = "get.users.success.msg";
}

View File

@@ -33,6 +33,7 @@ import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.stream.Collectors;
import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
@@ -354,5 +355,22 @@ public class UserDao {
return authService.validateNewUserToken(token);
}
public List<UserResponseBean> getAllUsers(Long roleId) {
List<UserEntity> users;
if (roleId != null) {
log.info("Fetching users by role ID: {}", roleId);
users = userRepository.findByRoleEntityId(roleId);
} else {
log.info("Fetching all users");
users = userRepository.findAll();
}
List<UserResponseBean> userResponseBeans = users.stream()
.map(this::convertUserEntityToUserResponse)
.collect(Collectors.toList());
log.info("Total users found with role ID {}: {}", roleId, userResponseBeans.size());
return userResponseBeans;
}
}

View File

@@ -1,9 +1,11 @@
package net.gepafin.tendermanagement.repositories;
import net.gepafin.tendermanagement.entities.UserEntity;
import net.gepafin.tendermanagement.model.response.UserResponseBean;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
@Repository
@@ -21,5 +23,5 @@ public interface UserRepository extends JpaRepository<UserEntity, Long> {
UserEntity findByBeneficiaryId(Long beneficiaryId);
Long countByStatusAndRoleEntity_RoleType(String status, String roleName);
List<UserEntity> findByRoleEntityId(Long roleId);
}

View File

@@ -12,6 +12,8 @@ import net.gepafin.tendermanagement.model.response.UserSamlResponse;
import net.gepafin.tendermanagement.model.response.UserResponseBean;
import net.gepafin.tendermanagement.model.util.JWTToken;
import java.util.List;
public interface UserService {
JWTToken createUser(HttpServletRequest request, String tempToken, UserReq userReq);
@@ -43,5 +45,6 @@ public interface UserService {
UserEntity getUserByBeneficiaryId(Long beneficiaryId);
public UserEntity getUserEntityById(Long userId);
List<UserResponseBean> getAllUsers(Long roleId);
}

View File

@@ -72,7 +72,7 @@ public class AuthenticationService {
public JWTToken login(LoginReq loginReq,HttpServletRequest request) {
UserEntity user=null;
try {
LoginAttemptEntity loginAttemptEntity = prepareLoginAttemptEntity(loginReq, request);
log.info("Attempting login for email: {}", loginReq.getEmail());
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(
@@ -89,10 +89,6 @@ public class AuthenticationService {
Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG));
}
createSuccessLoginAttempt(loginAttemptEntity);
} catch (Exception e) {
}
return getJWTTokenBean(user, loginReq.getRememberMe());
}

View File

@@ -21,6 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service
@@ -124,4 +125,10 @@ public class UserServiceImpl implements UserService {
// Calling DAO Function
return userDao.validateUser(userId);
}
@Override
@Transactional(readOnly = true)
public List<UserResponseBean> getAllUsers(Long roleId) {
// Calling DAO Function
return userDao.getAllUsers(roleId);
}
}

View File

@@ -22,6 +22,8 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@Validated
public interface UserApi {
@@ -219,6 +221,19 @@ public interface UserApi {
ResponseEntity<Response<UserSamlResponse>> validateNewUserToken(HttpServletRequest request,
@Parameter(description = "The spid token", required = true) @PathVariable("token") String token);
@Operation(summary = "Api to get all users",
responses = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE)})),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE)})),
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE)}))})
@RequestMapping(value = "", produces = {"application/json"}, method = RequestMethod.GET)
@PreAuthorize("hasRole('ROLE_SUPER_ADMIN')")
ResponseEntity<Response<List<UserResponseBean>>> getAllUsers(
@Parameter( required = false)@RequestParam(value ="roleId", required = false) Long roleId);
@RequestMapping("favicon.ico")

View File

@@ -22,6 +22,8 @@ import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("${openapi.gepafin.base-path:/v1/user}")
@@ -139,7 +141,14 @@ public class UserApiController implements UserApi {
UserSamlResponse data = userService.validateNewUserToken(request,token);
return ResponseEntity.ok(new Response<>(data, Status.SUCCESS, Translator.toLocale(GepafinConstant.TOKEN_VALIDATE_SUCCESS_MSE)));
}
@Override
public ResponseEntity<Response<List<UserResponseBean>>> getAllUsers(
Long roleId) {
log.info("Get all Users by Role ID - Role ID: {}", roleId);
List<UserResponseBean> users = userService.getAllUsers(roleId);
return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(users, Status.SUCCESS, Translator.toLocale(GepafinConstant.GET_USERS_SUCCESS_MSG)));
}
@Override
public void returnNoFavicon() {

View File

@@ -251,4 +251,5 @@ dashboard.widget.fetched.successfully=Dasboard widget fetched sucessfully.
login_attempt_successfully_created = Login attempt successfully created.
get_login_attempt_se_msg=Login attempts fetched successfully.
application.in.submit.status.cannot.delete.company=The company cannot be deleted because there are active applications in the SUBMITTED status.
get.users.success.msg = Successfully fetched users.

View File

@@ -248,3 +248,4 @@ login_attempt_successfully_created= Tentativo di login creato con successo.
get_login_attempt_se_msg=Lista dei tentativi di accesso recuperata correttamente.
application.in.submit.status.cannot.delete.company=Non è possibile eliminare l'azienda perché ci sono domande attive con stato SUBMITTED.
get.users.success.msg = Utenti recuperati con successo