Class: KerberosAuthenticator::Krb5::Context
- Inherits:
-
Object
- Object
- KerberosAuthenticator::Krb5::Context
- Defined in:
- lib/kerberos_authenticator/krb5/context.rb
Overview
A Kerberos context, holding all per-thread state.
Instance Attribute Summary collapse
-
#ptr ⇒ FFI::Pointer
readonly
The pointer to the wrapped krb5_context struct.
Class Method Summary collapse
-
.context ⇒ Context
A fibre-local Context.
-
.release(pointer) ⇒ Object
private
Frees a Context.
Instance Method Summary collapse
-
#default_realm ⇒ String
Retrieves the default realm.
-
#initialize(secure = false) ⇒ Context
constructor
A new instance of Context.
Constructor Details
#initialize(secure = false) ⇒ Context
Returns a new instance of Context.
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/kerberos_authenticator/krb5/context.rb', line 53 def initialize(secure = false) pointer = FFI::MemoryPointer.new :pointer if secure Krb5::LibCallError.raise_if_error { Krb5.init_secure_context(pointer) } else Krb5::LibCallError.raise_if_error { Krb5.init_context(pointer) } end @ptr = FFI::AutoPointer.new pointer.get_pointer(0), self.class.method(:release) self end |
Instance Attribute Details
#ptr ⇒ FFI::Pointer (readonly)
Returns the pointer to the wrapped krb5_context struct.
|
# File 'lib/kerberos_authenticator/krb5/context.rb', line 35
|
Class Method Details
.context ⇒ Context
Returns a fibre-local Context.
42 43 44 45 46 47 48 |
# File 'lib/kerberos_authenticator/krb5/context.rb', line 42 def self.context if Krb5.use_secure_context Thread.current[:krb5_secure_context] ||= new(true) else Thread.current[:krb5_context] ||= new end end |
.release(pointer) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Frees a Context
85 86 87 |
# File 'lib/kerberos_authenticator/krb5/context.rb', line 85 def self.release(pointer) Krb5.free_context pointer end |
Instance Method Details
#default_realm ⇒ String
Retrieves the default realm
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/kerberos_authenticator/krb5/context.rb', line 70 def default_realm out_ptr = FFI::MemoryPointer.new :pointer Krb5.get_default_realm(ptr, out_ptr) str_ptr = out_ptr.read_pointer copy = String.new(str_ptr.read_string).force_encoding('UTF-8') Krb5.free_string(ptr, str_ptr) copy end |