Class Credentials
- All Implemented Interfaces:
Proxy
GCredentials
type is a reference-counted wrapper for native
credentials.
The information in GCredentials
is typically used for identifying,
authenticating and authorizing other processes.
Some operating systems supports looking up the credentials of the remote
peer of a communication endpoint - see e.g. Socket.getCredentials()
.
Some operating systems supports securely sending and receiving
credentials over a Unix Domain Socket, see UnixCredentialsMessage
,
UnixConnection.sendCredentials(org.gnome.gio.Cancellable)
and
UnixConnection.receiveCredentials(org.gnome.gio.Cancellable)
for details.
On Linux, the native credential type is a struct ucred
- see the
unix(7)
man page) for details. This corresponds to
G_CREDENTIALS_TYPE_LINUX_UCRED
.
On Apple operating systems (including iOS, tvOS, and macOS), the native credential
type is a struct xucred
. This corresponds to G_CREDENTIALS_TYPE_APPLE_XUCRED
.
On FreeBSD, Debian GNU/kFreeBSD, and GNU/Hurd, the native credential type is a
struct cmsgcred
. This corresponds to G_CREDENTIALS_TYPE_FREEBSD_CMSGCRED
.
On NetBSD, the native credential type is a struct unpcbid
.
This corresponds to G_CREDENTIALS_TYPE_NETBSD_UNPCBID
.
On OpenBSD, the native credential type is a struct sockpeercred
.
This corresponds to G_CREDENTIALS_TYPE_OPENBSD_SOCKPEERCRED
.
On Solaris (including OpenSolaris and its derivatives), the native credential type
is a ucred_t
. This corresponds to G_CREDENTIALS_TYPE_SOLARIS_UCRED
.
Since GLib 2.72, on Windows, the native credentials may contain the PID of a
process. This corresponds to G_CREDENTIALS_TYPE_WIN32_PID
.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Credentials.Builder<B extends Credentials.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static class
Class structure forGCredentials
.Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
-
Constructor Summary
ConstructorDescriptionCreates a newGCredentials
object with credentials matching the the current process.Credentials
(MemorySegment address) Create a Credentials proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected Credentials
asParent()
Returns this instance as if it were its parent type.static Credentials.Builder
<? extends Credentials.Builder> builder()
ACredentials.Builder
object constructs aCredentials
with the specified properties.getNative
(CredentialsType nativeType) Gets a pointer to native credentials of typenativeType
from this Credentials.static Type
getType()
Get the GType of the Credentials classlong
Tries to get the UNIX process identifier from this Credentials.int
Tries to get the UNIX user identifier from this Credentials.boolean
isSameUser
(Credentials otherCredentials) Checks if this Credentials andotherCredentials
is the same user.void
setNative
(CredentialsType nativeType, MemorySegment native_) Copies the native credentials of typenativeType
fromnative_
into this Credentials.boolean
setUnixUser
(int uid) Tries to set the UNIX user identifier on this Credentials.toString()
Creates a human-readable textual representation of this Credentials that can be used in logging and debug messages.Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getMemoryLayout, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newInstance, newInstance, newv, notify_, notify_, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Credentials
Create a Credentials proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
Credentials
public Credentials()Creates a newGCredentials
object with credentials matching the the current process.
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()
doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName()
. This will call the native function pointer of this virtual method in the typeclass of the parent type. -
getNative
Gets a pointer to native credentials of typenativeType
from this Credentials.It is a programming error (which will cause a warning to be logged) to use this method if there is no
GCredentials
support for the OS or ifnativeType
isn't supported by the OS.- Parameters:
nativeType
- The type of native credentials to get.- Returns:
- The pointer to native credentials or
null
if there is noGCredentials
support for the OS or ifnativeType
isn't supported by the OS. Do not free the returned data, it is owned by this Credentials.
-
getUnixPid
Tries to get the UNIX process identifier from this Credentials. This method is only available on UNIX platforms.This operation can fail if
GCredentials
is not supported on the OS or if the native credentials type does not contain information about the UNIX process ID.- Returns:
- The UNIX process ID, or
-1
iferror
is set. - Throws:
GErrorException
- seeGError
-
getUnixUser
Tries to get the UNIX user identifier from this Credentials. This method is only available on UNIX platforms.This operation can fail if
GCredentials
is not supported on the OS or if the native credentials type does not contain information about the UNIX user.- Returns:
- The UNIX user identifier or
-1
iferror
is set. - Throws:
GErrorException
- seeGError
-
isSameUser
Checks if this Credentials andotherCredentials
is the same user.This operation can fail if
GCredentials
is not supported on the the OS.- Parameters:
otherCredentials
- AGCredentials
.- Returns:
true
if this Credentials andotherCredentials
has the same user,false
otherwise or iferror
is set.- Throws:
GErrorException
- seeGError
-
setNative
Copies the native credentials of typenativeType
fromnative_
into this Credentials.It is a programming error (which will cause a warning to be logged) to use this method if there is no
GCredentials
support for the OS or ifnativeType
isn't supported by the OS.- Parameters:
nativeType
- The type of native credentials to set.native_
- A pointer to native credentials.
-
setUnixUser
Tries to set the UNIX user identifier on this Credentials. This method is only available on UNIX platforms.This operation can fail if
GCredentials
is not supported on the OS or if the native credentials type does not contain information about the UNIX user. It can also fail if the OS does not allow the use of "spoofed" credentials.- Parameters:
uid
- The UNIX user identifier to set.- Returns:
true
ifuid
was set,false
if error is set.- Throws:
GErrorException
- seeGError
-
toString
-
builder
ACredentials.Builder
object constructs aCredentials
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withCredentials.Builder.build()
.
-