示例#1
0
    def __setitem__(self, key, value):
        if isinstance(key, six.text_type):
            key = key.encode(_utils._get_encoding())

        rname_rfc6680.delete_name_attribute(self._name, key)

        if isinstance(value, tuples.GetNameAttributeResult):
            complete = value.complete
            value = value.values
        elif isinstance(value, tuple) and len(value) == 2:
            complete = value[1]
            value = value[0]
        else:
            complete = False

        if (isinstance(value, (six.string_types, bytes))
                or not isinstance(value, Iterable)):
            # NB(directxman12): this allows us to easily assign a single
            # value, since that's a common case
            value = [value]

            rname_rfc6680.set_name_attribute(self._name,
                                             key,
                                             value,
                                             complete=complete)
示例#2
0
 def __str__(self):
     if issubclass(str, six.text_type):
         # Python 3 -- we should return unicode
         return bytes(self).decode(_utils._get_encoding())
     else:
         # Python 2 -- we should return a string
         return self.__bytes__()
示例#3
0
    def __new__(cls, base=None, name_type=None, token=None, composite=False):
        if token is not None:
            if composite:
                if rname_rfc6680 is None:
                    raise NotImplementedError(
                        "Your GSSAPI implementation does not support RFC 6680 "
                        "(the GSSAPI naming extensions)")

                if rname_rfc6680_comp_oid is not None:
                    base_name = rname.import_name(token,
                                                  NameType.composite_export)
                    displ_name = rname.display_name(base_name, name_type=True)
                    if displ_name.name_type == NameType.composite_export:
                        # NB(directxman12): there's a bug in MIT krb5 <= 1.13
                        # where GSS_C_NT_COMPOSITE_EXPORT doesn't trigger
                        # immediate import logic.  However, we can just use
                        # the normal GSS_C_NT_EXPORT_NAME in this case.
                        base_name = rname.import_name(token, NameType.export)
                else:
                    # NB(directxman12): some older versions of MIT krb5 don't
                    # have support for the GSS_C_NT_COMPOSITE_EXPORT, but do
                    # support composite tokens via GSS_C_NT_EXPORT_NAME.
                    base_name = rname.import_name(token, NameType.export)
            else:
                base_name = rname.import_name(token, NameType.export)
        elif isinstance(base, rname.Name):
            base_name = base
        else:
            if isinstance(base, six.text_type):
                base = base.encode(_utils._get_encoding())

            base_name = rname.import_name(base, name_type)

        return super(Name, cls).__new__(cls, base_name)
示例#4
0
 def __str__(self):
     if issubclass(str, six.text_type):
         # Python 3 -- we should return unicode
         return bytes(self).decode(_utils._get_encoding())
     else:
         # Python 2 -- we should return a string
         return self.__bytes__()
    def test_to_unicode(self):
        name = gssnames.Name(SERVICE_PRINCIPAL, gb.NameType.kerberos_principal)

        name_str = six.text_type(name)

        name_str.should_be_a(six.text_type)
        name_str.should_be(SERVICE_PRINCIPAL.decode(gssutils._get_encoding()))
示例#6
0
    def __new__(cls, base=None, name_type=None, token=None,
                composite=False):
        if token is not None:
            if composite:
                if rname_rfc6680 is None:
                    raise NotImplementedError(
                        "Your GSSAPI implementation does not support RFC 6680 "
                        "(the GSSAPI naming extensions)")

                if rname_rfc6680_comp_oid is not None:
                    base_name = rname.import_name(token,
                                                  NameType.composite_export)
                    displ_name = rname.display_name(base_name, name_type=True)
                    if displ_name.name_type == NameType.composite_export:
                        # NB(directxman12): there's a bug in MIT krb5 <= 1.13
                        # where GSS_C_NT_COMPOSITE_EXPORT doesn't trigger
                        # immediate import logic.  However, we can just use
                        # the normal GSS_C_NT_EXPORT_NAME in this case.
                        base_name = rname.import_name(token, NameType.export)
                else:
                    # NB(directxman12): some older versions of MIT krb5 don't
                    # have support for the GSS_C_NT_COMPOSITE_EXPORT, but do
                    # support composite tokens via GSS_C_NT_EXPORT_NAME.
                    base_name = rname.import_name(token, NameType.export)
            else:
                base_name = rname.import_name(token, NameType.export)
        elif isinstance(base, rname.Name):
            base_name = base
        else:
            if isinstance(base, six.text_type):
                base = base.encode(_utils._get_encoding())

            base_name = rname.import_name(base, name_type)

        return super(Name, cls).__new__(cls, base_name)
