Adapt to changes in Commons
authorMathieu Baudier <mbaudier@argeo.org>
Tue, 21 Feb 2017 21:03:14 +0000 (22:03 +0100)
committerMathieu Baudier <mbaudier@argeo.org>
Tue, 21 Feb 2017 21:03:14 +0000 (22:03 +0100)
.gitignore [new file with mode: 0644]
demo/.gitignore
demo/modules/.gitignore [new file with mode: 0644]
demo/slc_demo_rcp.properties
dist/.gitignore [new file with mode: 0644]
dist/slc/.gitignore [new file with mode: 0644]
lib/.gitignore [new file with mode: 0644]
org.argeo.slc.support/src/org/argeo/slc/jsch/AbstractJschTask.java
org.argeo.slc.support/src/org/argeo/slc/jsch/GetMachineId.java [new file with mode: 0644]
org.argeo.slc.support/src/org/argeo/slc/jsch/jaas.cfg [new file with mode: 0644]
pom.xml

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..b83d222
--- /dev/null
@@ -0,0 +1 @@
+/target/
index 45dfa56f4afb8ab77dcb0a7f95e3f08b2f714a23..0980598ed076d25987f7a997f46a31add69db589 100644 (file)
@@ -1 +1,2 @@
 /exec/
+/target/
diff --git a/demo/modules/.gitignore b/demo/modules/.gitignore
new file mode 100644 (file)
index 0000000..b83d222
--- /dev/null
@@ -0,0 +1 @@
+/target/
index 284b1e6ea9048f1c2e4e7184686e4da38a4606ca..fd77839173579e56bd212f3e53aa90b5aca86354 100644 (file)
@@ -3,17 +3,18 @@ org.eclipse.equinox.http.servlet,\
 org.eclipse.equinox.http.jetty,\
 org.eclipse.equinox.metatype,\
 org.eclipse.equinox.cm,\
-org.eclipse.rap.rwt.osgi
 
 argeo.osgi.start.3.node=\
 org.argeo.cms
 
-
 argeo.osgi.start.4.apps=\
 org.eclipse.gemini.blueprint.extender
 
-argeo.osgi.start.5.apps=\
-org.argeo.jackrabbit.webapp,\
+argeo.osgi.start.5.slc=\
+org.argeo.slc.agent,\
+org.argeo.slc.agent.jcr,\
+
+argeo.node.repo.type=localfs
 
 slc.executionModules=org.argeo.slc.demo.ant,\
 org.argeo.slc.demo.basic,\
@@ -27,7 +28,9 @@ log4j.configuration=file:../../log4j.properties
 
 #argeo.server.tomcat.config=conf/default-server-ssl.xml
 
+sun.security.jgss.native=false
 org.osgi.framework.security=osgi
 java.security.policy=file:../../all.policy
 
+# DON'T CHANGE BELOW UNLESS YOU KNOW WHAT YOU ARE DOING
 org.eclipse.equinox.http.jetty.autostart=false
diff --git a/dist/.gitignore b/dist/.gitignore
new file mode 100644 (file)
index 0000000..b83d222
--- /dev/null
@@ -0,0 +1 @@
+/target/
diff --git a/dist/slc/.gitignore b/dist/slc/.gitignore
new file mode 100644 (file)
index 0000000..b83d222
--- /dev/null
@@ -0,0 +1 @@
+/target/
diff --git a/lib/.gitignore b/lib/.gitignore
new file mode 100644 (file)
index 0000000..b83d222
--- /dev/null
@@ -0,0 +1 @@
+/target/
index ed37069ef3a14288230ff9abffc03109f49de3d2..2dbcd84e74a3a9c01d7eca195049dbed7af7b511 100644 (file)
@@ -17,6 +17,7 @@ package org.argeo.slc.jsch;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.security.PrivilegedAction;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -24,7 +25,9 @@ import org.argeo.slc.SlcException;
 
 import com.jcraft.jsch.JSch;
 import com.jcraft.jsch.JSchException;
+import com.jcraft.jsch.Logger;
 import com.jcraft.jsch.Session;
