oracle_ebs_authentication 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,8 +12,32 @@ module OracleEbsAuthentication
12
12
  if result[:p_password]
13
13
  @security.decrypt(username + "/" + password, result[:p_password], false)
14
14
  end
15
- rescue OCIError
16
- nil
15
+ rescue OCIError => e
16
+ if e.message.include?("ORA-20001: Your account does not exist or has expired.")
17
+ nil
18
+ else
19
+ raise e
20
+ end
21
+ end
22
+
23
+ def get_fnd_user_id(username)
24
+ username &&= username.upcase
25
+ plsql.apps.fnd_security_pkg.fnd_encrypted_pwd(username, nil, nil, nil)[:p_user_id]
26
+ end
27
+
28
+ def get_fnd_responsibilities(username)
29
+ user_id = get_fnd_user_id(username)
30
+ if user_id
31
+ plsql.select(:all, <<-SQL, user_id).map{|row| row[:responsibility_name]}
32
+ SELECT r.responsibility_name
33
+ FROM apps.fnd_user_resp_groups_all ur, apps.fnd_responsibility_vl r
34
+ WHERE ur.user_id = :p_user_id
35
+ AND TRUNC(SYSDATE) BETWEEN NVL(ur.start_date,TRUNC(SYSDATE)) AND NVL(ur.end_date, TRUNC(SYSDATE))
36
+ AND ur.responsibility_id = r.responsibility_id
37
+ SQL
38
+ else
39
+ []
40
+ end
17
41
  end
18
42
 
19
43
  def validate_user_password(username, password)
@@ -8,6 +8,45 @@ module OracleEbsAuthentication
8
8
  # as similar as possible to Java code to avoid differences in functionality.
9
9
  #
10
10
  class Security
11
+ if RUBY_VERSION =~ /^1.9/
12
+ class Bytes < String
13
+ def initialize(string)
14
+ super(string.force_encoding('ASCII-8BIT'))
15
+ end
16
+
17
+ def [](*args)
18
+ if args.length == 1
19
+ super(*args).ord
20
+ else
21
+ super
22
+ end
23
+ end
24
+
25
+ def []=(*args)
26
+ if args.length == 2
27
+ super(args[0], args[1].chr)
28
+ else
29
+ super
30
+ end
31
+ end
32
+ end
33
+
34
+ def bytes(string)
35
+ Bytes.new(string)
36
+ end
37
+
38
+ else
39
+ def bytes(string)
40
+ string
41
+ end
42
+
43
+ end
44
+
45
+ def null_bytes(count)
46
+ bytes("\0") * count
47
+ end
48
+
49
+
11
50
  def initialize
12
51
  end
13
52
 
@@ -71,7 +110,7 @@ module OracleEbsAuthentication
71
110
  s2[0, "ZG_ENCRYPT_FAILED_".length] == "ZG_ENCRYPT_FAILED_")
72
111
  return nil
73
112
  end
74
- abyte0 = s1.dup
113
+ abyte0 = bytes s1.dup
75
114
  l2 = abyte0.length
76
115
  i3 = s2.length
77
116
  i1 = 1
@@ -95,11 +134,11 @@ module OracleEbsAuthentication
95
134
  end
96
135
  s3 = s2[2..-1]
97
136
  abyte1 = p(s3)
98
- abyte2 = "\0"*(abyte1.length - i2)
99
- abyte3 = "\0"*i2
137
+ abyte2 = null_bytes(abyte1.length - i2)
138
+ abyte3 = null_bytes i2
100
139
  abyte2[0, abyte1.length - i2] = abyte1[0, abyte1.length - i2]
101
140
  abyte3[0, i2] = abyte1[abyte1.length - i2, i2]
102
- abyte4 = "\0"*(i2 + l2)
141
+ abyte4 = null_bytes(i2 + l2)
103
142
  abyte4[0, i2] = abyte3[0, i2]
104
143
  abyte4[i2, l2] = abyte0[0, l2]
105
144
  # puts "<br/>DEBUG new_check: abyte4=#{abyte4.inspect} abyte2=#{abyte2.unpack("H*")[0]}"
