--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
+ xmlns:p="http://www.springframework.org/schema/p"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd">
+
+ <bean
+ class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
+ <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
+ <property name="locations">
+ <value>osgibundle:securityui.properties</value>
+ </property>
+ </bean>
+
+ <bean id="nodeSession" class="org.argeo.jcr.spring.ThreadBoundSession"
+ destroy-method="dispose">
+ <property name="repository" ref="nodeRepository" />
+ </bean>
+
+ <bean id="keyring" class="org.argeo.jcr.security.JcrKeyring">
+ <property name="session" ref="nodeSession" />
+ <property name="defaultCallbackHandler" ref="defaultCallbackHandler" />
+ <property name="secreteKeyLength" value="${argeo.keyring.secreteKeyLength}" />
+ </bean>
+
+</beans>
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"\r
osgi:default-timeout="30000">\r
\r
+<!-- <reference id="nodeRepository" interface="javax.jcr.Repository" -->\r
+<!-- filter="(argeo.jcr.repository.alias=node)" /> -->\r
+\r
<reference id="nodeRepository" interface="javax.jcr.Repository"\r
- filter="(argeo.jcr.repository.alias=node)" />\r
+ filter="(argeo.jcr.repository.alias=home)" />\r
+\r
\r
<!-- New user admin -->\r
<reference id="userAdmin" interface="org.osgi.service.useradmin.UserAdmin" />\r
<reference id="userTransaction" interface="javax.transaction.UserTransaction" />\r
+ \r
+ <reference id="secureLogger" interface="org.argeo.node.ArgeoLogger"\r
+ cardinality="0..1" />\r
+\r
+\r
+ <reference id="defaultCallbackHandler" interface="javax.security.auth.callback.CallbackHandler" />\r
+\r
+ <!-- SERVICES -->\r
+ <service interface="org.argeo.util.security.CryptoKeyring"\r
+ ref="keyring" />\r
</beans:beans>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+ <bean id="logView" class="org.argeo.security.ui.views.LogView"
+ scope="prototype">
+ <property name="argeoLogger" ref="secureLogger" />
+ </bean>
+
+ <bean id="adminLogView" class="org.argeo.security.ui.views.AdminLogView"
+ scope="prototype">
+ <property name="argeoLogger" ref="secureLogger" />
+ </bean>
+
+</beans>
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,\
org.osgi.framework,\
org.springframework.core,\
*
+
+
+# org.argeo.eclipse.ui.workbench;resolution:=optional,\
<perspective
class="org.argeo.security.ui.admin.SecurityAdminPerspective"
icon="icons/security.gif"
- id="org.argeo.security.ui.admin.adminSecurityPerspective"
+ id="org.argeo.cms.ui.workbench.adminSecurityPerspective"
name="Security">
</perspective>
+ <perspective
+ class="org.argeo.security.ui.UserHomePerspective"
+ icon="icons/home.gif"
+ id="org.argeo.cms.ui.workbench.userHomePerspective"
+ name="Home">
+ </perspective>
+ <perspective
+ class="org.argeo.security.ui.MaintenancePerspective"
+ icon="icons/maintenance.gif"
+ id="org.argeo.cms.ui.workbench.adminMaintenancePerspective"
+ name="Maintenance">
+ </perspective>
</extension>
<!-- VIEWS -->
<extension
point="org.eclipse.ui.views">
+ <!-- Security -->
<view
class="org.argeo.eclipse.spring.SpringExtensionFactory"
icon="icons/users.gif"
- id="org.argeo.security.ui.admin.usersView"
+ id="org.argeo.cms.ui.workbench.usersView"
name="Users"
restorable="true">
</view>
<view
class="org.argeo.eclipse.spring.SpringExtensionFactory"
icon="icons/role.gif"
- id="org.argeo.security.ui.admin.groupsView"
+ id="org.argeo.cms.ui.workbench.groupsView"
name="Groups"
restorable="false">
</view>
+ <!-- Home -->
+ <view
+ id="org.argeo.cms.ui.workbench.userProfile"
+ class="org.argeo.security.ui.views.UserProfile"
+ icon="icons/user.gif"
+ name="Profile"
+ restorable="true">
+ </view>
+ <!-- Maintenance -->
+ <view
+ id="org.argeo.cms.ui.workbench.logView"
+ class="org.argeo.eclipse.spring.SpringExtensionFactory"
+ name="Log"
+ icon="icons/log.gif"
+ restorable="true">
+ </view>
+ <view
+ id="org.argeo.cms.ui.workbench.adminLogView"
+ class="org.argeo.eclipse.spring.SpringExtensionFactory"
+ name="Admin Log"
+ icon="icons/adminLog.gif"
+ restorable="true">
+ </view>
+
</extension>
<!-- EDITORS -->
point="org.eclipse.ui.editors">
<editor
class="org.argeo.eclipse.spring.SpringExtensionFactory"
- id="org.argeo.security.ui.admin.userEditor"
+ id="org.argeo.cms.ui.workbench.userEditor"
name="User"
icon="icons/user.gif"
default="false">
</editor>
<editor
class="org.argeo.eclipse.spring.SpringExtensionFactory"
- id="org.argeo.security.ui.admin.groupEditor"
+ id="org.argeo.cms.ui.workbench.groupEditor"
name="User"
icon="icons/users.gif"
default="false">
point="org.eclipse.ui.commands">
<!-- User CRUD -->
<command
- id="org.argeo.security.ui.admin.newUser"
+ id="org.argeo.cms.ui.workbench.newUser"
defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
name="New User">
</command>
<command
- id="org.argeo.security.ui.admin.deleteUsers"
+ id="org.argeo.cms.ui.workbench.deleteUsers"
defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
name="Delete User">
</command>
<command
defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
- id="org.argeo.security.ui.admin.userBatchUpdate"
+ id="org.argeo.cms.ui.workbench.userBatchUpdate"
name="User batch update">
</command>
<!-- Group CRUD -->
<command
- id="org.argeo.security.ui.admin.newGroup"
+ id="org.argeo.cms.ui.workbench.newGroup"
defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
name="New Group">
</command>
<command
- id="org.argeo.security.ui.admin.deleteGroups"
+ id="org.argeo.cms.ui.workbench.deleteGroups"
defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
name="Delete Group">
</command>
<!-- Transaction -->
<command
- id="org.argeo.security.ui.admin.userTransactionHandler"
+ id="org.argeo.cms.ui.workbench.userTransactionHandler"
defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
name="Manage a user transaction">
<commandParameter
<!-- Force the refresh when the various listener are not enough -->
<command
defaultHandler="org.argeo.security.ui.admin.internal.commands.ForceRefresh"
- id="org.argeo.security.ui.admin.forceRefresh"
+ id="org.argeo.cms.ui.workbench.forceRefresh"
name="Force Refresh">
</command>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
- locationURI="toolbar:org.argeo.security.ui.rap.userToolbar?after=org.eclipse.ui.file.saveAll">
+ locationURI="toolbar:org.argeo.cms.ui.workbench.rap.userToolbar?after=org.eclipse.ui.file.saveAll">
<!-- Transaction management -->
<command
- commandId="org.argeo.security.ui.admin.userTransactionHandler"
+ commandId="org.argeo.cms.ui.workbench.userTransactionHandler"
icon="icons/commit.gif"
label="Commit Transaction"
style="push"
tooltip="Commit a user transaction">
<parameter name="param.commandId" value="transaction.commit" />
<visibleWhen>
- <with variable="org.argeo.security.ui.admin.userTransactionState">
+ <with variable="org.argeo.cms.ui.workbench.userTransactionState">
<equals value="status.active" />
</with>
</visibleWhen>
</command>
<command
- commandId="org.argeo.security.ui.admin.userTransactionHandler"
+ commandId="org.argeo.cms.ui.workbench.userTransactionHandler"
icon="icons/rollback.gif"
label="Rollback Transaction"
style="push"
tooltip="Abandon current changes and rollback to the latest commited version">
<parameter name="param.commandId" value="transaction.rollback" />
<visibleWhen>
- <with variable="org.argeo.security.ui.admin.userTransactionState">
+ <with variable="org.argeo.cms.ui.workbench.userTransactionState">
<equals value="status.active" />
</with>
</visibleWhen>
<!-- UsersView specific toolbar menu -->
<menuContribution
- locationURI="toolbar:org.argeo.security.ui.admin.usersView">
+ locationURI="toolbar:org.argeo.cms.ui.workbench.usersView">
<command
- commandId="org.argeo.security.ui.admin.deleteUsers"
+ commandId="org.argeo.cms.ui.workbench.deleteUsers"
icon="icons/remove.gif"
label="Delete User"
tooltip="Delete selected users">
</command>
<command
- commandId="org.argeo.security.ui.admin.forceRefresh"
+ commandId="org.argeo.cms.ui.workbench.forceRefresh"
icon="icons/refresh.png"
label="Refresh list"
tooltip="Force the full refresh of the user list">
</command>
<command
- commandId="org.argeo.security.ui.admin.newUser"
+ commandId="org.argeo.cms.ui.workbench.newUser"
icon="icons/add.gif"
label="Add User"
tooltip="Create a new user">
</command>
<command
- commandId="org.argeo.security.ui.admin.userBatchUpdate"
+ commandId="org.argeo.cms.ui.workbench.userBatchUpdate"
icon="icons/batch.gif"
label="Update users"
tooltip="Perform maintenance activities on a list of chosen users">
<!-- GroupsView specific toolbar menu -->
<menuContribution
- locationURI="toolbar:org.argeo.security.ui.admin.groupsView">
+ locationURI="toolbar:org.argeo.cms.ui.workbench.groupsView">
<command
- commandId="org.argeo.security.ui.admin.deleteGroups"
+ commandId="org.argeo.cms.ui.workbench.deleteGroups"
icon="icons/remove.gif"
label="Delete Group"
tooltip="Delete selected groups">
</command>
<command
- commandId="org.argeo.security.ui.admin.forceRefresh"
+ commandId="org.argeo.cms.ui.workbench.forceRefresh"
icon="icons/refresh.png"
label="Refresh list"
tooltip="Force the full refresh of the group list">
</command>
<command
- commandId="org.argeo.security.ui.admin.newGroup"
+ commandId="org.argeo.cms.ui.workbench.newGroup"
icon="icons/add.gif"
label="Add Group"
tooltip="Create a new group">
</menuContribution>
<!-- <menuContribution
- locationURI="toolbar:org.argeo.security.ui.admin.adminRolesView">
+ locationURI="toolbar:org.argeo.cms.ui.workbench.admin.adminRolesView">
<command
- commandId="org.argeo.security.ui.admin.refreshRoles"
+ commandId="org.argeo.cms.ui.workbench.admin.refreshRoles"
icon="icons/sync.gif"
label="LDAP Roles Sync"
tooltip="Synchronize roles from LDAP">
<!-- SERVICES -->
<extension
point="org.eclipse.ui.services">
- <sourceProvider
- id="org.argeo.security.ui.admin.userTransactionProvider"
+ <sourceProvider
+ id="org.argeo.cms.ui.workbench.userTransactionProvider"
provider="org.argeo.eclipse.spring.SpringExtensionFactory" >
<variable
- name="org.argeo.security.ui.admin.userTransactionState"
+ name="org.argeo.cms.ui.workbench.userTransactionState"
priorityLevel="workbench">
</variable>
</sourceProvider>
+ <sourceProvider
+ provider="org.argeo.cms.ui.workbench.RolesSourceProvider">
+ <variable
+ name="org.argeo.cms.ui.workbench.rolesVariable"
+ priorityLevel="workbench">
+ </variable>
+ </sourceProvider>
</extension>
<!-- ACTIVITIES -->
point="org.eclipse.ui.activities">
<!-- group admin is intended to make all user and group maintenance operations -->
<!--<activityPatternBinding
- activityId="org.argeo.security.ui.userAdminActivity"
+ activityId="org.argeo.cms.ui.workbench.userAdminActivity"
isEqualityPattern="true"
- pattern="org.argeo.security.ui.admin/org.argeo.security.ui.admin.adminSecurityPerspective">
+ pattern="org.argeo.cms.ui.workbench.admin/org.argeo.cms.ui.workbench.admin.adminSecurityPerspective">
</activityPatternBinding>-->
<activityPatternBinding
- activityId="org.argeo.security.ui.groupAdminActivity"
+ activityId="org.argeo.cms.ui.workbench.groupAdminActivity"
isEqualityPattern="true"
- pattern="org.argeo.security.ui.admin/org.argeo.security.ui.admin.adminSecurityPerspective">
+ pattern="org.argeo.cms.ui.workbench/org.argeo.cms.ui.workbench.adminSecurityPerspective">
</activityPatternBinding>
+
+ <activity
+ description="Authenticated users"
+ id="org.argeo.cms.ui.workbench.userActivity"
+ name="User">
+ <enabledWhen>
+ <with variable="roles">
+ <iterate ifEmpty="false" operator="or">
+ <equals value="cn=user,ou=roles,ou=node" />
+ </iterate>
+ </with>
+ </enabledWhen>
+ </activity>
+ <activity
+ description="Admins"
+ id="org.argeo.cms.ui.workbench.adminActivity"
+ name="Admin">
+ <enabledWhen>
+ <with variable="roles">
+ <iterate ifEmpty="false" operator="or">
+ <equals value="cn=admin,ou=roles,ou=node" />
+ </iterate>
+ </with>
+ </enabledWhen>
+ </activity>
+ <activity
+ description="User Admins"
+ id="org.argeo.cms.ui.workbench.userAdminActivity"
+ name="User Admin">
+ <enabledWhen>
+ <with variable="roles">
+ <iterate ifEmpty="false" operator="or">
+ <equals value="cn=userAdmin,ou=roles,ou=node" />
+ </iterate>
+ </with>
+ </enabledWhen>
+ </activity>
+ <activity
+ description="Group Admins"
+ id="org.argeo.cms.ui.workbench.groupAdminActivity"
+ name="User Admin">
+ <enabledWhen>
+ <with variable="roles">
+ <iterate ifEmpty="false" operator="or">
+ <equals value="cn=groupAdmin,ou=roles,ou=node" />
+ </iterate>
+ </with>
+ </enabledWhen>
+ </activity>
+ <activity
+ description="Non admins"
+ id="org.argeo.cms.ui.workbench.notAdminActivity"
+ name="Not Admin">
+ <enabledWhen>
+ <not>
+ <with variable="roles">
+ <iterate ifEmpty="false" operator="or">
+ <equals value="cn=admin,ou=roles,ou=node" />
+ </iterate>
+ </with>
+ </not>
+ </enabledWhen>
+ </activity>
+ <activity
+ description="Non remote"
+ id="org.argeo.cms.ui.workbench.notRemoteActivity"
+ name="NonRemote">
+ <enabledWhen>
+ <not>
+ <with variable="roles">
+ <iterate ifEmpty="false" operator="or">
+ <equals value="ROLE_REMOTE" />
+ </iterate>
+ </with>
+ </not>
+ </enabledWhen>
+ </activity>
+ <activityPatternBinding
+ activityId="org.argeo.cms.ui.workbench.adminActivity"
+ isEqualityPattern="true"
+ pattern="org.argeo.cms.ui.workbench/org.argeo.cms.ui.workbench.adminMaintenancePerspective">
+ </activityPatternBinding>
+ <activityPatternBinding
+ activityId="org.argeo.cms.ui.workbench.adminActivity"
+ isEqualityPattern="true"
+ pattern="org.argeo.cms.ui.workbench/org.argeo.cms.ui.workbench.adminLogView">
+ </activityPatternBinding>
+ <activityPatternBinding
+ activityId="org.argeo.cms.ui.workbench.userActivity"
+ isEqualityPattern="true"
+ pattern="org.argeo.cms.ui.workbench/org.argeo.cms.ui.workbench.userHomePerspective">
+ </activityPatternBinding>
+ <activityPatternBinding
+ activityId="org.argeo.cms.ui.workbench.userActivity"
+ isEqualityPattern="true"
+ pattern="org.argeo.cms.ui.workbench/org.argeo.cms.ui.workbench.userProfile">
+ </activityPatternBinding>
+
</extension>
<!-- STARTUP -->
<artifactId>org.argeo.cms</artifactId>
<version>2.1.46-SNAPSHOT</version>
</dependency>
- <dependency>
+ <dependency>
<groupId>org.argeo.commons</groupId>
- <artifactId>org.argeo.util</artifactId>
+ <artifactId>org.argeo.eclipse.ui.workbench</artifactId>
<version>2.1.46-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.argeo.commons</groupId>
- <artifactId>org.argeo.security.ui</artifactId>
+ <artifactId>org.argeo.util</artifactId>
<version>2.1.46-SNAPSHOT</version>
</dependency>
+<!-- <dependency> -->
+<!-- <groupId>org.argeo.commons</groupId> -->
+<!-- <artifactId>org.argeo.security.ui</artifactId> -->
+<!-- <version>2.1.46-SNAPSHOT</version> -->
+<!-- </dependency> -->
<dependency>
<groupId>org.argeo.commons</groupId>
<artifactId>org.argeo.enterprise</artifactId>
--- /dev/null
+argeo.keyring.secreteKeyLength=256
\ No newline at end of file
--- /dev/null
+/*
+ * 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);
+
+ }
+
+}
--- /dev/null
+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<IStatus> privilegedAction = new PrivilegedAction<IStatus>() {
+ 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
--- /dev/null
+/*
+ * 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<String, Set<String>> getCurrentState() {
+ Map<String, Set<String>> stateMap = new HashMap<String, Set<String>>();
+ 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
--- /dev/null
+/*
+ * 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> display = new InheritableThreadLocal<Display>() {
+
+ @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<CallbackHandler> 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);
+ }
+}
--- /dev/null
+/*
+ * 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);
+ }
+
+}
*/
package org.argeo.security.ui.admin;
+import org.argeo.security.ui.SecurityUiPlugin;
import org.eclipse.jface.resource.ImageDescriptor;
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();
}
*/
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);
+// }
+//
+// }
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;
/** 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 */
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;
/** 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;
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;
/** 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;
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;
*/
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;
*/
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;
/** 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 {
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;
/** 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";
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;
/** 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;
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;
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 */
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;
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;
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;
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";
@Override
public String[] getProvidedSourceNames() {
- return new String[] { TRANSACTION_STATE};
+ return new String[] { TRANSACTION_STATE };
}
@Override
public Map<String, String> getCurrentState() {
Map<String, String> currentState = new HashMap<String, String>(1);
- currentState.put(TRANSACTION_STATE, getInternalCurrentState());
+ currentState.put(TRANSACTION_STATE, getInternalCurrentState());
return currentState;
}
--- /dev/null
+/*
+ * 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());
+ }
+
+ }
+}
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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
+ : "<anonymous>", 16)).append(' ');
+ }
+ };
+ viewer.setContentProvider(logContentProvider);
+ // viewer.setUseHashlookup(true);
+ viewer.setInput(new ArrayList<String>());
+
+ 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;
+ }
+
+}
--- /dev/null
+/*
+ * 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<LogLine> lines;
+
+ public LogContentProvider(TableViewer viewer) {
+ this.viewer = viewer;
+ start = System.currentTimeMillis();
+ lines = new LinkedList<LogLine>();
+ current = start;
+ }
+
+ public synchronized void dispose() {
+ lines.clear();
+ lines = null;
+ }
+
+ @SuppressWarnings("unchecked")
+ public synchronized void inputChanged(Viewer viewer, Object oldInput,
+ Object newInput) {
+ List<String> lin = (List<String>) 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
--- /dev/null
+/*
+ * 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<String>());
+
+ 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;
+ }
+
+}
--- /dev/null
+/*
+ * 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<String>(CurrentUser.roles()).toArray();
+ }
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ }
+
+}
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" path="src" />
- <classpathentry kind="con"
- path="org.eclipse.pde.core.requiredPlugins" />
- <classpathentry kind="con"
- path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8" />
- <classpathentry kind="output" path="bin" />
-</classpath>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>org.argeo.security.ui</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.pde.ManifestBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.pde.SchemaBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.pde.PluginNature</nature>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
+++ /dev/null
-#Sat Jan 15 18:15:48 CET 2011
-eclipse.preferences.version=1
-resolve.requirebundle=false
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd">
-
-</beans>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
- xmlns:p="http://www.springframework.org/schema/p"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd">
-
- <bean
- class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
- <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
- <property name="locations">
- <value>osgibundle:securityui.properties</value>
- </property>
- </bean>
-
- <bean id="nodeSession" class="org.argeo.jcr.spring.ThreadBoundSession"
- destroy-method="dispose">
- <property name="repository" ref="nodeRepository" />
- </bean>
-
- <bean id="keyring" class="org.argeo.jcr.security.JcrKeyring">
- <property name="session" ref="nodeSession" />
- <property name="defaultCallbackHandler" ref="defaultCallbackHandler" />
- <property name="secreteKeyLength" value="${argeo.keyring.secreteKeyLength}" />
- </bean>
-
-</beans>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>\r
-<beans:beans xmlns="http://www.springframework.org/schema/osgi"\r
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"\r
- xmlns:osgi="http://www.springframework.org/schema/osgi"\r
- xsi:schemaLocation="http://www.springframework.org/schema/osgi \r
- http://www.springframework.org/schema/osgi/spring-osgi-1.1.xsd\r
- http://www.springframework.org/schema/beans \r
- http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">\r
-\r
- <!-- REFERENCES -->\r
- <reference id="secureLogger" interface="org.argeo.node.ArgeoLogger"\r
- cardinality="0..1" />\r
-\r
- <reference id="nodeRepository" interface="javax.jcr.Repository"\r
- filter="(argeo.jcr.repository.alias=home)" />\r
-\r
- <reference id="defaultCallbackHandler" interface="javax.security.auth.callback.CallbackHandler" />\r
-\r
- <!-- SERVICES -->\r
- <service interface="org.argeo.util.security.CryptoKeyring"\r
- ref="keyring" />\r
-</beans:beans>
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd">
-
- <bean id="logView" class="org.argeo.security.ui.views.LogView"
- scope="prototype">
- <property name="argeoLogger" ref="secureLogger" />
- </bean>
-
- <bean id="adminLogView" class="org.argeo.security.ui.views.AdminLogView"
- scope="prototype">
- <property name="argeoLogger" ref="secureLogger" />
- </bean>
-
-</beans>
+++ /dev/null
-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,\
-*
+++ /dev/null
-source.. = src/
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<?eclipse version="3.4"?>
-<plugin>
- <!-- Security -->
- <extension point="org.eclipse.ui.services">
- <sourceProvider
- provider="org.argeo.security.ui.RolesSourceProvider">
- <variable
- name="org.argeo.security.ui.rolesVariable"
- priorityLevel="workbench">
- </variable>
- </sourceProvider>
- </extension>
- <extension
- point="org.eclipse.ui.views">
- <view
- id="org.argeo.security.ui.userProfile"
- class="org.argeo.security.ui.views.UserProfile"
- icon="icons/user.gif"
- name="Profile"
- restorable="true">
- </view>
- <view
- id="org.argeo.security.ui.logView"
- class="org.argeo.eclipse.spring.SpringExtensionFactory"
- name="Log"
- icon="icons/log.gif"
- restorable="true">
- </view>
- <view
- id="org.argeo.security.ui.adminLogView"
- class="org.argeo.eclipse.spring.SpringExtensionFactory"
- name="Admin Log"
- icon="icons/adminLog.gif"
- restorable="true">
- </view>
- </extension>
- <extension
- point="org.eclipse.ui.perspectives">
- <perspective
- class="org.argeo.security.ui.UserHomePerspective"
- icon="icons/home.gif"
- id="org.argeo.security.ui.userHomePerspective"
- name="Home">
- </perspective>
- <perspective
- class="org.argeo.security.ui.MaintenancePerspective"
- icon="icons/maintenance.gif"
- id="org.argeo.security.ui.adminMaintenancePerspective"
- name="Maintenance">
- </perspective>
- </extension>
- <extension
- point="org.eclipse.ui.activities">
- <activity
- description="Authenticated users"
- id="org.argeo.security.ui.userActivity"
- name="User">
- <enabledWhen>
- <with variable="roles">
- <iterate ifEmpty="false" operator="or">
- <equals value="cn=user,ou=roles,ou=node" />
- </iterate>
- </with>
- </enabledWhen>
- </activity>
- <activity
- description="Admins"
- id="org.argeo.security.ui.adminActivity"
- name="Admin">
- <enabledWhen>
- <with variable="roles">
- <iterate ifEmpty="false" operator="or">
- <equals value="cn=admin,ou=roles,ou=node" />
- </iterate>
- </with>
- </enabledWhen>
- </activity>
- <activity
- description="User Admins"
- id="org.argeo.security.ui.userAdminActivity"
- name="User Admin">
- <enabledWhen>
- <with variable="roles">
- <iterate ifEmpty="false" operator="or">
- <equals value="cn=userAdmin,ou=roles,ou=node" />
- </iterate>
- </with>
- </enabledWhen>
- </activity>
- <activity
- description="Group Admins"
- id="org.argeo.security.ui.groupAdminActivity"
- name="User Admin">
- <enabledWhen>
- <with variable="roles">
- <iterate ifEmpty="false" operator="or">
- <equals value="cn=groupAdmin,ou=roles,ou=node" />
- </iterate>
- </with>
- </enabledWhen>
- </activity>
- <activity
- description="Non admins"
- id="org.argeo.security.ui.notAdminActivity"
- name="Not Admin">
- <enabledWhen>
- <not>
- <with variable="roles">
- <iterate ifEmpty="false" operator="or">
- <equals value="cn=admin,ou=roles,ou=node" />
- </iterate>
- </with>
- </not>
- </enabledWhen>
- </activity>
- <activity
- description="Non remote"
- id="org.argeo.security.ui.notRemoteActivity"
- name="NonRemote">
- <enabledWhen>
- <not>
- <with variable="roles">
- <iterate ifEmpty="false" operator="or">
- <equals value="ROLE_REMOTE" />
- </iterate>
- </with>
- </not>
- </enabledWhen>
- </activity>
- <activityPatternBinding
- activityId="org.argeo.security.ui.adminActivity"
- isEqualityPattern="true"
- pattern="org.argeo.security.ui/org.argeo.security.ui.adminMaintenancePerspective">
- </activityPatternBinding>
- <activityPatternBinding
- activityId="org.argeo.security.ui.adminActivity"
- isEqualityPattern="true"
- pattern="org.argeo.security.ui/org.argeo.security.ui.adminLogView">
- </activityPatternBinding>
- <activityPatternBinding
- activityId="org.argeo.security.ui.userActivity"
- isEqualityPattern="true"
- pattern="org.argeo.security.ui/org.argeo.security.ui.userHomePerspective">
- </activityPatternBinding>
- <activityPatternBinding
- activityId="org.argeo.security.ui.userActivity"
- isEqualityPattern="true"
- pattern="org.argeo.security.ui/org.argeo.security.ui.userProfile">
- </activityPatternBinding>
- </extension>
- </plugin>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.argeo.commons</groupId>
- <version>2.1.46-SNAPSHOT</version>
- <artifactId>argeo-commons</artifactId>
- <relativePath>..</relativePath>
- </parent>
- <artifactId>org.argeo.security.ui</artifactId>
- <name>CMS Workbench</name>
- <packaging>jar</packaging>
- <dependencies>
- <dependency>
- <groupId>org.argeo.commons</groupId>
- <artifactId>org.argeo.cms</artifactId>
- <version>2.1.46-SNAPSHOT</version>
- </dependency>
-<!-- <dependency> -->
-<!-- <groupId>org.argeo.commons</groupId> -->
-<!-- <artifactId>org.argeo.security.core</artifactId> -->
-<!-- <version>2.1.46-SNAPSHOT</version> -->
-<!-- </dependency> -->
- <dependency>
- <groupId>org.argeo.commons</groupId>
- <artifactId>org.argeo.eclipse.ui.workbench</artifactId>
- <version>2.1.46-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>org.argeo.commons</groupId>
- <artifactId>org.argeo.util</artifactId>
- <version>2.1.46-SNAPSHOT</version>
- </dependency>
- </dependencies>
-</project>
\ No newline at end of file
+++ /dev/null
-argeo.keyring.secreteKeyLength=256
\ No newline at end of file
+++ /dev/null
-/*
- * 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);
-
- }
-
-}
+++ /dev/null
-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<IStatus> privilegedAction = new PrivilegedAction<IStatus>() {
- 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
+++ /dev/null
-/*
- * 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<String, Set<String>> getCurrentState() {
- Map<String, Set<String>> stateMap = new HashMap<String, Set<String>>();
- 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
+++ /dev/null
-/*
- * 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> display = new InheritableThreadLocal<Display>() {
-
- @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<CallbackHandler> 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);
- // }
- }
-
- }
-}
+++ /dev/null
-/*
- * 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);
- }
-
-}
+++ /dev/null
-/*
- * 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());
- }
-
- }
-}
+++ /dev/null
-/*
- * 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;
- }
-}
+++ /dev/null
-/*
- * 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
- : "<anonymous>", 16)).append(' ');
- }
- };
- viewer.setContentProvider(logContentProvider);
- // viewer.setUseHashlookup(true);
- viewer.setInput(new ArrayList<String>());
-
- 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;
- }
-
-}
+++ /dev/null
-/*
- * 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<LogLine> lines;
-
- public LogContentProvider(TableViewer viewer) {
- this.viewer = viewer;
- start = System.currentTimeMillis();
- lines = new LinkedList<LogLine>();
- current = start;
- }
-
- public synchronized void dispose() {
- lines.clear();
- lines = null;
- }
-
- @SuppressWarnings("unchecked")
- public synchronized void inputChanged(Viewer viewer, Object oldInput,
- Object newInput) {
- List<String> lin = (List<String>) 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
+++ /dev/null
-/*
- * 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<String>());
-
- 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;
- }
-
-}
+++ /dev/null
-/*
- * 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<String>(CurrentUser.roles()).toArray();
- }
-
- public void dispose() {
- }
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- }
-
- }
-
-}