Admin REST¶
Extensions project module
Mirror all resources in admin context: on admin side special servlet simply redirects all incoming requests into the jersey context. Hides admin-only resources from user context: resource is working under admin context and return 404 on user context.
Such approach is better than registering a completely separate jersey context for admin rest because of no overhead and the simplicity of jersey extensions management.
Features: * All user context rest available in admin context * Admin-only resources not visible in user context
Setup¶
Remove version
in dependency declaration below if you using the BOM extensions.
Maven:
<dependency>
<groupId>ru.vyarus.guicey</groupId>
<artifactId>guicey-admin-rest</artifactId>
<version>5.4.2-1</version>
</dependency>
Gradle:
implementation 'ru.vyarus.guicey:guicey-admin-rest:5.4.2-1'
See the most recent version in the badge above.
Usage¶
Register bundle:
GuiceBundle.builder()
.bundles(new AdminRestBundle());
In this case, rest is registered either to '/api/', if main context rest is mapped to root ('/') or to the same path as main context rest.
To register on a custom path:
.bundles(new AdminRestBundle("/custom/*"));
Note
In case if multiple bundles registered, only first registration will be used (due to de-duplication)
Security¶
In order to hide specific resource methods or entire resources on the main context, annotate resource methods
or resource classes with the @AdminResource
annotation.
For example:
@GET
@Path("/admin")
@AdminResource
public String admin() {
return "admin"
}
This (annotated) method will return 404 error when called from main context, but should function normally when called from the admin context.