@@ -116,7 +155,7 @@ module OracleEbsAuthentication
116
155
  j3 = k2
117
156
  break
118
157
  end
119
- abyte6 = "\0"*(j3 - byte0)
158
+ abyte6 = null_bytes(j3 - byte0)
120
159
  abyte6[0, j3 - byte0] = abyte5[byte0, j3 - byte0]
121
160
  s4 = abyte6
122
161
  if (s4 != nil && flag)
@@ -145,10 +184,10 @@ module OracleEbsAuthentication
145
184
  end
146
185
 
147
186
  def e(ai)
148
- abyte0 = "\0"*4
187
+ abyte0 = null_bytes 4
149
188
  abyte1 = nil
150
189
  if (ai != nil)
151
- abyte1 = "\0"*(ai.length)
190
+ abyte1 = null_bytes(ai.length)
152
191
  for i1 in 0...ai.length
153
192
  abyte0[3] = (ai[i1] & 0xff)
154
193
  abyte0[2] = ( (ai[i1] & 0xff00) >> 8)
@@ -181,10 +220,10 @@ module OracleEbsAuthentication
181
220
  return nil
182
221
  end
183
222
  i1 = abyte1.length / 8
184
- abyte3 = "\0"*8
185
- abyte4 = "\0"*8
186
- abyte5 = "\0"*8
187
- abyte2 = "\0"*8
223
+ abyte3 = null_bytes 8
224
+ abyte4 = null_bytes 8
225
+ abyte5 = null_bytes 8
226
+ abyte2 = null_bytes 8
188
227
  abyte3[0,8] = abyte0[0, 8]
189
228
  abyte4[0,8] = abyte0[8, 8]
190
229
  abyte5[0,8] = abyte0[16, 8]
@@ -192,7 +231,7 @@ module OracleEbsAuthentication
192
231
  ai = l(abyte3, false)
193
232
  ai1 = l(abyte4, true)
194
233
  ai2 = l(abyte5, false)
195
- abyte6 = "\0"*(abyte1.length)
234
+ abyte6 = null_bytes(abyte1.length)
196
235
  j1 = 0
197
236
  k1 = 0
198
237
  while (j1 < i1)
@@ -216,7 +255,7 @@ module OracleEbsAuthentication
216
255
  return nil
217
256
  end
218
257
  end
219
- abyte7 = "\0"*(abyte1.length - byte0)
258
+ abyte7 = null_bytes(abyte1.length - byte0)
220
259
  abyte7[0, abyte1.length - byte0] = abyte6[0, abyte1.length - byte0]
221
260
  # puts "<br/>DEBUG g: abyte7=#{abyte7.unpack("H*")[0]}"
222
261
  return abyte7
@@ -241,17 +280,17 @@ module OracleEbsAuthentication
241
280
  else
242
281
  ai = a(abyte0, abyte0.length)
243
282
  abyte2 = e(ai)
244
- abyte3 = "\0"*258
283
+ abyte3 = null_bytes 258
245
284
  b_(abyte3, abyte2, nil, 5)
246
- abyte4 = "\0"*i1
285
+ abyte4 = null_bytes i1
247
286
  b_(abyte3, abyte1, abyte4, i1)
248
287
  return abyte4
249
288
  end
250
289
  end
251
290
 
252
291
  def l(abyte0, flag)
253
- abyte1 = "\0"*56
254
- abyte2 = "\0"*56
292
+ abyte1 = null_bytes 56
293
+ abyte2 = null_bytes 56
255
294
  ai = [nil]*32
256
295
  # TODO: check impact of >>> substitution with >>
257
296
  for j1 in 0...56
@@ -315,7 +354,7 @@ module OracleEbsAuthentication
315
354
  end
316
355
  abyte1 = e(ai)
317
356
  abyte2 = a_( (s2 + "\0") )
318
- abyte3 = "\0"*(k1 + abyte2.length)
357
+ abyte3 = null_bytes(k1 + abyte2.length)
319
358
  abyte3[0, abyte2.length] = abyte2[0, abyte2.length]
