Exemple #1
0
def bisque_request_classifier(environ):
    request_method = REQUEST_METHOD(environ)
    content_type = CONTENT_TYPE(environ)
    if request_method == "POST" and content_type.startswith(
            "application/json"):
        return "json"
    if content_type.startswith("application/xml"):
        return "xml"
    return default_request_classifier(environ)
Exemple #2
0
def checkContentTypeIgnoreCase(request, expectedContentType):
    """Performs Content-Type validation of the incoming request, ignoring case
    and any <code>charset</code> parameter.

    @see   #checkCharacterEncodingIgnoreCase(HttpServletRequest, String)
    @param request the incoming request
    @param expectedContentType the expected Content-Type for the incoming
           request
    @throws ServletException if the request's content type is not
            <code>null</code> and does not, ignoring case, equal
            <code>expectedContentType</code>,
    """
    assert expectedContentType is not None
    contentType = CONTENT_TYPE(request.environ())
    contentTypeIsOkay = False
    if contentType is not None:
        contentType = contentType.lower()
        # NOTE:We use startsWith because some servlet engines, do
        # not remove the charset component but others do.
        if contentType.startswith(expectedContentType.lower()):
            contentTypeIsOkay = True
    if not contentTypeIsOkay:
        raise ServletException('Content-Type was \'' + (
            '(null)' if contentType is None else contentType) +
                               '\'. Expected \'' + expectedContentType + '\'.')
Exemple #3
0
def checkContentTypeIgnoreCase(request, expectedContentType):
    """Performs Content-Type validation of the incoming request, ignoring case
    and any <code>charset</code> parameter.

    @see   #checkCharacterEncodingIgnoreCase(HttpServletRequest, String)
    @param request the incoming request
    @param expectedContentType the expected Content-Type for the incoming
           request
    @throws ServletException if the request's content type is not
            <code>null</code> and does not, ignoring case, equal
            <code>expectedContentType</code>,
    """
    assert expectedContentType is not None
    contentType = CONTENT_TYPE(request.environ())
    contentTypeIsOkay = False
    if contentType is not None:
        contentType = contentType.lower()
        # NOTE:We use startsWith because some servlet engines, do
        # not remove the charset component but others do.
        if contentType.startswith(expectedContentType.lower()):
            contentTypeIsOkay = True
    if not contentTypeIsOkay:
        raise ServletException('Content-Type was \''
                + ('(null)' if contentType is None else contentType)
                + '\'. Expected \'' + expectedContentType + '\'.')
Exemple #4
0
 def challenge(self, environ, status, app_headers, forget_headers):
     log.debug ("APP CHALLENGE %s %s %s %s", environ.keys(), status, app_headers, forget_headers)
     content_type = CONTENT_TYPE(environ)
     log.debug ("APP CONTENT %s", content_type)
     if any (content_type.startswith(v) for v in ('application/json', 'application/xml')):
         return  Response(status=401, content_type=content_type, body="")
     return None
Exemple #5
0
    def identify(self, environ):
        request = Request(environ)

        # first test for logout as we then don't need the rest
        if request.path == self.logout_path:
            headers = self.forget(environ, {})
            raise HTTPFound (location="/", headers = headers)

        if request.path == self.login_path:
            content_type = CONTENT_TYPE(environ)
            if content_type.startswith('application/json'):
                login_data = json.load (request.body_file)
            elif content_type.startswith('application/xml'):
                xml = etree.parse (request.body_file).getroot()
                login_data = dict (username = xml.find ("tag[@name='username']").get('value'),
                                   password = xml.find ("tag[@name='password']").get('value'))
            else:
                return None
            log.debug ("found user %s", login_data.get('username', None))
            return { 'login': login_data.get('username', None), 'password': login_data.get('password', None) }
        return None