Class UnauthorizedException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
me.josephsf.jobportaljosephsfeir.exception.UnauthorizedException
- All Implemented Interfaces:
Serializable
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 Summary
ConstructorsConstructorDescriptionUnauthorizedException(String message) Constructs a new unauthorized exception with the specified detail message.UnauthorizedException(String message, Throwable cause) Constructs a new unauthorized exception with the specified detail message and cause. -
Method Summary
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
UnauthorizedException
Constructs a new unauthorized exception with the specified detail message.- Parameters:
message- the detail message (which is saved for later retrieval by theThrowable.getMessage()method)
-
UnauthorizedException
Constructs a new unauthorized exception with the specified detail message and cause.- Parameters:
message- the detail message (which is saved for later retrieval by theThrowable.getMessage()method)cause- the cause (which is saved for later retrieval by theThrowable.getCause()method)
-