Пример #1
0
def application(environ, start_response):
    """
    WSGI application. Handles all requests.
    :param environ: WSGI enviroment.
    :param start_response: WSGI start response.
    :return: Depends on the request. Always a WSGI response where start_response first have to be initialized.
    """
    session = Session(environ)

    http_helper = HttpHandler(environ, start_response, session, logger)

    parameters = http_helper.query_dict()

    test = Test(environ, start_response, session, logger, LOOKUP, config,
                parameters, CACHE)
    path = http_helper.path()

    http_helper.log_request()
    response = None
    if http_helper.verify_static(path):
        return http_helper.handle_static(path)

    if test.verify(path):
        return test.handle(path)

    if response is None:
        response = http_helper.http404()

    http_helper.log_response(response)
    return response
Пример #2
0
def application(environ, start_response):
    """
    WSGI application. Handles all requests.
    :param environ: WSGI enviroment.
    :param start_response: WSGI start response.
    :return: Depends on the request. Always a WSGI response where start_response first have to be initialized.
    """
    try:
        start_response = start_response_intercept(start_response)
        session = Session(environ)

        http_helper = HttpHandler(environ, start_response, session, logger)
        path = http_helper.path()

        environ = sphandler.verify_sp_user_validity(session, environ, path)
        http_helper.log_request()
        response = None
        if server_conf.OP_FRONTEND and ophandler.verify_provider_requests(
                path):
            response = ophandler.handle_provider_requests(
                environ, start_response, path, session)
        if server_conf.IDP_FRONTEND and idphandler.verify_provider_requests(
                path, environ):
            response = idphandler.handle_provider_requests(
                environ, start_response, path)
        elif sphandler.verify_sp_requests(path):
            response = sphandler.handle_sp_requests(environ, start_response,
                                                    path, session)
        elif http_helper.verify_static(path):
            return http_helper.handle_static(path)

        if response is None:
            response = http_helper.http404()

        http_helper.log_response(response)
        #Catch all unauthorized attempts and present a better web page.
        if start_response.status[0:3] == "401":
            mte = LOOKUP.get_template("unauthorized.mako")
            message = None
            if len(response) == 1:
                message = str(response[0])
            if message is None or len(message.strip()) == 0:
                message = "You are not authorized!"
            argv = {
                "message": message,
            }
            return [mte.render(**argv)]
        return response
    except Exception, excp:
        urn = uuid4().urn
        logger.error("uuid: " + str(urn) + str(exception_trace(excp)))
        argv = {
            "log_id": str(urn),
        }
        mte = LOOKUP.get_template("bad_request.mako")
        resp = BadRequest(mte.render(**argv))
        return resp(environ, start_response)
Пример #3
0
def handle_path(environ, start_response, response_encoder):
    path = environ.get('PATH_INFO', '').lstrip('/')
    session = environ['beaker.session']
    http_helper = HttpHandler(environ, start_response, session, LOGGER)

    parameters = http_helper.query_dict()
    if path == "favicon.ico":
        return static(environ, start_response, "static/favicon.ico")
    if path.startswith("static/"):
        return static(environ, start_response, path)

    # TODO This is all web frameworks which should be imported via dirg-util
    if path.startswith("_static/"):
        return static(environ, start_response, path)
    if path.startswith("export/"):
        return static(environ, start_response, path)
    if path == "":
        return op_config(environ, start_response, "test_instance_list.mako")
    if path == "config_page":
        return op_config(environ, start_response, "op_config.mako")
    if path == "create_new_config_file":
        return handle_create_new_config_file(response_encoder, session,
                                             parameters)
    if path == "get_op_config":
        return handle_get_op_config(session, response_encoder)
    if path == "does_op_config_exist":
        return handle_does_op_config_exist(session, response_encoder)
    if path == "download_config_file":
        return handle_download_config_file(response_encoder, parameters)
    if path == "upload_config_file":
        return handle_upload_config_file(parameters, session, response_encoder)
    if path == "start_op_tester":
        return handle_start_test_instance(session, response_encoder,
                                          parameters)
    if path == "get_redirect_url":
        return handle_get_redirect_url(session, response_encoder, parameters)
    if path == "request_instance_ids":
        return handle_request_instance_ids(response_encoder, parameters)
    if path == "submit_contact_info":
        return handle_submit_contact_info(response_encoder, parameters)
    if path == "load_existing_config":
        return handle_load_existing_config(response_encoder, session,
                                           parameters)
    if path == "load_existing_contact_info":
        return handle_load_existing_contact_info(response_encoder, parameters)
    if path == "restart_test_instance":
        return handle_restart_test_instance(response_encoder, parameters)
    return http_helper.http404()