diff --git a/skill-tree/src/main/java/com/RDS/skilltree/annotations/AuthorizedRoles.java b/skill-tree/src/main/java/com/RDS/skilltree/annotations/AuthorizedRoles.java index 93a03c1e..32e798b8 100644 --- a/skill-tree/src/main/java/com/RDS/skilltree/annotations/AuthorizedRoles.java +++ b/skill-tree/src/main/java/com/RDS/skilltree/annotations/AuthorizedRoles.java @@ -1,7 +1,6 @@ package com.RDS.skilltree.annotations; import com.RDS.skilltree.User.UserRoleEnum; - import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; diff --git a/skill-tree/src/main/java/com/RDS/skilltree/apis/SkillsApi.java b/skill-tree/src/main/java/com/RDS/skilltree/apis/SkillsApi.java index e7052432..b5e76f43 100644 --- a/skill-tree/src/main/java/com/RDS/skilltree/apis/SkillsApi.java +++ b/skill-tree/src/main/java/com/RDS/skilltree/apis/SkillsApi.java @@ -9,6 +9,7 @@ import com.RDS.skilltree.viewmodels.SkillViewModel; import jakarta.validation.Valid; import jakarta.validation.constraints.Min; +import java.util.List; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Page; @@ -16,8 +17,6 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import java.util.List; - @Slf4j @RestController @RequiredArgsConstructor diff --git a/skill-tree/src/main/java/com/RDS/skilltree/aspects/AuthorizedRolesAspect.java b/skill-tree/src/main/java/com/RDS/skilltree/aspects/AuthorizedRolesAspect.java index 34e0e92d..65ff6c2f 100644 --- a/skill-tree/src/main/java/com/RDS/skilltree/aspects/AuthorizedRolesAspect.java +++ b/skill-tree/src/main/java/com/RDS/skilltree/aspects/AuthorizedRolesAspect.java @@ -4,6 +4,7 @@ import com.RDS.skilltree.User.UserRoleEnum; import com.RDS.skilltree.annotations.AuthorizedRoles; import com.RDS.skilltree.exceptions.ForbiddenException; +import java.lang.reflect.Method; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; @@ -11,19 +12,17 @@ import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Component; -import java.lang.reflect.Method; - @Aspect @Component public class AuthorizedRolesAspect { @Around("@within(authorizedRoles) || @annotation(authorizedRoles)") - public Object authorize(ProceedingJoinPoint joinPoint, AuthorizedRoles authorizedRoles) throws Throwable { + public Object authorize(ProceedingJoinPoint joinPoint, AuthorizedRoles authorizedRoles) + throws Throwable { JwtUserModel jwtDetails = (JwtUserModel) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); UserRoleEnum role = jwtDetails.getRole(); - MethodSignature signature = (MethodSignature) joinPoint.getSignature(); Method method = signature.getMethod(); Class targetClass = method.getDeclaringClass(); diff --git a/skill-tree/src/main/java/com/RDS/skilltree/exceptions/GlobalExceptionHandler.java b/skill-tree/src/main/java/com/RDS/skilltree/exceptions/GlobalExceptionHandler.java index 73b0e4c7..c21e447f 100644 --- a/skill-tree/src/main/java/com/RDS/skilltree/exceptions/GlobalExceptionHandler.java +++ b/skill-tree/src/main/java/com/RDS/skilltree/exceptions/GlobalExceptionHandler.java @@ -2,6 +2,7 @@ import com.RDS.skilltree.utils.GenericResponse; import jakarta.validation.ConstraintViolationException; +import java.util.List; import lombok.extern.slf4j.Slf4j; import org.apache.tomcat.websocket.AuthenticationException; import org.springframework.http.HttpStatus; @@ -14,8 +15,6 @@ import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.context.request.WebRequest; -import java.util.List; - @Slf4j @ControllerAdvice public class GlobalExceptionHandler {