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:



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

#ptrFFI::Pointer (readonly)

Returns the pointer to the wrapped krb5_context struct.

Returns:

  • (FFI::Pointer)

    the pointer to the wrapped krb5_context struct



# File 'lib/kerberos_authenticator/krb5/context.rb', line 35

Class Method Details

.contextContext

Returns a fibre-local Context.

Returns:

  • (Context)

    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

See Also:



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_realmString

Retrieves the default realm

Returns:

  • (String)

See Also:



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