Class: KerberosAuthenticator::Krb5::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/kerberos_authenticator/krb5/context.rb

Overview

A Kerberos context, holding all per-thread state.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(secure = false) ⇒ Context

Returns a new instance of Context.

Parameters:

  • secure (Boolean) (defaults to: false)

    whether to ignore environmental variables when constructing a library context

See Also:



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/kerberos_authenticator/krb5/context.rb', line 52

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

#ptrObject (readonly)

Returns the value of attribute ptr.



38
39
40
# File 'lib/kerberos_authenticator/krb5/context.rb', line 38

def ptr
  @ptr
end

Class Method Details

.contextContext

Returns a fibre-local Context.

Returns:

  • (Context)

    a fibre-local Context



41
42
43
44
45
46
47
# File 'lib/kerberos_authenticator/krb5/context.rb', line 41

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

See Also:



84
85
86
# File 'lib/kerberos_authenticator/krb5/context.rb', line 84

def self.release(pointer)
  Krb5.free_context pointer
end

Instance Method Details

#default_realmString

Retrieves the default realm

Returns:

  • (String)

See Also:



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/kerberos_authenticator/krb5/context.rb', line 69

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