Class: RSAML::Action

Inherits:
Object
  • Object
show all
Includes:
Validatable
Defined in:
lib/rsaml/action.rb

Overview

Specifies an action on the specified resource for which permission is sought. Its value provides the label for an action sought to be performed on the specified resource.

Instance Attribute Summary collapse

Attributes included from Validatable

#verbose

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Validatable

#valid?

Constructor Details

#initialize(value) ⇒ Action

Initialize the action with the given value.



25
26
27
# File 'lib/rsaml/action.rb', line 25

def initialize(value)
  @value = value
end

Instance Attribute Details

#namespaceObject

The action namespace.



19
20
21
# File 'lib/rsaml/action.rb', line 19

def namespace
  @namespace
end

#valueObject

The action value



22
23
24
# File 'lib/rsaml/action.rb', line 22

def value
  @value
end

Class Method Details

.from_xml(element) ⇒ Object

Construct an Action instance from the given XML Element or fragment.



48
49
50
51
52
53
54
55
# File 'lib/rsaml/action.rb', line 48

def self.from_xml(element)
  element = REXML::Document.new(element).root if element.is_a?(String)
  action = Action.new(element.text)
  if (namespace_attribute = element.attribute('Namespace'))
    action.namespace = ActionNamespace.namespace_for_uri(namespace_attribute.value)
  end
  action
end

.namespacesObject

Identifiers that MAY be used in the namespace attribute of the Action element to refer to common sets of actions to perform on resources.

Each namespace provides a defined set of actions. Please refer to the SAML 2.0 specification for additional information.



12
13
14
# File 'lib/rsaml/action.rb', line 12

def self.namespaces
  ActionNamespace.namespaces
end

Instance Method Details

#to_xml(xml = Builder::XmlMarkup.new) ⇒ Object

Construct an XML fragment representing the action.



41
42
43
44
45
# File 'lib/rsaml/action.rb', line 41

def to_xml(xml=Builder::XmlMarkup.new)
  attributes = {}
  attributes['Namespace'] = namespace unless namespace.nil?
  xml.tag!('saml:Action', attributes, value)
end

#validateObject

Validate the structure

Raises:



35
36
37
38
# File 'lib/rsaml/action.rb', line 35

def validate
  raise ValidationError, "Action value must be specified" if value.nil?
  raise ValidationError, "Action value not in given namespace" unless namespace.valid_action?(value)
end