def authenticate(self, headers, target_host, target_port):
    # check authentification
    if 'Cookie' not in headers: # error if not Cookie is defined
      raise auth_plugins.AuthenticationError(log_msg="No cookie provided.")
    # get cookie and get the mbsimenvsessionid form the cookie
    cookie=headers['Cookie']
    c=Cookie.SimpleCookie(cookie)
    if 'mbsimenvsessionid' not in c:
      raise auth_plugins.AuthenticationError(log_msg="No mbsimenvsessionid provided in cookie.")
    sessionid=c['mbsimenvsessionid'].value
    # call www.mbsim-env.de to check to session ID (we can do this my checking the config file of the server directly
    # but this file is not readable for this user for security reasons)
    response=requests.post('https://www.mbsim-env.de/cgi-bin/mbsimBuildServiceServer.py/checkmbsimenvsessionid',
      json={'mbsimenvsessionid': sessionid})
    # if the response is OK and success is true than continue
    if response.status_code!=200:
      raise auth_plugins.AuthenticationError(log_msg="Checking session ID failed.")
    d=response.json()
    if 'success' not in d:
      raise auth_plugins.AuthenticationError(log_msg="Invalid response from mbsim server.")
    if not d['success']:
      raise auth_plugins.AuthenticationError(log_msg=d['message'])

    token=globalToken
    display=target_port-5900

    # start vnc and other processes in a sandbox
    if os.path.exists(PIDFILE%(display)): os.remove(PIDFILE%(display))
    w=subprocess.Popen(['/usr/bin/python', os.path.dirname(__file__)+'/mbsimwebapp_service_run_wrapper.py', token, str(display)])
    # ... and wait until the pid file exists
    count=0
    while not os.path.exists(PIDFILE%(display)) and count<2000:
      time.sleep(0.01)
      count=count+1
    if not os.path.exists(PIDFILE%(display)):
      w.terminate()
      raise auth_plugins.AuthenticationError(log_msg="Failed to start vnc server.")
 def authenticate(self, headers, target_host, target_port):
     if target_host == self.source:
         raise auth_plugins.AuthenticationError(
             response_msg="some_error")