Class: Savon::WSSE

Inherits:
Object show all
Defined in:
lib/savon/wsse.rb

Overview

Savon::WSSE

Savon::WSSE represents WSSE authentication. Pass a block to your SOAP call and the WSSE object is passed to it as the second argument. The object allows setting the WSSE username, password and whether to use digest authentication.

Credentials

By default, Savon does not use WSSE authentication. Simply specify a username and password to change this.

response = client.get_all_users do |soap, wsse|
  wsse.username = "eve"
  wsse.password = "secret"
end

Digest

To use WSSE digest authentication, just use the digest method and set it to true.

response = client.get_all_users do |soap, wsse|
  wsse.username = "eve"
  wsse.password = "secret"
  wsse.digest = true
end

Default to WSSE

In case all you’re services require WSSE authentication, you can set your credentials and whether to use WSSE digest for every request:

Savon::WSSE.username = "eve"
Savon::WSSE.password = "secret"
Savon::WSSE.digest = true

Constant Summary collapse

BaseAddress =

Base address for WSSE docs.

"http://docs.oasis-open.org/wss/2004/01"
WSENamespace =

Namespace for WS Security Secext.

"#{BaseAddress}/oasis-200401-wss-wssecurity-secext-1.0.xsd"
WSUNamespace =

Namespace for WS Security Utility.

"#{BaseAddress}/oasis-200401-wss-wssecurity-utility-1.0.xsd"
PasswordTextURI =

URI for “wsse:Password/@Type” #PasswordText.

"#{BaseAddress}/oasis-200401-wss-username-token-profile-1.0#PasswordText"
PasswordDigestURI =

URI for “wsse:Password/@Type” #PasswordDigest.

"#{BaseAddress}/oasis-200401-wss-username-token-profile-1.0#PasswordDigest"
@@username =

Global WSSE username.

nil
@@password =

Global WSSE password.

nil
@@digest =

Global setting of whether to use WSSE digest.

false

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#digest=(value) ⇒ Object (writeonly)

Sets whether to use WSSE digest per request.



114
115
116
# File 'lib/savon/wsse.rb', line 114

def digest=(value)
  @digest = value
end

Class Method Details

.digest=(digest) ⇒ Object

Global setting of whether to use WSSE digest.



89
90
91
# File 'lib/savon/wsse.rb', line 89

def self.digest=(digest)
  @@digest = digest
end

.digest?Boolean

Returns the global setting of whether to use WSSE digest.

Returns:

  • (Boolean)


84
85
86
# File 'lib/savon/wsse.rb', line 84

def self.digest?
  @@digest
end

.passwordObject

Returns the global WSSE password.



71
72
73
# File 'lib/savon/wsse.rb', line 71

def self.password
  @@password
end

.password=(password) ⇒ Object

Sets the global WSSE password.



76
77
78
# File 'lib/savon/wsse.rb', line 76

def self.password=(password)
  @@password = password.nil? ? nil : password.to_s
end

.usernameObject

Returns the global WSSE username.



58
59
60
# File 'lib/savon/wsse.rb', line 58

def self.username
  @@username
end

.username=(username) ⇒ Object

Sets the global WSSE username.



63
64
65
# File 'lib/savon/wsse.rb', line 63

def self.username=(username)
  @@username = username.nil? ? nil : username.to_s
end

Instance Method Details

#digest?Boolean

Returns whether to use WSSE digest. Defaults to the global setting.

Returns:

  • (Boolean)


117
118
119
# File 'lib/savon/wsse.rb', line 117

def digest?
  @digest || self.class.digest?
end

#headerObject

Returns the XML for a WSSE header or an empty String unless both username and password were specified.



123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/savon/wsse.rb', line 123

def header
  return "" unless username && password

  builder = Builder::XmlMarkup.new
  builder.wsse :Security, "xmlns:wsse" => WSENamespace do |xml|
    xml.wsse :UsernameToken, "xmlns:wsu" => WSUNamespace do
      xml.wsse :Username, username
      xml.wsse :Nonce, nonce
      xml.wsu :Created, timestamp
      xml.wsse :Password, password_node, :Type => password_type
    end
  end
end

#passwordObject

Returns the WSSE password. Defaults to the global setting.



109
110
111
# File 'lib/savon/wsse.rb', line 109

def password
  @password || self.class.password
end

#password=(password) ⇒ Object

Sets the WSSE password per request.



104
105
106
# File 'lib/savon/wsse.rb', line 104

def password=(password)
  @password = password.nil? ? nil : password.to_s
end

#usernameObject

Returns the WSSE username. Defaults to the global setting.



99
100
101
# File 'lib/savon/wsse.rb', line 99

def username
  @username || self.class.username
end

#username=(username) ⇒ Object

Sets the WSSE username per request.



94
95
96
# File 'lib/savon/wsse.rb', line 94

def username=(username)
  @username = username.nil? ? nil : username.to_s
end