+import com.jcraft.jsch.UserAuthGSSAPIWithMIC;
 
 public abstract class AbstractJschTask implements Runnable {
        private final Log log = LogFactory.getLog(getClass());
@@ -36,38 +39,34 @@ public abstract class AbstractJschTask implements Runnable {
                        Session session = sshTarget.getSession();
                        if (session.isConnected()) {
                                if (log.isTraceEnabled())
-                                       log.debug("Using cached session to " + getSshTarget()
-                                                       + " via SSH");
+                                       log.debug("Using cached session to " + getSshTarget() + " via SSH");
                                return session;
                        }
                }
 
                try {
                        JSch jsch = new JSch();
-                       if (sshTarget.getUsePrivateKey()
-                                       && sshTarget.getLocalPrivateKey().exists())
-                               jsch.addIdentity(sshTarget.getLocalPrivateKey()
-                                               .getAbsolutePath());
-                       Session session = jsch.getSession(getSshTarget().getUser(),
-                                       getSshTarget().getHost(), getSshTarget().getPort());
+                       if (sshTarget.getUsePrivateKey() && sshTarget.getLocalPrivateKey().exists())
+                               jsch.addIdentity(sshTarget.getLocalPrivateKey().getAbsolutePath());
+                       Session session = jsch.getSession(getSshTarget().getUser(), getSshTarget().getHost(),
+                                       getSshTarget().getPort());
 
                        session.setUserInfo(getSshTarget().getUserInfo());
+                       session.setConfig("userauth.gssapi-with-mic", UserAuthGSSAPIWithMIC.class.getName());
                        session.setServerAliveInterval(1000);
                        session.connect();
                        if (log.isTraceEnabled())
                                log.trace("Connected to " + getSshTarget() + " via SSH");
                        if (sshTarget.getSession() != null) {
                                if (log.isTraceEnabled())
-                                       log.trace("The cached session to " + getSshTarget()
-                                                       + " was disconnected and was reset.");
+                                       log.trace("The cached session to " + getSshTarget() + " was disconnected and was reset.");
                                sshTarget.setSession(session);
                        }
                        return session;
                } catch (JSchException e) {
                        if (sshTarget.getUserInfo() instanceof SimpleUserInfo)
                                ((SimpleUserInfo) sshTarget.getUserInfo()).reset();
-                       throw new SlcException("Could not open session to "
-                                       + getSshTarget(), e);
+                       throw new SlcException("Could not open session to " + getSshTarget(), e);
                }
        }
 
@@ -79,8 +78,7 @@ public abstract class AbstractJschTask implements Runnable {
                        if (sshTarget != null && sshTarget.getSession() == null) {
                                session.disconnect();
                                if (log.isTraceEnabled())
-                                       log.trace("Disconnected from " + getSshTarget()
-                                                       + " via SSH");
+                                       log.trace("Disconnected from " + getSshTarget() + " via SSH");
                        }
                }
        }
@@ -124,4 +122,34 @@ public abstract class AbstractJschTask implements Runnable {
                this.sshTarget = sshTarget;
        }
 
+       PrivilegedAction<Void> asPrivilegedAction() {
+               return new PrivilegedAction<Void>() {
+                       public Void run() {
+                               AbstractJschTask.this.run();
+                               return null;
+                       }
+               };
+       }
+
+       static {
+               JSch.setLogger(new JschLogger());
+       }
+
+       private static class JschLogger implements Logger {
+               private final Log log = LogFactory.getLog(JschLogger.class);
+
+               // TODO better support levels
+               @Override
+               public boolean isEnabled(int level) {
+                       if (log.isTraceEnabled())
+                               return true;
+                       return false;
+               }
+
+               @Override
+               public void log(int level, String message) {
+                       log.trace(message);
+               }
+
+       }
 }
diff --git a/org.argeo.slc.support/src/org/argeo/slc/jsch/GetMachineId.java b/org.argeo.slc.support/src/org/argeo/slc/jsch/GetMachineId.java
new file mode 100644 (file)
index 0000000..fc7e88b
--- /dev/null
@@ -0,0 +1,39 @@
+package org.argeo.slc.jsch;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.security.auth.Subject;
+import javax.security.auth.login.LoginContext;
+
+class GetMachineId {
+
+       public static void main(String[] args) {
+               URL url = GetMachineId.class.getResource("jaas.cfg");
+               System.setProperty("java.security.auth.login.config", url.toExternalForm());
+
+               String hostname = args[0];
+               try {
+                       LoginContext lc = new LoginContext("SINGLE_USER");
+                       lc.login();
+
+                       SshTarget sshTarget = new SshTarget();
+                       sshTarget.setHost(hostname);
+                       RemoteExec remoteExec = new RemoteExec();
+                       remoteExec.setCommand("cat /etc/machine-id");
+                       remoteExec.setSshTarget(sshTarget);
+                       List<String> lines = new ArrayList<>();
+                       remoteExec.setStdOutLines(lines);
+
+                       Subject.doAs(lc.getSubject(), remoteExec.asPrivilegedAction());
+
+                       String machineId = lines.get(0);
+                       System.out.println(hostname + ": " + machineId);
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
+
+       }
+
+}
diff --git a/org.argeo.slc.support/src/org/argeo/slc/jsch/jaas.cfg b/org.argeo.slc.support/src/org/argeo/slc/jsch/jaas.cfg
new file mode 100644 (file)
index 0000000..21176b9
--- /dev/null
@@ -0,0 +1,5 @@
+SINGLE_USER {
+    com.sun.security.auth.module.Krb5LoginModule optional
+     principal="${user.name}"
+     useTicketCache=true;
+};
diff --git a/pom.xml b/pom.xml
index d668d16e7e047096b51f52918eb441d5fbd6519f..60d35173fcc8c9fc2995d84109bdf3856f13979a 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
        <parent>
                <groupId>org.argeo.commons</groupId>
                <artifactId>argeo-commons</artifactId>
-               <version>2.1.55</version>
+               <version>2.1.62-SNAPSHOT</version>
        </parent>
        <groupId>org.argeo.slc</groupId>
        <artifactId>argeo-slc</artifactId>