示例#7
0
    def test_to_unicode(self):
        name = gssnames.Name(SERVICE_PRINCIPAL, gb.NameType.kerberos_principal)

        name_str = six.text_type(name)

        name_str.should_be_a(six.text_type)
        name_str.should_be(SERVICE_PRINCIPAL.decode(gssutils._get_encoding()))
示例#8
0
    def __getitem__(self, key):
        if isinstance(key, six.text_type):
            key = key.encode(_utils._get_encoding())

        res = rname_rfc6680.get_name_attribute(self._name, key)
        return tuples.GetNameAttributeResult(frozenset(res.values),
                                             frozenset(res.display_values),
                                             res.authenticated, res.complete)
示例#9
0
    def _bytes_desc(self):
        base = self.dotted_form
        if rfc5801 is not None and self._saslname and self._saslname.mech_name:
            base = self._saslname.mech_name

        if isinstance(base, six.text_type):
            base = base.encode(_utils._get_encoding())

        return base
示例#10
0
    def __getitem__(self, key):
        if isinstance(key, six.text_type):
            key = key.encode(_utils._get_encoding())

        res = rname_rfc6680.get_name_attribute(self._name, key)
        return tuples.GetNameAttributeResult(frozenset(res.values),
                                             frozenset(res.display_values),
                                             res.authenticated,
                                             res.complete)
示例#11
0
    def _bytes_desc(self):
        base = self.dotted_form
        if rfc5801 is not None and self._saslname and self._saslname.mech_name:
            base = self._saslname.mech_name

        if isinstance(base, str):
            base = base.encode(_utils._get_encoding())

        return base
示例#12
0
    def test_to_str(self):
        name = gssnames.Name(SERVICE_PRINCIPAL, gb.NameType.kerberos_principal)

        name_str = str(name)

        if sys.version_info[0] == 2:
            target_val = SERVICE_PRINCIPAL
        else:
            target_val = SERVICE_PRINCIPAL.decode(gssutils._get_encoding())

        self.assertEqual(name_str, target_val)
示例#13
0
    def test_to_str(self):
        name = gssnames.Name(SERVICE_PRINCIPAL, gb.NameType.kerberos_principal)

        name_str = str(name)

        name_str.should_be_a(str)
        if sys.version_info[0] == 2:
            target_val = SERVICE_PRINCIPAL
        else:
            target_val = SERVICE_PRINCIPAL.decode(gssutils._get_encoding())

        name_str.should_be(target_val)
示例#14
0
    def test_to_str(self):
        name = gssnames.Name(SERVICE_PRINCIPAL, gb.NameType.kerberos_principal)

        name_str = str(name)

        name_str.should_be_a(str)
        if sys.version_info[0] == 2:
            target_val = SERVICE_PRINCIPAL
        else:
            target_val = SERVICE_PRINCIPAL.decode(gssutils._get_encoding())

        name_str.should_be(target_val)
示例#15
0
    def display_as(self, name_type):
        """
        Display this name as the given name type.

        This method attempts to display the current :class:`Name`
        using the syntax of the given :class:`NameType`, if possible.

        Warning:

            In MIT krb5 versions below 1.13.3, this method can segfault if
            the name was not *originally* created with a `name_type` that was
            not ``None`` (even in cases when a ``name_type``
            is later "added", such as via :meth:`canonicalize`).
            **Do not use this method unless you are sure the above
            conditions can never happen in your code.**

        Warning:

            In addition to the above warning, current versions of MIT krb5 do
            not actually fully implement this method, and it may return
            incorrect results in the case of canonicalized names.

        :requires-ext:`rfc6680`

        Args:
            name_type (OID): the :class:`NameType` to use to display the given
                name

        Returns:
            str: the displayed name

        Raises:
            OperationUnavailableError
        """

        if rname_rfc6680 is None:
            raise NotImplementedError("Your GSSAPI implementation does not "
                                      "support RFC 6680 (the GSSAPI naming "
                                      "extensions)")
        return rname_rfc6680.display_name_ext(self, name_type).decode(
            _utils._get_encoding())
示例#16
0
    def display_as(self, name_type):
        """
        Display this name as the given name type.

        This method attempts to display the current :class:`Name`
        using the syntax of the given :class:`NameType`, if possible.

        Warning:

            In MIT krb5 versions below 1.13.3, this method can segfault if
            the name was not *originally* created with a `name_type` that was
            not ``None`` (even in cases when a ``name_type``
            is later "added", such as via :meth:`canonicalize`).
            **Do not use this method unless you are sure the above
            conditions can never happen in your code.**

        Warning:

            In addition to the above warning, current versions of MIT krb5 do
            not actually fully implement this method, and it may return
            incorrect results in the case of canonicalized names.

        :requires-ext:`rfc6680`

        Args:
            name_type (OID): the :class:`NameType` to use to display the given
                name

        Returns:
            str: the displayed name

        Raises:
            OperationUnavailableError
        """

        if rname_rfc6680 is None:
            raise NotImplementedError("Your GSSAPI implementation does not "
                                      "support RFC 6680 (the GSSAPI naming "
                                      "extensions)")
        return rname_rfc6680.display_name_ext(self, name_type).decode(
            _utils._get_encoding())
示例#17
0
    def __setitem__(self, key, value):
        if isinstance(key, six.text_type):
            key = key.encode(_utils._get_encoding())

        rname_rfc6680.delete_name_attribute(self._name, key)

        if isinstance(value, tuples.GetNameAttributeResult):
            complete = value.complete
            value = value.values
        elif isinstance(value, tuple) and len(value) == 2:
            complete = value[1]
            value = value[0]
        else:
            complete = False

        if (isinstance(value, (six.string_types, bytes)) or
                not isinstance(value, Iterable)):
            # NB(directxman12): this allows us to easily assign a single
            # value, since that's a common case
            value = [value]

            rname_rfc6680.set_name_attribute(self._name, key, value,
                                             complete=complete)
示例#18
0
    def from_sasl_name(cls, name=None):
        """
        Create a Mechanism from its SASL name

        Args:
            name (str): SASL name of the desired mechanism

        Returns:
            Mechanism: the desired mechanism

        Raises:
            GSSError

        :requires-ext:`rfc5801`
        """
        if rfc5801 is None:
            raise NotImplementedError("Your GSSAPI implementation does not "
                                      "have support for RFC 5801")
        if isinstance(name, six.text_type):
            name = name.encode(_utils._get_encoding())

        m = rfc5801.inquire_mech_for_saslname(name)

        return cls(m)
示例#19
0
    def from_sasl_name(cls, name=None):
        """
        Create a Mechanism from its SASL name

        Args:
            name (str): SASL name of the desired mechanism

        Returns:
            Mechanism: the desired mechanism

        Raises:
            GSSError

        :requires-ext:`rfc5801`
        """
        if rfc5801 is None:
            raise NotImplementedError("Your GSSAPI implementation does not "
                                      "have support for RFC 5801")
        if isinstance(name, str):
            name = name.encode(_utils._get_encoding())

        m = rfc5801.inquire_mech_for_saslname(name)

        return cls(m)
示例#20
0
 def __unicode__(self):
     # Python 2 -- someone asked for unicode
     return self.__bytes__().decode(_utils._get_encoding())
示例#21
0
 def __unicode__(self):
     return self._bytes_desc().decode(_utils._get_encoding())
示例#22
0
 def test_to_unicode(self):
     name = gssnames.Name(SERVICE_PRINCIPAL, gb.NameType.kerberos_principal)
     self.assertEqual(str(name),
                      SERVICE_PRINCIPAL.decode(gssutils._get_encoding()))
示例#23
0
 def __unicode__(self):
     # Python 2 -- someone asked for unicode
     return self.__bytes__().decode(_utils._get_encoding())
示例#24
0
    def __delitem__(self, key):
        if isinstance(key, six.text_type):
            key = key.encode(_utils._get_encoding())

        rname_rfc6680.delete_name_attribute(self._name, key)
示例#25
0
 def __unicode__(self):
     return self._bytes_desc().decode(_utils._get_encoding())
示例#26
0
 def __str__(self):
     return bytes(self).decode(_utils._get_encoding())
示例#27
0
    def __delitem__(self, key):
        if isinstance(key, six.text_type):
            key = key.encode(_utils._get_encoding())

        rname_rfc6680.delete_name_attribute(self._name, key)