# File lib/openshift-origin-controller/app/controllers/legacy_broker_controller.rb, line 397
  def authenticate
    @request_id = gen_req_uuid
    begin
      auth = OpenShift::AuthService.instance.login(request, params, cookies)

      if auth  
        @login = auth[:username]
        @auth_method = auth[:auth_method]

        @cloud_user = CloudUser.find @login
        if @cloud_user.nil?
          Rails.logger.debug "Adding user #{@login}...inside legacy_controller"
          @cloud_user = CloudUser.new(@login)
          begin
            @cloud_user.save
          rescue Exception => e
            cu = CloudUser.find @login
            raise unless cu && (@cloud_user.parent_user_login == cu.parent_user_login)
            @cloud_user = cu
          end
        end
        @cloud_user.auth_method = @auth_method unless @cloud_user.nil?
      end
      unless @login
        log_action('nil','nil', 'nil', "LEGACY_BROKER", true, "Authentication failed: Invalid user credentials")
        @reply.resultIO << "Invalid user credentials"
        @reply.exitcode = 97
        render :json => @reply, :status => :unauthorized
      end
    rescue OpenShift::AccessDeniedException
      log_action('nil','nil', 'nil', "LEGACY_BROKER", true, "Authentication failed: Invalid user credentials")
      @reply.resultIO << "Invalid user credentials"
      @reply.exitcode = 97
      render :json => @reply, :status => :unauthorized
    end
  end