Logging management
authorMathieu Baudier <mbaudier@argeo.org>
Tue, 21 Feb 2012 18:13:05 +0000 (18:13 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Tue, 21 Feb 2012 18:13:05 +0000 (18:13 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@5109 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

21 files changed:
basic/runtime/org.argeo.basic.nodeps/src/main/java/org/argeo/ArgeoLogListener.java [new file with mode: 0644]
basic/runtime/org.argeo.basic.nodeps/src/main/java/org/argeo/util/tabular/TabularColumn.java
demo/argeo_node_rcp.properties
demo/log4j.properties
security/plugins/org.argeo.security.ui/META-INF/spring/monitor.xml [new file with mode: 0644]
security/plugins/org.argeo.security.ui/META-INF/spring/osgi.xml
security/plugins/org.argeo.security.ui/plugin.xml
security/plugins/org.argeo.security.ui/pom.xml
security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/UserHomePerspective.java
security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/LogContentProvider.java [new file with mode: 0644]
security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/LogView.java [new file with mode: 0644]
security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/UserProfile.java
security/runtime/org.argeo.security.core/pom.xml
security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/OsAuthenticationToken.java
security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/jcr/OsJcrAuthenticationProvider.java
security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/log4j/SecureLogger.java [new file with mode: 0644]
server/plugins/org.argeo.jcr.ui.explorer/META-INF/spring/commands.xml
server/plugins/org.argeo.jcr.ui.explorer/META-INF/spring/osgi.xml
server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/jackrabbit/JackrabbitRepositoryFactory.java
server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/JcrUtils.java
server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/tabular/JcrTabularWriter.java

diff --git a/basic/runtime/org.argeo.basic.nodeps/src/main/java/org/argeo/ArgeoLogListener.java b/basic/runtime/org.argeo.basic.nodeps/src/main/java/org/argeo/ArgeoLogListener.java
new file mode 100644 (file)
index 0000000..8c83db4
--- /dev/null
@@ -0,0 +1,24 @@
+package org.argeo;
+
+/** Framework agnostic interface for log notifications */
+public interface ArgeoLogListener {
+       /**
+        * Appends a log
+        * 
+        * @param username
+        *            authentified user, null for anonymous
+        * @param level
+        *            INFO, DEBUG, WARN, etc. (logging framework specific)
+        * @param category
+        *            hierarchy (logging framework specific)
+        * @param thread
+        *            name of the thread which logged this message
+        * @param msg
+        *            any object as long as its toString() method returns the
+        *            message
+        * @param the
+        *            exception in log4j ThrowableStrRep format
+        */
+       public void appendLog(String username, Long timestamp, String level,
+                       String category, String thread, Object msg, String[] exception);
+}
index ab3b74ba48f94e885b979a6e4f8c23631d1ecd9d..fda5f0b73a61bb5b89673b2e3b1f1295e4788206 100644 (file)
@@ -6,7 +6,7 @@ public class TabularColumn {
        /**
         * JCR types, see
         * http://www.day.com/maven/javax.jcr/javadocs/jcr-2.0/index.html
-        * ?javax/jcr/Property.html
+        * ?javax/jcr/PropertyType.html
         */
        private Integer type;
 
index cd705db2dd748ef3be6bcfeb994a54d0005ec802..d9eaf77d22a98d1b761e2c90bf0272962316814b 100644 (file)
@@ -5,8 +5,8 @@ org.argeo.node.repo.jackrabbit,\
 org.argeo.security.dao.os,\
 org.argeo.security.equinox,\
 
-org.argeo.security.ui.initialPerspective=org.argeo.osgi.ui.explorer.perspective
-
+#org.argeo.security.ui.initialPerspective=org.argeo.osgi.ui.explorer.perspective
+org.argeo.security.ui.initialPerspective==org.argeo.security.ui.userHomePerspective
 #argeo.node.repo.uri=http://localhost:7070/org.argeo.jcr.webapp/remoting/node
 
 log4j.configuration=file:../../log4j.properties
index 5be6d57f1cca36dc29c5757d01076bfa1ca97d19..15ce795ea4b95a8dd9f027a9f562065080d12244 100644 (file)
@@ -12,7 +12,7 @@ log4j.logger.org.apache.coyote=INFO
 log4j.logger.org.apache.directory.server=ERROR
 log4j.logger.org.apache.jackrabbit.core.query.lucene=ERROR
 
-log4j.logger.org.springframework.security.context=DEBUG
+#log4j.logger.org.springframework.security.context=DEBUG
 
 ## Appenders
 # console is set to be a ConsoleAppender.
diff --git a/security/plugins/org.argeo.security.ui/META-INF/spring/monitor.xml b/security/plugins/org.argeo.security.ui/META-INF/spring/monitor.xml
new file mode 100644 (file)
index 0000000..f2faeb2
--- /dev/null
@@ -0,0 +1,32 @@
+<?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-2.5.xsd">
+
+       <!-- Log4j appender singleton -->
+       <bean id="secureAppender" class="org.argeo.security.log4j.SecureLogger"
+               init-method="init" destroy-method="destroy">
+               <property name="listeners" ref="logListeners" />
+               <property name="configuration">
+                       <value><![CDATA[
+log4j.rootLogger=WARN, console
+
+## Levels
+log4j.logger.org.argeo=DEBUG
+log4j.logger.org.argeo.jackrabbit.remote.ExtendedDispatcherServlet=WARN
+log4j.logger.org.argeo.server.webextender.TomcatDeployer=WARN
+
+log4j.logger.org.apache.catalina=INFO
+log4j.logger.org.apache.coyote=INFO
+log4j.logger.org.apache.directory.server=ERROR
+log4j.logger.org.apache.jackrabbit.core.query.lucene=ERROR
+log4j.logger.org.apache.jackrabbit.core.config=ERROR
+
+log4j.appender.console=org.apache.log4j.ConsoleAppender
+log4j.appender.console.layout=org.apache.log4j.PatternLayout
+log4j.appender.console.layout.ConversionPattern=%d{yyMMdd HH:mm:ss} %-5p %m [%t] %c%n
+                       ]]></value>
+               </property>
+       </bean>
+</beans>
index 9e357a36d5af331af439e1b88d0ae2c432e72393..010fd3bba8ec3238631edf544518bb7d9aeb8cd5 100644 (file)
@@ -8,7 +8,11 @@
        http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"\r
        osgi:default-timeout="30000">\r
 \r
+       <!-- REFERENCES -->\r
        <reference id="userDetailsManager"\r
                interface="org.springframework.security.userdetails.UserDetailsManager"\r
                cardinality="0..1" />\r
+\r
+       <list id="logListeners" interface="org.argeo.ArgeoLogListener"\r
+               cardinality="0..N" />\r
 </beans:beans>
\ No newline at end of file
index 6f688635991cdd194a6f253151cd2f5d2014f80f..d016464e89a4aec3e4cba81157527a3a9d12cfa9 100644 (file)
             name="Profile"
             restorable="true">
       </view>
+      <view
+            class="org.argeo.security.ui.views.LogView"
+            id="org.argeo.security.ui.logView"
+            name="Log"
+            restorable="true">
+      </view>
    </extension>
    <extension
          point="org.eclipse.ui.perspectives">
index dd85204cc7febffde356d234102996bdb1bfb69c..f51404d8089344aa97133a1c95487d9c231b68d7 100644 (file)
@@ -1,4 +1,5 @@
-<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">
+<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.security</groupId>
@@ -33,6 +34,7 @@
                                                <Require-Bundle>org.eclipse.ui;resolution:=optional,org.eclipse.rap.ui;resolution:=optional,org.eclipse.core.runtime</Require-Bundle>
                                                <Import-Package>
                                                        org.argeo.eclipse.spring,
+                                                       org.apache.log4j;resolution:=optional,
                                                        *
                                                </Import-Package>
                                                <Export-Package>
@@ -85,5 +87,6 @@
                        <groupId>org.slf4j</groupId>
                        <artifactId>com.springsource.slf4j.org.apache.commons.logging</artifactId>
                </dependency>
+
        </dependencies>
 </project>
index 329c1ade1dd864879fa9f4fcf8b4246e121963fa..1ce7364e88395dab092292665ff608687251f4fd 100644 (file)
@@ -1,5 +1,6 @@
 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;
@@ -18,6 +19,10 @@ public class UserHomePerspective implements IPerspectiveFactory {
                                0.30f, editorArea);
                left.addView(UserProfile.ID);
                // left.addView(RolesView.ID);
+
+               IFolderLayout bottom = layout.createFolder("bottom",
+                               IPageLayout.BOTTOM, 0.30f, editorArea);
+               bottom.addView(LogView.ID);
        }
 
 }
diff --git a/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/LogContentProvider.java b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/LogContentProvider.java
new file mode 100644 (file)
index 0000000..5e28228
--- /dev/null
@@ -0,0 +1,81 @@
+package org.argeo.security.ui.views;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+
+import org.argeo.ArgeoLogListener;
+import org.eclipse.jface.viewers.ILazyContentProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+
+/** A content provider maintaing an array of lines */
+class LogContentProvider implements ILazyContentProvider, ArgeoLogListener {
+       private DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
+
+       private final TableViewer viewer;
+       private List<String> lines;
+
+       public LogContentProvider(TableViewer viewer) {
+               this.viewer = viewer;
+       }
+
+       public synchronized void dispose() {
+               lines = null;
+       }
+
+       @SuppressWarnings("unchecked")
+       public synchronized void inputChanged(Viewer viewer, Object oldInput,
+                       Object newInput) {
+               lines = (List<String>) newInput;
+               if (lines == null)
+                       return;
+               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();
+               StringBuffer buf = new StringBuffer("");
+               buf.append(dateFormat.format(new Date(timestamp))).append(" ");
+               buf.append(level).append(" ");
+               int count = 0;
+               String lastLine = null;
+               for (String line : message.split("\n")) {
+                       if (count == 0)
+                               lastLine = buf + line;
+                       else
+                               lastLine = line;
+                       lines.add(lastLine);
+                       count++;
+               }
+
+               if (exception != null) {
+                       for (String ste : exception) {
+                               lastLine = ste;
+                               lines.add(lastLine);
+                       }
+               }
+               final Object lastElement = lastLine;
+               viewer.getTable().getDisplay().asyncExec(new Runnable() {
+                       public void run() {
+                               viewer.setItemCount(lines.size());
+                               if (lastElement != null)
+                                       viewer.reveal(lastElement);
+                       }
+               });
+       }
+       // private class LogLine {
+       // private String message;
+       // }
+}
\ No newline at end of file
diff --git a/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/LogView.java b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/LogView.java
new file mode 100644 (file)
index 0000000..e494007
--- /dev/null
@@ -0,0 +1,54 @@
+package org.argeo.security.ui.views;
+
+import java.util.ArrayList;
+
+import org.argeo.ArgeoLogListener;
+import org.argeo.security.ui.SecurityUiPlugin;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.part.ViewPart;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * 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 ServiceRegistration serviceRegistration;
+
+       @Override
+       public void createPartControl(Composite parent) {
+               viewer = new TableViewer(parent, SWT.VIRTUAL);
+               viewer.setLabelProvider(new LabelProvider());
+               logContentProvider = new LogContentProvider(viewer);
+               serviceRegistration = getBundleContext().registerService(
+                               ArgeoLogListener.class.getName(), logContentProvider, null);
+               viewer.setContentProvider(logContentProvider);
+               viewer.setUseHashlookup(true);
+               viewer.setInput(new ArrayList<String>());
+       }
+
+       @Override
+       public void setFocus() {
+               viewer.getTable().setFocus();
+       }
+
+       @Override
+       public void dispose() {
+               if (serviceRegistration != null)
+                       serviceRegistration.unregister();
+       }
+
+       private BundleContext getBundleContext() {
+               return SecurityUiPlugin.getDefault().getBundle().getBundleContext();
+       }
+}
index f28ab57339cacb2337d7498a47889ecb606232d8..4d17b42c601a9e92a0c7080139eef1295292563b 100644 (file)
@@ -14,7 +14,6 @@ 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.swt.widgets.Text;
 import org.eclipse.ui.part.ViewPart;
 import org.springframework.security.Authentication;
 
