File tree Expand file tree Collapse file tree 5 files changed +77
-9
lines changed Expand file tree Collapse file tree 5 files changed +77
-9
lines changed Original file line number Diff line number Diff line change 1+ module Net
2+ class LDAP
3+ class AuthAdapter
4+ def self . regiseter ( names , adapter )
5+ names = Array ( names )
6+ @adapters ||= { }
7+ names . each do |name |
8+ @adapters [ name ] = adapter
9+ end
10+ end
11+
12+ def self . []( name )
13+ @adapters [ name ]
14+ end
15+
16+ def initialize ( conn )
17+ @connection = conn
18+ end
19+
20+ def bind
21+ raise "bind method must be overwritten"
22+ end
23+ end
24+ end
25+ end
Original file line number Diff line number Diff line change 1+ require 'net/ldap/auth_adapters/simple'
2+
3+ Net ::LDAP ::AuthAdapter . register ( :anon , Net ::LDAP ::AuthAdapters ::Simple )
Original file line number Diff line number Diff line change 1+ require 'net/ldap/auth_adapters/simple'
2+
3+ Net ::LDAP ::AuthAdapter . register ( :anonymous , Net ::LDAP ::AuthAdapters ::Simple )
Original file line number Diff line number Diff line change 1+ module Net
2+ class LDAP
3+ module AuthAdapters
4+ class Simple < AuthAdapter
5+ def bind ( auth )
6+ user , psw = if auth [ :method ] == :simple
7+ [ auth [ :username ] || auth [ :dn ] , auth [ :password ] ]
8+ else
9+ [ "" , "" ]
10+ end
11+
12+ raise Net ::LDAP ::BindingInformationInvalidError , "Invalid binding information" unless ( user && psw )
13+
14+ message_id = @connection . next_msgid
15+ request = [
16+ LdapVersion . to_ber , user . to_ber ,
17+ psw . to_ber_contextspecific ( 0 )
18+ ] . to_ber_appsequence ( Net ::LDAP ::PDU ::BindRequest )
19+
20+ @connection . write ( request , nil , message_id )
21+ pdu = @connection . queued_read ( message_id )
22+
23+ if !pdu || pdu . app_tag != Net ::LDAP ::PDU ::BindResult
24+ raise Net ::LDAP ::NoBindResultError , "no bind result"
25+ end
26+
27+ pdu
28+ end
29+ end
30+ end
31+ end
32+ end
33+
34+ Net ::LDAP ::AuthAdapter . register ( :simple , Net ::LDAP ::AuthAdapters ::Simple )
Original file line number Diff line number Diff line change @@ -250,15 +250,18 @@ def next_msgid
250250 def bind ( auth )
251251 instrument "bind.net_ldap_connection" do |payload |
252252 payload [ :method ] = meth = auth [ :method ]
253- if [ :simple , :anonymous , :anon ] . include? ( meth )
254- bind_simple auth
255- elsif meth == :sasl
256- bind_sasl ( auth )
257- elsif meth == :gss_spnego
258- bind_gss_spnego ( auth )
259- else
260- raise Net ::LDAP ::AuthMethodUnsupportedError , "Unsupported auth method (#{ meth } )"
261- end
253+ require "net/ldap/auth_adapters/#{ meth } "
254+ adapter = Net ::LDAP ::AuthAdapterp [ meth ]
255+ adapter . bind ( auth )
256+ # if [:simple, :anonymous, :anon].include?(meth)
257+ # bind_simple auth
258+ # elsif meth == :sasl
259+ # bind_sasl(auth)
260+ # elsif meth == :gss_spnego
261+ # bind_gss_spnego(auth)
262+ # else
263+ # raise Net::LDAP::AuthMethodUnsupportedError, "Unsupported auth method (#{meth})"
264+ # end
262265 end
263266 end
264267
You can’t perform that action at this time.
0 commit comments