dot_net_services 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +21 -24
- data/README +26 -16
- data/Rakefile +65 -0
- data/lib/acs/saml_token_provider.rb +54 -0
- data/lib/acs/shared_secret_token_provider.rb +55 -0
- data/lib/acs/simple_api_auth_token_provider.rb +57 -0
- data/lib/acs/simple_web_token_provider.rb +54 -0
- data/lib/acs/token_constants.rb +112 -0
- data/lib/acs/token_info.rb +33 -0
- data/lib/acs/token_provider.rb +74 -0
- data/lib/acs/token_validator.rb +114 -0
- data/lib/common/dot_net_services_environment.rb +61 -0
- data/lib/common/environment.yml +23 -0
- data/lib/common/host_name_config.yml +45 -0
- data/lib/dot_net_services.rb +31 -144
- data/lib/service_bus/http_proxy.rb +34 -0
- data/lib/service_bus/locked_message_info.rb +34 -0
- data/lib/service_bus/message_buffer.rb +313 -0
- data/lib/service_bus/message_buffer_constants.rb +48 -0
- data/lib/service_bus/message_buffer_policy.rb +55 -0
- data/lib/service_bus/requests.rb +95 -0
- data/test/config/test_config.yml +40 -0
- data/test/dot_net_services_environment_test.rb +54 -0
- data/test/message_buffer_test.rb +96 -0
- data/test/token_test.rb +98 -0
- metadata +50 -48
- data/lib/dot_net_services/authentication.rb +0 -168
- data/lib/dot_net_services/error.rb +0 -4
- data/lib/dot_net_services/message_buffer.rb +0 -283
- data/lib/dot_net_services/session.rb +0 -308
- data/lib/net/http/create_mb.rb +0 -14
- data/lib/net/http/retrieve.rb +0 -14
- data/lib/net/http/subscribe.rb +0 -14
- data/lib/net/http/unsubscribe.rb +0 -14
- data/spec/integration/TestService/Service/AnonymousResourceService.cs +0 -9
- data/spec/integration/TestService/Service/App.config +0 -32
- data/spec/integration/TestService/Service/PlainTextService.cs +0 -37
- data/spec/integration/TestService/Service/Program.cs +0 -49
- data/spec/integration/TestService/Service/Properties/AssemblyInfo.cs +0 -33
- data/spec/integration/TestService/Service/ResourceContract.cs +0 -17
- data/spec/integration/TestService/Service/ResourceService.cs +0 -58
- data/spec/integration/TestService/Service/Service.csproj +0 -71
- data/spec/integration/TestService/TestService.sln +0 -33
- data/spec/integration/end_to_end_spec.rb +0 -84
- data/spec/integration/vmb_spec.rb +0 -30
- data/spec/spec_helper.rb +0 -23
- data/spec/unit/dot_net_services/authentication_spec.rb +0 -289
- data/spec/unit/dot_net_services/message_buffer_spec.rb +0 -161
- data/spec/unit/dot_net_services/session_spec.rb +0 -247
data/LICENSE
CHANGED
@@ -1,24 +1,21 @@
|
|
1
|
-
Copyright (c)
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
23
|
-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
24
|
-
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
1
|
+
Copyright (c) 2009, Persistent Systems Limited
|
2
|
+
|
3
|
+
Redistribution and use, with or without modification, are permitted
|
4
|
+
provided that the following conditions are met:
|
5
|
+
- Redistributions of source code must retain the above copyright notice,
|
6
|
+
this list of conditions and the following disclaimer.
|
7
|
+
- Neither the name of Persistent Systems Limited nor the names of its contributors
|
8
|
+
may be used to endorse or promote products derived from this software
|
9
|
+
without specific prior written permission.
|
10
|
+
|
11
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
12
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
13
|
+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
14
|
+
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
15
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
16
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
17
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
18
|
+
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
19
|
+
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
20
|
+
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
21
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README
CHANGED
@@ -1,16 +1,14 @@
|
|
1
|
-
|
1
|
+
== .NET Services for Ruby
|
2
2
|
|
3
3
|
* Project homepage: http://dotnetservicesruby.com
|
4
4
|
* Download: http://rubyforge.org/frs/?group_id=7155
|
5
|
-
* Demo application: http://dotnetservicesruby.com/billboard
|
6
5
|
* Source code: http://rubyforge.org/frs/?group_id=7155
|
7
6
|
* Documentation: http://dotnetservicesruby.com/documentation/index.html
|
8
7
|
|
9
8
|
== What's this?
|
10
9
|
|
11
10
|
.NET Services for Ruby is an open source library that helps Ruby programs communicate with Microsoft's .NET Services
|
12
|
-
using plain HTTP.
|
13
|
-
technical guidance for the project.
|
11
|
+
using plain HTTP.
|
14
12
|
|
15
13
|
== Installation
|
16
14
|
|
@@ -20,9 +18,6 @@ The library can be installed as a 'dot_net_services' gem, from RubyForge gem rep
|
|
20
18
|
|
21
19
|
or downloaded as an archive from RubyForge [http://rubyforge.org/frs/?group_id=7155].
|
22
20
|
|
23
|
-
<i>NOTE: Version number 0.3.0 tells you that the API will have backwards-incompatible changes in future, so
|
24
|
-
Vendor Everything! [http://errtheblog.com/posts/50-vendor-everything]</i>
|
25
|
-
|
26
21
|
== Documentation
|
27
22
|
|
28
23
|
API: http://dotnetservicesruby.com/documentation/classes/DotNetServices.html
|
@@ -31,22 +26,37 @@ API: http://dotnetservicesruby.com/documentation/classes/DotNetServices.html
|
|
31
26
|
|
32
27
|
== Demo application
|
33
28
|
|
34
|
-
|
35
|
-
We were working on the API while building the app, which helped us study the technology and discover the right
|
36
|
-
abstractions.
|
37
|
-
|
38
|
-
You can see BillBoard in action at http://dotnetservicesruby.com/billboard and download BillBoard source code from
|
39
|
-
RubyForge [http://rubyforge.org/frs/?group_id=7155].
|
29
|
+
A demo application that demonstrates usage of the API (gem) will be added soon.
|
40
30
|
|
41
31
|
== Contacts
|
42
32
|
|
43
33
|
Users maillist: http://rubyforge.org/mailman/listinfo/dotnetsrv-ruby-users
|
44
|
-
ThoughtWorks: info-us@thoughtworks.com
|
45
34
|
|
46
35
|
== License
|
47
36
|
|
48
|
-
|
37
|
+
See [LICENSE].
|
49
38
|
|
50
39
|
== Copyright
|
40
|
+
Copyright (c) 2009, Persistent Systems Limited
|
41
|
+
|
42
|
+
Redistribution and use, with or without modification, are permitted
|
43
|
+
provided that the following conditions are met:
|
44
|
+
- Redistributions of source code must retain the above copyright notice,
|
45
|
+
this list of conditions and the following disclaimer.
|
46
|
+
- Neither the name of Persistent Systems Limited nor the names of its contributors
|
47
|
+
may be used to endorse or promote products derived from this software
|
48
|
+
without specific prior written permission.
|
49
|
+
|
50
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
51
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
52
|
+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
53
|
+
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
54
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
55
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
56
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
57
|
+
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
58
|
+
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
59
|
+
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
60
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
61
|
+
|
51
62
|
|
52
|
-
(c) ThoughtWorks, Inc 2008
|
data/Rakefile
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# Copyright (c) 2009, Persistent Systems Limited
|
2
|
+
#
|
3
|
+
# Redistribution and use, with or without modification, are permitted
|
4
|
+
# provided that the following conditions are met:
|
5
|
+
# - Redistributions of source code must retain the above copyright notice,
|
6
|
+
# this list of conditions and the following disclaimer.
|
7
|
+
# - Neither the name of Persistent Systems Limited nor the names of its contributors
|
8
|
+
# may be used to endorse or promote products derived from this software
|
9
|
+
# without specific prior written permission.
|
10
|
+
#
|
11
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
12
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
13
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
14
|
+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
15
|
+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
16
|
+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
17
|
+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES LOSS OF USE, DATA, OR PROFITS
|
18
|
+
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
19
|
+
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
20
|
+
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
21
|
+
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
22
|
+
|
23
|
+
require 'rubygems'
|
24
|
+
require 'rake'
|
25
|
+
require 'rake/clean'
|
26
|
+
require 'rake/gempackagetask'
|
27
|
+
require 'rake/rdoctask'
|
28
|
+
require 'rake/testtask'
|
29
|
+
|
30
|
+
spec = Gem::Specification.new do |s|
|
31
|
+
s.name = 'dot_net_services'
|
32
|
+
s.version = '0.4.0'
|
33
|
+
s.has_rdoc = true
|
34
|
+
s.extra_rdoc_files = ['README', 'LICENSE']
|
35
|
+
s.summary = 'Ruby wrapper for .NET services'
|
36
|
+
s.description = s.summary
|
37
|
+
s.author = ''
|
38
|
+
s.email = ''
|
39
|
+
s.files = %w(LICENSE README Rakefile) + Dir.glob("{bin,lib,spec,test}/**/*")
|
40
|
+
s.require_path = "lib"
|
41
|
+
s.add_dependency(%q<ruby-hmac>, [">= 0.3.1"])
|
42
|
+
end
|
43
|
+
|
44
|
+
#spec.add_runtime_dependency('ruby_hmac', '>= 0.3.1')
|
45
|
+
|
46
|
+
Rake::GemPackageTask.new(spec) do |p|
|
47
|
+
p.gem_spec = spec
|
48
|
+
p.need_tar = true
|
49
|
+
p.need_zip = true
|
50
|
+
end
|
51
|
+
|
52
|
+
#spec.add_runtime_dependency('ruby_hmac')
|
53
|
+
|
54
|
+
Rake::RDocTask.new do |rdoc|
|
55
|
+
files =['README', 'LICENSE', 'lib/**/*.rb']
|
56
|
+
rdoc.rdoc_files.add(files)
|
57
|
+
rdoc.main = "README" # page to start on
|
58
|
+
rdoc.title = "dot_net_services Docs"
|
59
|
+
rdoc.rdoc_dir = 'doc/rdoc' # rdoc output folder
|
60
|
+
rdoc.options << '--line-numbers'
|
61
|
+
end
|
62
|
+
|
63
|
+
Rake::TestTask.new do |t|
|
64
|
+
t.test_files = FileList['test/**/*.rb']
|
65
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# Copyright (c) 2009, Persistent Systems Limited
|
2
|
+
#
|
3
|
+
# Redistribution and use, with or without modification, are permitted
|
4
|
+
# provided that the following conditions are met:
|
5
|
+
# - Redistributions of source code must retain the above copyright notice,
|
6
|
+
# this list of conditions and the following disclaimer.
|
7
|
+
# - Neither the name of Persistent Systems Limited nor the names of its contributors
|
8
|
+
# may be used to endorse or promote products derived from this software
|
9
|
+
# without specific prior written permission.
|
10
|
+
#
|
11
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
12
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
13
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
14
|
+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
15
|
+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
16
|
+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
17
|
+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES LOSS OF USE, DATA, OR PROFITS
|
18
|
+
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
19
|
+
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
20
|
+
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
21
|
+
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
22
|
+
|
23
|
+
require 'cgi'
|
24
|
+
require "#{__FILE__}/../token_constants"
|
25
|
+
require "#{__FILE__}/../token_info"
|
26
|
+
require "#{__FILE__}/../token_provider"
|
27
|
+
require "#{__FILE__}/../../service_bus/http_proxy"
|
28
|
+
|
29
|
+
class SamlTokenProvider < TokenProvider
|
30
|
+
include DotNetServices::HTTPRequests
|
31
|
+
include HTTPProxy
|
32
|
+
|
33
|
+
attr_reader :saml_token
|
34
|
+
|
35
|
+
# * issuer_name: Issuer name provided when the service is created
|
36
|
+
# * issuer_key: Management key provided when the service is created
|
37
|
+
# * proxy: Hash containing http_proxy_server, http_proxy_port and optional http_porxy_username, http_proxy_password
|
38
|
+
def initialize(issuer_name, issuer_key, proxy = nil)
|
39
|
+
set_http_web_proxy(proxy) if proxy
|
40
|
+
@saml_token = TokenProvider.compute_simple_web_token(issuer_name, issuer_key)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Constructs params to sent along with the token reuqest uri and calls issue_token
|
44
|
+
# * request_uri: Request url
|
45
|
+
# * applies_to: URL the token applies to
|
46
|
+
def token(request_uri, applies_to)
|
47
|
+
simple_auth_parameter_name = TokenConstants.simple_auth_saml_token
|
48
|
+
params = ''
|
49
|
+
params = TokenConstants.simple_auth_applies_to + "=" + CGI::escape(applies_to)
|
50
|
+
params << TokenConstants.url_parameter_separator
|
51
|
+
params << simple_auth_parameter_name + "=" + CGI::escape(@saml_token)
|
52
|
+
issue_token(request_uri, params)
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# Copyright (c) 2009, Persistent Systems Limited
|
2
|
+
#
|
3
|
+
# Redistribution and use, with or without modification, are permitted
|
4
|
+
# provided that the following conditions are met:
|
5
|
+
# - Redistributions of source code must retain the above copyright notice,
|
6
|
+
# this list of conditions and the following disclaimer.
|
7
|
+
# - Neither the name of Persistent Systems Limited nor the names of its contributors
|
8
|
+
# may be used to endorse or promote products derived from this software
|
9
|
+
# without specific prior written permission.
|
10
|
+
#
|
11
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
12
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
13
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
14
|
+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
15
|
+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
16
|
+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
17
|
+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES LOSS OF USE, DATA, OR PROFITS
|
18
|
+
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
19
|
+
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
20
|
+
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
21
|
+
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
22
|
+
|
23
|
+
require 'cgi'
|
24
|
+
require "#{__FILE__}/../token_provider"
|
25
|
+
require "#{__FILE__}/../token_constants"
|
26
|
+
require "#{__FILE__}/../token_info"
|
27
|
+
require "#{__FILE__}/../../service_bus/http_proxy"
|
28
|
+
|
29
|
+
class SharedSecretTokenProvider < TokenProvider
|
30
|
+
attr_reader :issuer_name, :issuer_secret
|
31
|
+
|
32
|
+
# * issuer_name: Issuer name provided when the service is created
|
33
|
+
# * issuer_key: Management key provided when the service is created
|
34
|
+
# * proxy: Hash containing http_proxy_server, http_proxy_port and optional http_porxy_username, http_proxy_password
|
35
|
+
def initialize(issuer_name, issuer_secret, proxy = nil)
|
36
|
+
set_http_web_proxy(proxy) if proxy
|
37
|
+
@issuer_name = issuer_name
|
38
|
+
@issuer_secret = issuer_secret
|
39
|
+
end
|
40
|
+
|
41
|
+
# Constructs params to sent along with the token reuqest uri and calls issue_token
|
42
|
+
# * request_uri: Request url
|
43
|
+
# * applies_to: URL the token applies to
|
44
|
+
def token(request_uri, applies_to)
|
45
|
+
computed_simple_web_token_string = TokenProvider.compute_simple_web_token(@issuer_name, @issuer_secret)
|
46
|
+
simple_auth_parameter_name = TokenConstants.simple_auth_simple_web_token
|
47
|
+
params = ''
|
48
|
+
params = TokenConstants.simple_auth_applies_to + "=" + CGI::escape(applies_to)
|
49
|
+
params << TokenConstants.url_parameter_separator
|
50
|
+
params << simple_auth_parameter_name + "=" + CGI::escape(computed_simple_web_token_string)
|
51
|
+
issue_token(request_uri, params)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# Copyright (c) 2009, Persistent Systems Limited
|
2
|
+
#
|
3
|
+
# Redistribution and use, with or without modification, are permitted
|
4
|
+
# provided that the following conditions are met:
|
5
|
+
# - Redistributions of source code must retain the above copyright notice,
|
6
|
+
# this list of conditions and the following disclaimer.
|
7
|
+
# - Neither the name of Persistent Systems Limited nor the names of its contributors
|
8
|
+
# may be used to endorse or promote products derived from this software
|
9
|
+
# without specific prior written permission.
|
10
|
+
#
|
11
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
12
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
13
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
14
|
+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
15
|
+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
16
|
+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
17
|
+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES LOSS OF USE, DATA, OR PROFITS
|
18
|
+
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
19
|
+
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
20
|
+
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
21
|
+
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
22
|
+
|
23
|
+
require 'cgi'
|
24
|
+
require "#{__FILE__}/../token_constants"
|
25
|
+
require "#{__FILE__}/../token_info"
|
26
|
+
require "#{__FILE__}/../token_provider"
|
27
|
+
require "#{__FILE__}/../../service_bus/http_proxy"
|
28
|
+
|
29
|
+
class SimpleApiAuthTokenProvider < TokenProvider
|
30
|
+
attr_reader :wrap_name, :wrap_secret
|
31
|
+
|
32
|
+
# * wrap_name: Scope name provided when the service is created
|
33
|
+
# * wrap_password: 'Client Getting Started Issuer key' provided when the service is created
|
34
|
+
# * proxy: Hash containing http_web_proxy_server, http_web_proxy_port and optional http_web_proxy_username, http_web_proxy_password
|
35
|
+
def initialize(wrap_name, wrap_password, proxy = nil)
|
36
|
+
@wrap_name = wrap_name
|
37
|
+
@wrap_password = wrap_password
|
38
|
+
proxy = {'http_web_proxy_server' => 'itgproxy.redmond.corp.microsoft.com','http_web_proxy_port' => '80'}
|
39
|
+
set_http_web_proxy(proxy) if proxy
|
40
|
+
end
|
41
|
+
|
42
|
+
# Constructs params to sent along with the token reuqest uri and calls issue_token
|
43
|
+
# * request_uri: Request url
|
44
|
+
# * applies_to: URL the token applies to
|
45
|
+
def token(request_uri, applies_to)
|
46
|
+
params = ''
|
47
|
+
params = TokenConstants.simple_auth_applies_to + "=" + CGI::escape(applies_to)
|
48
|
+
params << TokenConstants.url_parameter_separator
|
49
|
+
params << TokenConstants.simple_auth_name + "=" + CGI::escape(@wrap_name)
|
50
|
+
params << TokenConstants.url_parameter_separator
|
51
|
+
params << TokenConstants.simple_auth_password + "=" + CGI::escape(@wrap_password)
|
52
|
+
issue_token(request_uri, params)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# Copyright (c) 2009, Persistent Systems Limited
|
2
|
+
#
|
3
|
+
# Redistribution and use, with or without modification, are permitted
|
4
|
+
# provided that the following conditions are met:
|
5
|
+
# - Redistributions of source code must retain the above copyright notice,
|
6
|
+
# this list of conditions and the following disclaimer.
|
7
|
+
# - Neither the name of Persistent Systems Limited nor the names of its contributors
|
8
|
+
# may be used to endorse or promote products derived from this software
|
9
|
+
# without specific prior written permission.
|
10
|
+
#
|
11
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
12
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
13
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
14
|
+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
15
|
+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
16
|
+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
17
|
+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES LOSS OF USE, DATA, OR PROFITS
|
18
|
+
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
19
|
+
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
20
|
+
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
21
|
+
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
22
|
+
|
23
|
+
require 'cgi'
|
24
|
+
require "#{__FILE__}/../token_constants"
|
25
|
+
require "#{__FILE__}/../token_info"
|
26
|
+
require "#{__FILE__}/../token_provider"
|
27
|
+
require "#{__FILE__}/../../service_bus/http_proxy"
|
28
|
+
|
29
|
+
class SimpleWebTokenProvider < TokenProvider
|
30
|
+
include DotNetServices::HTTPRequests
|
31
|
+
include HTTPProxy
|
32
|
+
|
33
|
+
attr_reader :simple_web_token
|
34
|
+
|
35
|
+
# * issuer_name: Issuer name provided when the service is created
|
36
|
+
# * issuer_key: Management key provided when the service is created
|
37
|
+
# * proxy: Hash containing http_proxy_server, http_proxy_port and optional http_porxy_username, http_proxy_password
|
38
|
+
def initialize(issuer_name, issuer_key, proxy = nil)
|
39
|
+
set_http_web_proxy(proxy) if proxy
|
40
|
+
@simple_web_token = TokenProvider.compute_simple_web_token(issuer_name, issuer_key)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Constructs params to sent along with the token request uri and calls issue_token
|
44
|
+
# * request_uri: Request url
|
45
|
+
# * applies_to: URL the token applies to
|
46
|
+
def token(request_uri, applies_to)
|
47
|
+
simple_auth_parameter_name = TokenConstants.simple_auth_simple_web_token
|
48
|
+
params = ''
|
49
|
+
params = TokenConstants.simple_auth_applies_to + "=" + CGI::escape(applies_to)
|
50
|
+
params << TokenConstants.url_parameter_separator
|
51
|
+
params << simple_auth_parameter_name + "=" + CGI::escape(@simple_web_token)
|
52
|
+
issue_token(request_uri, params)
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
# Copyright (c) 2009, Persistent Systems Limited
|
2
|
+
#
|
3
|
+
# Redistribution and use, with or without modification, are permitted
|
4
|
+
# provided that the following conditions are met:
|
5
|
+
# - Redistributions of source code must retain the above copyright notice,
|
6
|
+
# this list of conditions and the following disclaimer.
|
7
|
+
# - Neither the name of Persistent Systems Limited nor the names of its contributors
|
8
|
+
# may be used to endorse or promote products derived from this software
|
9
|
+
# without specific prior written permission.
|
10
|
+
#
|
11
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
12
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
13
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
14
|
+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
15
|
+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
16
|
+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
17
|
+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES LOSS OF USE, DATA, OR PROFITS
|
18
|
+
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
19
|
+
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
20
|
+
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
21
|
+
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
22
|
+
|
23
|
+
# Holds following constants related to the Tokens along with its accessor methods
|
24
|
+
# default_compound_claim_delimiter,
|
25
|
+
# http_auth_parameter_separator,
|
26
|
+
# http_method_get,
|
27
|
+
# http_method_head,
|
28
|
+
# http_method_post,
|
29
|
+
# http_method_trace,
|
30
|
+
# management_issuer_name,
|
31
|
+
# output_claim_issuer_id,
|
32
|
+
# saml11_confirmation_method_bearertoken,
|
33
|
+
# service_bus_issuer_name,
|
34
|
+
# simple_auth_accesstoken,
|
35
|
+
# simple_auth_applies_to,
|
36
|
+
# simple_auth_authentication_type,
|
37
|
+
# simple_auth_content_type,
|
38
|
+
# simple_auth_name,
|
39
|
+
# simple_auth_password,
|
40
|
+
# simple_auth_requested_lifetime,
|
41
|
+
# simple_auth_saml_token,
|
42
|
+
# simple_auth_simple_web_token,
|
43
|
+
# simple_authtoken_expires_in,
|
44
|
+
# token_audience,
|
45
|
+
# token_digest256,
|
46
|
+
# token_expires_on,
|
47
|
+
# token_issuer,
|
48
|
+
# tracking_id_header_name,
|
49
|
+
# url_parameter_separator,
|
50
|
+
# content_language
|
51
|
+
class TokenConstants
|
52
|
+
@default_compound_claim_delimiter = ','
|
53
|
+
@http_auth_parameter_separator = ','
|
54
|
+
@http_method_get = "GET"
|
55
|
+
@http_method_head = "HEAD"
|
56
|
+
@http_method_post = "POST"
|
57
|
+
@http_method_trace = "TRACE"
|
58
|
+
@management_issuer_name = "owner"
|
59
|
+
@max_issuer_name_size = 0x80
|
60
|
+
@max_issuer_secret_size = 0x80
|
61
|
+
@output_claim_issuer_id = "ACS"
|
62
|
+
@saml11_confirmation_method_bearertoken = "urn:oasis:names:tc:SAML:1.0:cm:bearer"
|
63
|
+
@service_bus_issuer_name = "owner"
|
64
|
+
@simple_auth_accesstoken = "wrap_token_"
|
65
|
+
@simple_auth_applies_to = "applies_to"
|
66
|
+
@simple_auth_authentication_type = "WRAPv0.8"
|
67
|
+
@simple_auth_content_type = "application/x-www-form-urlencoded"
|
68
|
+
@simple_auth_content_types = ["*/*", "application/*", "application/x-www-form-urlencoded"]
|
69
|
+
@simple_auth_name = "wrap_name"
|
70
|
+
@simple_auth_password = "wrap_password"
|
71
|
+
@simple_auth_requested_lifetime = "requested_lifetime"
|
72
|
+
@simple_auth_saml_token = "wrap_SAML"
|
73
|
+
@simple_auth_simple_web_token = "wrap_SWT"
|
74
|
+
@simple_authtoken_expires_in = "wrap_token__expires_in"
|
75
|
+
@token_audience = "Audience"
|
76
|
+
@token_digest256 = "HMACSHA256"
|
77
|
+
@token_expires_on = "ExpiresOn"
|
78
|
+
@token_issuer = "Issuer"
|
79
|
+
@tracking_id_header_name = "x-ms-request-id"
|
80
|
+
@url_parameter_separator = '&'
|
81
|
+
@content_language = "en-US"
|
82
|
+
|
83
|
+
class << self
|
84
|
+
attr_accessor :default_compound_claim_delimiter,
|
85
|
+
:http_auth_parameter_separator,
|
86
|
+
:http_method_get,
|
87
|
+
:http_method_head,
|
88
|
+
:http_method_post,
|
89
|
+
:http_method_trace,
|
90
|
+
:management_issuer_name,
|
91
|
+
:output_claim_issuer_id,
|
92
|
+
:saml11_confirmation_method_bearertoken,
|
93
|
+
:service_bus_issuer_name,
|
94
|
+
:simple_auth_accesstoken,
|
95
|
+
:simple_auth_applies_to,
|
96
|
+
:simple_auth_authentication_type,
|
97
|
+
:simple_auth_content_type,
|
98
|
+
:simple_auth_name,
|
99
|
+
:simple_auth_password,
|
100
|
+
:simple_auth_requested_lifetime,
|
101
|
+
:simple_auth_saml_token,
|
102
|
+
:simple_auth_simple_web_token,
|
103
|
+
:simple_authtoken_expires_in,
|
104
|
+
:token_audience,
|
105
|
+
:token_digest256,
|
106
|
+
:token_expires_on,
|
107
|
+
:token_issuer,
|
108
|
+
:tracking_id_header_name,
|
109
|
+
:url_parameter_separator,
|
110
|
+
:content_language
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Copyright (c) 2009, Persistent Systems Limited
|
2
|
+
#
|
3
|
+
# Redistribution and use, with or without modification, are permitted
|
4
|
+
# provided that the following conditions are met:
|
5
|
+
# - Redistributions of source code must retain the above copyright notice,
|
6
|
+
# this list of conditions and the following disclaimer.
|
7
|
+
# - Neither the name of Persistent Systems Limited nor the names of its contributors
|
8
|
+
# may be used to endorse or promote products derived from this software
|
9
|
+
# without specific prior written permission.
|
10
|
+
#
|
11
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
12
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
13
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
14
|
+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
15
|
+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
16
|
+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
17
|
+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES LOSS OF USE, DATA, OR PROFITS
|
18
|
+
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
19
|
+
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
20
|
+
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
21
|
+
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
22
|
+
|
23
|
+
class TokenInfo
|
24
|
+
attr_reader :token, :expires_in
|
25
|
+
|
26
|
+
# * token: Actual token returned by tge .NET services
|
27
|
+
# * expires_in: Token expiration time in seconds
|
28
|
+
def initialize(token,expires_in)
|
29
|
+
@token = token
|
30
|
+
@expires_in = expires_in
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# Copyright (c) 2009, Persistent Systems Limited
|
2
|
+
#
|
3
|
+
# Redistribution and use, with or without modification, are permitted
|
4
|
+
# provided that the following conditions are met:
|
5
|
+
# - Redistributions of source code must retain the above copyright notice,
|
6
|
+
# this list of conditions and the following disclaimer.
|
7
|
+
# - Neither the name of Persistent Systems Limited nor the names of its contributors
|
8
|
+
# may be used to endorse or promote products derived from this software
|
9
|
+
# without specific prior written permission.
|
10
|
+
#
|
11
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
12
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
13
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
14
|
+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
15
|
+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
16
|
+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
17
|
+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES LOSS OF USE, DATA, OR PROFITS
|
18
|
+
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
19
|
+
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
20
|
+
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
21
|
+
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
22
|
+
|
23
|
+
require 'base64'
|
24
|
+
require 'rubygems'
|
25
|
+
require 'hmac-sha2'
|
26
|
+
require "#{__FILE__}/../token_constants"
|
27
|
+
require "#{__FILE__}/../../service_bus/requests"
|
28
|
+
require "#{__FILE__}/../../service_bus/http_proxy"
|
29
|
+
|
30
|
+
class TokenProvider
|
31
|
+
include DotNetServices::HTTPRequests
|
32
|
+
include HTTPProxy
|
33
|
+
|
34
|
+
# Computes the simple_web_token
|
35
|
+
# * issuer_name: Issuer name provided when the service is created
|
36
|
+
# * issuer_secret: Management key provided when the service is created
|
37
|
+
def self.compute_simple_web_token(issuer_name, issuer_secret)
|
38
|
+
@token = TokenConstants.token_issuer + "=" + CGI::unescape(issuer_name)
|
39
|
+
@hmcKey = self.token_hmc_key(CGI::unescape(@token), issuer_secret)
|
40
|
+
@computedSimpleWebTokenString = @token + "&" + TokenConstants.token_digest256 + "=" + CGI::escape(@hmcKey)
|
41
|
+
@computedSimpleWebTokenString
|
42
|
+
end
|
43
|
+
|
44
|
+
# Computes HMAC signature
|
45
|
+
# * token: token_issuer + issuer_name
|
46
|
+
# * issuer_secret_key: Management key provided when the service is created
|
47
|
+
def self.token_hmc_key(token, issuer_secret_key)
|
48
|
+
signature = Base64.encode64(HMAC::SHA256.digest(Base64.decode64(issuer_secret_key), token))
|
49
|
+
signature = signature.gsub("\n", '')
|
50
|
+
return signature
|
51
|
+
end
|
52
|
+
|
53
|
+
# Returns token received from the .NET services
|
54
|
+
# * request_uri: Request url
|
55
|
+
# * params: Parameter string to be sent as post request data
|
56
|
+
def issue_token(request_uri, params)
|
57
|
+
options = {}
|
58
|
+
header = {
|
59
|
+
'Content-Type' => TokenConstants.simple_auth_content_type,
|
60
|
+
'Content-Length' => params.length.to_s,
|
61
|
+
'Content-Language' => TokenConstants.content_language,
|
62
|
+
'Accept' => '*/*'
|
63
|
+
}
|
64
|
+
options.store(:header, header)
|
65
|
+
options.store(:use_ssl, true)
|
66
|
+
response = post(request_uri, params, options)
|
67
|
+
token_response = response.body
|
68
|
+
token_response.extend ToHash
|
69
|
+
the_token = token_response.to_hash['wrap_token']
|
70
|
+
token_expires_in = token_response.to_hash['wrap_token_expires_in']
|
71
|
+
TokenInfo.new(the_token, token_expires_in)
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|