index c4a2c98e06e3ae3f84e3a40d95a162e1e06309ac..a91656c9bba2805aa4d9a73a65ed6bb8191fb862 100644 (file)
                        <artifactId>com.springsource.slf4j.org.apache.commons.logging</artifactId>
                </dependency>
 
+               <dependency>
+                       <groupId>org.apache.log4j</groupId>
+                       <artifactId>com.springsource.org.apache.log4j</artifactId>
+                       <optional>true</optional>
+               </dependency>
+
                <!-- TEST -->
                <dependency>
                        <groupId>org.junit</groupId>
index 61ec539c610f08290ae093b423f8eb000ad735c6..8ba3f9fbca9dad3f8d74f6398a216e63b43f5414 100644 (file)
@@ -71,7 +71,11 @@ public class OsAuthenticationToken implements Authentication {
                this(null);
        }
 
+       /** @return the name, or null if not yet logged */
        public String getName() {
+               Subject subject = Subject.getSubject(AccessController.getContext());
+               if (subject == null)
+                       return null;
                return getUser().getName();
        }
 
index bccd1c616d67c1aed8fec1d55ed77f24e683bdb5..5307673ced6eb589e4e49ea822f5a05d57e29f74 100644 (file)
@@ -4,6 +4,7 @@ import javax.jcr.Node;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.security.Privilege;
 
 import org.argeo.ArgeoException;
 import org.argeo.jcr.JcrUtils;
