[KEYCLOAK-4083] SSSD Federation is only enabled with superuser permissions

This commit is contained in:
Bruno Oliveira 2016-12-16 16:55:24 -02:00
parent a4cbf130b4
commit 3f2e9c3592
3 changed files with 17 additions and 14 deletions

View file

@ -26,7 +26,6 @@
*/ */
package cx.ath.matthew.unix; package cx.ath.matthew.unix;
import cx.ath.matthew.LibraryLoader;
import cx.ath.matthew.debug.Debug; import cx.ath.matthew.debug.Debug;
import java.io.IOException; import java.io.IOException;
@ -37,9 +36,6 @@ import java.io.OutputStream;
* Represents a UnixSocket. * Represents a UnixSocket.
*/ */
public class UnixSocket { public class UnixSocket {
static {
LibraryLoader.load();
}
private native void native_set_pass_cred(int sock, boolean passcred) throws IOException; private native void native_set_pass_cred(int sock, boolean passcred) throws IOException;

View file

@ -34,11 +34,13 @@ public interface InfoPipe extends DBusInterface {
String OBJECTPATH = "/org/freedesktop/sssd/infopipe"; String OBJECTPATH = "/org/freedesktop/sssd/infopipe";
String BUSNAME = "org.freedesktop.sssd.infopipe"; String BUSNAME = "org.freedesktop.sssd.infopipe";
@DBusMemberName("GetUserAttr") @DBusMemberName("GetUserAttr")
Map<String, Variant> getUserAttributes(String user, List<String> attr); Map<String, Variant> getUserAttributes(String user, List<String> attr);
@DBusMemberName("GetUserGroups") @DBusMemberName("GetUserGroups")
List<String> getUserGroups(String user); List<String> getUserGroups(String user);
@DBusMemberName("Ping")
String ping(String ping);
} }

View file

@ -17,15 +17,13 @@
package org.keycloak.federation.sssd.api; package org.keycloak.federation.sssd.api;
import cx.ath.matthew.LibraryLoader;
import org.freedesktop.dbus.DBusConnection; import org.freedesktop.dbus.DBusConnection;
import org.freedesktop.dbus.Variant; import org.freedesktop.dbus.Variant;
import org.freedesktop.dbus.exceptions.DBusException; import org.freedesktop.dbus.exceptions.DBusException;
import org.freedesktop.sssd.infopipe.InfoPipe; import org.freedesktop.sssd.infopipe.InfoPipe;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -52,7 +50,8 @@ public class Sssd {
public Sssd(String username) { public Sssd(String username) {
this.username = username; this.username = username;
try { try {
dBusConnection = DBusConnection.getConnection(DBusConnection.SYSTEM); if (LibraryLoader.load().succeed())
dBusConnection = DBusConnection.getConnection(DBusConnection.SYSTEM);
} catch (DBusException e) { } catch (DBusException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -96,14 +95,20 @@ public class Sssd {
public static boolean isAvailable() { public static boolean isAvailable() {
boolean sssdAvailable = false; boolean sssdAvailable = false;
try { try {
Path path = Paths.get("/etc/sssd"); if (LibraryLoader.load().succeed()) {
if (!Files.exists(path)) { DBusConnection connection = DBusConnection.getConnection(DBusConnection.SYSTEM);
logger.debugv("SSSD is not available in your system. Federation provider will be disabled."); InfoPipe infoPipe = connection.getRemoteObject(InfoPipe.BUSNAME, InfoPipe.OBJECTPATH, InfoPipe.class);
if (infoPipe.ping("PING") == null || infoPipe.ping("PING").isEmpty()) {
logger.debugv("SSSD is not available in your system. Federation provider will be disabled.");
} else {
sssdAvailable = true;
}
} else { } else {
sssdAvailable = true; logger.debugv("The RPM libunix-dbus-java is not installed. SSSD Federation provider will be disabled.");
} }
} catch (Exception e) { } catch (Exception e) {
logger.error("SSSD check failed", e); logger.debugv("SSSD is not available in your system. Federation provider will be disabled.", e);
} }
return sssdAvailable; return sssdAvailable;
} }