cmsso 0.2.4

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d5fd75c0872a3351c92a0a367052ad4b782ef709
4
+ data.tar.gz: 4336dfcee5175a5c0135fcf5edf57f0a58f476d1
5
+ SHA512:
6
+ metadata.gz: e9791aae1513db7de4776816aef93269da545f50e90858987f7ffb65059ba2e24f7f1a28f7c0774b1411203679317114cf9030d8841ef18d296ce29811e440d5
7
+ data.tar.gz: 612163f9ac81dc2beb83c4745dab3174f2fc22a2d612dde21ca4987c91eb995fa72d8753f76bb7865e56a0470e75cdfff55b31e46cdbc6530cd1db23623e621e
@@ -0,0 +1,20 @@
1
+ Copyright 2013 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,3 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ Dir["tasks/*.rake"].each {|ext| load ext }
@@ -0,0 +1,177 @@
1
+ module Cmsso
2
+
3
+ class Member
4
+
5
+ @@type = nil
6
+ @@note = nil
7
+
8
+ attr_accessor :id
9
+ attr_accessor :full_name
10
+ attr_accessor :first_name
11
+ attr_accessor :last_name
12
+ attr_accessor :email
13
+ attr_accessor :roles
14
+ attr_accessor :reference
15
+ attr_accessor :status
16
+ attr_accessor :note
17
+
18
+ def initialize(args={})
19
+ return nil unless args.class == Hash
20
+
21
+ # convert keys to symbols
22
+ new_args = ActiveSupport::HashWithIndifferentAccess.new(args)
23
+
24
+ # assign and format
25
+ @id = new_args[:person_id]
26
+ @reference = new_args[:person_reference]
27
+ @full_name = new_args[:full_name]
28
+ @first_name = new_args[:first_name]
29
+ @last_name = new_args[:last_name]
30
+ @email = new_args[:email]
31
+ @roles = []
32
+ @roles = new_args[:roles].map{ |item| item.downcase.to_sym } if new_args[:roles]
33
+ @status = new_args[:status]
34
+ @note = new_args[:note]
35
+ end
36
+
37
+ def method_missing(method)
38
+ @roles.include?(method[0..-2].to_sym)
39
+ end
40
+
41
+ def self.type
42
+ @@type
43
+ end
44
+
45
+ def self.note
46
+ @@note
47
+ end
48
+
49
+ def self.find(headers)
50
+ # get person reference from http header
51
+ person_from_header = get_person_from_header(headers)
52
+ return nil unless person_from_header
53
+
54
+ # call service
55
+ person = nil
56
+
57
+ # set proxy as defined during configuration
58
+ ENV['http_proxy'] = Cmsso.configuration.proxy if ENV
59
+
60
+ begin
61
+ RestClient.post Cmsso.configuration.base_uri + "/role", build_request(person_from_header), :content_type => :json do |response,request,result|
62
+ # parse reponse and return person object
63
+ person = Member.new(JSON.parse(response)["response"]["persons"][0])
64
+
65
+ # check about invalid status
66
+ unless person.status == 'valid'
67
+ @@type, @@note = :role_or_person, person.note
68
+ return nil
69
+ end
70
+
71
+ end
72
+
73
+ # parsing error
74
+ rescue JSON::ParserError => e
75
+ @@type, @@note = :parse,"Error while parsing role service response"
76
+ return nil
77
+
78
+ # service specific
79
+ rescue SocketError, Errno::ECONNREFUSED => e
80
+ @@type, @@note = :service,"Error while calling role service: #{e.to_s}"
81
+ return nil
82
+
83
+ # unexpected exceptions
84
+ rescue => e
85
+ @@type, @@note = :unexpected,"Error while calling role service: #{e.to_s}"
86
+ return nil
87
+ end
88
+
89
+ return person
90
+ end
91
+
92
+ def self.create(headers)
93
+ # get person reference from http header
94
+ person_from_header = get_person_from_header(headers)
95
+ return nil unless person_from_header
96
+
97
+ # call service
98
+ person = nil
99
+
100
+ # set proxy as defined during configuration
101
+ ENV['http_proxy'] = Cmsso.configuration.proxy
102
+
103
+
104
+ request = build_request(person_from_header)
105
+ puts request
106
+
107
+ begin
108
+ RestClient.put Cmsso.configuration.base_uri, request, :content_type => :json do |response,request,result|
109
+ # parse reponse and return person object
110
+ person = Member.new(JSON.parse(response)["response"]["persons"][0])
111
+
112
+ # check about invalid status
113
+ unless person.status == 'valid'
114
+ @@type, @@note = :role_or_person,person.note
115
+ return nil
116
+ end
117
+
118
+ end
119
+
120
+ # parsing error
121
+ rescue JSON::ParserError => e
122
+ @@type, @@note = :parse,"Error while parsing role service response"
123
+ return nil
124
+
125
+ # service specific
126
+ rescue SocketError, Errno::ECONNREFUSED => e
127
+ @@type, @@note = :service,"Error while calling role service: #{e.to_s}"
128
+ return nil
129
+
130
+ # unexpected exceptions
131
+ rescue => e
132
+ @@type, @@note = :unexpected,"Error while calling role service: #{e.to_s}"
133
+ return nil
134
+ end
135
+
136
+ return person
137
+ end
138
+
139
+ private
140
+
141
+ def self.get_person_from_header(headers)
142
+
143
+ person = Member.new
144
+ if headers["HTTP_NIBR521"].nil? || headers["HTTP_NIBR521"].size == 0
145
+ @@type, @@note = :header, "Person could not be authenticated. Is Authentication System (Vordel) running fine?"
146
+ return nil
147
+ else
148
+ person.reference = headers["HTTP_NIBR521"].downcase
149
+ if headers["HTTP_NIBRFULL"] && headers["HTTP_NIBRFULL"] !~ /null null/i
150
+ person.full_name = headers["HTTP_NIBRFULL"].titlecase
151
+ else
152
+ person.full_name = person.reference
153
+ end
154
+
155
+ # take all parts of full name except last for first name
156
+ person.first_name = person.full_name.split(' ')[0..-2].join(' ')
157
+
158
+ # take last part of full name only
159
+ person.last_name = person.full_name.split(' ')[-1]
160
+
161
+ person.email = headers["HTTP_NIBREMAIL"].downcase if headers["HTTP_NIBREMAIL"] && headers["HTTP_NIBREMAIL"] !~ /^null$/i
162
+ end
163
+
164
+ return person
165
+ end
166
+
167
+ def self.build_request(person,module_key=Cmsso.configuration.module_key)
168
+ now = Time.now
169
+ data = {}
170
+ data[:header] = { id: SecureRandom.uuid, action: "Compound Management.Core.Person", version: "1.0.0", date: (now.strftime("%Y-%m-%d") + 'T' + now.strftime("%H:%M:%S.000%:z"))}
171
+ data[:request] = { persons: [{person_reference: person.reference, full_name: person.full_name, first_name: person.first_name, last_name: person.last_name, email: person.email, module_key: module_key}]}
172
+ data.to_json
173
+ end
174
+
175
+ end
176
+
177
+ end
@@ -0,0 +1,6 @@
1
+ require 'cmsso/configuration'
2
+ require "cmsso/engine"
3
+ require "cmsso/version"
4
+
5
+ module Cmsso
6
+ end
@@ -0,0 +1,28 @@
1
+ module Cmsso
2
+
3
+ class Configuration
4
+ attr_accessor :module_key
5
+ attr_accessor :base_uri
6
+ attr_accessor :proxy
7
+
8
+ def initialize
9
+ @environment = nil if Rails.env.production?
10
+ @environment = "-test" if Rails.env.development? || Rails.env.test?
11
+ @environment = "-int" if Rails.env.integration?
12
+
13
+ @proxy = nil
14
+ @module_key = "cm_chbs_portal"
15
+ @base_uri = "http://cmservice-chbs#{@environment}.novartis.net:3056/persons"
16
+ end
17
+ end
18
+
19
+ class << self
20
+ attr_accessor :configuration
21
+ end
22
+
23
+ def self.configure
24
+ self.configuration ||= Configuration.new
25
+ yield(configuration)
26
+ end
27
+
28
+ end
@@ -0,0 +1,8 @@
1
+ #require "cmsso/application_controller"
2
+ require "rails"
3
+ require 'rest_client'
4
+
5
+ module Cmsso
6
+ class Engine < ::Rails::Engine
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module Cmsso
2
+ VERSION = "0.2.4"
3
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cmsso
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.4
5
+ platform: ruby
6
+ authors:
7
+ - Thomas Steiner
8
+ - Patrick Kaddu
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rest-client
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ description: CM Single Sign On
29
+ email:
30
+ - thomas.steiner@ikey.ch
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - app/models/cmsso/member.rb
36
+ - lib/cmsso/configuration.rb
37
+ - lib/cmsso/engine.rb
38
+ - lib/cmsso/version.rb
39
+ - lib/cmsso.rb
40
+ - MIT-LICENSE
41
+ - Rakefile
42
+ homepage: http://github.com/thomis/cmsso
43
+ licenses: []
44
+ metadata: {}
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ - app
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 2.0.3
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: CM Signle Sign On
66
+ test_files: []