Introduce bundle context callback
authorMathieu Baudier <mbaudier@argeo.org>
Sun, 6 Sep 2015 19:03:08 +0000 (19:03 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Sun, 6 Sep 2015 19:03:08 +0000 (19:03 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@8377 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

org.argeo.security.core/src/org/argeo/osgi/auth/BuncleContextCallbackHander.java [new file with mode: 0644]
org.argeo.security.core/src/org/argeo/osgi/auth/BundleContextCallback.java [new file with mode: 0644]

diff --git a/org.argeo.security.core/src/org/argeo/osgi/auth/BuncleContextCallbackHander.java b/org.argeo.security.core/src/org/argeo/osgi/auth/BuncleContextCallbackHander.java
new file mode 100644 (file)
index 0000000..08cf37c
--- /dev/null
@@ -0,0 +1,29 @@
+package org.argeo.osgi.auth;
+
+import java.io.IOException;
+
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.UnsupportedCallbackException;
+
+import org.osgi.framework.BundleContext;
+
+public class BuncleContextCallbackHander implements CallbackHandler {
+       private final BundleContext bundleContext;
+
+       public BuncleContextCallbackHander(BundleContext bundleContext) {
+               this.bundleContext = bundleContext;
+       }
+
+       @Override
+       public void handle(Callback[] callbacks) throws IOException,
+                       UnsupportedCallbackException {
+               for (Callback callback : callbacks) {
+                       if (!(callback instanceof BundleContextCallback))
+                               throw new UnsupportedCallbackException(callback);
+                       ((BundleContextCallback) callback).setBundleContext(bundleContext);
+               }
+
+       }
+
+}
diff --git a/org.argeo.security.core/src/org/argeo/osgi/auth/BundleContextCallback.java b/org.argeo.security.core/src/org/argeo/osgi/auth/BundleContextCallback.java
new file mode 100644 (file)
index 0000000..193da34
--- /dev/null
@@ -0,0 +1,20 @@
+package org.argeo.osgi.auth;
+
+import javax.security.auth.callback.Callback;
+import javax.security.auth.spi.LoginModule;
+
+import org.osgi.framework.BundleContext;
+
+/** Allows a {@link LoginModule} to as for a {@link BundleContext} */
+public class BundleContextCallback implements Callback {
+       private BundleContext bundleContext;
+
+       public BundleContext getBundleContext() {
+               return bundleContext;
+       }
+
+       public void setBundleContext(BundleContext bundleContext) {
+               this.bundleContext = bundleContext;
+       }
+
+}