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
;
47 public static InheritableThreadLocal
<Display
> display
= new InheritableThreadLocal
<Display
>() {
50 protected Display
initialValue() {
51 return Display
.getCurrent();
55 public void start(BundleContext context
) throws Exception
{
59 defaultCallbackHandler
= new DefaultCallbackHandler();
60 defaultCallbackHandlerReg
= context
.registerService(
61 CallbackHandler
.class.getName(), defaultCallbackHandler
, null);
64 public void stop(BundleContext context
) throws Exception
{
66 defaultCallbackHandlerReg
.unregister();
71 * Returns the shared instance
73 * @return the shared instance
75 public static SecurityUiPlugin
getDefault() {
79 public static ImageDescriptor
getImageDescriptor(String path
) {
80 return imageDescriptorFromPlugin(PLUGIN_ID
, path
);
83 protected class DefaultCallbackHandler
implements CallbackHandler
{
84 public void handle(final Callback
[] callbacks
) throws IOException
,
85 UnsupportedCallbackException
{
87 // if (display != null) // RCP
88 Display displayToUse
= display
.get();
89 if (displayToUse
== null)// RCP
90 displayToUse
= Display
.getDefault();
91 displayToUse
.syncExec(new Runnable() {
93 DefaultLoginDialog dialog
= new DefaultLoginDialog(display
94 .get().getActiveShell());
96 dialog
.handle(callbacks
);
97 } catch (IOException e
) {
98 throw new ArgeoException("Cannot open dialog", e
);
103 // DefaultLoginDialog dialog = new DefaultLoginDialog();
104 // dialog.handle(callbacks);