validate assigned application
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user