From 4a94400d605ae24a84b5c8b89ed0c46001b08725 Mon Sep 17 00:00:00 2001 From: Benton Barnett Date: Wed, 4 Apr 2012 20:02:11 -0400 Subject: [PATCH] Namespaces and Uri's can now be configured --- lib/akami/wsse.rb | 17 ++++++++++++++-- spec/akami/wsse_spec.rb | 44 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/lib/akami/wsse.rb b/lib/akami/wsse.rb index d70f5ad0..631f65ac 100644 --- a/lib/akami/wsse.rb +++ b/lib/akami/wsse.rb @@ -9,6 +9,12 @@ module Akami # # Building Web Service Security. class WSSE + + #Configurable Attributes + [:wse_namespace, :wsu_namespace, :password_text_uri, :password_digest_uri].each do |attribute| + attr_accessor attribute + attr_writer attribute + end # Namespace for WS Security Secext. WSE_NAMESPACE = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" @@ -22,6 +28,13 @@ class WSSE # PasswordDigest URI. PASSWORD_DIGEST_URI = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest" + def initialize + @wse_namespace = WSE_NAMESPACE + @wsu_namespace = WSU_NAMESPACE + @password_text_uri = PASSWORD_TEXT_URI + @password_digest_uri = PASSWORD_DIGEST_URI + end + # Returns a value from the WSSE Hash. def [](key) hash[key] @@ -113,9 +126,9 @@ def security_hash(namespace, tag, hash) { "wsse:Security" => { "#{namespace}:#{tag}" => hash, - :attributes! => { "#{namespace}:#{tag}" => { "wsu:Id" => "#{tag}-#{count}", "xmlns:wsu" => WSU_NAMESPACE } } + :attributes! => { "#{namespace}:#{tag}" => { "wsu:Id" => "#{tag}-#{count}", "xmlns:wsu" => @wsu_namespace } } }, - :attributes! => { "wsse:Security" => { "xmlns:wsse" => WSE_NAMESPACE } } + :attributes! => { "wsse:Security" => { "xmlns:wsse" => @wse_namespace } } } end diff --git a/spec/akami/wsse_spec.rb b/spec/akami/wsse_spec.rb index 1738cf82..d7f9d743 100644 --- a/spec/akami/wsse_spec.rb +++ b/spec/akami/wsse_spec.rb @@ -69,6 +69,50 @@ wsse.should be_digest end end + + describe "#wse_namespace" do + it "returns the default wse namespace" do + wsse.wse_namespace.should == Akami::WSSE::WSE_NAMESPACE + end + + it "sets the wse_namespace" do + wsse.wse_namespace = "test" + wsse.wse_namespace.should == "test" + end + end + + describe "#wsu_namespace" do + it "returns the default wsu namespace" do + wsse.wsu_namespace.should == Akami::WSSE::WSU_NAMESPACE + end + + it "sets the wsu_namespace" do + wsse.wsu_namespace = "test" + wsse.wsu_namespace.should == "test" + end + end + + describe "#password_text_uri" do + it "returns the default password text uri" do + wsse.password_text_uri.should == Akami::WSSE::PASSWORD_TEXT_URI + end + + it "sets the password_text_uri" do + wsse.password_text_uri = "test" + wsse.password_text_uri.should == "test" + end + end + + describe "#password_digest_uri" do + it "returns the default password digest uri" do + wsse.password_digest_uri.should == Akami::WSSE::PASSWORD_DIGEST_URI + end + + it "sets the password_digest_uri" do + wsse.password_digest_uri = "test" + wsse.password_digest_uri.should == "test" + end + end describe "#to_xml" do context "with no credentials" do