use of org.apache.nifi.registry.security.authorization.resource.ResourceType in project nifi-registry by apache.
the class ResourceAuthorizationFilter method doFilter.
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse;
boolean authorizationCheckIsRequired = false;
String resourcePath = null;
RequestAction action = null;
// Only require authorization if the NiFi Registry is running securely.
if (servletRequest.isSecure()) {
// Only require authorization for resources for which this filter has been configured
resourcePath = httpServletRequest.getServletPath();
if (resourcePath != null) {
final ResourceType resourceType = ResourceType.mapFullResourcePathToResourceType(resourcePath);
final HttpMethodAuthorizationRules authorizationRules = resourceTypeAuthorizationRules.get(resourceType);
if (authorizationRules != null) {
final String httpMethodStr = httpServletRequest.getMethod().toUpperCase();
HttpMethod httpMethod = HttpMethod.resolve(httpMethodStr);
// Only require authorization for HTTP methods included in this resource type's rule set
if (httpMethod != null && authorizationRules.requiresAuthorization(httpMethod)) {
authorizationCheckIsRequired = true;
action = authorizationRules.mapHttpMethodToAction(httpMethod);
}
}
}
}
if (!authorizationCheckIsRequired) {
forwardRequestWithoutAuthorizationCheck(httpServletRequest, httpServletResponse, filterChain);
return;
}
// Perform authorization check
try {
authorizeAccess(resourcePath, action);
successfulAuthorization(httpServletRequest, httpServletResponse, filterChain);
} catch (Exception e) {
logger.debug("Exception occurred while performing authorization check.", e);
failedAuthorization(httpServletRequest, httpServletResponse, filterChain, e);
}
}
Aggregations