320
359
  abyte3[abyte2.length, k1] = abyte1[0, k1]
321
360
  abyte4 = k(abyte0, abyte3, i1)
@@ -327,7 +366,7 @@ module OracleEbsAuthentication
327
366
  if (abyte0 == nil)
328
367
  return nil
329
368
  end
330
- ac = "\0"*(abyte0.length)
369
+ ac = null_bytes(abyte0.length)
331
370
  i1 = 0
332
371
  flag = false
333
372
  flag1 = false
@@ -378,7 +417,7 @@ module OracleEbsAuthentication
378
417
  if break_value == :label0
379
418
  next
380
419
  end
381
- ac1 = "\0"*i1
420
+ ac1 = null_bytes i1
382
421
  ac1[0,i1] = ac[0,i1]
383
422
  end
384
423
  return ac1
@@ -399,6 +438,7 @@ module OracleEbsAuthentication
399
438
  end
400
439
 
401
440
  def p(s1)
441
+ s1 = bytes s1
402
442
  flag = false
403
443
  flag1 = false
404
444
  i1 = 0
@@ -409,7 +449,7 @@ module OracleEbsAuthentication
409
449
  end
410
450
  k1 = s1.length / 2
411
451
  if (k1 > 0)
412
- abyte0 = "\0"*k1
452
+ abyte0 = null_bytes k1
413
453
  while (k1 > 0)
414
454
  #c1 = s1.chars[i1]
415
455
  c1 = s1[i1]
@@ -428,7 +468,7 @@ module OracleEbsAuthentication
428
468
  def q(abyte0, i1, abyte1, j1, ai,
429
469
  ai1, ai2, abyte2,
430
470
  flag)
431
- abyte3 = "\0"*8
471
+ abyte3 = null_bytes 8
432
472
  abyte3[0, 8] = abyte0[i1, 8]
433
473
  if (!flag)
434
474
  # puts "<br/>DEBUG q: initial abyte3=#{abyte3.unpack("H*")[0]}"
@@ -536,18 +576,18 @@ module OracleEbsAuthentication
536
576
  end
537
577
  abyte5 = e(ai)
538
578
  ai = nil
539
- abyte6 = "\0"*(byte1 + j4 + k3)
579
+ abyte6 = null_bytes(byte1 + j4 + k3)
540
580
  abyte6[0, byte1] = abyte4[0, byte1]
541
581
  abyte6[byte1, k3] = abyte2[0, k3]
542
582
  abyte6[byte1+k3, j4] = abyte5[0, j4]
543
- abyte7 = "\0"*(l2 + j3)
583
+ abyte7 = null_bytes(l2 + j3)
544
584
  abyte7[0, l2] = abyte3[0, l2]
545
585
  abyte7[l2, j3] = abyte0[0, j3]
546
586
  abyte8 = i(nil, abyte7, abyte6)
547
587
  if (abyte8 == nil)
548
588
  return "ZG_ENCRYPT_FAILED_MISC"
549
589
  else
550
- abyte9 = "\0"*(abyte8.length + l2)
590
+ abyte9 = null_bytes(abyte8.length + l2)
551
591
  abyte9[0, abyte8.length] = abyte8[0, abyte8.length]
552
592
  abyte9[abyte8.length, l2] = abyte3[0, l2]
553
593
  s3 = z(abyte9)
@@ -648,7 +688,7 @@ module OracleEbsAuthentication
648
688
  return ""
649
689
  end
650
690
  j1 = s1.length
651
- k1 = s1.index("\0")
691
+ k1 = s1.index(bytes("\0"))
652
692
  if (k1 > -1)
653
693
  j1 = k1
654
694
  end
@@ -699,7 +739,7 @@ module OracleEbsAuthentication
699
739
  def y(abyte0, abyte1)
700
740
  # puts "<br/>DEBUG y: abyte0=#{abyte0.nil? ? "nil" : abyte0.unpack("H*")[0]}"
701
741
  # puts "<br/>DEBUG y: abyte1=#{abyte1.nil? ? "nil" : abyte1.unpack("H*")[0]}"
