Class UnauthorizedException

java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
me.josephsf.jobportaljosephsfeir.exception.UnauthorizedException
All Implemented Interfaces:
Serializable

@ResponseStatus(UNAUTHORIZED) public class UnauthorizedException extends RuntimeException
Exception thrown when a user attempts to access a resource without proper authentication or with insufficient permissions.

This exception is automatically mapped to an HTTP 401 UNAUTHORIZED response status by Spring using the ResponseStatus annotation. It's used throughout the Job Portal application when authentication fails or when a user tries to perform an action they are not authorized to perform.

Examples of when this exception might be thrown:

  • User attempts to access a protected endpoint without a valid JWT token
  • The JWT token has expired or is invalid
  • A candidate tries to access recruiter-only endpoints
  • A recruiter tries to access another recruiter's job postings

Note: This differs from AccessDeniedException which results in a 403 FORBIDDEN response when a user is authenticated but explicitly not allowed to access a resource.

Since:
2025-05-15
See Also:
  • Constructor Details

    • UnauthorizedException

      public UnauthorizedException(String message)
      Constructs a new unauthorized exception with the specified detail message.
      Parameters:
      message - the detail message (which is saved for later retrieval by the Throwable.getMessage() method)
    • UnauthorizedException

      public UnauthorizedException(String message, Throwable cause)
      Constructs a new unauthorized exception with the specified detail message and cause.
      Parameters:
      message - the detail message (which is saved for later retrieval by the Throwable.getMessage() method)
      cause - the cause (which is saved for later retrieval by the Throwable.getCause() method)