2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.security
.ui
;
18 import java
.io
.IOException
;
20 import javax
.security
.auth
.callback
.Callback
;
21 import javax
.security
.auth
.callback
.CallbackHandler
;
22 import javax
.security
.auth
.callback
.UnsupportedCallbackException
;
24 import org
.argeo
.ArgeoException
;
25 import org
.argeo
.cms
.widgets
.auth
.DefaultLoginDialog
;
26 import org
.eclipse
.swt
.widgets
.Display
;
27 import org
.osgi
.framework
.BundleActivator
;
28 import org
.osgi
.framework
.BundleContext
;
29 import org
.osgi
.framework
.ServiceRegistration
;
32 * The activator class controls the plug-in life cycle
34 public class SecurityUiPlugin
implements BundleActivator
{
35 private static BundleContext bundleContext
;
36 public static InheritableThreadLocal
<Display
> display
= new InheritableThreadLocal
<Display
>() {
39 protected Display
initialValue() {
40 return Display
.getCurrent();
45 public final static String PLUGIN_ID
= "org.argeo.security.ui"; //$NON-NLS-1$
47 final static String CONTEXT_KEYRING
= "KEYRING";
49 private CallbackHandler defaultCallbackHandler
;
50 private ServiceRegistration
<CallbackHandler
> defaultCallbackHandlerReg
;
52 public void start(BundleContext context
) throws Exception
{
53 if (bundleContext
!= null)
54 if (!bundleContext
.equals(bundleContext
))
55 throw new ArgeoException(
56 "Bundle context already set with a different value");
60 bundleContext
= context
;
62 defaultCallbackHandler
= new DefaultCallbackHandler();
63 defaultCallbackHandlerReg
= context
.registerService(
64 CallbackHandler
.class, defaultCallbackHandler
, null);
67 public void stop(BundleContext context
) throws Exception
{
69 defaultCallbackHandlerReg
.unregister();
72 public static BundleContext
getBundleContext() {
76 protected class DefaultCallbackHandler
implements CallbackHandler
{
77 public void handle(final Callback
[] callbacks
) throws IOException
,
78 UnsupportedCallbackException
{
80 // if (display != null) // RCP
81 Display displayToUse
= display
.get();
82 if (displayToUse
== null)// RCP
83 displayToUse
= Display
.getDefault();
84 displayToUse
.syncExec(new Runnable() {
86 DefaultLoginDialog dialog
= new DefaultLoginDialog(display
87 .get().getActiveShell());
89 dialog
.handle(callbacks
);
90 } catch (IOException e
) {
91 throw new ArgeoException("Cannot open dialog", e
);
96 // DefaultLoginDialog dialog = new DefaultLoginDialog();
97 // dialog.handle(callbacks);