Merge pull request #3659 from abstractj/KEYCLOAK-4085
[KEYCLOAK-4083] and [KEYCLOAK-4085] SSSD federation provider should load libunix from alternative paths
This commit is contained in:
commit
20c5c6b60c
4 changed files with 25 additions and 15 deletions
|
@ -21,7 +21,14 @@ package cx.ath.matthew;
|
||||||
*/
|
*/
|
||||||
public class LibraryLoader {
|
public class LibraryLoader {
|
||||||
|
|
||||||
private static final String[] PATHS = {"/usr/lib/", "/usr/lib64/", "/usr/local/lib/", "/opt/local/lib/"};
|
private static final String[] PATHS = {
|
||||||
|
"/opt/rh/rh-sso7/root/lib/",
|
||||||
|
"/opt/rh/rh-sso7/root/lib64/",
|
||||||
|
"/usr/lib/",
|
||||||
|
"/usr/lib64/",
|
||||||
|
"/usr/local/lib/",
|
||||||
|
"/opt/local/lib/"
|
||||||
|
};
|
||||||
private static final String LIBRARY_NAME = "libunix_dbus_java";
|
private static final String LIBRARY_NAME = "libunix_dbus_java";
|
||||||
private static final String VERSION = "0.0.8";
|
private static final String VERSION = "0.0.8";
|
||||||
private static boolean loadSucceeded;
|
private static boolean loadSucceeded;
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
}
|
}
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue