From: Bruno Sinou Date: Wed, 14 Sep 2016 15:49:52 +0000 (+0000) Subject: Merge security.ui bundle in the cms.ui.workbench bundle X-Git-Tag: argeo-commons-2.1.46~35 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=c873a0359345503b8e3ca07828bd99d525ec7cc0;p=lgpl%2Fargeo-commons.git Merge security.ui bundle in the cms.ui.workbench bundle git-svn-id: https://svn.argeo.org/commons/trunk@9140 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/org.argeo.cms.ui.workbench/META-INF/spring/keyring.xml b/org.argeo.cms.ui.workbench/META-INF/spring/keyring.xml new file mode 100644 index 000000000..74c4ad6cf --- /dev/null +++ b/org.argeo.cms.ui.workbench/META-INF/spring/keyring.xml @@ -0,0 +1,27 @@ + + + + + + + osgibundle:securityui.properties + + + + + + + + + + + + + + diff --git a/org.argeo.cms.ui.workbench/META-INF/spring/osgi.xml b/org.argeo.cms.ui.workbench/META-INF/spring/osgi.xml index 02a63748f..e884f7838 100644 --- a/org.argeo.cms.ui.workbench/META-INF/spring/osgi.xml +++ b/org.argeo.cms.ui.workbench/META-INF/spring/osgi.xml @@ -8,10 +8,24 @@ http://www.springframework.org/schema/beans/spring-beans-2.5.xsd" osgi:default-timeout="30000"> + + + + filter="(argeo.jcr.repository.alias=home)" /> + + + + + + + + + \ No newline at end of file diff --git a/org.argeo.cms.ui.workbench/META-INF/spring/views.xml b/org.argeo.cms.ui.workbench/META-INF/spring/views.xml new file mode 100644 index 000000000..e5363dcc0 --- /dev/null +++ b/org.argeo.cms.ui.workbench/META-INF/spring/views.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + diff --git a/org.argeo.cms.ui.workbench/bnd.bnd b/org.argeo.cms.ui.workbench/bnd.bnd index 4ace8db0e..2a5b6bf67 100644 --- a/org.argeo.cms.ui.workbench/bnd.bnd +++ b/org.argeo.cms.ui.workbench/bnd.bnd @@ -1,12 +1,12 @@ Bundle-SymbolicName: org.argeo.cms.ui.workbench;singleton:=true -Bundle-Activator: org.argeo.security.ui.admin.SecurityAdminPlugin +Bundle-Activator: org.argeo.security.ui.SecurityUiPlugin Bundle-ActivationPolicy: lazy Require-Bundle: org.eclipse.core.runtime -Import-Package: org.eclipse.core.runtime.jobs,\ -org.argeo.cms.auth,\ +Import-Package: org.argeo.cms.auth,\ org.argeo.eclipse.spring,\ +org.eclipse.core.runtime.jobs,\ org.eclipse.jface.window,\ org.eclipse.swt,\ org.eclipse.swt.widgets,\ @@ -14,3 +14,6 @@ org.eclipse.ui.services,\ org.osgi.framework,\ org.springframework.core,\ * + + +# org.argeo.eclipse.ui.workbench;resolution:=optional,\ diff --git a/org.argeo.cms.ui.workbench/icons/adminLog.gif b/org.argeo.cms.ui.workbench/icons/adminLog.gif new file mode 100644 index 000000000..6ef3bca66 Binary files /dev/null and b/org.argeo.cms.ui.workbench/icons/adminLog.gif differ diff --git a/org.argeo.cms.ui.workbench/icons/home.gif b/org.argeo.cms.ui.workbench/icons/home.gif new file mode 100644 index 000000000..fd0c66950 Binary files /dev/null and b/org.argeo.cms.ui.workbench/icons/home.gif differ diff --git a/org.argeo.cms.ui.workbench/icons/log.gif b/org.argeo.cms.ui.workbench/icons/log.gif new file mode 100644 index 000000000..e3ecc5535 Binary files /dev/null and b/org.argeo.cms.ui.workbench/icons/log.gif differ diff --git a/org.argeo.cms.ui.workbench/icons/maintenance.gif b/org.argeo.cms.ui.workbench/icons/maintenance.gif new file mode 100644 index 000000000..e5690ecb1 Binary files /dev/null and b/org.argeo.cms.ui.workbench/icons/maintenance.gif differ diff --git a/org.argeo.cms.ui.workbench/icons/password.gif b/org.argeo.cms.ui.workbench/icons/password.gif new file mode 100644 index 000000000..a6b251fc8 Binary files /dev/null and b/org.argeo.cms.ui.workbench/icons/password.gif differ diff --git a/org.argeo.cms.ui.workbench/plugin.xml b/org.argeo.cms.ui.workbench/plugin.xml index 2cf0ba210..2636818eb 100644 --- a/org.argeo.cms.ui.workbench/plugin.xml +++ b/org.argeo.cms.ui.workbench/plugin.xml @@ -6,28 +6,65 @@ + + + + + + + + + + + + + + @@ -35,14 +72,14 @@ point="org.eclipse.ui.editors"> @@ -53,34 +90,34 @@ point="org.eclipse.ui.commands"> @@ -101,30 +138,30 @@ + locationURI="toolbar:org.argeo.cms.ui.workbench.rap.userToolbar?after=org.eclipse.ui.file.saveAll"> - + - + @@ -133,27 +170,27 @@ + locationURI="toolbar:org.argeo.cms.ui.workbench.usersView"> @@ -162,21 +199,21 @@ + locationURI="toolbar:org.argeo.cms.ui.workbench.groupsView"> @@ -184,9 +221,9 @@ - + + + + @@ -212,15 +256,113 @@ point="org.eclipse.ui.activities"> + pattern="org.argeo.cms.ui.workbench/org.argeo.cms.ui.workbench.adminSecurityPerspective"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.argeo.cms.ui.workbench/pom.xml b/org.argeo.cms.ui.workbench/pom.xml index ead8e2e84..2dccd6a3f 100644 --- a/org.argeo.cms.ui.workbench/pom.xml +++ b/org.argeo.cms.ui.workbench/pom.xml @@ -16,16 +16,21 @@ org.argeo.cms 2.1.46-SNAPSHOT - + org.argeo.commons - org.argeo.util + org.argeo.eclipse.ui.workbench 2.1.46-SNAPSHOT org.argeo.commons - org.argeo.security.ui + org.argeo.util 2.1.46-SNAPSHOT + + + + + org.argeo.commons org.argeo.enterprise diff --git a/org.argeo.cms.ui.workbench/securityui.properties b/org.argeo.cms.ui.workbench/securityui.properties new file mode 100644 index 000000000..0228d47ee --- /dev/null +++ b/org.argeo.cms.ui.workbench/securityui.properties @@ -0,0 +1 @@ +argeo.keyring.secreteKeyLength=256 \ No newline at end of file diff --git a/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/MaintenancePerspective.java b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/MaintenancePerspective.java new file mode 100644 index 000000000..86307abd2 --- /dev/null +++ b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/MaintenancePerspective.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.security.ui; + +import org.argeo.security.ui.views.AdminLogView; +import org.argeo.security.ui.views.UserProfile; +import org.eclipse.ui.IFolderLayout; +import org.eclipse.ui.IPageLayout; +import org.eclipse.ui.IPerspectiveFactory; + +/** Home perspective for the current user */ +public class MaintenancePerspective implements IPerspectiveFactory { + public final static String ID = SecurityUiPlugin.PLUGIN_ID + + ".adminMaintenancePerspective"; + + public void createInitialLayout(IPageLayout layout) { + String editorArea = layout.getEditorArea(); + layout.setEditorAreaVisible(true); + layout.setFixed(false); + + IFolderLayout bottom = layout.createFolder("bottom", + IPageLayout.BOTTOM, 0.50f, editorArea); + bottom.addView(AdminLogView.ID); + + IFolderLayout left = layout.createFolder("left", IPageLayout.LEFT, + 0.30f, editorArea); + left.addView(UserProfile.ID); + // left.addView(RolesView.ID); + + } + +} diff --git a/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/PrivilegedJob.java b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/PrivilegedJob.java new file mode 100644 index 000000000..3a9ade427 --- /dev/null +++ b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/PrivilegedJob.java @@ -0,0 +1,49 @@ +package org.argeo.security.ui; + +import java.security.AccessControlContext; +import java.security.AccessController; +import java.security.PrivilegedAction; + +import javax.security.auth.Subject; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.jobs.Job; + +/** + * Propagate authentication to an eclipse job. Typically to execute a privileged + * action outside the UI thread + */ +public abstract class PrivilegedJob extends Job { + private final Subject subject; + + public PrivilegedJob(String jobName) { + this(jobName, AccessController.getContext()); + } + + public PrivilegedJob(String jobName, + AccessControlContext accessControlContext) { + super(jobName); + subject = Subject.getSubject(accessControlContext); + + // Must be called *before* the job is scheduled, + // it is required for the progress window to appear + setUser(true); + } + + @Override + protected IStatus run(final IProgressMonitor progressMonitor) { + PrivilegedAction privilegedAction = new PrivilegedAction() { + public IStatus run() { + return doRun(progressMonitor); + } + }; + return Subject.doAs(subject, privilegedAction); + } + + /** + * Implement here what should be executed with default context + * authentication + */ + protected abstract IStatus doRun(IProgressMonitor progressMonitor); +} \ No newline at end of file diff --git a/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/RolesSourceProvider.java b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/RolesSourceProvider.java new file mode 100644 index 000000000..42e6f10e7 --- /dev/null +++ b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/RolesSourceProvider.java @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.security.ui; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import org.argeo.cms.auth.CurrentUser; +import org.eclipse.ui.AbstractSourceProvider; + +/** + * Provides the roles of the current user as a variable to be used for activity + * binding + */ +public class RolesSourceProvider extends AbstractSourceProvider { + public final static String ROLES_VARIABLE = "roles"; + private final static String[] PROVIDED_SOURCE_NAMES = new String[] { ROLES_VARIABLE }; + + public Map> getCurrentState() { + Map> stateMap = new HashMap>(); + stateMap.put(ROLES_VARIABLE, CurrentUser.roles()); + return stateMap; + } + + public String[] getProvidedSourceNames() { + return PROVIDED_SOURCE_NAMES; + } + + public void updateRoles() { + fireSourceChanged(0, getCurrentState()); + } + + public void dispose() { + } +} \ No newline at end of file diff --git a/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/SecurityUiPlugin.java b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/SecurityUiPlugin.java new file mode 100644 index 000000000..617fcec63 --- /dev/null +++ b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/SecurityUiPlugin.java @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.security.ui; + +import java.io.IOException; + +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.callback.UnsupportedCallbackException; + +import org.argeo.cms.CmsException; +import org.argeo.cms.widgets.auth.DefaultLoginDialog; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; + +/** + * The activator class controls the plug-in life cycle + */ +public class SecurityUiPlugin extends AbstractUIPlugin { + private static BundleContext bundleContext; + public static InheritableThreadLocal display = new InheritableThreadLocal() { + + @Override + protected Display initialValue() { + return Display.getCurrent(); + } + }; + + // The plug-in ID + // public final static String PLUGIN_ID = "org.argeo.security.ui"; //$NON-NLS-1$ + public final static String PLUGIN_ID = "org.argeo.cms.ui.workbench"; //$NON-NLS-1$ + + final static String CONTEXT_KEYRING = "KEYRING"; + + private CallbackHandler defaultCallbackHandler; + private ServiceRegistration defaultCallbackHandlerReg; + + public void start(BundleContext context) throws Exception { + bundleContext = context; + + defaultCallbackHandler = new DefaultCallbackHandler(); + defaultCallbackHandlerReg = context.registerService( + CallbackHandler.class, defaultCallbackHandler, null); + } + + public void stop(BundleContext context) throws Exception { + bundleContext = null; + defaultCallbackHandlerReg.unregister(); + } + + public static BundleContext getBundleContext() { + return bundleContext; + } + + protected class DefaultCallbackHandler implements CallbackHandler { + public void handle(final Callback[] callbacks) throws IOException, + UnsupportedCallbackException { + + // if (display != null) // RCP + Display displayToUse = display.get(); + if (displayToUse == null)// RCP + displayToUse = Display.getDefault(); + displayToUse.syncExec(new Runnable() { + public void run() { + DefaultLoginDialog dialog = new DefaultLoginDialog(display + .get().getActiveShell()); + try { + dialog.handle(callbacks); + } catch (IOException e) { + throw new CmsException("Cannot open dialog", e); + } + } + }); + // else {// RAP + // DefaultLoginDialog dialog = new DefaultLoginDialog(); + // dialog.handle(callbacks); + // } + } + + } + + public static ImageDescriptor getImageDescriptor(String path) { + return imageDescriptorFromPlugin(PLUGIN_ID, path); + } +} diff --git a/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/UserHomePerspective.java b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/UserHomePerspective.java new file mode 100644 index 000000000..119549ffd --- /dev/null +++ b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/UserHomePerspective.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.security.ui; + +import org.argeo.security.ui.views.LogView; +import org.argeo.security.ui.views.UserProfile; +import org.eclipse.ui.IFolderLayout; +import org.eclipse.ui.IPageLayout; +import org.eclipse.ui.IPerspectiveFactory; + +/** Home perspective for the current user */ +public class UserHomePerspective implements IPerspectiveFactory { + public final static String ID = SecurityUiPlugin.PLUGIN_ID + + ".userHomePerspective"; + + public void createInitialLayout(IPageLayout layout) { + String editorArea = layout.getEditorArea(); + layout.setEditorAreaVisible(true); + layout.setFixed(false); + + IFolderLayout left = layout.createFolder("left", IPageLayout.LEFT, + 0.30f, editorArea); + left.addView(UserProfile.ID); + left.addView(LogView.ID); + } + +} diff --git a/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/SecurityAdminImages.java b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/SecurityAdminImages.java index f15f8ec9a..6cccb08a8 100644 --- a/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/SecurityAdminImages.java +++ b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/SecurityAdminImages.java @@ -26,6 +26,7 @@ */ package org.argeo.security.ui.admin; +import org.argeo.security.ui.SecurityUiPlugin; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.graphics.Image; @@ -33,15 +34,15 @@ import org.eclipse.swt.graphics.Image; public class SecurityAdminImages { private final static String PREFIX = "icons/"; - public final static ImageDescriptor ICON_REMOVE_DESC = SecurityAdminPlugin + public final static ImageDescriptor ICON_REMOVE_DESC = SecurityUiPlugin .getImageDescriptor(PREFIX + "remove.gif"); - public final static ImageDescriptor ICON_USER_DESC = SecurityAdminPlugin + public final static ImageDescriptor ICON_USER_DESC = SecurityUiPlugin .getImageDescriptor(PREFIX + "user.gif"); - + public final static Image ICON_USER = ICON_USER_DESC.createImage(); - public final static Image ICON_GROUP = SecurityAdminPlugin - .getImageDescriptor(PREFIX + "users.gif").createImage(); - public final static Image ICON_ROLE = SecurityAdminPlugin - .getImageDescriptor(PREFIX + "role.gif").createImage(); + public final static Image ICON_GROUP = SecurityUiPlugin.getImageDescriptor( + PREFIX + "users.gif").createImage(); + public final static Image ICON_ROLE = SecurityUiPlugin.getImageDescriptor( + PREFIX + "role.gif").createImage(); } diff --git a/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/SecurityAdminPlugin.java b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/SecurityAdminPlugin.java index f9c0ad9af..7222f9234 100644 --- a/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/SecurityAdminPlugin.java +++ b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/SecurityAdminPlugin.java @@ -15,40 +15,38 @@ */ package org.argeo.security.ui.admin; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.ui.plugin.AbstractUIPlugin; -import org.osgi.framework.BundleContext; - -public class SecurityAdminPlugin extends AbstractUIPlugin { - public static final String PLUGIN_ID = "org.argeo.security.ui.admin"; //$NON-NLS-1$ - private static SecurityAdminPlugin plugin; - private static BundleContext bundleContext; - - public SecurityAdminPlugin() { - } - - public void start(BundleContext context) throws Exception { - super.start(context); - plugin = this; - bundleContext = context; - } - - public void stop(BundleContext context) throws Exception { - plugin = null; - bundleContext = null; - super.stop(context); - } - - public static SecurityAdminPlugin getDefault() { - return plugin; - } - - public static BundleContext getBundleContext() { - return bundleContext; - } - - public static ImageDescriptor getImageDescriptor(String path) { - return imageDescriptorFromPlugin(PLUGIN_ID, path); - } - -} +public class SecurityAdminPlugin{} + +// public class SecurityAdminPlugin extends AbstractUIPlugin { +// public static final String PLUGIN_ID = "org.argeo.security.ui.admin"; //$NON-NLS-1$ +// private static SecurityAdminPlugin plugin; +// private static BundleContext bundleContext; +// +// public SecurityAdminPlugin() { +// } +// +// public void start(BundleContext context) throws Exception { +// super.start(context); +// plugin = this; +// bundleContext = context; +// } +// +// public void stop(BundleContext context) throws Exception { +// plugin = null; +// bundleContext = null; +// super.stop(context); +// } +// +// public static SecurityAdminPlugin getDefault() { +// return plugin; +// } +// +// public static BundleContext getBundleContext() { +// return bundleContext; +// } +// +// public static ImageDescriptor getImageDescriptor(String path) { +// return imageDescriptorFromPlugin(PLUGIN_ID, path); +// } +// +// } diff --git a/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/commands/DeleteGroups.java b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/commands/DeleteGroups.java index df5d430ab..5a9b033bb 100644 --- a/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/commands/DeleteGroups.java +++ b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/commands/DeleteGroups.java @@ -20,7 +20,7 @@ import java.util.Iterator; import java.util.List; import org.argeo.cms.util.useradmin.UserAdminUtils; -import org.argeo.security.ui.admin.SecurityAdminPlugin; +import org.argeo.security.ui.SecurityUiPlugin; import org.argeo.security.ui.admin.internal.UserAdminWrapper; import org.argeo.security.ui.admin.internal.parts.UserEditorInput; import org.eclipse.core.commands.AbstractHandler; @@ -38,7 +38,7 @@ import org.osgi.service.useradmin.UserAdminEvent; /** Delete the selected groups */ public class DeleteGroups extends AbstractHandler { - public final static String ID = SecurityAdminPlugin.PLUGIN_ID + public final static String ID = SecurityUiPlugin.PLUGIN_ID + ".deleteGroups"; /* DEPENDENCY INJECTION */ diff --git a/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/commands/DeleteUsers.java b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/commands/DeleteUsers.java index e583bef53..3618be187 100644 --- a/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/commands/DeleteUsers.java +++ b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/commands/DeleteUsers.java @@ -20,7 +20,7 @@ import java.util.Iterator; import java.util.List; import org.argeo.cms.util.useradmin.UserAdminUtils; -import org.argeo.security.ui.admin.SecurityAdminPlugin; +import org.argeo.security.ui.SecurityUiPlugin; import org.argeo.security.ui.admin.internal.UserAdminWrapper; import org.argeo.security.ui.admin.internal.parts.UserEditorInput; import org.eclipse.core.commands.AbstractHandler; @@ -38,8 +38,7 @@ import org.osgi.service.useradmin.UserAdminEvent; /** Delete the selected users */ public class DeleteUsers extends AbstractHandler { - public final static String ID = SecurityAdminPlugin.PLUGIN_ID - + ".deleteUsers"; + public final static String ID = SecurityUiPlugin.PLUGIN_ID + ".deleteUsers"; /* DEPENDENCY INJECTION */ private UserAdminWrapper userAdminWrapper; diff --git a/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/commands/NewGroup.java b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/commands/NewGroup.java index 75b9b0b33..755f05bf3 100644 --- a/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/commands/NewGroup.java +++ b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/commands/NewGroup.java @@ -24,7 +24,7 @@ import org.argeo.eclipse.ui.dialogs.ErrorFeedback; import org.argeo.jcr.ArgeoNames; import org.argeo.osgi.useradmin.LdifName; import org.argeo.osgi.useradmin.UserAdminConf; -import org.argeo.security.ui.admin.SecurityAdminPlugin; +import org.argeo.security.ui.SecurityUiPlugin; import org.argeo.security.ui.admin.internal.UserAdminWrapper; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; @@ -48,7 +48,7 @@ import org.osgi.service.useradmin.UserAdminEvent; /** Create a new group */ public class NewGroup extends AbstractHandler { - public final static String ID = SecurityAdminPlugin.PLUGIN_ID + ".newGroup"; + public final static String ID = SecurityUiPlugin.PLUGIN_ID + ".newGroup"; /* DEPENDENCY INJECTION */ private UserAdminWrapper userAdminWrapper; diff --git a/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/commands/NewUser.java b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/commands/NewUser.java index c04c83562..8289d59bf 100644 --- a/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/commands/NewUser.java +++ b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/commands/NewUser.java @@ -30,7 +30,7 @@ import org.argeo.eclipse.ui.dialogs.ErrorFeedback; import org.argeo.jcr.ArgeoNames; import org.argeo.osgi.useradmin.LdifName; import org.argeo.osgi.useradmin.UserAdminConf; -import org.argeo.security.ui.admin.SecurityAdminPlugin; +import org.argeo.security.ui.SecurityUiPlugin; import org.argeo.security.ui.admin.internal.UserAdminWrapper; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; @@ -62,7 +62,7 @@ public class NewUser extends AbstractHandler { */ public final static String EMAIL_PATTERN = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"; // private final static Log log = LogFactory.getLog(NewUser.class); - public final static String ID = SecurityAdminPlugin.PLUGIN_ID + ".newUser"; + public final static String ID = SecurityUiPlugin.PLUGIN_ID + ".newUser"; /* DEPENDENCY INJECTION */ private UserAdminWrapper userAdminWrapper; diff --git a/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/commands/SaveArgeoUser.java b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/commands/SaveArgeoUser.java index 61d8a7daf..c2c78f90c 100644 --- a/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/commands/SaveArgeoUser.java +++ b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/commands/SaveArgeoUser.java @@ -15,7 +15,7 @@ */ package org.argeo.security.ui.admin.internal.commands; -import org.argeo.security.ui.admin.SecurityAdminPlugin; +import org.argeo.security.ui.SecurityUiPlugin; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; @@ -27,7 +27,7 @@ import org.eclipse.ui.handlers.HandlerUtil; /** Save the currently edited Argeo user. */ public class SaveArgeoUser extends AbstractHandler { - public final static String ID = SecurityAdminPlugin.PLUGIN_ID + public final static String ID = SecurityUiPlugin.PLUGIN_ID + ".saveArgeoUser"; public Object execute(ExecutionEvent event) throws ExecutionException { diff --git a/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/commands/UserTransactionHandler.java b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/commands/UserTransactionHandler.java index 236584ca3..6f04635af 100644 --- a/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/commands/UserTransactionHandler.java +++ b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/commands/UserTransactionHandler.java @@ -19,7 +19,7 @@ import javax.transaction.Status; import javax.transaction.UserTransaction; import org.argeo.cms.CmsException; -import org.argeo.security.ui.admin.SecurityAdminPlugin; +import org.argeo.security.ui.SecurityUiPlugin; import org.argeo.security.ui.admin.internal.UiAdminUtils; import org.argeo.security.ui.admin.internal.UserAdminWrapper; import org.eclipse.core.commands.AbstractHandler; @@ -29,7 +29,7 @@ import org.osgi.service.useradmin.UserAdminEvent; /** Manage the transaction that is bound to the current perspective */ public class UserTransactionHandler extends AbstractHandler { - public final static String ID = SecurityAdminPlugin.PLUGIN_ID + public final static String ID = SecurityUiPlugin.PLUGIN_ID + ".userTransactionHandler"; public final static String PARAM_COMMAND_ID = "param.commandId"; diff --git a/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/parts/GroupsView.java b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/parts/GroupsView.java index 82f4e1bdd..7225ef865 100644 --- a/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/parts/GroupsView.java +++ b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/parts/GroupsView.java @@ -28,7 +28,7 @@ import org.argeo.eclipse.ui.EclipseUiUtils; import org.argeo.eclipse.ui.parts.LdifUsersTable; import org.argeo.jcr.ArgeoNames; import org.argeo.osgi.useradmin.LdifName; -import org.argeo.security.ui.admin.SecurityAdminPlugin; +import org.argeo.security.ui.SecurityUiPlugin; import org.argeo.security.ui.admin.internal.UiUserAdminListener; import org.argeo.security.ui.admin.internal.UserAdminWrapper; import org.argeo.security.ui.admin.internal.providers.CommonNameLP; @@ -58,8 +58,7 @@ import org.osgi.service.useradmin.UserAdminListener; /** List all groups with filter */ public class GroupsView extends ViewPart implements ArgeoNames { private final static Log log = LogFactory.getLog(GroupsView.class); - public final static String ID = SecurityAdminPlugin.PLUGIN_ID - + ".groupsView"; + public final static String ID = SecurityUiPlugin.PLUGIN_ID + ".groupsView"; /* DEPENDENCY INJECTION */ private UserAdminWrapper userAdminWrapper; diff --git a/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/parts/UserEditor.java b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/parts/UserEditor.java index 6c0731d01..d6cae1a1a 100644 --- a/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/parts/UserEditor.java +++ b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/parts/UserEditor.java @@ -21,7 +21,7 @@ import java.util.List; import org.argeo.cms.CmsException; import org.argeo.cms.util.useradmin.UserAdminUtils; import org.argeo.osgi.useradmin.LdifName; -import org.argeo.security.ui.admin.SecurityAdminPlugin; +import org.argeo.security.ui.SecurityUiPlugin; import org.argeo.security.ui.admin.internal.UiUserAdminListener; import org.argeo.security.ui.admin.internal.UserAdminWrapper; import org.eclipse.core.runtime.IProgressMonitor; @@ -44,9 +44,9 @@ import org.osgi.service.useradmin.UserAdminEvent; public class UserEditor extends FormEditor { private static final long serialVersionUID = 8357851520380820241L; - public final static String USER_EDITOR_ID = SecurityAdminPlugin.PLUGIN_ID + public final static String USER_EDITOR_ID = SecurityUiPlugin.PLUGIN_ID + ".userEditor"; - public final static String GROUP_EDITOR_ID = SecurityAdminPlugin.PLUGIN_ID + public final static String GROUP_EDITOR_ID = SecurityUiPlugin.PLUGIN_ID + ".groupEditor"; /* DEPENDENCY INJECTION */ diff --git a/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/parts/UsersView.java b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/parts/UsersView.java index a397432a8..86fb439ff 100644 --- a/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/parts/UsersView.java +++ b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/parts/UsersView.java @@ -26,7 +26,7 @@ import org.argeo.eclipse.ui.EclipseUiUtils; import org.argeo.eclipse.ui.parts.LdifUsersTable; import org.argeo.jcr.ArgeoNames; import org.argeo.osgi.useradmin.LdifName; -import org.argeo.security.ui.admin.SecurityAdminPlugin; +import org.argeo.security.ui.SecurityUiPlugin; import org.argeo.security.ui.admin.internal.UiUserAdminListener; import org.argeo.security.ui.admin.internal.UserAdminWrapper; import org.argeo.security.ui.admin.internal.providers.CommonNameLP; @@ -53,8 +53,7 @@ import org.osgi.service.useradmin.UserAdminListener; public class UsersView extends ViewPart implements ArgeoNames { // private final static Log log = LogFactory.getLog(UsersView.class); - public final static String ID = SecurityAdminPlugin.PLUGIN_ID - + ".usersView"; + public final static String ID = SecurityUiPlugin.PLUGIN_ID + ".usersView"; /* DEPENDENCY INJECTION */ private UserAdminWrapper userAdminWrapper; diff --git a/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/providers/UserTransactionProvider.java b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/providers/UserTransactionProvider.java index 4ba304bb5..d4a53fcff 100644 --- a/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/providers/UserTransactionProvider.java +++ b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/admin/internal/providers/UserTransactionProvider.java @@ -9,7 +9,7 @@ import javax.transaction.UserTransaction; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.argeo.cms.CmsException; -import org.argeo.security.ui.admin.SecurityAdminPlugin; +import org.argeo.security.ui.SecurityUiPlugin; import org.eclipse.ui.AbstractSourceProvider; import org.eclipse.ui.ISources; @@ -18,7 +18,7 @@ public class UserTransactionProvider extends AbstractSourceProvider { private final static Log log = LogFactory .getLog(UserTransactionProvider.class); - public final static String TRANSACTION_STATE = SecurityAdminPlugin.PLUGIN_ID + public final static String TRANSACTION_STATE = SecurityUiPlugin.PLUGIN_ID + ".userTransactionState"; public final static String STATUS_ACTIVE = "status.active"; public final static String STATUS_NO_TRANSACTION = "status.noTransaction"; @@ -28,13 +28,13 @@ public class UserTransactionProvider extends AbstractSourceProvider { @Override public String[] getProvidedSourceNames() { - return new String[] { TRANSACTION_STATE}; + return new String[] { TRANSACTION_STATE }; } @Override public Map getCurrentState() { Map currentState = new HashMap(1); - currentState.put(TRANSACTION_STATE, getInternalCurrentState()); + currentState.put(TRANSACTION_STATE, getInternalCurrentState()); return currentState; } diff --git a/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/commands/OpenChangePasswordDialog.java b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/commands/OpenChangePasswordDialog.java new file mode 100644 index 000000000..817354f70 --- /dev/null +++ b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/commands/OpenChangePasswordDialog.java @@ -0,0 +1,171 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.security.ui.commands; + +import static org.argeo.cms.CmsMsg.changePassword; +import static org.argeo.cms.CmsMsg.currentPassword; +import static org.argeo.cms.CmsMsg.newPassword; +import static org.argeo.cms.CmsMsg.passwordChanged; +import static org.argeo.cms.CmsMsg.repeatNewPassword; +import static org.eclipse.jface.dialogs.IMessageProvider.INFORMATION; + +import java.security.AccessController; + +import javax.naming.InvalidNameException; +import javax.naming.ldap.LdapName; +import javax.security.auth.Subject; +import javax.security.auth.x500.X500Principal; +import javax.transaction.UserTransaction; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.argeo.cms.CmsException; +import org.argeo.eclipse.ui.dialogs.ErrorFeedback; +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.dialogs.TitleAreaDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.handlers.HandlerUtil; +import org.osgi.service.useradmin.User; +import org.osgi.service.useradmin.UserAdmin; + +/** Opens the change password dialog. */ +public class OpenChangePasswordDialog extends AbstractHandler { + private final static Log log = LogFactory + .getLog(OpenChangePasswordDialog.class); + private UserAdmin userAdmin; + private UserTransaction userTransaction; + + public Object execute(ExecutionEvent event) throws ExecutionException { + ChangePasswordDialog dialog = new ChangePasswordDialog( + HandlerUtil.getActiveShell(event), userAdmin); + if (dialog.open() == Dialog.OK) { + MessageDialog.openInformation(HandlerUtil.getActiveShell(event), + passwordChanged.lead(), passwordChanged.lead()); + } + return null; + } + + @SuppressWarnings("unchecked") + protected void changePassword(char[] oldPassword, char[] newPassword) { + Subject subject = Subject.getSubject(AccessController.getContext()); + String name = subject.getPrincipals(X500Principal.class).iterator() + .next().toString(); + LdapName dn; + try { + dn = new LdapName(name); + } catch (InvalidNameException e) { + throw new CmsException("Invalid user dn " + name, e); + } + User user = (User) userAdmin.getRole(dn.toString()); + if (!user.hasCredential(null, oldPassword)) + throw new CmsException("Invalid password"); + if (newPassword.equals("")) + throw new CmsException("New password empty"); + try { + userTransaction.begin(); + user.getCredentials().put(null, newPassword); + userTransaction.commit(); + } catch (Exception e) { + try { + userTransaction.rollback(); + } catch (Exception e1) { + log.error("Could not roll back", e1); + } + if (e instanceof RuntimeException) + throw (RuntimeException) e; + else + throw new CmsException("Cannot change password", e); + } + } + + public void setUserAdmin(UserAdmin userDetailsManager) { + this.userAdmin = userDetailsManager; + } + + public void setUserTransaction(UserTransaction userTransaction) { + this.userTransaction = userTransaction; + } + + class ChangePasswordDialog extends TitleAreaDialog { + private static final long serialVersionUID = -6963970583882720962L; + private Text oldPassword, newPassword1, newPassword2; + + public ChangePasswordDialog(Shell parentShell, UserAdmin securityService) { + super(parentShell); + } + + protected Point getInitialSize() { + return new Point(400, 450); + } + + protected Control createDialogArea(Composite parent) { + Composite dialogarea = (Composite) super.createDialogArea(parent); + dialogarea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, + true)); + Composite composite = new Composite(dialogarea, SWT.NONE); + composite.setLayout(new GridLayout(2, false)); + composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, + false)); + oldPassword = createLP(composite, currentPassword.lead()); + newPassword1 = createLP(composite, newPassword.lead()); + newPassword2 = createLP(composite, repeatNewPassword.lead()); + + setMessage(changePassword.lead(), INFORMATION); + parent.pack(); + return composite; + } + + @Override + protected void okPressed() { + try { + if (!newPassword1.getText().equals(newPassword2.getText())) + throw new CmsException("New passwords are different"); + changePassword(oldPassword.getTextChars(), + newPassword1.getTextChars()); + close(); + } catch (Exception e) { + ErrorFeedback.show("Cannot change password", e); + } + } + + /** Creates label and password. */ + protected Text createLP(Composite parent, String label) { + new Label(parent, SWT.NONE).setText(label); + Text text = new Text(parent, SWT.SINGLE | SWT.LEAD | SWT.PASSWORD + | SWT.BORDER); + text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + return text; + } + + protected void configureShell(Shell shell) { + super.configureShell(shell); + shell.setText(changePassword.lead()); + } + + } +} diff --git a/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/commands/OpenHomePerspective.java b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/commands/OpenHomePerspective.java new file mode 100644 index 000000000..f6aa0d19e --- /dev/null +++ b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/commands/OpenHomePerspective.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.security.ui.commands; + +import org.argeo.eclipse.ui.dialogs.ErrorFeedback; +import org.argeo.security.ui.UserHomePerspective; +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.ui.WorkbenchException; +import org.eclipse.ui.handlers.HandlerUtil; + +/** Default action of the user menu */ +public class OpenHomePerspective extends AbstractHandler { + + public Object execute(ExecutionEvent event) throws ExecutionException { + try { + HandlerUtil.getActiveSite(event).getWorkbenchWindow() + .openPage(UserHomePerspective.ID, null); + } catch (WorkbenchException e) { + ErrorFeedback.show("Cannot open home perspective", e); + } + return null; + } +} diff --git a/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/views/AdminLogView.java b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/views/AdminLogView.java new file mode 100644 index 000000000..61efc8cb6 --- /dev/null +++ b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/views/AdminLogView.java @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.security.ui.views; + +import java.util.ArrayList; + +import org.argeo.node.ArgeoLogger; +import org.argeo.security.ui.SecurityUiPlugin; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Table; +import org.eclipse.ui.part.ViewPart; + +/** + * Display log lines for all users with a virtual table. + */ +public class AdminLogView extends ViewPart { + public static String ID = SecurityUiPlugin.PLUGIN_ID + ".adminLogView"; + + private TableViewer viewer; + + private LogContentProvider logContentProvider; + private ArgeoLogger argeoLogger; + + @Override + public void createPartControl(Composite parent) { + // FIXME doesn't return a monospace font in RAP + Font font = JFaceResources.getTextFont(); + Table table = new Table(parent, SWT.VIRTUAL | SWT.MULTI | SWT.H_SCROLL + | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER); + table.setFont(font); + + viewer = new TableViewer(table); + viewer.setLabelProvider(new LabelProvider()); + logContentProvider = new LogContentProvider(viewer) { + private static final long serialVersionUID = -3401776448301180724L; + + @Override + protected StringBuffer prefix(String username, Long timestamp, + String level, String category, String thread) { + return super + .prefix(username, timestamp, level, category, thread) + .append(norm(level, 5)) + .append(' ') + .append(norm(username != null ? username + : "", 16)).append(' '); + } + }; + viewer.setContentProvider(logContentProvider); + // viewer.setUseHashlookup(true); + viewer.setInput(new ArrayList()); + + if (argeoLogger != null) + argeoLogger.registerForAll(logContentProvider, 1000, true); + } + + @Override + public void setFocus() { + viewer.getTable().setFocus(); + } + + @Override + public void dispose() { + if (argeoLogger != null) + argeoLogger.unregisterForAll(logContentProvider); + } + + public void setArgeoLogger(ArgeoLogger argeoLogger) { + this.argeoLogger = argeoLogger; + } + +} diff --git a/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/views/LogContentProvider.java b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/views/LogContentProvider.java new file mode 100644 index 000000000..5b12f439a --- /dev/null +++ b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/views/LogContentProvider.java @@ -0,0 +1,189 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.security.ui.views; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.Date; +import java.util.LinkedList; +import java.util.List; + +import org.argeo.node.ArgeoLogListener; +import org.eclipse.jface.viewers.ILazyContentProvider; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableItem; + +/** A content provider maintaining an array of lines */ +class LogContentProvider implements ILazyContentProvider, ArgeoLogListener { + private static final long serialVersionUID = -2084872367738339721L; + + private DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); + + private final Long start; + /** current - start = line number. first line is number '1' */ + private Long current; + + // TODO make it configurable + private final Integer maxLineBufferSize = 10 * 1000; + + private final TableViewer viewer; + private LinkedList lines; + + public LogContentProvider(TableViewer viewer) { + this.viewer = viewer; + start = System.currentTimeMillis(); + lines = new LinkedList(); + current = start; + } + + public synchronized void dispose() { + lines.clear(); + lines = null; + } + + @SuppressWarnings("unchecked") + public synchronized void inputChanged(Viewer viewer, Object oldInput, + Object newInput) { + List lin = (List) newInput; + if (lin == null) + return; + for (String line : lin) { + addLine(line); + } + this.viewer.setItemCount(lines.size()); + } + + public void updateElement(int index) { + viewer.replace(lines.get(index), index); + } + + public synchronized void appendLog(String username, Long timestamp, + String level, String category, String thread, Object msg, + String[] exception) { + // check if valid + if (lines == null) + return; + + String message = msg.toString(); + int count = 0; + String prefix = prefix(username, timestamp, level, category, thread) + .toString(); + // String suffix = suffix(username, timestamp, level, category, thread); + for (String line : message.split("\n")) { + addLine(count == 0 ? prefix + line : line); + count++; + } + + if (exception != null) { + for (String ste : exception) { + addLine(ste); + } + } + + viewer.getTable().getDisplay().asyncExec(new Runnable() { + public void run() { + if (lines == null) + return; + viewer.setItemCount(lines.size()); + // doesn't work with syncExec + scrollToLastLine(); + } + }); + } + + protected StringBuffer prefix(String username, Long timestamp, + String level, String category, String thread) { + StringBuffer buf = new StringBuffer(""); + buf.append(dateFormat.format(new Date(timestamp))).append(" "); + // buf.append(level).append(" "); + return buf; + } + + /** Normalize string to the given size */ + protected String norm(String str, Integer size) { + int length = str.length(); + if (length == size) + return str; + else if (length > size) + return str.substring(0, size); + else { + char[] arr = new char[size - length]; + Arrays.fill(arr, ' '); + return str + new String(arr); + } + } + + // protected String suffix(String username, Long timestamp, String level, + // String category, String thread) { + // return ""; + // } + + /** Scroll to the last line */ + protected synchronized void scrollToLastLine() { + // we try to show last line with two methods + // viewer.reveal(lines.peekLast()); + + Table table = viewer.getTable(); + TableItem ti = table.getItem(table.getItemCount() - 1); + table.showItem(ti); + } + + protected synchronized LogLine addLine(String line) { + // check for maximal size and purge if necessary + while (lines.size() >= maxLineBufferSize) { + for (int i = 0; i < maxLineBufferSize / 10; i++) { + lines.poll(); + } + } + + current++; + LogLine logLine = new LogLine(current, line); + lines.add(logLine); + return logLine; + } + + private class LogLine { + private Long linenumber; + private String message; + + public LogLine(Long linenumber, String message) { + this.linenumber = linenumber; + this.message = message; + } + + @Override + public int hashCode() { + return linenumber.intValue(); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof LogLine) + return ((LogLine) obj).linenumber.equals(linenumber); + else + return false; + } + + @Override + public String toString() { + return message; + } + + } +} \ No newline at end of file diff --git a/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/views/LogView.java b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/views/LogView.java new file mode 100644 index 000000000..f9e197ac0 --- /dev/null +++ b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/views/LogView.java @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.security.ui.views; + +import java.util.ArrayList; + +import org.argeo.node.ArgeoLogListener; +import org.argeo.node.ArgeoLogger; +import org.argeo.security.ui.SecurityUiPlugin; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Table; +import org.eclipse.ui.part.ViewPart; + +/** + * Display log lines with a virtual table. Register and unregisters a + * {@link ArgeoLogListener} via OSGi services. + */ +public class LogView extends ViewPart { + public static String ID = SecurityUiPlugin.PLUGIN_ID + ".logView"; + + private TableViewer viewer; + + private LogContentProvider logContentProvider; + private ArgeoLogger argeoLogger; + + @Override + public void createPartControl(Composite parent) { + Font font = JFaceResources.getTextFont(); + Table table = new Table(parent, SWT.VIRTUAL | SWT.MULTI | SWT.H_SCROLL + | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER); + table.setFont(font); + + viewer = new TableViewer(table); + viewer.setLabelProvider(new LabelProvider()); + logContentProvider = new LogContentProvider(viewer); + viewer.setContentProvider(logContentProvider); + // viewer.setUseHashlookup(true); + viewer.setInput(new ArrayList()); + + if (argeoLogger != null) + argeoLogger.register(logContentProvider, 1000); + } + + @Override + public void setFocus() { + viewer.getTable().setFocus(); + } + + @Override + public void dispose() { + if (argeoLogger != null) + argeoLogger.unregister(logContentProvider); + } + + public void setArgeoLogger(ArgeoLogger argeoLogger) { + this.argeoLogger = argeoLogger; + } + +} diff --git a/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/views/UserProfile.java b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/views/UserProfile.java new file mode 100644 index 000000000..49f5bea5a --- /dev/null +++ b/org.argeo.cms.ui.workbench/src/org/argeo/security/ui/views/UserProfile.java @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.security.ui.views; + +import java.util.TreeSet; + +import org.argeo.cms.auth.CurrentUser; +import org.argeo.eclipse.ui.EclipseUiUtils; +import org.argeo.security.ui.SecurityUiPlugin; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Table; +import org.eclipse.ui.part.ViewPart; + +/** Information about the currently logged in user */ +public class UserProfile extends ViewPart { + public static String ID = SecurityUiPlugin.PLUGIN_ID + ".userProfile"; + + private TableViewer viewer; + + @Override + public void createPartControl(Composite parent) { + parent.setLayout(new GridLayout(2, false)); + + // Authentication authentication = CurrentUser.getAuthentication(); + // EclipseUiUtils.createGridLL(parent, "Name", authentication + // .getPrincipal().toString()); + EclipseUiUtils.createGridLL(parent, "User ID", + CurrentUser.getUsername()); + + // roles table + Table table = new Table(parent, SWT.V_SCROLL | SWT.BORDER); + table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); + table.setLinesVisible(false); + table.setHeaderVisible(false); + viewer = new TableViewer(table); + viewer.setContentProvider(new RolesContentProvider()); + viewer.setLabelProvider(new LabelProvider()); + getViewSite().setSelectionProvider(viewer); + viewer.setInput(getViewSite()); + } + + @Override + public void setFocus() { + viewer.getTable(); + } + + private class RolesContentProvider implements IStructuredContentProvider { + private static final long serialVersionUID = -4576917440167866233L; + + public Object[] getElements(Object inputElement) { + return new TreeSet(CurrentUser.roles()).toArray(); + } + + public void dispose() { + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + + } + +} diff --git a/org.argeo.security.ui/.classpath b/org.argeo.security.ui/.classpath deleted file mode 100644 index 457b11571..000000000 --- a/org.argeo.security.ui/.classpath +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - diff --git a/org.argeo.security.ui/.project b/org.argeo.security.ui/.project deleted file mode 100644 index a052e9a57..000000000 --- a/org.argeo.security.ui/.project +++ /dev/null @@ -1,28 +0,0 @@ - - - org.argeo.security.ui - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.pde.ManifestBuilder - - - - - org.eclipse.pde.SchemaBuilder - - - - - - org.eclipse.pde.PluginNature - org.eclipse.jdt.core.javanature - - diff --git a/org.argeo.security.ui/.settings/org.eclipse.pde.core.prefs b/org.argeo.security.ui/.settings/org.eclipse.pde.core.prefs deleted file mode 100644 index dfa507d81..000000000 --- a/org.argeo.security.ui/.settings/org.eclipse.pde.core.prefs +++ /dev/null @@ -1,3 +0,0 @@ -#Sat Jan 15 18:15:48 CET 2011 -eclipse.preferences.version=1 -resolve.requirebundle=false diff --git a/org.argeo.security.ui/META-INF/spring/commands.xml b/org.argeo.security.ui/META-INF/spring/commands.xml deleted file mode 100644 index 3b2e6ccb0..000000000 --- a/org.argeo.security.ui/META-INF/spring/commands.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - diff --git a/org.argeo.security.ui/META-INF/spring/keyring.xml b/org.argeo.security.ui/META-INF/spring/keyring.xml deleted file mode 100644 index 74c4ad6cf..000000000 --- a/org.argeo.security.ui/META-INF/spring/keyring.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - osgibundle:securityui.properties - - - - - - - - - - - - - - diff --git a/org.argeo.security.ui/META-INF/spring/osgi.xml b/org.argeo.security.ui/META-INF/spring/osgi.xml deleted file mode 100644 index 500efd1df..000000000 --- a/org.argeo.security.ui/META-INF/spring/osgi.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/org.argeo.security.ui/META-INF/spring/views.xml b/org.argeo.security.ui/META-INF/spring/views.xml deleted file mode 100644 index e5363dcc0..000000000 --- a/org.argeo.security.ui/META-INF/spring/views.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - diff --git a/org.argeo.security.ui/bnd.bnd b/org.argeo.security.ui/bnd.bnd deleted file mode 100644 index 66284b153..000000000 --- a/org.argeo.security.ui/bnd.bnd +++ /dev/null @@ -1,11 +0,0 @@ -Bundle-SymbolicName: org.argeo.security.ui;singleton:=true -Bundle-ActivationPolicy: lazy -Bundle-Activator: org.argeo.security.ui.SecurityUiPlugin - -Import-Package: org.argeo.eclipse.spring,\ -org.osgi.framework,\ -org.eclipse.swt,\ -org.eclipse.jface.window,\ -org.apache.log4j;resolution:=optional,\ -org.eclipse.ui;resolution:=optional,\ -* diff --git a/org.argeo.security.ui/build.properties b/org.argeo.security.ui/build.properties deleted file mode 100644 index 30f715358..000000000 --- a/org.argeo.security.ui/build.properties +++ /dev/null @@ -1 +0,0 @@ -source.. = src/ diff --git a/org.argeo.security.ui/icons/adminLog.gif b/org.argeo.security.ui/icons/adminLog.gif deleted file mode 100644 index 6ef3bca66..000000000 Binary files a/org.argeo.security.ui/icons/adminLog.gif and /dev/null differ diff --git a/org.argeo.security.ui/icons/home.gif b/org.argeo.security.ui/icons/home.gif deleted file mode 100644 index fd0c66950..000000000 Binary files a/org.argeo.security.ui/icons/home.gif and /dev/null differ diff --git a/org.argeo.security.ui/icons/log.gif b/org.argeo.security.ui/icons/log.gif deleted file mode 100644 index e3ecc5535..000000000 Binary files a/org.argeo.security.ui/icons/log.gif and /dev/null differ diff --git a/org.argeo.security.ui/icons/maintenance.gif b/org.argeo.security.ui/icons/maintenance.gif deleted file mode 100644 index e5690ecb1..000000000 Binary files a/org.argeo.security.ui/icons/maintenance.gif and /dev/null differ diff --git a/org.argeo.security.ui/icons/password.gif b/org.argeo.security.ui/icons/password.gif deleted file mode 100644 index a6b251fc8..000000000 Binary files a/org.argeo.security.ui/icons/password.gif and /dev/null differ diff --git a/org.argeo.security.ui/icons/user.gif b/org.argeo.security.ui/icons/user.gif deleted file mode 100644 index 90a00147b..000000000 Binary files a/org.argeo.security.ui/icons/user.gif and /dev/null differ diff --git a/org.argeo.security.ui/plugin.xml b/org.argeo.security.ui/plugin.xml deleted file mode 100644 index b843d9c91..000000000 --- a/org.argeo.security.ui/plugin.xml +++ /dev/null @@ -1,152 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/org.argeo.security.ui/pom.xml b/org.argeo.security.ui/pom.xml deleted file mode 100644 index beb37408e..000000000 --- a/org.argeo.security.ui/pom.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - 4.0.0 - - org.argeo.commons - 2.1.46-SNAPSHOT - argeo-commons - .. - - org.argeo.security.ui - CMS Workbench - jar - - - org.argeo.commons - org.argeo.cms - 2.1.46-SNAPSHOT - - - - - - - - org.argeo.commons - org.argeo.eclipse.ui.workbench - 2.1.46-SNAPSHOT - - - org.argeo.commons - org.argeo.util - 2.1.46-SNAPSHOT - - - \ No newline at end of file diff --git a/org.argeo.security.ui/securityui.properties b/org.argeo.security.ui/securityui.properties deleted file mode 100644 index 0228d47ee..000000000 --- a/org.argeo.security.ui/securityui.properties +++ /dev/null @@ -1 +0,0 @@ -argeo.keyring.secreteKeyLength=256 \ No newline at end of file diff --git a/org.argeo.security.ui/src/org/argeo/security/ui/MaintenancePerspective.java b/org.argeo.security.ui/src/org/argeo/security/ui/MaintenancePerspective.java deleted file mode 100644 index 86307abd2..000000000 --- a/org.argeo.security.ui/src/org/argeo/security/ui/MaintenancePerspective.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2007-2012 Argeo GmbH - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.security.ui; - -import org.argeo.security.ui.views.AdminLogView; -import org.argeo.security.ui.views.UserProfile; -import org.eclipse.ui.IFolderLayout; -import org.eclipse.ui.IPageLayout; -import org.eclipse.ui.IPerspectiveFactory; - -/** Home perspective for the current user */ -public class MaintenancePerspective implements IPerspectiveFactory { - public final static String ID = SecurityUiPlugin.PLUGIN_ID - + ".adminMaintenancePerspective"; - - public void createInitialLayout(IPageLayout layout) { - String editorArea = layout.getEditorArea(); - layout.setEditorAreaVisible(true); - layout.setFixed(false); - - IFolderLayout bottom = layout.createFolder("bottom", - IPageLayout.BOTTOM, 0.50f, editorArea); - bottom.addView(AdminLogView.ID); - - IFolderLayout left = layout.createFolder("left", IPageLayout.LEFT, - 0.30f, editorArea); - left.addView(UserProfile.ID); - // left.addView(RolesView.ID); - - } - -} diff --git a/org.argeo.security.ui/src/org/argeo/security/ui/PrivilegedJob.java b/org.argeo.security.ui/src/org/argeo/security/ui/PrivilegedJob.java deleted file mode 100644 index 3a9ade427..000000000 --- a/org.argeo.security.ui/src/org/argeo/security/ui/PrivilegedJob.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.argeo.security.ui; - -import java.security.AccessControlContext; -import java.security.AccessController; -import java.security.PrivilegedAction; - -import javax.security.auth.Subject; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.jobs.Job; - -/** - * Propagate authentication to an eclipse job. Typically to execute a privileged - * action outside the UI thread - */ -public abstract class PrivilegedJob extends Job { - private final Subject subject; - - public PrivilegedJob(String jobName) { - this(jobName, AccessController.getContext()); - } - - public PrivilegedJob(String jobName, - AccessControlContext accessControlContext) { - super(jobName); - subject = Subject.getSubject(accessControlContext); - - // Must be called *before* the job is scheduled, - // it is required for the progress window to appear - setUser(true); - } - - @Override - protected IStatus run(final IProgressMonitor progressMonitor) { - PrivilegedAction privilegedAction = new PrivilegedAction() { - public IStatus run() { - return doRun(progressMonitor); - } - }; - return Subject.doAs(subject, privilegedAction); - } - - /** - * Implement here what should be executed with default context - * authentication - */ - protected abstract IStatus doRun(IProgressMonitor progressMonitor); -} \ No newline at end of file diff --git a/org.argeo.security.ui/src/org/argeo/security/ui/RolesSourceProvider.java b/org.argeo.security.ui/src/org/argeo/security/ui/RolesSourceProvider.java deleted file mode 100644 index 42e6f10e7..000000000 --- a/org.argeo.security.ui/src/org/argeo/security/ui/RolesSourceProvider.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2007-2012 Argeo GmbH - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.security.ui; - -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -import org.argeo.cms.auth.CurrentUser; -import org.eclipse.ui.AbstractSourceProvider; - -/** - * Provides the roles of the current user as a variable to be used for activity - * binding - */ -public class RolesSourceProvider extends AbstractSourceProvider { - public final static String ROLES_VARIABLE = "roles"; - private final static String[] PROVIDED_SOURCE_NAMES = new String[] { ROLES_VARIABLE }; - - public Map> getCurrentState() { - Map> stateMap = new HashMap>(); - stateMap.put(ROLES_VARIABLE, CurrentUser.roles()); - return stateMap; - } - - public String[] getProvidedSourceNames() { - return PROVIDED_SOURCE_NAMES; - } - - public void updateRoles() { - fireSourceChanged(0, getCurrentState()); - } - - public void dispose() { - } -} \ No newline at end of file diff --git a/org.argeo.security.ui/src/org/argeo/security/ui/SecurityUiPlugin.java b/org.argeo.security.ui/src/org/argeo/security/ui/SecurityUiPlugin.java deleted file mode 100644 index 935b54386..000000000 --- a/org.argeo.security.ui/src/org/argeo/security/ui/SecurityUiPlugin.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (C) 2007-2012 Argeo GmbH - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.security.ui; - -import java.io.IOException; - -import javax.security.auth.callback.Callback; -import javax.security.auth.callback.CallbackHandler; -import javax.security.auth.callback.UnsupportedCallbackException; - -import org.argeo.cms.CmsException; -import org.argeo.cms.widgets.auth.DefaultLoginDialog; -import org.eclipse.swt.widgets.Display; -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceRegistration; - -/** - * The activator class controls the plug-in life cycle - */ -public class SecurityUiPlugin implements BundleActivator { - private static BundleContext bundleContext; - public static InheritableThreadLocal display = new InheritableThreadLocal() { - - @Override - protected Display initialValue() { - return Display.getCurrent(); - } - }; - - // The plug-in ID - public final static String PLUGIN_ID = "org.argeo.security.ui"; //$NON-NLS-1$ - - final static String CONTEXT_KEYRING = "KEYRING"; - - private CallbackHandler defaultCallbackHandler; - private ServiceRegistration defaultCallbackHandlerReg; - - public void start(BundleContext context) throws Exception { - bundleContext = context; - - defaultCallbackHandler = new DefaultCallbackHandler(); - defaultCallbackHandlerReg = context.registerService( - CallbackHandler.class, defaultCallbackHandler, null); - } - - public void stop(BundleContext context) throws Exception { - bundleContext = null; - defaultCallbackHandlerReg.unregister(); - } - - public static BundleContext getBundleContext() { - return bundleContext; - } - - protected class DefaultCallbackHandler implements CallbackHandler { - public void handle(final Callback[] callbacks) throws IOException, - UnsupportedCallbackException { - - // if (display != null) // RCP - Display displayToUse = display.get(); - if (displayToUse == null)// RCP - displayToUse = Display.getDefault(); - displayToUse.syncExec(new Runnable() { - public void run() { - DefaultLoginDialog dialog = new DefaultLoginDialog(display - .get().getActiveShell()); - try { - dialog.handle(callbacks); - } catch (IOException e) { - throw new CmsException("Cannot open dialog", e); - } - } - }); - // else {// RAP - // DefaultLoginDialog dialog = new DefaultLoginDialog(); - // dialog.handle(callbacks); - // } - } - - } -} diff --git a/org.argeo.security.ui/src/org/argeo/security/ui/UserHomePerspective.java b/org.argeo.security.ui/src/org/argeo/security/ui/UserHomePerspective.java deleted file mode 100644 index 119549ffd..000000000 --- a/org.argeo.security.ui/src/org/argeo/security/ui/UserHomePerspective.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2007-2012 Argeo GmbH - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.security.ui; - -import org.argeo.security.ui.views.LogView; -import org.argeo.security.ui.views.UserProfile; -import org.eclipse.ui.IFolderLayout; -import org.eclipse.ui.IPageLayout; -import org.eclipse.ui.IPerspectiveFactory; - -/** Home perspective for the current user */ -public class UserHomePerspective implements IPerspectiveFactory { - public final static String ID = SecurityUiPlugin.PLUGIN_ID - + ".userHomePerspective"; - - public void createInitialLayout(IPageLayout layout) { - String editorArea = layout.getEditorArea(); - layout.setEditorAreaVisible(true); - layout.setFixed(false); - - IFolderLayout left = layout.createFolder("left", IPageLayout.LEFT, - 0.30f, editorArea); - left.addView(UserProfile.ID); - left.addView(LogView.ID); - } - -} diff --git a/org.argeo.security.ui/src/org/argeo/security/ui/commands/OpenChangePasswordDialog.java b/org.argeo.security.ui/src/org/argeo/security/ui/commands/OpenChangePasswordDialog.java deleted file mode 100644 index 817354f70..000000000 --- a/org.argeo.security.ui/src/org/argeo/security/ui/commands/OpenChangePasswordDialog.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright (C) 2007-2012 Argeo GmbH - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.security.ui.commands; - -import static org.argeo.cms.CmsMsg.changePassword; -import static org.argeo.cms.CmsMsg.currentPassword; -import static org.argeo.cms.CmsMsg.newPassword; -import static org.argeo.cms.CmsMsg.passwordChanged; -import static org.argeo.cms.CmsMsg.repeatNewPassword; -import static org.eclipse.jface.dialogs.IMessageProvider.INFORMATION; - -import java.security.AccessController; - -import javax.naming.InvalidNameException; -import javax.naming.ldap.LdapName; -import javax.security.auth.Subject; -import javax.security.auth.x500.X500Principal; -import javax.transaction.UserTransaction; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.argeo.cms.CmsException; -import org.argeo.eclipse.ui.dialogs.ErrorFeedback; -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.dialogs.TitleAreaDialog; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.handlers.HandlerUtil; -import org.osgi.service.useradmin.User; -import org.osgi.service.useradmin.UserAdmin; - -/** Opens the change password dialog. */ -public class OpenChangePasswordDialog extends AbstractHandler { - private final static Log log = LogFactory - .getLog(OpenChangePasswordDialog.class); - private UserAdmin userAdmin; - private UserTransaction userTransaction; - - public Object execute(ExecutionEvent event) throws ExecutionException { - ChangePasswordDialog dialog = new ChangePasswordDialog( - HandlerUtil.getActiveShell(event), userAdmin); - if (dialog.open() == Dialog.OK) { - MessageDialog.openInformation(HandlerUtil.getActiveShell(event), - passwordChanged.lead(), passwordChanged.lead()); - } - return null; - } - - @SuppressWarnings("unchecked") - protected void changePassword(char[] oldPassword, char[] newPassword) { - Subject subject = Subject.getSubject(AccessController.getContext()); - String name = subject.getPrincipals(X500Principal.class).iterator() - .next().toString(); - LdapName dn; - try { - dn = new LdapName(name); - } catch (InvalidNameException e) { - throw new CmsException("Invalid user dn " + name, e); - } - User user = (User) userAdmin.getRole(dn.toString()); - if (!user.hasCredential(null, oldPassword)) - throw new CmsException("Invalid password"); - if (newPassword.equals("")) - throw new CmsException("New password empty"); - try { - userTransaction.begin(); - user.getCredentials().put(null, newPassword); - userTransaction.commit(); - } catch (Exception e) { - try { - userTransaction.rollback(); - } catch (Exception e1) { - log.error("Could not roll back", e1); - } - if (e instanceof RuntimeException) - throw (RuntimeException) e; - else - throw new CmsException("Cannot change password", e); - } - } - - public void setUserAdmin(UserAdmin userDetailsManager) { - this.userAdmin = userDetailsManager; - } - - public void setUserTransaction(UserTransaction userTransaction) { - this.userTransaction = userTransaction; - } - - class ChangePasswordDialog extends TitleAreaDialog { - private static final long serialVersionUID = -6963970583882720962L; - private Text oldPassword, newPassword1, newPassword2; - - public ChangePasswordDialog(Shell parentShell, UserAdmin securityService) { - super(parentShell); - } - - protected Point getInitialSize() { - return new Point(400, 450); - } - - protected Control createDialogArea(Composite parent) { - Composite dialogarea = (Composite) super.createDialogArea(parent); - dialogarea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, - true)); - Composite composite = new Composite(dialogarea, SWT.NONE); - composite.setLayout(new GridLayout(2, false)); - composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, - false)); - oldPassword = createLP(composite, currentPassword.lead()); - newPassword1 = createLP(composite, newPassword.lead()); - newPassword2 = createLP(composite, repeatNewPassword.lead()); - - setMessage(changePassword.lead(), INFORMATION); - parent.pack(); - return composite; - } - - @Override - protected void okPressed() { - try { - if (!newPassword1.getText().equals(newPassword2.getText())) - throw new CmsException("New passwords are different"); - changePassword(oldPassword.getTextChars(), - newPassword1.getTextChars()); - close(); - } catch (Exception e) { - ErrorFeedback.show("Cannot change password", e); - } - } - - /** Creates label and password. */ - protected Text createLP(Composite parent, String label) { - new Label(parent, SWT.NONE).setText(label); - Text text = new Text(parent, SWT.SINGLE | SWT.LEAD | SWT.PASSWORD - | SWT.BORDER); - text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); - return text; - } - - protected void configureShell(Shell shell) { - super.configureShell(shell); - shell.setText(changePassword.lead()); - } - - } -} diff --git a/org.argeo.security.ui/src/org/argeo/security/ui/commands/OpenHomePerspective.java b/org.argeo.security.ui/src/org/argeo/security/ui/commands/OpenHomePerspective.java deleted file mode 100644 index f6aa0d19e..000000000 --- a/org.argeo.security.ui/src/org/argeo/security/ui/commands/OpenHomePerspective.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2007-2012 Argeo GmbH - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.security.ui.commands; - -import org.argeo.eclipse.ui.dialogs.ErrorFeedback; -import org.argeo.security.ui.UserHomePerspective; -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.ui.WorkbenchException; -import org.eclipse.ui.handlers.HandlerUtil; - -/** Default action of the user menu */ -public class OpenHomePerspective extends AbstractHandler { - - public Object execute(ExecutionEvent event) throws ExecutionException { - try { - HandlerUtil.getActiveSite(event).getWorkbenchWindow() - .openPage(UserHomePerspective.ID, null); - } catch (WorkbenchException e) { - ErrorFeedback.show("Cannot open home perspective", e); - } - return null; - } -} diff --git a/org.argeo.security.ui/src/org/argeo/security/ui/views/AdminLogView.java b/org.argeo.security.ui/src/org/argeo/security/ui/views/AdminLogView.java deleted file mode 100644 index 61efc8cb6..000000000 --- a/org.argeo.security.ui/src/org/argeo/security/ui/views/AdminLogView.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) 2007-2012 Argeo GmbH - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.security.ui.views; - -import java.util.ArrayList; - -import org.argeo.node.ArgeoLogger; -import org.argeo.security.ui.SecurityUiPlugin; -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Table; -import org.eclipse.ui.part.ViewPart; - -/** - * Display log lines for all users with a virtual table. - */ -public class AdminLogView extends ViewPart { - public static String ID = SecurityUiPlugin.PLUGIN_ID + ".adminLogView"; - - private TableViewer viewer; - - private LogContentProvider logContentProvider; - private ArgeoLogger argeoLogger; - - @Override - public void createPartControl(Composite parent) { - // FIXME doesn't return a monospace font in RAP - Font font = JFaceResources.getTextFont(); - Table table = new Table(parent, SWT.VIRTUAL | SWT.MULTI | SWT.H_SCROLL - | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER); - table.setFont(font); - - viewer = new TableViewer(table); - viewer.setLabelProvider(new LabelProvider()); - logContentProvider = new LogContentProvider(viewer) { - private static final long serialVersionUID = -3401776448301180724L; - - @Override - protected StringBuffer prefix(String username, Long timestamp, - String level, String category, String thread) { - return super - .prefix(username, timestamp, level, category, thread) - .append(norm(level, 5)) - .append(' ') - .append(norm(username != null ? username - : "", 16)).append(' '); - } - }; - viewer.setContentProvider(logContentProvider); - // viewer.setUseHashlookup(true); - viewer.setInput(new ArrayList()); - - if (argeoLogger != null) - argeoLogger.registerForAll(logContentProvider, 1000, true); - } - - @Override - public void setFocus() { - viewer.getTable().setFocus(); - } - - @Override - public void dispose() { - if (argeoLogger != null) - argeoLogger.unregisterForAll(logContentProvider); - } - - public void setArgeoLogger(ArgeoLogger argeoLogger) { - this.argeoLogger = argeoLogger; - } - -} diff --git a/org.argeo.security.ui/src/org/argeo/security/ui/views/LogContentProvider.java b/org.argeo.security.ui/src/org/argeo/security/ui/views/LogContentProvider.java deleted file mode 100644 index 5b12f439a..000000000 --- a/org.argeo.security.ui/src/org/argeo/security/ui/views/LogContentProvider.java +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Copyright (C) 2007-2012 Argeo GmbH - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.security.ui.views; - -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Arrays; -import java.util.Date; -import java.util.LinkedList; -import java.util.List; - -import org.argeo.node.ArgeoLogListener; -import org.eclipse.jface.viewers.ILazyContentProvider; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableItem; - -/** A content provider maintaining an array of lines */ -class LogContentProvider implements ILazyContentProvider, ArgeoLogListener { - private static final long serialVersionUID = -2084872367738339721L; - - private DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); - - private final Long start; - /** current - start = line number. first line is number '1' */ - private Long current; - - // TODO make it configurable - private final Integer maxLineBufferSize = 10 * 1000; - - private final TableViewer viewer; - private LinkedList lines; - - public LogContentProvider(TableViewer viewer) { - this.viewer = viewer; - start = System.currentTimeMillis(); - lines = new LinkedList(); - current = start; - } - - public synchronized void dispose() { - lines.clear(); - lines = null; - } - - @SuppressWarnings("unchecked") - public synchronized void inputChanged(Viewer viewer, Object oldInput, - Object newInput) { - List lin = (List) newInput; - if (lin == null) - return; - for (String line : lin) { - addLine(line); - } - this.viewer.setItemCount(lines.size()); - } - - public void updateElement(int index) { - viewer.replace(lines.get(index), index); - } - - public synchronized void appendLog(String username, Long timestamp, - String level, String category, String thread, Object msg, - String[] exception) { - // check if valid - if (lines == null) - return; - - String message = msg.toString(); - int count = 0; - String prefix = prefix(username, timestamp, level, category, thread) - .toString(); - // String suffix = suffix(username, timestamp, level, category, thread); - for (String line : message.split("\n")) { - addLine(count == 0 ? prefix + line : line); - count++; - } - - if (exception != null) { - for (String ste : exception) { - addLine(ste); - } - } - - viewer.getTable().getDisplay().asyncExec(new Runnable() { - public void run() { - if (lines == null) - return; - viewer.setItemCount(lines.size()); - // doesn't work with syncExec - scrollToLastLine(); - } - }); - } - - protected StringBuffer prefix(String username, Long timestamp, - String level, String category, String thread) { - StringBuffer buf = new StringBuffer(""); - buf.append(dateFormat.format(new Date(timestamp))).append(" "); - // buf.append(level).append(" "); - return buf; - } - - /** Normalize string to the given size */ - protected String norm(String str, Integer size) { - int length = str.length(); - if (length == size) - return str; - else if (length > size) - return str.substring(0, size); - else { - char[] arr = new char[size - length]; - Arrays.fill(arr, ' '); - return str + new String(arr); - } - } - - // protected String suffix(String username, Long timestamp, String level, - // String category, String thread) { - // return ""; - // } - - /** Scroll to the last line */ - protected synchronized void scrollToLastLine() { - // we try to show last line with two methods - // viewer.reveal(lines.peekLast()); - - Table table = viewer.getTable(); - TableItem ti = table.getItem(table.getItemCount() - 1); - table.showItem(ti); - } - - protected synchronized LogLine addLine(String line) { - // check for maximal size and purge if necessary - while (lines.size() >= maxLineBufferSize) { - for (int i = 0; i < maxLineBufferSize / 10; i++) { - lines.poll(); - } - } - - current++; - LogLine logLine = new LogLine(current, line); - lines.add(logLine); - return logLine; - } - - private class LogLine { - private Long linenumber; - private String message; - - public LogLine(Long linenumber, String message) { - this.linenumber = linenumber; - this.message = message; - } - - @Override - public int hashCode() { - return linenumber.intValue(); - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof LogLine) - return ((LogLine) obj).linenumber.equals(linenumber); - else - return false; - } - - @Override - public String toString() { - return message; - } - - } -} \ No newline at end of file diff --git a/org.argeo.security.ui/src/org/argeo/security/ui/views/LogView.java b/org.argeo.security.ui/src/org/argeo/security/ui/views/LogView.java deleted file mode 100644 index f9e197ac0..000000000 --- a/org.argeo.security.ui/src/org/argeo/security/ui/views/LogView.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2007-2012 Argeo GmbH - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.security.ui.views; - -import java.util.ArrayList; - -import org.argeo.node.ArgeoLogListener; -import org.argeo.node.ArgeoLogger; -import org.argeo.security.ui.SecurityUiPlugin; -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Table; -import org.eclipse.ui.part.ViewPart; - -/** - * Display log lines with a virtual table. Register and unregisters a - * {@link ArgeoLogListener} via OSGi services. - */ -public class LogView extends ViewPart { - public static String ID = SecurityUiPlugin.PLUGIN_ID + ".logView"; - - private TableViewer viewer; - - private LogContentProvider logContentProvider; - private ArgeoLogger argeoLogger; - - @Override - public void createPartControl(Composite parent) { - Font font = JFaceResources.getTextFont(); - Table table = new Table(parent, SWT.VIRTUAL | SWT.MULTI | SWT.H_SCROLL - | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER); - table.setFont(font); - - viewer = new TableViewer(table); - viewer.setLabelProvider(new LabelProvider()); - logContentProvider = new LogContentProvider(viewer); - viewer.setContentProvider(logContentProvider); - // viewer.setUseHashlookup(true); - viewer.setInput(new ArrayList()); - - if (argeoLogger != null) - argeoLogger.register(logContentProvider, 1000); - } - - @Override - public void setFocus() { - viewer.getTable().setFocus(); - } - - @Override - public void dispose() { - if (argeoLogger != null) - argeoLogger.unregister(logContentProvider); - } - - public void setArgeoLogger(ArgeoLogger argeoLogger) { - this.argeoLogger = argeoLogger; - } - -} diff --git a/org.argeo.security.ui/src/org/argeo/security/ui/views/UserProfile.java b/org.argeo.security.ui/src/org/argeo/security/ui/views/UserProfile.java deleted file mode 100644 index 49f5bea5a..000000000 --- a/org.argeo.security.ui/src/org/argeo/security/ui/views/UserProfile.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (C) 2007-2012 Argeo GmbH - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.security.ui.views; - -import java.util.TreeSet; - -import org.argeo.cms.auth.CurrentUser; -import org.argeo.eclipse.ui.EclipseUiUtils; -import org.argeo.security.ui.SecurityUiPlugin; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Table; -import org.eclipse.ui.part.ViewPart; - -/** Information about the currently logged in user */ -public class UserProfile extends ViewPart { - public static String ID = SecurityUiPlugin.PLUGIN_ID + ".userProfile"; - - private TableViewer viewer; - - @Override - public void createPartControl(Composite parent) { - parent.setLayout(new GridLayout(2, false)); - - // Authentication authentication = CurrentUser.getAuthentication(); - // EclipseUiUtils.createGridLL(parent, "Name", authentication - // .getPrincipal().toString()); - EclipseUiUtils.createGridLL(parent, "User ID", - CurrentUser.getUsername()); - - // roles table - Table table = new Table(parent, SWT.V_SCROLL | SWT.BORDER); - table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); - table.setLinesVisible(false); - table.setHeaderVisible(false); - viewer = new TableViewer(table); - viewer.setContentProvider(new RolesContentProvider()); - viewer.setLabelProvider(new LabelProvider()); - getViewSite().setSelectionProvider(viewer); - viewer.setInput(getViewSite()); - } - - @Override - public void setFocus() { - viewer.getTable(); - } - - private class RolesContentProvider implements IStructuredContentProvider { - private static final long serialVersionUID = -4576917440167866233L; - - public Object[] getElements(Object inputElement) { - return new TreeSet(CurrentUser.roles()).toArray(); - } - - public void dispose() { - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - } - - } - -}