Record Class ServletMapping
- Record Components:
pathMapping
- ant path to match urls that will be handled by provided servletorder
- order of servlet used to define overriding order (negative values are also supported but not recommended)servlet
- servlet to be invoked when path is matchedinitParameters
- parameters to be passed toServlet.init(ServletConfig)
when servlet is initiated
- All Implemented Interfaces:
FeatureDescriptor
Overriding works by utilizing order parameter. Servlets will lesser value of order are executed earlier, and when two servlets have the same order, then the one with more specific path matcher is executed as first. So it means if plugin with path mapping `/**` and order 1 will execute before all servlets with order 10. It allows to override paths defined by other servlets, which can be useful for use cases like: overriding login form, overriding MFA mechanism, etc. It is powerful tool, so consider using other tools before using servlets override.
Passing through is supplemental functionality to overriding. If plugin defined servlet throws NotHandledException
,
then request will be passed to the next servlet that matches request. For example if servlet matching `/login/**` throws
NotHandledException
then DispatcherServlet
will be invoked.
If all servlets matching request will throw NotHandledException
then 404 Not Found error will be returned.
DispatcherServlet
provided by spring, that supports all spring based controllers
(including ones defined by plugins) is defined as mapping `/**` with order 10, and it passes through all requests that don't
match any controller. So it is possible to define servlets that matches all not mapped requests by defining servlet
mapping `/**` with order 11.
There are implemented some security mechanisms that affects all requests like authentication or CSRF protection.
To enable some degree of control over these mechanisms provided servlet may implement control interfaces that are
available in package eu.rarogsoftware.rarog.platform.api.plugins.web.servlets
and their name ends with `Aware`,
like AuthorizationManagerAware
or CsrfProtectionAware
.
Example:
public class OverridingServlet extends HttpServlet implements AuthorizationManagerAware, CsrfProtectionAware { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { resp.setStatus(HttpServletResponse.SC_OK); resp.getWriter().write("Overriding servlet response"); } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { resp.setStatus(HttpServletResponse.SC_OK); resp.getWriter().write("Overriding servlet response"); } @Override public OptionalgetAccessDecisionVoter(HttpServletRequest request) { return Optional.of(new AccessDecisionVoter() { @Override public boolean supports(ConfigAttribute attribute) { return true; } @Override public boolean supports(Class clazz) { return true; } @Override public int vote(Authentication authentication, Object object, Collection collection) { return ACCESS_GRANTED; } }); } @Override public Optional shouldDisableCsrfProtection(HttpServletRequest request) { return Optional.of(true); } }
NOTE: org.springframework.security.web.util.matcher.AntPathRequestMatcher
is used to match the patterns.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionServletMapping
(String pathMapping, int order, jakarta.servlet.http.HttpServlet servlet) ServletMapping
(String pathMapping, int order, jakarta.servlet.http.HttpServlet servlet, Map<String, String> initParameters) Creates an instance of aServletMapping
record class.ServletMapping
(String pathMapping, jakarta.servlet.http.HttpServlet servlet) -
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
Indicates whether some other object is "equal to" this one.final int
hashCode()
Returns a hash code value for this object.Returns the value of theinitParameters
record component.int
order()
Returns the value of theorder
record component.Returns the value of thepathMapping
record component.jakarta.servlet.http.HttpServlet
servlet()
Returns the value of theservlet
record component.final String
toString()
Returns a string representation of this record class.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface eu.rarogsoftware.rarog.platform.api.plugins.FeatureDescriptor
getName
-
Field Details
-
DEFAULT_ORDER
public static final int DEFAULT_ORDER- See Also:
-
-
Constructor Details
-
ServletMapping
public ServletMapping(String pathMapping, int order, jakarta.servlet.http.HttpServlet servlet, Map<String, String> initParameters) Creates an instance of aServletMapping
record class.- Parameters:
pathMapping
- the value for thepathMapping
record componentorder
- the value for theorder
record componentservlet
- the value for theservlet
record componentinitParameters
- the value for theinitParameters
record component
-
ServletMapping
-
ServletMapping
-
-
Method Details
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object)
; primitive components are compared with '=='. -
pathMapping
Returns the value of thepathMapping
record component.- Returns:
- the value of the
pathMapping
record component
-
order
public int order()Returns the value of theorder
record component.- Returns:
- the value of the
order
record component
-
servlet
public jakarta.servlet.http.HttpServlet servlet()Returns the value of theservlet
record component.- Returns:
- the value of the
servlet
record component
-
initParameters
Returns the value of theinitParameters
record component.- Returns:
- the value of the
initParameters
record component
-