Sha256: 49ea4ba892bc95debbfd216b6e13ab82c96e09672398048ba524f3758a58567c

Contents?: true

Size: 1.72 KB

Versions: 12

Compression:

Stored size: 1.72 KB

Contents

# encoding: ascii-8bit

# Copyright 2022 Ball Aerospace & Technologies Corp.
# All Rights Reserved.
#
# This program is free software; you can modify and/or redistribute it
# under the terms of the GNU Affero General Public License
# as published by the Free Software Foundation; version 3 with
# attribution addendums as found in the LICENSE.txt
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.

# Modified by OpenC3, Inc.
# All changes Copyright 2022, OpenC3, Inc.
# All Rights Reserved
#
# This file may also be used under the terms of a commercial license
# if purchased from OpenC3, Inc.

require 'openc3/models/auth_model'

begin
  require 'openc3-enterprise/utilities/authorization'
rescue LoadError
  # If we're not in openc3-enterprise we define our own
  module OpenC3
    class AuthError < StandardError
    end

    class ForbiddenError < StandardError
    end

    module Authorization
      private

      # Raises an exception if unauthorized, otherwise does nothing
      def authorize(permission: nil, target_name: nil, packet_name: nil, interface_name: nil, router_name: nil, scope: nil, token: nil)
        raise AuthError.new("Scope is required") unless scope

        if $openc3_authorize
          raise AuthError.new("Token is required") unless token
          unless OpenC3::AuthModel.verify(token, permission: permission)
            raise AuthError.new("Current role is invalid for '#{permission}' permission")
          end
        end
      end

      def user_info(_token)
        {} # EE does stuff here
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
openc3-5.8.1 lib/openc3/utilities/authorization.rb
openc3-5.8.0 lib/openc3/utilities/authorization.rb
openc3-5.7.2 lib/openc3/utilities/authorization.rb
openc3-5.7.0 lib/openc3/utilities/authorization.rb
openc3-5.6.1 lib/openc3/utilities/authorization.rb
openc3-5.6.0 lib/openc3/utilities/authorization.rb
openc3-5.5.2 lib/openc3/utilities/authorization.rb
openc3-5.5.2.pre.beta0 lib/openc3/utilities/authorization.rb
openc3-5.5.1 lib/openc3/utilities/authorization.rb
openc3-5.5.0 lib/openc3/utilities/authorization.rb
openc3-5.5.0.pre.beta0 lib/openc3/utilities/authorization.rb
openc3-5.4.3.pre.beta0 lib/openc3/utilities/authorization.rb