702
- abyte2 = "\0"*32
742
+ abyte2 = null_bytes 32
703
743
  messagedigest = Digest::SHA1.new
704
744
  messagedigest.reset
705
745
  byte0 = 20
@@ -734,7 +774,7 @@ module OracleEbsAuthentication
734
774
  def a_(ac)
735
775
  # RSI: if we receive String then return the same value (as it should already be in UTF-8)
736
776
  return ac if ac.is_a? String
737
- abyte0 = "\0"*(ac.length * 3)
777
+ abyte0 = null_bytes(ac.length * 3)
738
778
  i1 = 0
739
779
  flag = false
740
780
  for j1 in 0...ac.length
@@ -756,7 +796,7 @@ module OracleEbsAuthentication
756
796
  i1 += 1
757
797
  end
758
798
  end
759
- abyte1 = "\0"*i1
799
+ abyte1 = null_bytes i1
760
800
  abyte1[0, i1] = abyte0[0, i1]
761
801
  abyte1
762
802
  end
@@ -941,10 +981,10 @@ module OracleEbsAuthentication
941
981
  if (abyte0.length < 32)
942
982
  return nil
943
983
  end
944
- abyte3 = "\0"*8
945
- abyte4 = "\0"*8
946
- abyte5 = "\0"*8
947
- abyte2 = "\0"*8
984
+ abyte3 = null_bytes 8
985
+ abyte4 = null_bytes 8
986
+ abyte5 = null_bytes 8
987
+ abyte2 = null_bytes 8
948
988
  abyte3[0, 8] = abyte0[0, 8]
949
989
  abyte4[0, 8] = abyte0[8, 8]
950
990
  abyte5[0, 8] = abyte0[16, 8]
@@ -954,10 +994,10 @@ module OracleEbsAuthentication
954
994
  ai2 = l(abyte5, true)
955
995
  i1 = abyte1.length % 8
956
996
  byte0 = (8 - i1)
957
- abyte6 = "\0"*(abyte1.length + byte0)
997
+ abyte6 = null_bytes(abyte1.length + byte0)
958
998
  j1 = abyte6.length / 8 - 1
959
999
  k1 = 8 * j1
960
- abyte7 = "\0"*8
1000
+ abyte7 = null_bytes 8
961
1001
  abyte7[0, i1] = abyte1[k1, i1]
962
1002
  for l1 in i1...8
963
1003
  abyte7[l1] = byte0
@@ -1,3 +1,3 @@
1
1
  module OracleEbsAuthentication
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -5,14 +5,14 @@ describe "Authenticator" do
5
5
  if DATABASE_NAME && DATABASE_USERNAME && DATABASE_PASSWORD
6
6
  plsql.connect! DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_NAME
7
7
  else
8
- raise "You need to specify DATABASE_NAME, DATABASE_USERNAME, DATABASE_PASSWORD"
8
+ pending "You need to specify DATABASE_NAME, DATABASE_USERNAME, DATABASE_PASSWORD"
9
9
  end
10
10
  end
11
11
 
12
12
  before(:each) do
13
13
  @auth = OracleEbsAuthentication::Authenticator.new
14
- @user = "SIMANRAI"
15
- @password = "welcome1"
14
+ @user = "OPERATIONS"
15
+ @password = "welcome"
16
16
  end
17
17
 
18
18
  describe "#get_fnd_password" do
@@ -34,4 +34,10 @@ describe "Authenticator" do
34
34
  @auth.validate_user_password(@user, @password).should be_true
35
35
  end
36
36
  end
37
+
38
+ describe "#get_fnd_responsibilities" do
39
+ it "should return responsibility names for given user" do
40
+ @auth.get_fnd_responsibilities("OPERATIONS").should include("System Administrator")
41
+ end
42
+ end
37
43
  end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe "Security" do
@@ -2,6 +2,6 @@ $:.unshift File.dirname(__FILE__) + '/../lib'
2
2
 
3
3
  require "oracle_ebs_authentication"
4
4
 
