Sha256: fc11ed8828b2d97c5d246c2ea5c28d282f219936266d0424edab441362cb71ba

Contents?: true

Size: 1.74 KB

Versions: 6

Compression:

Stored size: 1.74 KB

Contents

require "i18n"

module Shamu
  module Security

    # A generic error class for problems with shamu services.
    class Error < Shamu::Error
      private

        def translation_scope
          super.dup.insert( 1, :security )
        end

    end

    # The requested action was not permitted on the resource.
    class AccessDeniedError < Error

      # ============================================================================
      # @!group Attributes
      #

      # @return [Symbol] the requested action that was denied.
      attr_reader :action

      # @return [Object] the resource the {#action} was to be performed on.
      attr_reader :resource

      # @return [Principal] the security {Principal} in use at the time of the
      #     policy violation.
      attr_reader :principal

      # @return [Object] additional principal provided to the policy authorization
      #     method.
      attr_reader :additional_context

      #
      # @!endgroup Attributes

      def initialize( message = :access_denied, action: nil, resource: nil, principal: nil, additional_context: nil )
        @action             = action
        @resource           = resource
        @principal          = principal
        @additional_context = additional_context

        super translate( :access_denied, action: action, resource: resource )
      end
    end

    # Security has been included but has not been completely set up.
    class IncompleteSetupError < Error
      def initialize( message = :incomplete_setup )
        super
      end
    end

    # A policy check was performed on an ActiveRecord resource
    class NoActiveRecordPolicyChecksError < Error
      def initialize( message = :no_actiev_record_policy_checks )
        super
      end
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
shamu-0.0.8 lib/shamu/security/error.rb
shamu-0.0.7 lib/shamu/security/error.rb
shamu-0.0.5 lib/shamu/security/error.rb
shamu-0.0.4 lib/shamu/security/error.rb
shamu-0.0.3 lib/shamu/security/error.rb
shamu-0.0.2 lib/shamu/security/error.rb