Class MultipartMalwareScanReader

  • All Implemented Interfaces:
    javax.ws.rs.ext.MessageBodyReader<org.jboss.resteasy.plugins.providers.multipart.MultipartInput>

    @Provider
    @Priority(5000)
    @Consumes("multipart/*")
    public class MultipartMalwareScanReader
    extends Object
    A reader for 'multipart/*' requests that checks uploads for invalid/illegal content. If such content is detected, the request is rejected.
    Since:
    8.4.0
    Author:
    XIMA MEDIA GmbH, Dresden
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected javax.ws.rs.ext.Providers workers  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean isReadable​(Class<?> type, Type genericType, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType)
      Checks if the given type is supported by this multipart reader implementation.
      protected T prepareAndVerify​(javax.ws.rs.core.MediaType mediaType, javax.servlet.http.HttpServletRequest servletRequest, Supplier<org.jboss.resteasy.plugins.providers.multipart.MultipartInputImpl> multipartInputFactory)
      Processes the multipart data and does the actual malware and content type checks.
      org.jboss.resteasy.plugins.providers.multipart.MultipartInput readFrom​(Class<org.jboss.resteasy.plugins.providers.multipart.MultipartInput> type, Type genericType, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType, javax.ws.rs.core.MultivaluedMap<String,​String> httpHeaders, InputStream entityStream)
      Reads the request and scans the content of the parts for malware.
    • Field Detail

      • workers

        @Context
        protected javax.ws.rs.ext.Providers workers
    • Constructor Detail

      • MultipartMalwareScanReader

        public MultipartMalwareScanReader()
    • Method Detail

      • readFrom

        public org.jboss.resteasy.plugins.providers.multipart.MultipartInput readFrom​(Class<org.jboss.resteasy.plugins.providers.multipart.MultipartInput> type,
                                                                                      Type genericType,
                                                                                      Annotation[] annotations,
                                                                                      javax.ws.rs.core.MediaType mediaType,
                                                                                      javax.ws.rs.core.MultivaluedMap<String,​String> httpHeaders,
                                                                                      InputStream entityStream)
                                                                               throws IOException,
                                                                                      javax.ws.rs.WebApplicationException
        Reads the request and scans the content of the parts for malware. If malware is detected, the request is rejected.
        Parameters:
        type - the type to read
        genericType - the generic type
        annotations - the annotations
        mediaType - the media type
        httpHeaders - the HTTP headers
        entityStream - the input stream
        Returns:
        the parsed and verified MultipartInput
        Throws:
        IOException - if an I/O error occurs
        javax.ws.rs.WebApplicationException - if a web application error occurs
      • isReadable

        public boolean isReadable​(Class<?> type,
                                  Type genericType,
                                  Annotation[] annotations,
                                  javax.ws.rs.core.MediaType mediaType)
        Checks if the given type is supported by this multipart reader implementation.
        Specified by:
        isReadable in interface javax.ws.rs.ext.MessageBodyReader<T extends org.jboss.resteasy.plugins.providers.multipart.MultipartInput>
        Parameters:
        type - the type to check
        genericType - the generic type
        annotations - the annotations
        mediaType - the media type
        Returns:
        true if the type matches, false otherwise
      • prepareAndVerify

        protected T prepareAndVerify​(javax.ws.rs.core.MediaType mediaType,
                                     javax.servlet.http.HttpServletRequest servletRequest,
                                     Supplier<org.jboss.resteasy.plugins.providers.multipart.MultipartInputImpl> multipartInputFactory)
                              throws IOException,
                                     UnsafeUploadRequestException
        Processes the multipart data and does the actual malware and content type checks.
        Parameters:
        mediaType - the media type
        servletRequest - resteasy context: the related request
        multipartInputFactory - supplier for creating the concrete MultipartInput instance
        Returns:
        a new instance of T
        Throws:
        IOException - in case of an I/O error
        javax.ws.rs.WebApplicationException - in case of detected malware or a mismatching content type
        UnsafeUploadRequestException