5
- DATABASE_NAME = ENV['DATABASE_NAME']
6
- DATABASE_USERNAME = ENV['DATABASE_USERNAME']
7
- DATABASE_PASSWORD = ENV['DATABASE_PASSWORD']
5
+ DATABASE_NAME = ENV['DATABASE_NAME'] || 'VIS'
6
+ DATABASE_USERNAME = ENV['DATABASE_USERNAME'] || 'APPS'
7
+ DATABASE_PASSWORD = ENV['DATABASE_PASSWORD'] || 'APPS'
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oracle_ebs_authentication
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease:
4
+ prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 1
9
- - 1
10
- version: 0.1.1
8
+ - 2
9
+ version: 0.1.2
11
10
  platform: ruby
12
11
  authors:
13
12
  - Raimonds Simanovskis
@@ -16,18 +15,16 @@ autorequire:
16
15
  bindir: bin
17
16
  cert_chain: []
18
17
 
19
- date: 2011-03-25 00:00:00 +02:00
18
+ date: 2012-06-17 00:00:00 +03:00
20
19
  default_executable:
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
23
22
  name: activesupport
24
23
  prerelease: false
25
24
  requirement: &id001 !ruby/object:Gem::Requirement
26
- none: false
27
25
  requirements:
28
26
  - - ">="
29
27
  - !ruby/object:Gem::Version
30
- hash: 7
31
28
  segments:
32
29
  - 2
33
30
  - 2
@@ -38,11 +35,9 @@ dependencies:
38
35
  name: ruby-plsql
39
36
  prerelease: false
40
37
  requirement: &id002 !ruby/object:Gem::Requirement
41
- none: false
42
38
  requirements:
43
39
  - - ">="
44
40
  - !ruby/object:Gem::Version
45
- hash: 11
46
41
  segments:
47
42
  - 0
48
43
  - 4
@@ -54,11 +49,9 @@ dependencies:
54
49
  name: rake
55
50
  prerelease: false
56
51
  requirement: &id003 !ruby/object:Gem::Requirement
57
- none: false
58
52
  requirements:
59
53
  - - ">="
60
54
  - !ruby/object:Gem::Version
61
- hash: 3
62
55
  segments:
63
56
  - 0
64
57
  version: "0"
@@ -68,11 +61,9 @@ dependencies:
68
61
  name: rspec
69
62
  prerelease: false
70
63
  requirement: &id004 !ruby/object:Gem::Requirement
71
- none: false
72
64
  requirements:
73
65
  - - ~>
74
66
  - !ruby/object:Gem::Version
75
- hash: 27
76
67
  segments:
77
68
  - 2
78
69
  - 5
@@ -84,11 +75,9 @@ dependencies:
84
75
  name: ruby-oci8
85
76
  prerelease: false
86
77
  requirement: &id005 !ruby/object:Gem::Requirement
87
- none: false
88
78
  requirements:
89
79
  - - ~>
90
80
  - !ruby/object:Gem::Version
91
- hash: 7
92
81
  segments:
93
82
  - 2
94
83
  - 0
@@ -124,27 +113,23 @@ rdoc_options: []
124
113
  require_paths:
125
114
  - lib
126
115
  required_ruby_version: !ruby/object:Gem::Requirement
127
- none: false
128
116
  requirements:
129
117
  - - ">="
130
118
  - !ruby/object:Gem::Version
131
- hash: 3
132
119
  segments:
133
120
  - 0
134
121
  version: "0"
135
122
  required_rubygems_version: !ruby/object:Gem::Requirement
136
- none: false
137
123
  requirements:
138
124
  - - ">="
139
125
  - !ruby/object:Gem::Version
140
- hash: 3
141
126
  segments:
142
127
  - 0
143
128
  version: "0"
144
129
  requirements: []
145
130
 
146
131
  rubyforge_project:
147
- rubygems_version: 1.6.2
132
+ rubygems_version: 1.3.6
148
133
  signing_key:
149
134
  specification_version: 3
150
135
  summary: This plugin provides Oracle E-Business Suite user authentication functionality.