validate assigned application

This commit is contained in:
rajesh
2024-10-25 12:00:21 +05:30
parent 4ef26827e7
commit 84636abbc5
6 changed files with 72 additions and 27 deletions

View File

@@ -64,6 +64,20 @@ public class Validator {
}
return false;
}
public Boolean checkIsPreInstructor() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication != null && authentication.isAuthenticated()) {
// Check if the user has the ROLE_SUPER_ADMIN authority
for (GrantedAuthority authority : authentication.getAuthorities()) {
if (RoleStatusEnum.ROLE_PRE_INSTRUCTOR.getValue().equals(authority.getAuthority())) {
return true;
}
}
}
return false;
}
public void validateRequest(HttpServletRequest request,RoleStatusEnum role) {
if (RoleStatusEnum.ROLE_SUPER_ADMIN.equals(role) && Boolean.FALSE.equals(checkIsSuperAdmin())) {
@@ -138,5 +152,20 @@ public class Validator {
String[] activeProfiles = environment.getActiveProfiles();
return Arrays.stream(activeProfiles).anyMatch("production"::equals);
}
public UserEntity validatePreInstructor(HttpServletRequest request, Long preInstructorUserId) {
UserEntity preInstructorUser = userService.validateUser(preInstructorUserId);
if (checkIsSuperAdmin()) {
if (preInstructorUserId != null) {
validateHubId(request, preInstructorUser.getHub().getId());
}
return preInstructorUser;
} else if (checkIsPreInstructor()) {
return validateUserId(request, preInstructorUserId);
} else {
throw new ForbiddenAccessException(Status.FORBIDDEN,
Translator.toLocale(GepafinConstant.PERMISSION_DENIED));
}
}
}