Class RestGuard
- Direct Known Subclasses:
- AdminGuard,- RoleBasedRestGuard
Description
Implements a guard mechanism for REST method calls that allows requests to be rejected before invocation of the REST method. For example, guards can be used to ensure that only administrators can call certain methods.
 Guards are applied to REST methods declaratively through the @Rest(guards) or
 @RestOp(guards) annotations.
 
If multiple guards are specified, ALL guards must pass in order for the request to proceed.
How to implement
Typically, guards will be used for permissions checking on the user making the request, but it can also be used for other purposes like pre-call validation of a request.
 Implementers should simply throw a BasicHttpException from the guard(RestRequest, RestResponse)
 method to abort processing on the current request.
 
Guards must implement a no-args constructor.
Example usage:
   
Example implementation:
   
See Also:
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionbooleanguard(RestRequest req, RestResponse res) Checks the current HTTP request and throws aBasicHttpExceptionif the guard does not permit the request.abstract booleanReturnstrue if the specified request can pass through this guard.
- 
Constructor Details- 
RestGuardpublic RestGuard()
 
- 
- 
Method Details- 
guardChecks the current HTTP request and throws aBasicHttpExceptionif the guard does not permit the request.By default, throws an SC_FORBIDDEN exception ifisRequestAllowed(RestRequest)returnsfalse .Subclasses are free to override this method to tailor the behavior of how to handle unauthorized requests. - Parameters:
- req- The servlet request.
- res- The servlet response.
- Returns:
- true if request can proceed. Specify- false if you're doing something like a redirection to a login page.
- Throws:
- BasicHttpException- Thrown to abort processing on current request.
 
- 
isRequestAllowedReturnstrue if the specified request can pass through this guard.- Parameters:
- req- The servlet request.
- Returns:
- true if the specified request can pass through this guard.
 
 
-