@@ -17,10 +18,12 @@ public class OsJcrAuthenticationProvider extends OsAuthenticationProvider {
        private Repository repository;
        private String securityWorkspace = "security";
        private Session securitySession;
+       private Session nodeSession;
 
        public void init() {
                try {
                        securitySession = repository.login(securityWorkspace);
+                       nodeSession = repository.login();
                } catch (RepositoryException e) {
                        throw new ArgeoException("Cannot initialize", e);
                }
@@ -28,6 +31,7 @@ public class OsJcrAuthenticationProvider extends OsAuthenticationProvider {
 
        public void destroy() {
                JcrUtils.logoutQuietly(securitySession);
+               JcrUtils.logoutQuietly(nodeSession);
        }
 
        public Authentication authenticate(Authentication authentication)
@@ -40,8 +44,17 @@ public class OsJcrAuthenticationProvider extends OsAuthenticationProvider {
                        String username = System.getProperty("user.name");
                        Node userProfile = JcrUtils.createUserProfileIfNeeded(
                                        securitySession, username);
-
                        JcrUserDetails.checkAccountStatus(userProfile);
+
+                       // each user should have a writable area in the default workspace of
+                       // the node
+                       Node userNodeHome = JcrUtils.createUserHomeIfNeeded(nodeSession,
+                                       username);
+                       JcrUtils.addPrivilege(nodeSession, userNodeHome.getPath(),
+                                       username, Privilege.JCR_ALL);
+                       if (nodeSession.hasPendingChanges())
+                               nodeSession.save();
+
                        // user details
                        JcrUserDetails userDetails = new JcrUserDetails(userProfile, authen
                                        .getCredentials().toString(), getBaseAuthorities());
diff --git a/security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/log4j/SecureLogger.java b/security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/log4j/SecureLogger.java
new file mode 100644 (file)
index 0000000..70945f0
--- /dev/null
@@ -0,0 +1,177 @@
+/*
+ * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
+ *
+ * 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.log4j;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.log4j.AppenderSkeleton;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PropertyConfigurator;
+import org.apache.log4j.spi.LoggingEvent;
+import org.argeo.ArgeoException;
+import org.argeo.ArgeoLogListener;
+import org.springframework.security.Authentication;
+import org.springframework.security.context.SecurityContext;
+import org.springframework.security.context.SecurityContextHolder;
+import org.springframework.security.providers.anonymous.AnonymousAuthenticationToken;
+
+/** Not meant to be used directly in standard log4j config */
+public class SecureLogger {
+       private List<ArgeoLogListener> listeners;
+
+       private Boolean disabled = false;
+
+       private String level = null;
+
+       private Level log4jLevel = null;
+       // private Layout layout;
+
+       private Properties configuration;
+
+       private AppenderImpl appender;
+
+       /** Marker to prevent stack overflow */
+       private ThreadLocal<Boolean> dispatching = new ThreadLocal<Boolean>() {
+
+               @Override
+               protected Boolean initialValue() {
+                       return false;
+               }
+       };
+
+       public void init() {
+               try {
+                       // if (layout != null)
+                       // setLayout(layout);
+                       // else
+                       // setLayout(new PatternLayout(pattern));
+                       appender = new AppenderImpl();
+
+                       if (configuration != null)
+                               PropertyConfigurator.configure(configuration);
+
+                       Logger.getRootLogger().addAppender(appender);
+               } catch (Exception e) {
+                       throw new ArgeoException("Cannot initialize log4j");
+               }
+       }
+
+       public void destroy() throws Exception {
+               Logger.getRootLogger().removeAppender(appender);
+       }
+
+       // public void setLayout(Layout layout) {
+       // this.layout = layout;
+       // }
+
+       /** For development purpose, since using regular logging is not easy here */
+       static void stdOut(Object obj) {
+               System.out.println(obj);
+       }
+
+       // public void setPattern(String pattern) {
+       // this.pattern = pattern;
+       // }
+
+       public void setDisabled(Boolean disabled) {
+               this.disabled = disabled;
+       }
+
+       public void setLevel(String level) {
+               this.level = level;
+       }
+
+       public void setListeners(List<ArgeoLogListener> listeners) {
+               this.listeners = listeners;
+       }
+
+       public void setConfiguration(Properties configuration) {
+               this.configuration = configuration;
+       }
+
+       private class AppenderImpl extends AppenderSkeleton {
+               public boolean requiresLayout() {
+                       return false;
+               }
+
+               public void close() {
+               }
+
+               @Override
+               protected void append(LoggingEvent event) {
+                       if (disabled)
+                               return;
+
+                       if (dispatching.get())
+                               return;
+
+                       if (level != null && !level.trim().equals("")) {
+                               if (log4jLevel == null || !log4jLevel.toString().equals(level))
+                                       try {
+                                               log4jLevel = Level.toLevel(level);
+                                       } catch (Exception e) {
+                                               System.err
+                                                               .println("Log4j level could not be set for level '"
+                                                                               + level + "', resetting it to null.");
+                                               e.printStackTrace();
+                                               level = null;
+                                       }
+
+                               if (log4jLevel != null
+                                               && !event.getLevel().isGreaterOrEqual(log4jLevel)) {
+                                       return;
+                               }
+                       }
+
+                       try {
+                               Thread currentThread = Thread.currentThread();
+                               String username = null;
+
+                               // find username
+                               SecurityContext securityContext = SecurityContextHolder
+                                               .getContext();
+                               if (securityContext != null) {
+                                       Authentication authentication = securityContext
+                                                       .getAuthentication();
+                                       if (authentication != null) {
+                                               if (authentication instanceof AnonymousAuthenticationToken) {
+                                                       username = null;
+                                               } else {
+                                                       username = authentication.getName();
+                                               }
+                                       }
+                               }
+
+                               // Spring OSGi safe
+                               Iterator<ArgeoLogListener> it = listeners.iterator();
+                               while (it.hasNext()) {
+                                       ArgeoLogListener logListener = it.next();
+                                       logListener.appendLog(username, event.getTimeStamp(), event
+                                                       .getLevel().toString(), event.getLoggerName(),
+                                                       currentThread.getName(), event.getMessage(), event.getThrowableStrRep());
+                               }
+                       } catch (Exception e) {
+                               stdOut("Cannot process logging event");
+                               e.printStackTrace();
+                       }
+               }
+
+       }
+}
index 96ad94dbd98d25eb98a42e7253ee761297d11d76..2bdd659e5cd7954c8d9df9ace80b7f26352bab5c 100644 (file)
@@ -21,7 +21,7 @@
        </bean>
 
        <bean id="addRemoteRepository" class="org.argeo.jcr.ui.explorer.commands.AddRemoteRepository">
-               <property name="repositoryFactory" ref="repositoryRegister" />
+               <property name="repositoryFactory" ref="repositoryFactory" />
                <property name="bundleContext" ref="bundleContext" />
                <property name="keyring" ref="jcrKeyring" />
        </bean>
index 4708847a2559fe5293504cbe2627cdda8979065a..7c415e0cccdbcfb477e1828517b4d91e3a9aad55 100644 (file)
@@ -16,6 +16,7 @@
 \r
        <reference id="nodeRepository" interface="javax.jcr.Repository"\r
                filter="(argeo.jcr.repository.alias=node)" />\r
+       <reference id="repositoryFactory" interface="javax.jcr.RepositoryFactory" />\r
 \r
        <reference id="defaultCallbackHandler" interface="javax.security.auth.callback.CallbackHandler" />\r
 \r
index 65bdf29393478ae0b1b99371ed441e54288e9762..d98448c7c266e3955e2da93f5729c7e5875bff53 100644 (file)
@@ -39,7 +39,7 @@ public class JackrabbitRepositoryFactory extends DefaultRepositoryFactory
                else if (parameters.containsKey(JcrUtils.REPOSITORY_URI))
                        uri = parameters.get(JcrUtils.REPOSITORY_URI).toString();
 
-               if (uri == null)
+               if (uri != null)
                        repository = createRemoteRepository(uri);
 
                if (parameters.containsKey(JCR_REPOSITORY_ALIAS)) {
index 3aa6493786976dad6923ced7b7f0a9a64a0666ab..7d8b6565e652d5abdbdf3843ff5bbc66f012bd27 100644 (file)
@@ -64,6 +64,7 @@ import org.apache.commons.io.IOUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.argeo.ArgeoException;
+import org.argeo.util.security.SimplePrincipal;
 
 /** Utility methods to simplify common JCR operations. */
 public class JcrUtils implements ArgeoJcrConstants {
@@ -1367,6 +1368,19 @@ public class JcrUtils implements ArgeoJcrConstants {
        /*
         * SECURITY
         */
+
+       /**
+        * Convenience method for adding a single privilege to a principal (user or
+        * role), typically jcr:all
+        */
+       public static void addPrivilege(Session session, String path,
+                       String principal, String privilege) throws RepositoryException {
+               List<Privilege> privileges = new ArrayList<Privilege>();
+               privileges.add(session.getAccessControlManager().privilegeFromName(
+                               privilege));
+               addPrivileges(session, path, new SimplePrincipal(principal), privileges);
+       }
+
        /**
         * Add privileges on a path to a {@link Principal}. The path must already
         * exist.
index 0727b784e617507dd8e2dc171d1b671371fab91a..55a0a312f5ece0b753d44b8585dd64d526d8dd56 100644 (file)
@@ -24,11 +24,13 @@ public class JcrTabularWriter implements TabularWriter {
        private Node contentNode;
        private ByteArrayOutputStream out;
        private CsvWriter csvWriter;
+       private final List<TabularColumn> columns;
 
        /** Creates a table node */
        public JcrTabularWriter(Node tableNode, List<TabularColumn> columns,
                        String contentNodeType) {
                try {
+                       this.columns = columns;
                        for (TabularColumn column : columns) {
                                String normalized = JcrUtils.replaceInvalidChars(column
                                                .getName());