Class DBusAuthObserver
- All Implemented Interfaces:
Proxy
GDBusAuthObserver
provides a mechanism for participating
in how a DBusServer
(or a DBusConnection
)
authenticates remote peers.
Simply instantiate a GDBusAuthObserver
and connect to the
signals you are interested in. Note that new signals may be added
in the future.
Controlling Authentication Mechanisms
By default, a GDBusServer
or server-side GDBusConnection
will allow
any authentication mechanism to be used. If you only want to allow D-Bus
connections with the EXTERNAL
mechanism, which makes use of credentials
passing and is the recommended mechanism for modern Unix platforms such
as Linux and the BSD family, you would use a signal handler like this:
static gboolean
on_allow_mechanism (GDBusAuthObserver *observer,
const gchar *mechanism,
gpointer user_data)
{
if (g_strcmp0 (mechanism, "EXTERNAL") == 0)
{
return TRUE;
}
return FALSE;
}
Controlling Authorization
By default, a GDBusServer
or server-side GDBusConnection
will accept
connections from any successfully authenticated user (but not from
anonymous connections using the ANONYMOUS
mechanism). If you only
want to allow D-Bus connections from processes owned by the same uid
as the server, since GLib 2.68, you should use the
G_DBUS_SERVER_FLAGS_AUTHENTICATION_REQUIRE_SAME_USER
flag. It’s equivalent
to the following signal handler:
static gboolean
on_authorize_authenticated_peer (GDBusAuthObserver *observer,
GIOStream *stream,
GCredentials *credentials,
gpointer user_data)
{
gboolean authorized;
authorized = FALSE;
if (credentials != NULL)
{
GCredentials *own_credentials;
own_credentials = g_credentials_new ();
if (g_credentials_is_same_user (credentials, own_credentials, NULL))
authorized = TRUE;
g_object_unref (own_credentials);
}
return authorized;
}
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Functional interface declaration of theAllowMechanismCallback
callback.static interface
Functional interface declaration of theAuthorizeAuthenticatedPeerCallback
callback.static class
DBusAuthObserver.Builder<B extends DBusAuthObserver.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
-
Constructor Summary
ConstructorDescriptionCreates a newGDBusAuthObserver
object.DBusAuthObserver
(MemorySegment address) Create a DBusAuthObserver proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionboolean
allowMechanism
(String mechanism) Emits theGDBusAuthObserver
::allow-mechanism signal on this DBusAuthObserver.protected DBusAuthObserver
asParent()
Returns this instance as if it were its parent type.boolean
authorizeAuthenticatedPeer
(IOStream stream, @Nullable Credentials credentials) Emits theGDBusAuthObserver
::authorize-authenticated-peer signal on this DBusAuthObserver.static DBusAuthObserver.Builder
<? extends DBusAuthObserver.Builder> builder()
ADBusAuthObserver.Builder
object constructs aDBusAuthObserver
with the specified properties.boolean
emitAllowMechanism
(String mechanism) Emits the "allow-mechanism" signal.boolean
emitAuthorizeAuthenticatedPeer
(IOStream stream, @Nullable Credentials credentials) Emits the "authorize-authenticated-peer" signal.static Type
getType()
Get the GType of the DBusAuthObserver classEmitted to check ifmechanism
is allowed to be used.Emitted to check if a peer that is successfully authenticated is authorized.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
-
DBusAuthObserver
Create a DBusAuthObserver proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
DBusAuthObserver
public DBusAuthObserver()Creates a newGDBusAuthObserver
object.
-
-
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. -
allowMechanism
Emits theGDBusAuthObserver
::allow-mechanism signal on this DBusAuthObserver.- Parameters:
mechanism
- The name of the mechanism, e.g.DBUS_COOKIE_SHA1
.- Returns:
true
ifmechanism
can be used to authenticate the other peer,false
if not.
-
authorizeAuthenticatedPeer
public boolean authorizeAuthenticatedPeer(IOStream stream, @Nullable @Nullable Credentials credentials) Emits theGDBusAuthObserver
::authorize-authenticated-peer signal on this DBusAuthObserver.- Parameters:
stream
- AGIOStream
for theGDBusConnection
.credentials
- Credentials received from the peer ornull
.- Returns:
true
if the peer is authorized,false
if not.
-
onAllowMechanism
public SignalConnection<DBusAuthObserver.AllowMechanismCallback> onAllowMechanism(DBusAuthObserver.AllowMechanismCallback handler) Emitted to check ifmechanism
is allowed to be used.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitAllowMechanism
Emits the "allow-mechanism" signal. SeeonAllowMechanism(org.gnome.gio.DBusAuthObserver.AllowMechanismCallback)
. -
onAuthorizeAuthenticatedPeer
public SignalConnection<DBusAuthObserver.AuthorizeAuthenticatedPeerCallback> onAuthorizeAuthenticatedPeer(DBusAuthObserver.AuthorizeAuthenticatedPeerCallback handler) Emitted to check if a peer that is successfully authenticated is authorized.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitAuthorizeAuthenticatedPeer
public boolean emitAuthorizeAuthenticatedPeer(IOStream stream, @Nullable @Nullable Credentials credentials) Emits the "authorize-authenticated-peer" signal. SeeonAuthorizeAuthenticatedPeer(org.gnome.gio.DBusAuthObserver.AuthorizeAuthenticatedPeerCallback)
. -
builder
ADBusAuthObserver.Builder
object constructs aDBusAuthObserver
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withDBusAuthObserver.Builder.build()
.
-