Sha256: e7f4883b88955e500b42ddaca49f5164e13e0f8c00e04b7f5d50c368d76ab3cb

Contents?: true

Size: 1.92 KB

Versions: 1

Compression:

Stored size: 1.92 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

    # Principal does not support impersonation.
    class NoPolicyImpersonationError < Error
      def initialize( message = :no_policy_impersonation )
        super
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shamu-0.0.24 lib/shamu/security/error.rb