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
.security
.ui
.dialogs
.DefaultLoginDialog
;
26 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
27 import org
.eclipse
.swt
.widgets
.Display
;
28 import org
.eclipse
.ui
.plugin
.AbstractUIPlugin
;
29 import org
.osgi
.framework
.BundleContext
;
30 import org
.osgi
.framework
.ServiceRegistration
;
33 * The activator class controls the plug-in life cycle
35 public class SecurityUiPlugin
extends AbstractUIPlugin
{
38 public static final String PLUGIN_ID
= "org.argeo.security.ui"; //$NON-NLS-1$
40 public final static String CONTEXT_KEYRING
= "KEYRING";
42 private CallbackHandler defaultCallbackHandler
;
43 private ServiceRegistration defaultCallbackHandlerReg
;
45 private static SecurityUiPlugin plugin
;
46 private static BundleContext bundleContext
;
48 public static InheritableThreadLocal
<Display
> display
= new InheritableThreadLocal
<Display
>() {
51 protected Display
initialValue() {
52 return Display
.getCurrent();
56 public void start(BundleContext context
) throws Exception
{
59 bundleContext
= context
;
61 defaultCallbackHandler
= new DefaultCallbackHandler();
62 defaultCallbackHandlerReg
= context
.registerService(
63 CallbackHandler
.class.getName(), defaultCallbackHandler
, null);
66 public void stop(BundleContext context
) throws Exception
{
69 defaultCallbackHandlerReg
.unregister();
74 * Returns the shared instance
76 * @return the shared instance
78 public static SecurityUiPlugin
getDefault() {
82 public static BundleContext
getBundleContext() {
86 public static ImageDescriptor
getImageDescriptor(String path
) {
87 return imageDescriptorFromPlugin(PLUGIN_ID
, path
);
90 protected class DefaultCallbackHandler
implements CallbackHandler
{
91 public void handle(final Callback
[] callbacks
) throws IOException
,
92 UnsupportedCallbackException
{
94 // if (display != null) // RCP
95 Display displayToUse
= display
.get();
96 if (displayToUse
== null)// RCP
97 displayToUse
= Display
.getDefault();
98 displayToUse
.syncExec(new Runnable() {
100 DefaultLoginDialog dialog
= new DefaultLoginDialog(display
101 .get().getActiveShell());
103 dialog
.handle(callbacks
);
104 } catch (IOException e
) {
105 throw new ArgeoException("Cannot open dialog", e
);
110 // DefaultLoginDialog dialog = new DefaultLoginDialog();
111 // dialog.handle(callbacks);