--- /dev/null
+package org.argeo;
+
+/** The current operating system. */
+public class OperatingSystem {
+ public final static int NIX = 1;
+ public final static int WINDOWS = 2;
+ public final static int SOLARIS = 3;
+
+ public final static int os;
+ static {
+ String osName = System.getProperty("os.name");
+ if (osName.startsWith("Win"))
+ os = WINDOWS;
+ else if (osName.startsWith("Solaris"))
+ os = SOLARIS;
+ else
+ os = NIX;
+ }
+
+}
<packaging>pom</packaging>
<name>Commons OSGi Minimal Jackrabbit</name>
<dependencies>
-
<dependency>
- <groupId>org.argeo.osgi</groupId>
+ <groupId>org.argeo.commons.osgi</groupId>
<artifactId>org.argeo.osgi.dep.stdruntime</artifactId>
<version>0.3.2-SNAPSHOT</version>
<type>pom</type>
</dependency>
-
<!-- Jackrabbit -->
<dependency>
<groupId>org.argeo.dep.osgi</groupId>
<artifactId>org.argeo.dep.osgi.jackrabbit</artifactId>
</dependency>
+
+ <!-- Database -->
<dependency>
- <groupId>org.argeo.commons.server</groupId>
- <artifactId>org.argeo.server.tika.jackrabbit</artifactId>
- <version>${version.argeo-commons}</version>
- </dependency>
- <dependency>
- <groupId>org.argeo.commons.server</groupId>
- <artifactId>org.argeo.server.ext.jackrabbit</artifactId>
- <version>${version.argeo-commons}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.xalan</groupId>
- <artifactId>com.springsource.org.apache.xalan</artifactId>
+ <groupId>com.h2database</groupId>
+ <artifactId>com.springsource.org.h2</artifactId>
</dependency>
<!-- Transitive dependencies -->
<type>pom</type>
</dependency>
+ <!-- Javax -->
+ <dependency>
+ <groupId>javax.xml.stream</groupId>
+ <artifactId>com.springsource.javax.xml.stream</artifactId>
+ </dependency>
+
<!-- Commons -->
<dependency>
<groupId>org.apache.commons</groupId>
</dependency>
<!-- For webdav -->
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>org.springframework.web.servlet</artifactId>
- </dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>com.springsource.javax.servlet</artifactId>
<groupId>org.argeo.dep.osgi</groupId>
<artifactId>org.argeo.dep.osgi.tika</artifactId>
</dependency>
- <dependency>
- <groupId>org.argeo.dep.osgi</groupId>
- <artifactId>org.argeo.dep.osgi.pdfbox</artifactId>
- </dependency>
- <dependency>
- <groupId>org.argeo.dep.osgi</groupId>
- <artifactId>org.argeo.dep.osgi.poi</artifactId>
- </dependency>
- <dependency>
- <groupId>org.argeo.dep.osgi</groupId>
- <artifactId>org.argeo.dep.osgi.boilerpipe</artifactId>
- </dependency>
- <dependency>
- <groupId>org.argeo.dep.osgi</groupId>
- <artifactId>org.argeo.dep.osgi.bouncycastle.jdk15</artifactId>
- </dependency>
- <dependency>
- <groupId>org.argeo.dep.osgi</groupId>
- <artifactId>org.argeo.dep.osgi.drewnoakes.metadata_extractor</artifactId>
- </dependency>
- <dependency>
- <groupId>org.argeo.dep.osgi</groupId>
- <artifactId>org.argeo.dep.osgi.netcdf</artifactId>
- </dependency>
- <dependency>
- <groupId>org.argeo.dep.osgi</groupId>
- <artifactId>org.argeo.dep.osgi.tagsoup</artifactId>
- </dependency>
-
- <!-- Logback <dependency> <groupId>ch.qos.logback</groupId> <artifactId>com.springsource.ch.qos.logback.classic</artifactId>
- </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>com.springsource.ch.qos.logback.core</artifactId>
- </dependency> -->
-
<!-- Required for OSGi completion -->
- <dependency>
- <groupId>net.sourceforge.nekohtml</groupId>
- <artifactId>com.springsource.org.cyberneko.html</artifactId>
- </dependency>
- <dependency>
- <groupId>javax.mail</groupId>
- <artifactId>com.springsource.javax.mail</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.xmlbeans</groupId>
- <artifactId>com.springsource.org.apache.xmlbeans</artifactId>
- </dependency>
<dependency>
<groupId>org.dom4j</groupId>
<artifactId>com.springsource.org.dom4j</artifactId>
<groupId>org.jdom</groupId>
<artifactId>com.springsource.org.jdom</artifactId>
</dependency>
- <dependency>
- <groupId>com.sun.syndication</groupId>
- <artifactId>com.springsource.com.sun.syndication</artifactId>
- </dependency>
<dependency>
<groupId>org.objectweb.asm</groupId>
<artifactId>com.springsource.org.objectweb.asm</artifactId>
<groupId>org.xmlpull</groupId>
<artifactId>com.springsource.org.xmlpull</artifactId>
</dependency>
- <dependency>
- <groupId>org.argeo.commons.server</groupId>
- <artifactId>org.argeo.server.dep.javax</artifactId>
- <version>0.3.2-SNAPSHOT</version>
- <type>pom</type>
- </dependency>
- <dependency>
- <groupId>org.apache.xmlcommons</groupId>
- <artifactId>com.springsource.org.apache.xmlcommons</artifactId>
- </dependency>
-
</dependencies>
</project>
\ No newline at end of file
<version>0.3.2-SNAPSHOT</version>
<type>pom</type>
</dependency>
- <!-- Spring OSGi -->
- <dependency>
- <groupId>org.springframework.osgi</groupId>
- <artifactId>org.springframework.osgi.core</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.osgi</groupId>
- <artifactId>org.springframework.osgi.extender</artifactId>
- </dependency>
</dependencies>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
-<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</groupId>
<packaging>pom</packaging>
<modules>
<module>org.argeo.osgi.dep.stdruntime</module>
+ <module>org.argeo.osgi.dep.jackrabbit</module>
</modules>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.argeo.maven.plugins</groupId>
+ <artifactId>maven-argeo-osgi-plugin</artifactId>
+ <version>${version.maven-argeo-osgi}</version>
+ <executions>
+ <execution>
+ <id>check-osgi</id>
+ <phase>test</phase>
+ <goals>
+ <goal>equinox</goal>
+ </goals>
+ <configuration>
+ <onlyCheck>true</onlyCheck>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <!-- OSGi test -->
+ <dependency>
+ <groupId>org.argeo.commons.osgi</groupId>
+ <artifactId>org.argeo.osgi.boot</artifactId>
+ <version>0.3.2-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
</project>
\ No newline at end of file
<packaging>pom</packaging>
<properties>
<developmentCycle>0.3</developmentCycle>
- <version.argeo-distribution>1.1.3</version.argeo-distribution>
+ <version.argeo-distribution>1.1.4-SNAPSHOT</version.argeo-distribution>
<version.argeo-commons>0.3.2-SNAPSHOT</version.argeo-commons>
<version.argeo-ria>0.12.5</version.argeo-ria>
<version.equinox>3.6.2</version.equinox>
<site.repoBase>file:///srv/projects/www/commons/site</site.repoBase>
<site.urlBase>http://projects.argeo.org/commons/site</site.urlBase>
</properties>
+ <modules>
+ <module>basic</module>
+ <module>osgi</module>
+ <module>server</module>
+ <module>eclipse</module>
+ <module>security</module>
+ <module>gis</module>
+ <module>sandbox</module>
+ </modules>
<url>${site.urlBase}/${developmentCycle}</url>
<scm>
<connection>scm:svn:https://svn.argeo.org/commons/trunk</connection>
</roles>
</developer>
</developers>
- <modules>
- <module>basic</module>
- <module>osgi</module>
- <module>server</module>
- <module>eclipse</module>
- <module>security</module>
- <module>gis</module>
- <module>sandbox</module>
- </modules>
<build>
<pluginManagement>
<plugins>
-<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>
<version>0.3.2-SNAPSHOT</version>
<type>pom</type>
</dependency>
- <dependency>
- <groupId>org.apache.xmlcommons</groupId>
- <artifactId>com.springsource.org.apache.xmlcommons</artifactId>
- </dependency>
- <!-- Security services -->
+ <!-- Argeo Security -->
<dependency>
<groupId>org.argeo.commons.security</groupId>
<artifactId>org.argeo.security.core</artifactId>
<artifactId>org.argeo.security.services</artifactId>
<version>${version.argeo-commons}</version>
</dependency>
+ <dependency>
+ <groupId>org.argeo.commons.security</groupId>
+ <artifactId>org.argeo.security.mvc</artifactId>
+ <version>${version.argeo-commons}</version>
+ </dependency>
<dependency>
<groupId>org.argeo.commons.security</groupId>
<artifactId>org.argeo.security.dao.ldap</artifactId>
<version>${version.argeo-commons}</version>
</dependency>
- <!-- LDAP server -->
+ <!-- Xerces and Xalan -->
<dependency>
- <groupId>org.argeo.commons.security</groupId>
- <artifactId>org.argeo.security.dep.ads</artifactId>
- <version>0.3.2-SNAPSHOT</version>
- <type>pom</type>
+ <groupId>org.apache.xmlcommons</groupId>
+ <artifactId>com.springsource.org.apache.xmlcommons</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.xalan</groupId>
+ <artifactId>com.springsource.org.apache.xalan</artifactId>
</dependency>
+
+ <!-- Spring -->
+ <dependency>
+ <groupId>org.springframework.osgi</groupId>
+ <artifactId>org.springframework.osgi.web.extender</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.osgi</groupId>
+ <artifactId>org.springframework.osgi.web</artifactId>
+ </dependency>
+
<!-- Tomcat -->
<dependency>
<groupId>org.argeo.commons.server</groupId>
<artifactId>org.argeo.server.webextender</artifactId>
<version>0.3.2-SNAPSHOT</version>
</dependency>
- <dependency>
- <groupId>org.springframework.osgi</groupId>
- <artifactId>org.springframework.osgi.web.extender</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.osgi</groupId>
- <artifactId>org.springframework.osgi.web</artifactId>
- </dependency>
<!-- Active MQ -->
<dependency>
<groupId>org.argeo.commons.server</groupId>
<artifactId>org.argeo.server.jcr.mvc</artifactId>
<version>0.3.2-SNAPSHOT</version>
</dependency>
- <dependency>
- <groupId>org.argeo.commons.server</groupId>
- <artifactId>org.argeo.server.dep.jackrabbit.server</artifactId>
- <version>0.3.2-SNAPSHOT</version>
- <type>pom</type>
- </dependency>
<dependency>
<groupId>org.argeo.commons.server</groupId>
<artifactId>org.argeo.jackrabbit.webapp</artifactId>
<groupId>org.postgresql</groupId>
<artifactId>com.springsource.org.postgresql.jdbc3</artifactId>
</dependency>
+ <!-- LDAP server (target platform generation only) -->
+ <dependency>
+ <groupId>org.argeo.commons.security</groupId>
+ <artifactId>org.argeo.security.dep.ads</artifactId>
+ <version>0.3.2-SNAPSHOT</version>
+ <type>pom</type>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
cardinality="0..1">\r
<listener ref="jcrAuthenticationProvider" bind-method="register"\r
unbind-method="unregister" />\r
+<!-- <listener ref="osJcrAuthenticationProvider" bind-method="register" -->\r
+<!-- unbind-method="unregister" /> -->\r
</reference>\r
+<!-- <reference id="systemExecutor" interface="org.argeo.security.SystemExecutionService" /> -->\r
\r
<!-- SERVICES -->\r
<service ref="jcrAuthenticationProvider"\r
interface="org.springframework.security.providers.AuthenticationProvider" />\r
- <service ref="jcrCurrentUserDao" interface="org.argeo.security.CurrentUserDao" />\r
-\r
+<!-- <service ref="osJcrAuthenticationProvider" -->\r
+<!-- interface="org.springframework.security.providers.AuthenticationProvider" /> -->\r
</beans:beans>
\ No newline at end of file
<bean id="jcrAuthenticationProvider"
class="org.argeo.security.jackrabbit.providers.JackrabbitAuthenticationProvider" />
- <bean id="jcrCurrentUserDao" class="org.argeo.security.jcr.CurrentUserDaoJcr" />
+<!-- <bean id="osJcrAuthenticationProvider" class="org.argeo.security.jcr.OsJcrAuthenticationProvider"> -->
+<!-- <property name="systemExecutor" ref="systemExecutor" /> -->
+<!-- </bean> -->
</beans>
\ No newline at end of file
<bean class="org.springframework.security.adapters.AuthByAdapterProvider">
<property name="key" value="${argeo.security.systemKey}" />
</bean>
+ <bean class="org.argeo.security.core.OsAuthenticationProvider" />
<bean
class="org.springframework.security.providers.anonymous.AnonymousAuthenticationProvider">
<property name="key" value="${argeo.security.systemKey}" />
scope="prototype">
<property name="authenticationManager" ref="authenticationManager" />
</bean>
+
+ <bean id="osSpringLoginModule" class="org.argeo.security.equinox.OsSpringLoginModule"
+ scope="prototype">
+ <property name="authenticationManager" ref="authenticationManager" />
+ </bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
- <extension
- id="springSecurityContextLoginModule"
- point="org.eclipse.equinox.security.loginModule">
- <loginModule
- class="org.springframework.security.providers.jaas.SecurityContextLoginModule"
- description="Spring Security Context (provided by Spring)">
- </loginModule>
- </extension>
- <extension id="unixLoginModule"
- name="Unix Login Module"
- point="org.eclipse.equinox.security.loginModule">
- <loginModule
- class="com.sun.security.auth.module.UnixLoginModule"
- description="Unix Login Module">
- </loginModule>
- </extension>
- <extension
- id="springLoginModule"
- point="org.eclipse.equinox.security.loginModule"
- name="Spring Login Module">
- <loginModule
- class="org.argeo.eclipse.spring.SpringExtensionFactory"
- description="Spring Login Module">
- </loginModule>
+ <!-- Argeo -->
+ <extension id="springLoginModule" name="Argeo Spring" point="org.eclipse.equinox.security.loginModule">
+ <loginModule class="org.argeo.eclipse.spring.SpringExtensionFactory" description="Argeo Spring Login Module"/>
</extension>
+ <extension id="osSpringLoginModule" name="Argeo Spring OS" point="org.eclipse.equinox.security.loginModule">
+ <loginModule class="org.argeo.eclipse.spring.SpringExtensionFactory" description="Argeo Spring OS Login Module"/>
+ </extension>
+
+ <!-- Java -->
+ <extension id="unixLoginModule" name="UNIX" point="org.eclipse.equinox.security.loginModule">
+ <loginModule class="com.sun.security.auth.module.UnixLoginModule" description="UNIX Login Module"/>
+ </extension>
+
+ <extension id="keyStoreLoginModule" name="Keystore" point="org.eclipse.equinox.security.loginModule">
+ <loginModule class="com.sun.security.auth.module.KeyStoreLoginModule" description="Keystore Login Module"/>
+ </extension>
+
+ <extension id="ntLoginModule" name="Windows" point="org.eclipse.equinox.security.loginModule">
+ <loginModule class="com.sun.security.auth.module.NTLoginModule" description="Windows Login Module"/>
+ </extension>
+
+ <!-- Spring -->
+ <extension id="springSecurityContextLoginModule" name="Spring" point="org.eclipse.equinox.security.loginModule">
+ <loginModule class="org.springframework.security.providers.jaas.SecurityContextLoginModule" description="Raw Spring Login Module"/>
+ </extension>
</plugin>
--- /dev/null
+package org.argeo.security.equinox;
+
+import java.util.Map;
+
+import javax.security.auth.Subject;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.login.LoginException;
+
+import org.argeo.security.OsAuthenticationToken;
+import org.springframework.security.Authentication;
+import org.springframework.security.AuthenticationManager;
+import org.springframework.security.context.SecurityContextHolder;
+import org.springframework.security.providers.jaas.SecurityContextLoginModule;
+
+/** Login module which caches one subject per thread. */
+public class OsSpringLoginModule extends SecurityContextLoginModule {
+ // private final static Log log =
+ // LogFactory.getLog(OsSpringLoginModule.class);
+
+ private AuthenticationManager authenticationManager;
+
+ private Subject subject;
+
+ public OsSpringLoginModule() {
+
+ }
+
+ @SuppressWarnings("rawtypes")
+ public void initialize(Subject subject, CallbackHandler callbackHandler,
+ Map sharedState, Map options) {
+ super.initialize(subject, callbackHandler, sharedState, options);
+ this.subject = subject;
+ }
+
+ public boolean login() throws LoginException {
+ // thread already logged in
+ if (SecurityContextHolder.getContext().getAuthentication() != null)
+ return super.login();
+
+ OsAuthenticationToken oat = new OsAuthenticationToken();
+ Authentication authentication = authenticationManager.authenticate(oat);
+ registerAuthentication(authentication);
+ return super.login();
+ }
+
+ @Override
+ public boolean logout() throws LoginException {
+ subject.getPrincipals().clear();
+ return super.logout();
+ }
+
+ /**
+ * Register an {@link Authentication} in the security context.
+ *
+ * @param authentication
+ * has to implement {@link Authentication}.
+ */
+ protected void registerAuthentication(Object authentication) {
+ SecurityContextHolder.getContext().setAuthentication(
+ (Authentication) authentication);
+ }
+
+ public void setAuthenticationManager(
+ AuthenticationManager authenticationManager) {
+ this.authenticationManager = authenticationManager;
+ }
+}
import org.argeo.security.SiteAuthenticationToken;
import org.springframework.security.Authentication;
import org.springframework.security.AuthenticationManager;
-import org.springframework.security.BadCredentialsException;
import org.springframework.security.context.SecurityContextHolder;
import org.springframework.security.providers.jaas.SecurityContextLoginModule;
SiteAuthenticationToken credentials = new SiteAuthenticationToken(
username, password, null, workspace);
- try {
- Authentication authentication = authenticationManager
- .authenticate(credentials);
- registerAuthentication(authentication);
- boolean res = super.login();
- return res;
- } catch (BadCredentialsException bce) {
- throw bce;
- } catch (Exception e) {
- LoginException loginException = new LoginException(
- "Bad credentials");
- loginException.initCause(e);
- throw loginException;
- }
+ // try {
+ Authentication authentication = authenticationManager
+ .authenticate(credentials);
+ registerAuthentication(authentication);
+ boolean res = super.login();
+ return res;
+ // } catch (BadCredentialsException bce) {
+ // throw bce;
+ // } catch (LoginException e) {
+ // // LoginException loginException = new LoginException(
+ // // "Bad credentials");
+ // // loginException.initCause(e);
+ // throw e;
+ // }
}
@Override
-UNIX {
- org.eclipse.equinox.security.auth.module.ExtensionLoginModule sufficient
+NIX {
+ org.eclipse.equinox.security.auth.module.ExtensionLoginModule requisite
extensionId="org.argeo.security.equinox.unixLoginModule";
+ org.eclipse.equinox.security.auth.module.ExtensionLoginModule required
+ extensionId="org.argeo.security.equinox.osSpringLoginModule";
};
-SPRING {
- org.eclipse.equinox.security.auth.module.ExtensionLoginModule sufficient
- extensionId="org.argeo.security.equinox.springLoginModule";
+WINDOWS {
+ org.eclipse.equinox.security.auth.module.ExtensionLoginModule requisite
+ extensionId="org.argeo.security.equinox.ntLoginModule";
+ org.eclipse.equinox.security.auth.module.ExtensionLoginModule required
+ extensionId="org.argeo.security.equinox.osSpringLoginModule";
};
-
-SPRING_SECURITY_CONTEXT {
- org.eclipse.equinox.security.auth.module.ExtensionLoginModule sufficient
- extensionId="org.argeo.security.equinox.springSecurityContextLoginModule";
-};
\ No newline at end of file
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.argeo.eclipse.ui.dialogs.Error;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
+import org.argeo.OperatingSystem;
import org.eclipse.equinox.app.IApplication;
import org.eclipse.equinox.app.IApplicationContext;
-import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.equinox.security.auth.ILoginContext;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.application.WorkbenchAdvisor;
/**
- * Common base class for authenticated access to the Eclipse UI framework (RAP
- * and RCP)
+ * RCP workbench initialization
*/
public abstract class AbstractSecureApplication implements IApplication {
private static final Log log = LogFactory
.getLog(AbstractSecureApplication.class);
- protected abstract WorkbenchAdvisor createWorkbenchAdvisor();
+ protected WorkbenchAdvisor createWorkbenchAdvisor(String username) {
+ return new SecureWorkbenchAdvisor(username);
+ }
public Object start(IApplicationContext context) throws Exception {
-
- Integer returnCode = null;
- Display display = PlatformUI.createDisplay();
+ // wait for the system to be initialized
try {
- Subject subject = null;
- Boolean retry = true;
- while (retry) {
- try {
- SecureApplicationActivator.getLoginContext().login();
- subject = SecureApplicationActivator.getLoginContext()
- .getSubject();
- retry = false;
- } catch (LoginException e) {
- Error.show("Cannot login", e);
- retry = true;
- } catch (Exception e) {
- Error.show("Unexpected exception while trying to login", e);
- retry = false;
- }
- }
+ Thread.sleep(3000);
+ } catch (Exception e2) {
+ // silent
+ }
+
+ // choose login context
+ final ILoginContext loginContext;
+ if (OperatingSystem.os == OperatingSystem.WINDOWS)
+ loginContext = SecureApplicationActivator
+ .createLoginContext(SecureApplicationActivator.CONTEXT_WINDOWS);
+ else
+ loginContext = SecureApplicationActivator
+ .createLoginContext(SecureApplicationActivator.CONTEXT_NIX);
- if (subject == null) {
- // IStatus status = new Status(IStatus.ERROR,
- // "org.argeo.security.application", "Login is mandatory",
- // loginException);
- // ErrorDialog.openError(null, "Error", "Shutdown...", status);
- // return status.getSeverity();
+ final Display display = PlatformUI.createDisplay();
- // TODO: log as anonymous
+ Subject subject = null;
+ try {
+ loginContext.login();
+ subject = loginContext.getSubject();
+ } catch (LoginException e) {
+ log.error("Error when logging in.", e);
+ display.dispose();
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException e1) {
+ // silent
}
+ return null;
+ }
- if (subject != null) {
- returnCode = (Integer) Subject.doAs(subject,
- getRunAction(display));
- SecureApplicationActivator.getLoginContext().logout();
- return processReturnCode(returnCode);
- } else {
- return -1;
+ // identify after successful login
+ if (log.isDebugEnabled())
+ log.debug("subject=" + subject);
+ final String username = subject.getPrincipals().iterator().next()
+ .getName();
+ if (log.isDebugEnabled())
+ log.debug(username + " logged in");
+ display.disposeExec(new Runnable() {
+ public void run() {
+ log.debug("Display disposed");
+ logout(loginContext, username);
}
+ });
+
+ try {
+ PrivilegedAction<?> privilegedAction = new PrivilegedAction<Object>() {
+ public Object run() {
+ int result = PlatformUI.createAndRunWorkbench(display,
+ createWorkbenchAdvisor(username));
+ return new Integer(result);
+ }
+ };
+
+ Integer returnCode = (Integer) Subject.doAs(subject,
+ privilegedAction);
+ logout(loginContext, username);
+ return processReturnCode(returnCode);
} catch (Exception e) {
- // e.printStackTrace();
- IStatus status = new Status(IStatus.ERROR,
- "org.argeo.security.rcp", "Login failed", e);
- ErrorDialog.openError(null, "Error", "Shutdown...", status);
- return returnCode;
+ if (subject != null)
+ logout(loginContext, username);
+ log.error("Unexpected error", e);
} finally {
display.dispose();
}
+ return null;
}
protected Integer processReturnCode(Integer returnCode) {
- return returnCode;
+ if (returnCode == PlatformUI.RETURN_RESTART)
+ return IApplication.EXIT_RESTART;
+ else
+ return IApplication.EXIT_OK;
}
- @SuppressWarnings("rawtypes")
- private PrivilegedAction getRunAction(final Display display) {
- return new PrivilegedAction() {
-
- public Object run() {
- int result = createAndRunWorkbench(display);
- return new Integer(result);
- }
- };
- }
-
- protected Integer createAndRunWorkbench(Display display) {
- return PlatformUI.createAndRunWorkbench(display,
- createWorkbenchAdvisor());
+ static void logout(ILoginContext secureContext, String username) {
+ try {
+ secureContext.logout();
+ log.info("Logged out " + (username != null ? username : "")
+ + " (THREAD=" + Thread.currentThread().getId() + ")");
+ } catch (LoginException e) {
+ log.error("Erorr when logging out", e);
+ }
}
public void stop() {
if (log.isDebugEnabled())
log.debug("workbench stopped");
- // String username = CurrentUser.getUsername();
- // if (log.isDebugEnabled())
- // log.debug("workbench stopped, logged in as " + username);
-
}
}
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
+/** Activator able to create {@link ILoginContext} */
public class SecureApplicationActivator implements BundleActivator {
- public final static String CONTEXT_SPRING = "SPRING";
+ public final static String CONTEXT_NIX = "NIX";
+ public final static String CONTEXT_WINDOWS = "WINDOWS";
private static final String JAAS_CONFIG_FILE = "/META-INF/jaas_default.txt";
- private static ILoginContext loginContext = null;
+ private static BundleContext bundleContext;
public void start(BundleContext bundleContext) throws Exception {
- URL configUrl = bundleContext.getBundle().getEntry(JAAS_CONFIG_FILE);
- loginContext = LoginContextFactory.createContext(CONTEXT_SPRING,
- configUrl);
+ SecureApplicationActivator.bundleContext = bundleContext;
}
public void stop(BundleContext context) throws Exception {
}
- static ILoginContext getLoginContext() {
- return loginContext;
+ static ILoginContext createLoginContext(String context) {
+ URL configUrl = bundleContext.getBundle().getEntry(JAAS_CONFIG_FILE);
+ return LoginContextFactory.createContext(context, configUrl);
}
}
package org.argeo.security.ui.rcp;
-import org.eclipse.equinox.app.IApplication;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.application.WorkbenchAdvisor;
public class SecureRcp extends AbstractSecureApplication {
-
- @Override
- protected WorkbenchAdvisor createWorkbenchAdvisor() {
- return new SecureWorkbenchAdvisor();
- }
-
- protected Integer processReturnCode(Integer returnCode) {
- if (returnCode == PlatformUI.RETURN_RESTART)
- return IApplication.EXIT_RESTART;
- else
- return IApplication.EXIT_OK;
- }
-
}
import org.eclipse.ui.application.WorkbenchWindowAdvisor;
public class SecureWorkbenchAdvisor extends WorkbenchAdvisor {
-
static final String DEFAULT_PERSPECTIVE_ID = "org.argeo.security.ui.adminSecurityPerspective"; //$NON-NLS-1$
-
public final static String INITIAL_PERSPECTIVE_PROPERTY = "org.argeo.security.ui.initialPerspective";
+
+ private final String username;
private String initialPerspective = System.getProperty(
INITIAL_PERSPECTIVE_PROPERTY, DEFAULT_PERSPECTIVE_ID);
+ public SecureWorkbenchAdvisor(String username) {
+ super();
+ this.username = username;
+ }
+
public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(
IWorkbenchWindowConfigurer configurer) {
- return new SecureWorkbenchWindowAdvisor(configurer);
+ return new SecureWorkbenchWindowAdvisor(configurer, username);
}
public String getInitialWindowPerspectiveId() {
import org.eclipse.ui.application.WorkbenchWindowAdvisor;
public class SecureWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
+ private final String username;
- public SecureWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
+ public SecureWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer,
+ String username) {
super(configurer);
+ this.username = username;
}
public ActionBarAdvisor createActionBarAdvisor(
configurer.setShowStatusLine(false);
configurer.setShowPerspectiveBar(true);
- configurer.setTitle("Argeo Secure UI"); //$NON-NLS-1$
+ configurer.setTitle("Argeo UI - " + username); //$NON-NLS-1$
}
-
}
}
public final static Set<String> roles() {
- Principal principal = getSubject().getPrincipals(Authentication.class)
- .iterator().next();
- Authentication authentication = (Authentication) principal;
Set<String> roles = Collections.synchronizedSet(new HashSet<String>());
- for (GrantedAuthority ga : authentication.getAuthorities()) {
- roles.add(ga.getAuthority());
+
+ Set<Authentication> authens = getSubject().getPrincipals(
+ Authentication.class);
+ if (authens != null && !authens.isEmpty()) {
+ Principal principal = authens.iterator().next();
+ Authentication authentication = (Authentication) principal;
+ for (GrantedAuthority ga : authentication.getAuthorities()) {
+ roles.add(ga.getAuthority());
+ }
}
return Collections.unmodifiableSet(roles);
}
--- /dev/null
+package org.argeo.security;
+
+import java.security.AccessController;
+import java.security.Principal;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+import javax.security.auth.Subject;
+
+import org.argeo.ArgeoException;
+import org.argeo.OperatingSystem;
+import org.springframework.security.Authentication;
+import org.springframework.security.GrantedAuthority;
+import org.springframework.security.GrantedAuthorityImpl;
+import org.springframework.security.userdetails.UserDetails;
+
+/** Abstracts principals provided by com.sun.security.auth.module login modules. */
+public class OsAuthenticationToken implements Authentication {
+ private static final long serialVersionUID = -7544626794250917244L;
+
+ final Class<? extends Principal> osUserPrincipalClass;
+ final Class<? extends Principal> osUserIdPrincipalClass;
+ final Class<? extends Principal> osGroupIdPrincipalClass;
+
+ private List<GrantedAuthority> grantedAuthorities;
+
+ private UserDetails details;
+
+ /** Request */
+ public OsAuthenticationToken(GrantedAuthority[] grantedAuthorities) {
+ this.grantedAuthorities = grantedAuthorities != null ? Arrays
+ .asList(grantedAuthorities) : null;
+ ClassLoader cl = getClass().getClassLoader();
+ switch (OperatingSystem.os) {
+ case OperatingSystem.WINDOWS:
+ osUserPrincipalClass = getPrincipalClass(cl,
+ "com.sun.security.auth.NTUserPrincipal");
+ osUserIdPrincipalClass = getPrincipalClass(cl,
+ "com.sun.security.auth.NTSidUserPrincipal");
+ osGroupIdPrincipalClass = getPrincipalClass(cl,
+ "com.sun.security.auth.NTSidGroupPrincipal");
+ break;
+ case OperatingSystem.NIX:
+ osUserPrincipalClass = getPrincipalClass(cl,
+ "com.sun.security.auth.UnixPrincipal");
+ osUserIdPrincipalClass = getPrincipalClass(cl,
+ "com.sun.security.auth.UnixNumericUserPrincipal");
+ osGroupIdPrincipalClass = getPrincipalClass(cl,
+ "com.sun.security.auth.UnixNumericGroupPrincipal");
+ break;
+ case OperatingSystem.SOLARIS:
+ osUserPrincipalClass = getPrincipalClass(cl,
+ "com.sun.security.auth.SolarisPrincipal");
+ osUserIdPrincipalClass = getPrincipalClass(cl,
+ "com.sun.security.auth.SolarisNumericUserPrincipal");
+ osGroupIdPrincipalClass = getPrincipalClass(cl,
+ "com.sun.security.auth.SolarisNumericGroupPrincipal");
+ break;
+
+ default:
+ throw new ArgeoException("Unsupported operating system "
+ + OperatingSystem.os);
+ }
+
+ }
+
+ /** Authenticated */
+ public OsAuthenticationToken() {
+ this(null);
+ }
+
+ public String getName() {
+ return getUser().getName();
+ }
+
+ public GrantedAuthority[] getAuthorities() {
+ // grantedAuthorities should not be null at this stage
+ List<GrantedAuthority> gas = new ArrayList<GrantedAuthority>(
+ grantedAuthorities);
+ for (Principal groupPrincipal : getGroupsIds()) {
+ gas.add(new GrantedAuthorityImpl("OSGROUP_"
+ + groupPrincipal.getName()));
+ }
+ return gas.toArray(new GrantedAuthority[gas.size()]);
+ }
+
+ public UserDetails getDetails() {
+ return details;
+ }
+
+ public void setDetails(UserDetails details) {
+ this.details = details;
+ }
+
+ public boolean isAuthenticated() {
+ return grantedAuthorities != null;
+ }
+
+ public void setAuthenticated(boolean isAuthenticated)
+ throws IllegalArgumentException {
+ if (grantedAuthorities != null)
+ grantedAuthorities.clear();
+ grantedAuthorities = null;
+ }
+
+ @SuppressWarnings("unchecked")
+ protected static Class<? extends Principal> getPrincipalClass(
+ ClassLoader cl, String className) {
+ try {
+ return (Class<? extends Principal>) cl.loadClass(className);
+ } catch (ClassNotFoundException e) {
+ throw new ArgeoException("Cannot load principal class", e);
+ }
+ }
+
+ public Object getPrincipal() {
+ return getUser();
+ }
+
+ public Principal getUser() {
+ Subject subject = Subject.getSubject(AccessController.getContext());
+ Set<? extends Principal> userPrincipals = subject
+ .getPrincipals(osUserPrincipalClass);
+ if (userPrincipals == null || userPrincipals.size() == 0)
+ throw new ArgeoException("No OS principal");
+ if (userPrincipals.size() > 1)
+ throw new ArgeoException("More than one OS principal");
+ Principal user = userPrincipals.iterator().next();
+ return user;
+ }
+
+ public Principal getUserId() {
+ Subject subject = Subject.getSubject(AccessController.getContext());
+ Set<? extends Principal> userIdsPrincipals = subject
+ .getPrincipals(osUserIdPrincipalClass);
+ if (userIdsPrincipals == null || userIdsPrincipals.size() == 0)
+ throw new ArgeoException("No user id principal");
+ if (userIdsPrincipals.size() > 1)
+ throw new ArgeoException("More than one user id principal");
+ Principal userId = userIdsPrincipals.iterator().next();
+ return userId;
+ }
+
+ public Set<? extends Principal> getGroupsIds() {
+ Subject subject = Subject.getSubject(AccessController.getContext());
+ return (Set<? extends Principal>) subject
+ .getPrincipals(osGroupIdPrincipalClass);
+ }
+
+ public Object getCredentials() {
+ return "";
+ }
+
+}
--- /dev/null
+package org.argeo.security.core;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.argeo.security.OsAuthenticationToken;
+import org.springframework.security.Authentication;
+import org.springframework.security.AuthenticationException;
+import org.springframework.security.GrantedAuthority;
+import org.springframework.security.GrantedAuthorityImpl;
+import org.springframework.security.providers.AuthenticationProvider;
+
+/** Validates an OS authentication. */
+public class OsAuthenticationProvider implements AuthenticationProvider {
+ private String osUserRole = "ROLE_OS_USER";
+ private String userRole = "ROLE_USER";
+ private String adminRole = "ROLE_ADMIN";
+
+ private Boolean isAdmin = true;
+
+ public Authentication authenticate(Authentication authentication)
+ throws AuthenticationException {
+ if (authentication instanceof OsAuthenticationToken) {
+ List<GrantedAuthority> auths = new ArrayList<GrantedAuthority>();
+ auths.add(new GrantedAuthorityImpl(osUserRole));
+ auths.add(new GrantedAuthorityImpl(userRole));
+ if (isAdmin)
+ auths.add(new GrantedAuthorityImpl(adminRole));
+ return new OsAuthenticationToken(
+ auths.toArray(new GrantedAuthority[auths.size()]));
+ }
+ return null;
+ }
+
+ @SuppressWarnings("rawtypes")
+ public boolean supports(Class authentication) {
+ return OsAuthenticationToken.class.isAssignableFrom(authentication);
+ }
+
+ public void setOsUserRole(String osUserRole) {
+ this.osUserRole = osUserRole;
+ }
+
+ public void setAdminRole(String adminRole) {
+ this.adminRole = adminRole;
+ }
+
+ public void setIsAdmin(Boolean isAdmin) {
+ this.isAdmin = isAdmin;
+ }
+
+}
}
/** Builds user details based on the authentication and the user home. */
- protected UserDetails getUserDetails(Node userHome,
- JcrAuthenticationToken authen) {
+ protected UserDetails getUserDetails(Node userHome, Authentication authen) {
try {
// TODO: loads enabled, locked, etc. from the home node.
return new JcrUserDetails(userHome.getPath(), authen.getPrincipal()
.toString(), authen.getCredentials().toString(),
- isEnabled(userHome),
- true, true, true, authen.getAuthorities());
+ isEnabled(userHome), true, true, true,
+ authen.getAuthorities());
} catch (Exception e) {
throw new ArgeoException("Cannot get user details for " + userHome,
e);
}
}
-
- protected Boolean isEnabled(Node userHome){
+
+ protected Boolean isEnabled(Node userHome) {
return true;
}
--- /dev/null
+package org.argeo.security.jcr;
+
+import java.util.Map;
+import java.util.concurrent.Executor;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.RepositoryFactory;
+import javax.jcr.Session;
+
+import org.argeo.ArgeoException;
+import org.argeo.jcr.JcrUtils;
+import org.argeo.security.OsAuthenticationToken;
+import org.argeo.security.core.OsAuthenticationProvider;
+import org.springframework.security.Authentication;
+import org.springframework.security.AuthenticationException;
+import org.springframework.security.userdetails.UserDetails;
+
+public class OsJcrAuthenticationProvider extends OsAuthenticationProvider {
+ private RepositoryFactory repositoryFactory;
+ private Executor systemExecutor;
+ private String homeBasePath = "/home";
+ private String repositoryAlias = "node";
+ private String workspace = null;
+
+ public Authentication authenticate(Authentication authentication)
+ throws AuthenticationException {
+ final OsAuthenticationToken authen = (OsAuthenticationToken) super
+ .authenticate(authentication);
+ systemExecutor.execute(new Runnable() {
+ public void run() {
+ try {
+ Session session = JcrUtils.getRepositoryByAlias(
+ repositoryFactory, repositoryAlias)
+ .login(workspace);
+ Node userHome = JcrUtils.getUserHome(session,
+ authen.getName());
+ if (userHome == null)
+ JcrUtils.createUserHome(session, homeBasePath,
+ authen.getName());
+ authen.setDetails(getUserDetails(userHome, authen));
+ } catch (RepositoryException e) {
+ throw new ArgeoException(
+ "Unexpected exception when synchronizing OS and JCR security ",
+ e);
+ }
+ }
+ });
+ return authen;
+ }
+
+ /** Builds user details based on the authentication and the user home. */
+ protected UserDetails getUserDetails(Node userHome, Authentication authen) {
+ try {
+ // TODO: loads enabled, locked, etc. from the home node.
+ return new JcrUserDetails(userHome.getPath(), authen.getPrincipal()
+ .toString(), authen.getCredentials().toString(),
+ isEnabled(userHome), true, true, true,
+ authen.getAuthorities());
+ } catch (Exception e) {
+ throw new ArgeoException("Cannot get user details for " + userHome,
+ e);
+ }
+ }
+
+ protected Boolean isEnabled(Node userHome) {
+ return true;
+ }
+
+ public void register(RepositoryFactory repositoryFactory,
+ Map<String, String> parameters) {
+ this.repositoryFactory = repositoryFactory;
+ }
+
+ public void unregister(RepositoryFactory repositoryFactory,
+ Map<String, String> parameters) {
+ this.repositoryFactory = null;
+ }
+
+ public void setSystemExecutor(Executor systemExecutor) {
+ this.systemExecutor = systemExecutor;
+ }
+
+ public void setHomeBasePath(String homeBasePath) {
+ this.homeBasePath = homeBasePath;
+ }
+
+ public void setRepositoryAlias(String repositoryAlias) {
+ this.repositoryAlias = repositoryAlias;
+ }
+
+ public void setWorkspace(String workspace) {
+ this.workspace = workspace;
+ }
+
+}
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.argeo.jcr.ThreadBoundJcrSessionFactory;
+import org.springframework.beans.factory.DisposableBean;
+import org.springframework.beans.factory.FactoryBean;
+import org.springframework.beans.factory.InitializingBean;
import org.springframework.security.Authentication;
import org.springframework.security.context.SecurityContextHolder;
import org.springframework.security.userdetails.UserDetails;
-public class SecureThreadBoundSession extends ThreadBoundJcrSessionFactory {
+/**
+ * Thread bounded JCR session factory which checks authentication and is
+ * autoconfigured in Spring.
+ */
+public class SecureThreadBoundSession extends ThreadBoundJcrSessionFactory
+ implements FactoryBean, InitializingBean, DisposableBean {
private final static Log log = LogFactory
.getLog(SecureThreadBoundSession.class);
+ public void afterPropertiesSet() throws Exception {
+ init();
+ }
+
+ public void destroy() throws Exception {
+ dispose();
+ }
+
@Override
protected Session preCall(Session session) {
Authentication authentication = SecurityContextHolder.getContext()
-<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>
<artifactId>runtime</artifactId>
- <version>0.2.3-SNAPSHOT</version>
+ <version>0.3.2-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>org.argeo.security.mvc</artifactId>
<dependency>
<groupId>org.argeo.commons.server</groupId>
<artifactId>org.argeo.server.core</artifactId>
- <version>0.2.3-SNAPSHOT</version>
+ <version>0.3.2-SNAPSHOT</version>
</dependency>
<!-- Argeo Security -->
<dependency>
<groupId>org.argeo.commons.security</groupId>
<artifactId>org.argeo.security.core</artifactId>
- <version>0.2.3-SNAPSHOT</version>
+ <version>0.3.2-SNAPSHOT</version>
</dependency>
<!-- Spring -->
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import org.argeo.security.ArgeoSecurityService;
+import org.argeo.security.UserAdminService;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
/** Add the current argeo user as an attribute to the request. */
public class ArgeoUserInterceptor extends HandlerInterceptorAdapter {
- private ArgeoSecurityService securityService;
+ private UserAdminService securityService;
@Override
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception {
- request.setAttribute("argeoUser", securityService.getCurrentUser());
+ //request.setAttribute("argeoUser", securityService.getCurrentUser());
return super.preHandle(request, response, handler);
}
- public void setSecurityService(ArgeoSecurityService securityService) {
+ public void setSecurityService(UserAdminService securityService) {
this.securityService = securityService;
}
package org.argeo.security.mvc;
-import java.io.Reader;
-import java.util.Set;
-
-import org.argeo.security.ArgeoSecurityService;
-import org.argeo.security.ArgeoUser;
-import org.argeo.security.SimpleArgeoUser;
-import org.argeo.server.BooleanAnswer;
-import org.argeo.server.Deserializer;
-import org.argeo.server.ServerAnswer;
import org.argeo.server.mvc.MvcConstants;
import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.ModelAttribute;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class UsersRolesController implements MvcConstants {
- // private final static Log log = LogFactory
- // .getLog(UsersRolesController.class);
-
- // private String digestType = "SHA";
-
- private ArgeoSecurityService securityService;
-
- private Deserializer userDeserializer = null;
+// private ArgeoSecurityService securityService;
+// private Deserializer userDeserializer = null;
/* USER */
- @RequestMapping("/getCredentials.*")
- @ModelAttribute("user")
- public ArgeoUser getCredentials() {
- ArgeoUser argeoUser = securityService.getCurrentUser();
- if (argeoUser == null)
- return new SimpleArgeoUser();
- else
- return argeoUser;
- }
-
- @RequestMapping("/getUsersList.*")
- @ModelAttribute("users")
- public Set<ArgeoUser> getUsersList() {
- return securityService.listUsers();
- }
-
- @RequestMapping("/userExists.*")
- public BooleanAnswer userExists(@RequestParam("username") String username) {
- return new BooleanAnswer(securityService.userExists(username));
- }
-
- @RequestMapping("/createUser.*")
- @ModelAttribute("user")
- public ArgeoUser createUser(Reader reader) {
- ArgeoUser user = userDeserializer.deserialize(reader,
- SimpleArgeoUser.class);
- // cleanUserBeforeCreate(user);
- securityService.newUser(user);
- return securityService.getUser(user.getUsername());
- }
-
- @RequestMapping("/updateUser.*")
- @ModelAttribute("user")
- public ArgeoUser updateUser(Reader reader) {
- ArgeoUser user = userDeserializer.deserialize(reader,
- SimpleArgeoUser.class);
- securityService.updateUser(user);
- return securityService.getUser(user.getUsername());
- }
-
- @RequestMapping("/updateUserSelf.*")
- @ModelAttribute("user")
- /** Will only update the user natures.*/
- public ArgeoUser updateUserSelf(Reader reader) {
- ArgeoUser user = securityService.getCurrentUser();
- ArgeoUser userForNatures = userDeserializer.deserialize(reader,
- SimpleArgeoUser.class);
- user.updateUserNatures(userForNatures.getUserNatures());
- securityService.updateUser(user);
- return securityService.getUser(user.getUsername());
- }
-
- @RequestMapping("/deleteUser.*")
- public ServerAnswer deleteUser(@RequestParam("username") String username) {
- securityService.deleteUser(username);
- return ServerAnswer.ok("User " + username + " deleted");
- }
-
- @RequestMapping("/getUserDetails.*")
- @ModelAttribute("user")
- public ArgeoUser getUserDetails(@RequestParam("username") String username) {
- return securityService.getUser(username);
- }
+// @RequestMapping("/getCredentials.*")
+// @ModelAttribute("user")
+// public ArgeoUser getCredentials() {
+// ArgeoUser argeoUser = securityService.getCurrentUser();
+// if (argeoUser == null)
+// return new SimpleArgeoUser();
+// else
+// return argeoUser;
+// }
+//
+// @RequestMapping("/getUsersList.*")
+// @ModelAttribute("users")
+// public Set<ArgeoUser> getUsersList() {
+// return securityService.listUsers();
+// }
+//
+// @RequestMapping("/userExists.*")
+// public BooleanAnswer userExists(@RequestParam("username") String username) {
+// return new BooleanAnswer(securityService.userExists(username));
+// }
+//
+// @RequestMapping("/createUser.*")
+// @ModelAttribute("user")
+// public ArgeoUser createUser(Reader reader) {
+// ArgeoUser user = userDeserializer.deserialize(reader,
+// SimpleArgeoUser.class);
+// securityService.newUser(user);
+// return securityService.getUser(user.getUsername());
+// }
+//
+// @RequestMapping("/updateUser.*")
+// @ModelAttribute("user")
+// public ArgeoUser updateUser(Reader reader) {
+// ArgeoUser user = userDeserializer.deserialize(reader,
+// SimpleArgeoUser.class);
+// securityService.updateUser(user);
+// return securityService.getUser(user.getUsername());
+// }
+//
+// @RequestMapping("/updateUserSelf.*")
+// @ModelAttribute("user")
+// /** Will only update the user natures.*/
+// public ArgeoUser updateUserSelf(Reader reader) {
+// ArgeoUser user = securityService.getCurrentUser();
+// ArgeoUser userForNatures = userDeserializer.deserialize(reader,
+// SimpleArgeoUser.class);
+// user.updateUserNatures(userForNatures.getUserNatures());
+// securityService.updateUser(user);
+// return securityService.getUser(user.getUsername());
+// }
+//
+// @RequestMapping("/deleteUser.*")
+// public ServerAnswer deleteUser(@RequestParam("username") String username) {
+// securityService.deleteUser(username);
+// return ServerAnswer.ok("User " + username + " deleted");
+// }
+//
+// @RequestMapping("/getUserDetails.*")
+// @ModelAttribute("user")
+// public ArgeoUser getUserDetails(@RequestParam("username") String username) {
+// return securityService.getUser(username);
+// }
/* ROLE */
- @RequestMapping("/getRolesList.*")
- @ModelAttribute("roles")
- public Set<String> getEditableRolesList() {
- return securityService.listEditableRoles();
- }
-
- @RequestMapping("/createRole.*")
- public ServerAnswer createRole(@RequestParam("role") String role) {
- securityService.newRole(role);
- return ServerAnswer.ok("Role " + role + " created");
- }
-
- @RequestMapping("/deleteRole.*")
- public ServerAnswer deleteRole(@RequestParam("role") String role) {
- securityService.deleteRole(role);
- return ServerAnswer.ok("Role " + role + " deleted");
- }
-
- @RequestMapping("/updateUserPassword.*")
- public ServerAnswer updateUserPassword(
- @RequestParam("username") String username,
- @RequestParam("password") String password) {
- securityService.updateUserPassword(username, password);
- return ServerAnswer.ok("Password updated for user " + username);
- }
-
- @RequestMapping("/updatePassword.*")
- public ServerAnswer updatePassword(
- @RequestParam("oldPassword") String oldPassword,
- @RequestParam("password") String password) {
- securityService.updateCurrentUserPassword(oldPassword, password);
- return ServerAnswer.ok("Password updated");
- }
-
- // protected String digestIfNecessary(String str) {
- //
- // if (!str.startsWith("{" + digestType + "}"))
- // return digest(str);
- // else
- // return str;
- // }
-
- // protected String digest(String nonEncrypted) {
- // try {
- // MessageDigest md = MessageDigest.getInstance(digestType);
- // byte[] dig = md.digest(nonEncrypted.getBytes());
- // return "{" + digestType + "}"
- // + new String(Base64.encodeBase64(dig));
- // } catch (NoSuchAlgorithmException e) {
- // throw new RuntimeException(
- // "Unexpected exception while digesting password");
- // }
- // }
-
- public void setUserDeserializer(Deserializer userDeserializer) {
- this.userDeserializer = userDeserializer;
- }
-
- public void setSecurityService(ArgeoSecurityService securityService) {
- this.securityService = securityService;
- }
+// @RequestMapping("/getRolesList.*")
+// @ModelAttribute("roles")
+// public Set<String> getEditableRolesList() {
+// return securityService.listEditableRoles();
+// }
+//
+// @RequestMapping("/createRole.*")
+// public ServerAnswer createRole(@RequestParam("role") String role) {
+// securityService.newRole(role);
+// return ServerAnswer.ok("Role " + role + " created");
+// }
+//
+// @RequestMapping("/deleteRole.*")
+// public ServerAnswer deleteRole(@RequestParam("role") String role) {
+// securityService.deleteRole(role);
+// return ServerAnswer.ok("Role " + role + " deleted");
+// }
+//
+// @RequestMapping("/updateUserPassword.*")
+// public ServerAnswer updateUserPassword(
+// @RequestParam("username") String username,
+// @RequestParam("password") String password) {
+// securityService.updateUserPassword(username, password);
+// return ServerAnswer.ok("Password updated for user " + username);
+// }
+//
+// @RequestMapping("/updatePassword.*")
+// public ServerAnswer updatePassword(
+// @RequestParam("oldPassword") String oldPassword,
+// @RequestParam("password") String password) {
+// securityService.updateCurrentUserPassword(oldPassword, password);
+// return ServerAnswer.ok("Password updated");
+// }
+//
+// public void setUserDeserializer(Deserializer userDeserializer) {
+// this.userDeserializer = userDeserializer;
+// }
+//
+// public void setSecurityService(ArgeoSecurityService securityService) {
+// this.securityService = securityService;
+// }
}
<module>org.argeo.security.ldap</module>
<module>org.argeo.security.activemq</module>
<module>org.argeo.security.jackrabbit</module>
+ <module>org.argeo.security.mvc</module>
</modules>
<build>
<resources>
-<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.server</groupId>
<name>Commons Jackrabbit Dependencies</name>
<dependencies>
<dependency>
- <groupId>org.argeo.dep.osgi</groupId>
- <artifactId>org.argeo.dep.osgi.jackrabbit</artifactId>
- </dependency>
- <dependency>
- <groupId>org.argeo.commons.server</groupId>
- <artifactId>org.argeo.server.tika.jackrabbit</artifactId>
- <version>${version.argeo-commons}</version>
- </dependency>
- <dependency>
- <groupId>org.argeo.commons.server</groupId>
- <artifactId>org.argeo.server.ext.jackrabbit</artifactId>
- <version>${version.argeo-commons}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.xalan</groupId>
- <artifactId>com.springsource.org.apache.xalan</artifactId>
- </dependency>
-
- <!-- Transitive dependencies -->
- <dependency>
- <groupId>org.argeo.dep.osgi</groupId>
- <artifactId>org.argeo.dep.osgi.jcr</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.lucene</groupId>
- <artifactId>com.springsource.org.apache.lucene</artifactId>
- </dependency>
- <dependency>
- <groupId>org.argeo.commons.basic</groupId>
- <artifactId>org.argeo.basic.dep.log4j</artifactId>
- <version>0.3.2-SNAPSHOT</version>
+ <groupId>org.argeo.commons.osgi</groupId>
+ <artifactId>org.argeo.osgi.dep.jackrabbit</artifactId>
<type>pom</type>
+ <version>0.3.2-SNAPSHOT</version>
</dependency>
- <!-- Commons -->
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>com.springsource.org.apache.commons.collections</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>com.springsource.org.apache.commons.io</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>com.springsource.org.apache.commons.httpclient</artifactId>
- </dependency>
+ <!-- Enhancements of Jackrabbit -->
<dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>com.springsource.org.apache.commons.fileupload</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>com.springsource.org.apache.commons.compress</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>com.springsource.org.apache.commons.pool</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>com.springsource.org.apache.commons.dbcp</artifactId>
+ <groupId>org.argeo.dep.osgi</groupId>
+ <artifactId>org.argeo.dep.osgi.bouncycastle.jdk15</artifactId>
</dependency>
-
- <!-- Misc -->
<dependency>
- <groupId>edu.oswego.cs.concurrent</groupId>
- <artifactId>com.springsource.edu.oswego.cs.dl.util.concurrent</artifactId>
+ <groupId>org.apache.xmlbeans</groupId>
+ <artifactId>com.springsource.org.apache.xmlbeans</artifactId>
</dependency>
-
- <!-- For webdav -->
<dependency>
- <groupId>org.springframework</groupId>
- <artifactId>org.springframework.web.servlet</artifactId>
+ <groupId>org.apache.xmlcommons</groupId>
+ <artifactId>com.springsource.org.apache.xmlcommons</artifactId>
</dependency>
<dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>com.springsource.javax.servlet</artifactId>
+ <groupId>org.argeo.dep.osgi</groupId>
+ <artifactId>org.argeo.dep.osgi.pdfbox</artifactId>
</dependency>
-
- <!-- Tika -->
<dependency>
<groupId>org.argeo.dep.osgi</groupId>
- <artifactId>org.argeo.dep.osgi.tika</artifactId>
+ <artifactId>org.argeo.dep.osgi.poi</artifactId>
</dependency>
<dependency>
- <groupId>org.argeo.dep.osgi</groupId>
- <artifactId>org.argeo.dep.osgi.pdfbox</artifactId>
+ <groupId>com.sun.syndication</groupId>
+ <artifactId>com.springsource.com.sun.syndication</artifactId>
</dependency>
<dependency>
- <groupId>org.argeo.dep.osgi</groupId>
- <artifactId>org.argeo.dep.osgi.poi</artifactId>
+ <groupId>net.sourceforge.nekohtml</groupId>
+ <artifactId>com.springsource.org.cyberneko.html</artifactId>
</dependency>
<dependency>
<groupId>org.argeo.dep.osgi</groupId>
<artifactId>org.argeo.dep.osgi.boilerpipe</artifactId>
</dependency>
<dependency>
- <groupId>org.argeo.dep.osgi</groupId>
- <artifactId>org.argeo.dep.osgi.bouncycastle.jdk15</artifactId>
+ <groupId>javax.mail</groupId>
+ <artifactId>com.springsource.javax.mail</artifactId>
</dependency>
<dependency>
<groupId>org.argeo.dep.osgi</groupId>
<groupId>org.argeo.dep.osgi</groupId>
<artifactId>org.argeo.dep.osgi.tagsoup</artifactId>
</dependency>
-
- <!-- Logback <dependency> <groupId>ch.qos.logback</groupId> <artifactId>com.springsource.ch.qos.logback.classic</artifactId>
- </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>com.springsource.ch.qos.logback.core</artifactId>
- </dependency> -->
-
- <!-- Required for OSGi completion -->
- <dependency>
- <groupId>net.sourceforge.nekohtml</groupId>
- <artifactId>com.springsource.org.cyberneko.html</artifactId>
- </dependency>
- <dependency>
- <groupId>javax.mail</groupId>
- <artifactId>com.springsource.javax.mail</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.xmlbeans</groupId>
- <artifactId>com.springsource.org.apache.xmlbeans</artifactId>
- </dependency>
- <dependency>
- <groupId>org.dom4j</groupId>
- <artifactId>com.springsource.org.dom4j</artifactId>
- </dependency>
- <dependency>
- <groupId>org.jdom</groupId>
- <artifactId>com.springsource.org.jdom</artifactId>
- </dependency>
- <dependency>
- <groupId>com.sun.syndication</groupId>
- <artifactId>com.springsource.com.sun.syndication</artifactId>
- </dependency>
- <dependency>
- <groupId>org.objectweb.asm</groupId>
- <artifactId>com.springsource.org.objectweb.asm</artifactId>
- </dependency>
- <dependency>
- <groupId>org.jaxen</groupId>
- <artifactId>com.springsource.org.jaxen</artifactId>
- </dependency>
- <dependency>
- <groupId>org.xmlpull</groupId>
- <artifactId>com.springsource.org.xmlpull</artifactId>
- </dependency>
- <dependency>
- <groupId>org.argeo.commons.server</groupId>
- <artifactId>org.argeo.server.dep.javax</artifactId>
- <version>0.3.2-SNAPSHOT</version>
- <type>pom</type>
- </dependency>
- <dependency>
- <groupId>org.apache.xmlcommons</groupId>
- <artifactId>com.springsource.org.apache.xmlcommons</artifactId>
- </dependency>
-
</dependencies>
</project>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.argeo.server.ext.jackrabbit</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <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>
+ </natures>
+</projectDescription>
--- /dev/null
+#Tue Jun 15 19:05:36 CEST 2010
+eclipse.preferences.version=1
+pluginProject.extensions=false
+resolve.requirebundle=false
--- /dev/null
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Jackrabbit
+Bundle-SymbolicName: org.argeo.ext.jackrabbit.sybase
+Bundle-Description: provides experimental support to Sybase in Jackrabbit
+Bundle-Version: 0.3.2.SNAPSHOT
+Fragment-Host: org.argeo.dep.osgi.jackrabbit
--- /dev/null
+bin.includes = META-INF/
--- /dev/null
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+create table ${schemaObjectPrefix}FSENTRY (FSENTRY_PATH varchar(2048) not null, FSENTRY_NAME varchar(255) not null, FSENTRY_DATA image null, FSENTRY_LASTMOD decimal(19,0) not null, FSENTRY_LENGTH decimal(19,0) not null)
+#create unique index ${schemaObjectPrefix}FSENTRY_IDX on ${schemaObjectPrefix}FSENTRY (FSENTRY_PATH, FSENTRY_NAME)
--- /dev/null
+# Licensed to the Apache Software Foundation (ASF) under one or more\r
+# contributor license agreements. See the NOTICE file distributed with\r
+# this work for additional information regarding copyright ownership.\r
+# The ASF licenses this file to You under the Apache License, Version 2.0\r
+# (the "License"); you may not use this file except in compliance with\r
+# the License. You may obtain a copy of the License at\r
+#\r
+# http://www.apache.org/licenses/LICENSE-2.0\r
+#\r
+# Unless required by applicable law or agreed to in writing, software\r
+# distributed under the License is distributed on an "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+# See the License for the specific language governing permissions and\r
+# limitations under the License.\r
+\r
+create table ${schemaObjectPrefix}JOURNAL (REVISION_ID decimal(19,0) NOT NULL, JOURNAL_ID varchar(255), PRODUCER_ID varchar(255), REVISION_DATA IMAGE)\r
+create unique index ${schemaObjectPrefix}JOURNAL_IDX on ${schemaObjectPrefix}JOURNAL (REVISION_ID)\r
+create table ${schemaObjectPrefix}GLOBAL_REVISION (REVISION_ID decimal(19,0) NOT NULL)\r
+create unique index ${schemaObjectPrefix}GLOBAL_REVISION_IDX on ${schemaObjectPrefix}GLOBAL_REVISION (REVISION_ID)\r
+\r
+# Inserting the one and only revision counter record now helps avoiding race conditions\r
+insert into ${schemaObjectPrefix}GLOBAL_REVISION VALUES(0)\r
--- /dev/null
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+create table ${schemaObjectPrefix}BUNDLE (NODE_ID binary(16) not null, BUNDLE_DATA image not null)
+create unique index ${schemaObjectPrefix}BUNDLE_IDX on ${schemaObjectPrefix}BUNDLE (NODE_ID)
+create table ${schemaObjectPrefix}REFS (NODE_ID binary(16) not null, REFS_DATA image not null)
+create unique index ${schemaObjectPrefix}REFS_IDX on ${schemaObjectPrefix}REFS (NODE_ID)
+create table ${schemaObjectPrefix}BINVAL (BINVAL_ID varchar(64) not null, BINVAL_DATA image not null)
+create unique index ${schemaObjectPrefix}BINVAL_IDX on ${schemaObjectPrefix}BINVAL (BINVAL_ID)
+#create table ${schemaObjectPrefix}NAMES (ID INTEGER IDENTITY(1,1) PRIMARY KEY, NAME varchar(255) COLLATE Latin1_General_CS_AS not null)
+create table ${schemaObjectPrefix}NAMES (ID INTEGER IDENTITY PRIMARY KEY, NAME varchar(255))
--- /dev/null
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+create table ${schemaObjectPrefix}NODE (NODE_ID char(36) not null, NODE_DATA image not null)
+create unique index ${schemaObjectPrefix}NODE_IDX on ${schemaObjectPrefix}NODE (NODE_ID)
+create table ${schemaObjectPrefix}PROP (PROP_ID varchar(1024) not null, PROP_DATA image not null)
+create unique index ${schemaObjectPrefix}PROP_IDX on ${schemaObjectPrefix}PROP (PROP_ID)
+create table ${schemaObjectPrefix}REFS (NODE_ID char(36) not null, REFS_DATA image not null)
+create unique index ${schemaObjectPrefix}REFS_IDX on ${schemaObjectPrefix}REFS (NODE_ID)
+create table ${schemaObjectPrefix}BINVAL (BINVAL_ID varchar(1024) not null, BINVAL_DATA image not null)
+create unique index ${schemaObjectPrefix}BINVAL_IDX on ${schemaObjectPrefix}BINVAL (BINVAL_ID)
org.argeo.jackrabbit.remote,
org.argeo.jcr,
org.argeo.jcr.mvc,
- org.argeo.server.json,
org.argeo.server.mvc,
org.springframework.aop;version="2.5.6.SEC01",
org.springframework.aop.framework;version="2.5.6.SEC01",
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
- <context:component-scan base-package="org.argeo.jcr.mvc" />
+<!-- <context:component-scan base-package="org.argeo.jcr.mvc" /> -->
- <bean name="**" class="org.argeo.jcr.mvc.JcrManagerController">
- </bean>
+<!-- <bean name="**" class="org.argeo.jcr.mvc.JcrManagerController"> -->
+<!-- </bean> -->
- <bean id="viewResolver" class="org.argeo.server.mvc.SerializingViewResolver">
- <property name="serializer" ref="serverMapper" />
- </bean>
+<!-- <bean id="viewResolver" class="org.argeo.server.mvc.SerializingViewResolver"> -->
+<!-- <property name="serializer" ref="serverMapper" /> -->
+<!-- </bean> -->
- <bean id="serverMapper" class="org.argeo.server.json.JsonServerMapper">
- </bean>
+<!-- <bean id="serverMapper" class="org.argeo.server.json.JsonServerMapper"> -->
+<!-- </bean> -->
- <bean class="org.argeo.server.mvc.DefaultHandlerExceptionResolver" />
+<!-- <bean class="org.argeo.server.mvc.DefaultHandlerExceptionResolver" /> -->
- <bean id="handlerMapping"
- class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping">
- <property name="interceptors">
- <list>
- <ref bean="osivInterceptor" />
- </list>
- </property>
- </bean>
+<!-- <bean id="handlerMapping" -->
+<!-- class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"> -->
+<!-- <property name="interceptors"> -->
+<!-- <list> -->
+<!-- <ref bean="osivInterceptor" /> -->
+<!-- </list> -->
+<!-- </property> -->
+<!-- </bean> -->
</beans>
\ No newline at end of file
argeo.node.repo.workspace=dev
# Repository base directory
-argeo.node.repo.home=${user.home}/.argeo/noderepo
+argeo.node.repo.home=${osgi.instance.area}/org/argeo/jackrabbit/node/repo
## H2 Embedded (DEFAULT)
argeo.node.repo.configuration=osgibundle:repository-h2.xml
-argeo.node.repo.dburl=jdbc:h2:file:~/.argeo/h2/noderepo_db
+argeo.node.repo.dburl=jdbc:h2:${osgi.instance.area}/org/argeo/jackrabbit/node/h2
argeo.node.repo.dbuser=sa
argeo.node.repo.dbpassword=
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>org.argeo.server.ext.jackrabbit</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <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>
- </natures>
-</projectDescription>
+++ /dev/null
-#Tue Jun 15 19:05:36 CEST 2010
-eclipse.preferences.version=1
-pluginProject.extensions=false
-resolve.requirebundle=false
+++ /dev/null
-Manifest-Version: 1.0
-Bundle-ManifestVersion: 2
-Bundle-Name: Jackrabbit
-Bundle-SymbolicName: org.argeo.server.ext.jackrabbit
-Bundle-Description: provides additional DLLs and imports to Jackrabbit
-Bundle-Version: 0.3.2.SNAPSHOT
-Fragment-Host: org.argeo.dep.osgi.jackrabbit
+++ /dev/null
-bin.includes = META-INF/
+++ /dev/null
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You 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.
-create table ${schemaObjectPrefix}FSENTRY (FSENTRY_PATH varchar(2048) not null, FSENTRY_NAME varchar(255) not null, FSENTRY_DATA image null, FSENTRY_LASTMOD decimal(19,0) not null, FSENTRY_LENGTH decimal(19,0) not null)
-#create unique index ${schemaObjectPrefix}FSENTRY_IDX on ${schemaObjectPrefix}FSENTRY (FSENTRY_PATH, FSENTRY_NAME)
+++ /dev/null
-# Licensed to the Apache Software Foundation (ASF) under one or more\r
-# contributor license agreements. See the NOTICE file distributed with\r
-# this work for additional information regarding copyright ownership.\r
-# The ASF licenses this file to You under the Apache License, Version 2.0\r
-# (the "License"); you may not use this file except in compliance with\r
-# the License. You may obtain a copy of the License at\r
-#\r
-# http://www.apache.org/licenses/LICENSE-2.0\r
-#\r
-# Unless required by applicable law or agreed to in writing, software\r
-# distributed under the License is distributed on an "AS IS" BASIS,\r
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-# See the License for the specific language governing permissions and\r
-# limitations under the License.\r
-\r
-create table ${schemaObjectPrefix}JOURNAL (REVISION_ID decimal(19,0) NOT NULL, JOURNAL_ID varchar(255), PRODUCER_ID varchar(255), REVISION_DATA IMAGE)\r
-create unique index ${schemaObjectPrefix}JOURNAL_IDX on ${schemaObjectPrefix}JOURNAL (REVISION_ID)\r
-create table ${schemaObjectPrefix}GLOBAL_REVISION (REVISION_ID decimal(19,0) NOT NULL)\r
-create unique index ${schemaObjectPrefix}GLOBAL_REVISION_IDX on ${schemaObjectPrefix}GLOBAL_REVISION (REVISION_ID)\r
-\r
-# Inserting the one and only revision counter record now helps avoiding race conditions\r
-insert into ${schemaObjectPrefix}GLOBAL_REVISION VALUES(0)\r
+++ /dev/null
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You 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.
-create table ${schemaObjectPrefix}BUNDLE (NODE_ID binary(16) not null, BUNDLE_DATA image not null)
-create unique index ${schemaObjectPrefix}BUNDLE_IDX on ${schemaObjectPrefix}BUNDLE (NODE_ID)
-create table ${schemaObjectPrefix}REFS (NODE_ID binary(16) not null, REFS_DATA image not null)
-create unique index ${schemaObjectPrefix}REFS_IDX on ${schemaObjectPrefix}REFS (NODE_ID)
-create table ${schemaObjectPrefix}BINVAL (BINVAL_ID varchar(64) not null, BINVAL_DATA image not null)
-create unique index ${schemaObjectPrefix}BINVAL_IDX on ${schemaObjectPrefix}BINVAL (BINVAL_ID)
-#create table ${schemaObjectPrefix}NAMES (ID INTEGER IDENTITY(1,1) PRIMARY KEY, NAME varchar(255) COLLATE Latin1_General_CS_AS not null)
-create table ${schemaObjectPrefix}NAMES (ID INTEGER IDENTITY PRIMARY KEY, NAME varchar(255))
+++ /dev/null
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You 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.
-create table ${schemaObjectPrefix}NODE (NODE_ID char(36) not null, NODE_DATA image not null)
-create unique index ${schemaObjectPrefix}NODE_IDX on ${schemaObjectPrefix}NODE (NODE_ID)
-create table ${schemaObjectPrefix}PROP (PROP_ID varchar(1024) not null, PROP_DATA image not null)
-create unique index ${schemaObjectPrefix}PROP_IDX on ${schemaObjectPrefix}PROP (PROP_ID)
-create table ${schemaObjectPrefix}REFS (NODE_ID char(36) not null, REFS_DATA image not null)
-create unique index ${schemaObjectPrefix}REFS_IDX on ${schemaObjectPrefix}REFS (NODE_ID)
-create table ${schemaObjectPrefix}BINVAL (BINVAL_ID varchar(1024) not null, BINVAL_DATA image not null)
-create unique index ${schemaObjectPrefix}BINVAL_IDX on ${schemaObjectPrefix}BINVAL (BINVAL_ID)
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>org.argeo.server.tika.jackrabbit</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <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>
- </natures>
-</projectDescription>
+++ /dev/null
-#Mon Jan 10 13:35:52 CET 2011
-eclipse.preferences.version=1
-pluginProject.extensions=false
-resolve.requirebundle=false
+++ /dev/null
-Manifest-Version: 1.0
-Bundle-ManifestVersion: 2
-Bundle-Name: Tika Jackrabbit extension
-Bundle-SymbolicName: org.argeo.server.tika.jackrabbit
-Bundle-Version: 0.3.2.SNAPSHOT
-Fragment-Host: org.argeo.dep.osgi.tika
-Import-Package: org.apache.jackrabbit.core.query.pdf
+++ /dev/null
-bin.includes = META-INF/
com.springsource.org.apache.log4j,\
com.springsource.org.apache.commons.collections,\
com.springsource.edu.oswego.cs.dl.util.concurrent,\
- com.springsource.org.apache.derby,\
+ com.springsource.org.h2,\
com.springsource.org.apache.lucene,\
org.springframework.context
source.. = src/main/java/,\
<artifactId>org.argeo.basic.nodeps</artifactId>
<version>0.3.2-SNAPSHOT</version>
</dependency>
-
<dependency>
<groupId>org.argeo.commons.server</groupId>
<artifactId>org.argeo.server.core</artifactId>
<!-- Jackrabbit -->
<dependency>
- <groupId>org.argeo.commons.server</groupId>
- <artifactId>org.argeo.server.dep.jackrabbit.server</artifactId>
- <version>0.3.2-SNAPSHOT</version>
+ <groupId>org.argeo.commons.osgi</groupId>
+ <artifactId>org.argeo.osgi.dep.jackrabbit</artifactId>
<type>pom</type>
- </dependency>
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>com.springsource.javax.servlet</artifactId>
- </dependency>
-
- <!-- Apache Commons -->
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>com.springsource.org.apache.commons.io</artifactId>
+ <version>0.3.2-SNAPSHOT</version>
</dependency>
<!-- Spring -->
<groupId>org.springframework</groupId>
<artifactId>org.springframework.beans</artifactId>
</dependency>
-
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.web.servlet</artifactId>
</dependency>
-
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>org.springframework.xml</artifactId>
</dependency>
- <!-- Logging -->
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>com.springsource.slf4j.org.apache.commons.logging</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>com.springsource.org.apache.commons.fileupload</artifactId>
- </dependency>
-
<!-- TEST -->
<dependency>
<groupId>org.argeo.commons.basic</groupId>
import java.io.ByteArrayInputStream;
import java.io.File;
+import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
+import org.springframework.util.SystemPropertyUtils;
import org.xml.sax.InputSource;
/**
}
RepositoryConfig config;
+ Properties vars = getConfigurationProperties();
InputStream in = configuration.getInputStream();
- InputStream propsIn = null;
try {
- Properties vars = new Properties();
- if (variables != null) {
- propsIn = variables.getInputStream();
- vars.load(propsIn);
- }
- // override with system properties
- vars.putAll(System.getProperties());
vars.put(RepositoryConfigurationParser.REPOSITORY_HOME_VARIABLE,
homeDirectory.getCanonicalPath());
config = RepositoryConfig.create(new InputSource(in), vars);
throw new RuntimeException("Cannot read configuration", e);
} finally {
IOUtils.closeQuietly(in);
- IOUtils.closeQuietly(propsIn);
}
if (inMemory)
+ homeDirectory + " with config " + configuration);
}
+ protected Properties getConfigurationProperties() {
+ InputStream propsIn = null;
+ Properties vars;
+ try {
+ vars = new Properties();
+ if (variables != null) {
+ propsIn = variables.getInputStream();
+ vars.load(propsIn);
+ }
+ // resolve system properties
+ for (Object key : vars.keySet()) {
+ // TODO: implement a smarter mechanism to resolve nested ${}
+ String newValue = SystemPropertyUtils.resolvePlaceholders(vars
+ .getProperty(key.toString()));
+ vars.put(key, newValue);
+ }
+ // override with system properties
+ vars.putAll(System.getProperties());
+ } catch (IOException e) {
+ throw new ArgeoException("Cannot read configuration properties", e);
+ } finally {
+ IOUtils.closeQuietly(propsIn);
+ }
+ return vars;
+ }
+
/**
* Import declared node type definitions, trying to update them if they have
* changed. In case of failures an error will be logged but no exception
else
action.run();
}
-
+
public void destroy() throws Exception {
if (repository != null) {
if (repository instanceof JackrabbitRepository)
<?xml version="1.0"?>
-<!--
-
- 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.
-
--->
-
<!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 1.6//EN"
- "http://jackrabbit.apache.org/dtd/repository-1.6.dtd">
- <!--
- Example Repository Configuration File Used by -
- org.apache.jackrabbit.core.config.RepositoryConfigTest.java -
- -->
+ "http://jackrabbit.apache.org/dtd/repository-2.0.dtd">
<Repository>
- <!--
- virtual file system where the repository stores global state (e.g.
- registered namespaces, custom node types, etc.)
- -->
- <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
- <param name="path" value="${rep.home}/repository" />
- </FileSystem>
-
- <!--
- security configuration
- -->
- <Security appName="Jackrabbit">
- <!--
- security manager: class: FQN of class implementing the
- JackrabbitSecurityManager interface
- -->
- <SecurityManager
- class="org.apache.jackrabbit.core.security.simple.SimpleSecurityManager"
- workspaceName="security">
- <!--
- workspace access: class: FQN of class implementing the
- WorkspaceAccessManager interface
- -->
- <!-- <WorkspaceAccessManager class="..."/> -->
- <!-- <param name="config" value="${rep.home}/security.xml"/> -->
- </SecurityManager>
-
- <!--
- access manager: class: FQN of class implementing the AccessManager
- interface
- -->
- <AccessManager
- class="org.apache.jackrabbit.core.security.simple.SimpleAccessManager">
- <!-- <param name="config" value="${rep.home}/access.xml"/> -->
- </AccessManager>
+ <!-- Shared datasource -->
+ <DataSources>
+ <DataSource name="dataSource">
+ <param name="driver" value="org.h2.Driver" />
+ <param name="url" value="jdbc:h2:mem:jackrabbit" />
+ <param name="user" value="sa" />
+ <param name="password" value="" />
+ <param name="databaseType" value="h2" />
+ <param name="maxPoolSize" value="10" />
+ </DataSource>
+ </DataSources>
- <LoginModule
- class="org.apache.jackrabbit.core.security.simple.SimpleLoginModule">
- <!--
- anonymous user name ('anonymous' is the default value)
- -->
- <param name="anonymousId" value="anonymous" />
- <!--
- administrator user id (default value if param is missing is 'admin')
- -->
- <param name="adminId" value="admin" />
- </LoginModule>
- </Security>
+ <!-- File system and datastore -->
+ <FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem">
+ <param name="dataSourceName" value="dataSource" />
+ <param name="schema" value="default" />
+ <param name="schemaObjectPrefix" value="fs_" />
+ </FileSystem>
+ <DataStore class="org.apache.jackrabbit.core.data.db.DbDataStore">
+ <param name="dataSourceName" value="dataSource" />
+ <param name="schemaObjectPrefix" value="ds_" />
+ </DataStore>
- <!--
- location of workspaces root directory and name of default workspace
- -->
+ <!-- Workspace templates -->
<Workspaces rootPath="${rep.home}/workspaces"
- defaultWorkspace="default" />
- <!--
- workspace configuration template: used to create the initial workspace
- if there's no workspace yet
- -->
+ defaultWorkspace="dev" />
<Workspace name="${wsp.name}">
- <!--
- virtual file system of the workspace: class: FQN of class
- implementing the FileSystem interface
- -->
- <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
- <param name="path" value="${wsp.home}" />
+ <FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem">
+ <param name="dataSourceName" value="dataSource" />
+ <param name="schema" value="default" />
+ <param name="schemaObjectPrefix" value="${wsp.name}_fs_" />
</FileSystem>
- <!--
- persistence manager of the workspace: class: FQN of class
- implementing the PersistenceManager interface
- -->
<PersistenceManager
- class="org.apache.jackrabbit.core.persistence.bundle.DerbyPersistenceManager">
- <!--
- <param name="url" value="jdbc:derby:memory:db;create=true" />
- -->
- <param name="url" value="jdbc:derby:${wsp.home}/db;create=true" />
- <param name="driver" value="org.apache.derby.jdbc.EmbeddedDriver" />
- <param name="schemaObjectPrefix" value="${wsp.name}_" />
+ class="org.apache.jackrabbit.core.persistence.pool.H2PersistenceManager">
+ <param name="dataSourceName" value="dataSource" />
+ <param name="schemaObjectPrefix" value="${wsp.name}_pm_" />
</PersistenceManager>
- <!--
- Search index and the file system it uses. class: FQN of class
- implementing the QueryHandler interface
- -->
<SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
<param name="path" value="${wsp.home}/index" />
- <param name="extractorPoolSize" value="2" />
- <param name="supportHighlighting" value="true" />
</SearchIndex>
</Workspace>
- <!--
- Configures the versioning
- -->
+ <!-- Versioning -->
<Versioning rootPath="${rep.home}/version">
- <!--
- Configures the filesystem to use for versioning for the respective
- persistence manager
- -->
- <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
- <param name="path" value="${rep.home}/version" />
+ <FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem">
+ <param name="dataSourceName" value="dataSource" />
+ <param name="schema" value="default" />
+ <param name="schemaObjectPrefix" value="fs_ver_" />
</FileSystem>
-
- <!--
- Configures the persistence manager to be used for persisting version
- state. Please note that the current versioning implementation is
- based on a 'normal' persistence manager, but this could change in
- future implementations.
- -->
<PersistenceManager
- class="org.apache.jackrabbit.core.persistence.bundle.DerbyPersistenceManager">
- <!--
- <param name="url" value="jdbc:derby:memory:version;create=true" />
- -->
- <param name="url" value="jdbc:derby:${rep.home}/version/db;create=true" />
- <param name="driver" value="org.apache.derby.jdbc.EmbeddedDriver" />
- <param name="schemaObjectPrefix" value="version_" />
+ class="org.apache.jackrabbit.core.persistence.pool.H2PersistenceManager">
+ <param name="dataSourceName" value="dataSource" />
+ <param name="schemaObjectPrefix" value="pm_ver_" />
</PersistenceManager>
</Versioning>
- <!--
- Search index for content that is shared repository wide (/jcr:system
- tree, contains mainly versions)
- -->
+ <!-- Indexing -->
<SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
<param name="path" value="${rep.home}/repository/index" />
<param name="extractorPoolSize" value="2" />
<param name="supportHighlighting" value="true" />
</SearchIndex>
-</Repository>
+
+ <!-- Security -->
+ <Security appName="Jackrabbit">
+ <SecurityManager
+ class="org.apache.jackrabbit.core.security.simple.SimpleSecurityManager"
+ workspaceName="security" />
+ <AccessManager
+ class="org.apache.jackrabbit.core.security.simple.SimpleAccessManager" />
+ <LoginModule
+ class="org.apache.jackrabbit.core.security.simple.SimpleLoginModule">
+ <param name="anonymousId" value="anonymous" />
+ <param name="adminId" value="admin" />
+ </LoginModule>
+ </Security>
+</Repository>
\ No newline at end of file
// pathInfo.indexOf('/'));
if (log.isDebugEnabled())
log.debug("Upload to " + path);
- resourceAdapter.update(path.toString(), res);
+ resourceAdapter.update(path.toString(), res.getInputStream());
return ServerAnswer.ok("File " + path + " imported");
}
com.springsource.org.apache.log4j,\
com.springsource.org.apache.commons.collections,\
com.springsource.edu.oswego.cs.dl.util.concurrent,\
- com.springsource.org.apache.derby,\
com.springsource.org.apache.lucene,\
com.springsource.junit,\
com.springsource.org.apache.xml.serializer,\
com.springsource.org.apache.commons.dbcp,\
com.springsource.org.apache.commons.pool,\
- org.argeo.dep.osgi.jackrabbit
+ org.argeo.dep.osgi.jackrabbit,\
+ com.springsource.org.h2
-<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.server</groupId>
<Import-Package>
junit.framework;resolution:=optional,
org.xml.sax;version="0.0.0",
+ org.springframework.core;resolution:=optional,
+ org.springframework.core.io;resolution:=optional,
+ org.springframework.*;resolution:=optional,
*</Import-Package>
</instructions>
</configuration>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.beans</artifactId>
+ <scope>provided</scope>
</dependency>
<!-- OSGi -->
<artifactId>com.springsource.slf4j.org.apache.commons.logging</artifactId>
</dependency>
+
+ <!-- TEST -->
<dependency>
<groupId>org.junit</groupId>
<artifactId>com.springsource.junit</artifactId>
<optional>true</optional>
</dependency>
-
- <!-- TEST -->
<dependency>
- <groupId>org.argeo.commons.server</groupId>
- <artifactId>org.argeo.server.dep.jackrabbit.server</artifactId>
+ <groupId>org.argeo.commons.osgi</groupId>
+ <artifactId>org.argeo.osgi.dep.jackrabbit</artifactId>
<version>0.3.2-SNAPSHOT</version>
<type>pom</type>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.apache.derby</groupId>
- <artifactId>com.springsource.org.apache.derby</artifactId>
- </dependency>
<dependency>
<groupId>org.argeo.commons.basic</groupId>
<artifactId>org.argeo.support.junit</artifactId>
+++ /dev/null
-<?xml version="1.0"?>
-<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You 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.
--->
-<!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 1.6//EN"
- "http://jackrabbit.apache.org/dtd/repository-1.6.dtd">
-<!-- Example Repository Configuration File
- Used by
- - org.apache.jackrabbit.core.config.RepositoryConfigTest.java
- -
--->
-<Repository>
- <!--
- virtual file system where the repository stores global state
- (e.g. registered namespaces, custom node types, etc.)
- -->
- <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
- <param name="path" value="${rep.home}/repository"/>
- </FileSystem>
-
- <!--
- security configuration
- -->
- <Security appName="Jackrabbit">
- <!--
- security manager:
- class: FQN of class implementing the JackrabbitSecurityManager interface
- -->
- <SecurityManager class="org.apache.jackrabbit.core.security.simple.SimpleSecurityManager" workspaceName="security">
- <!--
- workspace access:
- class: FQN of class implementing the WorkspaceAccessManager interface
- -->
- <!-- <WorkspaceAccessManager class="..."/> -->
- <!-- <param name="config" value="${rep.home}/security.xml"/> -->
- </SecurityManager>
-
- <!--
- access manager:
- class: FQN of class implementing the AccessManager interface
- -->
- <AccessManager class="org.apache.jackrabbit.core.security.simple.SimpleAccessManager">
- <!-- <param name="config" value="${rep.home}/access.xml"/> -->
- </AccessManager>
-
- <LoginModule class="org.apache.jackrabbit.core.security.simple.SimpleLoginModule">
- <!--
- anonymous user name ('anonymous' is the default value)
- -->
- <param name="anonymousId" value="anonymous"/>
- <!--
- administrator user id (default value if param is missing is 'admin')
- -->
- <param name="adminId" value="admin"/>
- </LoginModule>
- </Security>
-
- <!--
- location of workspaces root directory and name of default workspace
- -->
- <Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default"/>
- <!--
- workspace configuration template:
- used to create the initial workspace if there's no workspace yet
- -->
- <Workspace name="${wsp.name}">
- <!--
- virtual file system of the workspace:
- class: FQN of class implementing the FileSystem interface
- -->
- <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
- <param name="path" value="${wsp.home}"/>
- </FileSystem>
- <!--
- persistence manager of the workspace:
- class: FQN of class implementing the PersistenceManager interface
- -->
- <PersistenceManager class="org.apache.jackrabbit.core.persistence.bundle.DerbyPersistenceManager">
- <param name="url" value="jdbc:derby:${wsp.home}/db;create=true"/>
- <param name="schemaObjectPrefix" value="${wsp.name}_"/>
- </PersistenceManager>
- <!--
- Search index and the file system it uses.
- class: FQN of class implementing the QueryHandler interface
- -->
- <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
- <param name="path" value="${wsp.home}/index"/>
- <param name="extractorPoolSize" value="2"/>
- <param name="supportHighlighting" value="true"/>
- </SearchIndex>
- </Workspace>
-
- <!--
- Configures the versioning
- -->
- <Versioning rootPath="${rep.home}/version">
- <!--
- Configures the filesystem to use for versioning for the respective
- persistence manager
- -->
- <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
- <param name="path" value="${rep.home}/version" />
- </FileSystem>
-
- <!--
- Configures the persistence manager to be used for persisting version state.
- Please note that the current versioning implementation is based on
- a 'normal' persistence manager, but this could change in future
- implementations.
- -->
- <PersistenceManager class="org.apache.jackrabbit.core.persistence.bundle.DerbyPersistenceManager">
- <param name="url" value="jdbc:derby:${rep.home}/version/db;create=true"/>
- <param name="schemaObjectPrefix" value="version_"/>
- </PersistenceManager>
- </Versioning>
-
- <!--
- Search index for content that is shared repository wide
- (/jcr:system tree, contains mainly versions)
- -->
- <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
- <param name="path" value="${rep.home}/repository/index"/>
- <param name="extractorPoolSize" value="2"/>
- <param name="supportHighlighting" value="true"/>
- </SearchIndex>
-</Repository>
+++ /dev/null
-/*
- * 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.jcr;
-
-import java.beans.PropertyDescriptor;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.StringTokenizer;
-
-import javax.jcr.ItemNotFoundException;
-import javax.jcr.Node;
-import javax.jcr.NodeIterator;
-import javax.jcr.Property;
-import javax.jcr.PropertyIterator;
-import javax.jcr.PropertyType;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.Value;
-import javax.jcr.ValueFactory;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.ArgeoException;
-import org.springframework.beans.BeanWrapper;
-import org.springframework.beans.BeanWrapperImpl;
-
-public class BeanNodeMapper implements NodeMapper {
- private final static Log log = LogFactory.getLog(BeanNodeMapper.class);
-
- private final static String NODE_VALUE = "value";
-
- // private String keyNode = "bean:key";
- private String uuidProperty = "uuid";
- private String classProperty = "class";
-
- private Boolean versioning = false;
- private Boolean strictUuidReference = false;
-
- // TODO define a primaryNodeType Strategy
- private String primaryNodeType = null;
-
- private ClassLoader classLoader = getClass().getClassLoader();
-
- private NodeMapperProvider nodeMapperProvider;
-
- /**
- * exposed method to retrieve a bean from a node
- */
- public Object load(Node node) {
- try {
- if (nodeMapperProvider != null) {
- NodeMapper nodeMapper = nodeMapperProvider.findNodeMapper(node);
- if (nodeMapper != this) {
- return nodeMapper.load(node);
- }
- }
- return nodeToBean(node);
- } catch (RepositoryException e) {
- throw new ArgeoException("Cannot load object from node " + node, e);
- }
- }
-
- /** Update an existing node with an object */
- public void update(Node node, Object obj) {
- try {
- if (nodeMapperProvider != null) {
-
- NodeMapper nodeMapper = nodeMapperProvider.findNodeMapper(node);
- if (nodeMapper != this) {
- nodeMapper.update(node, obj);
- } else
- beanToNode(createBeanWrapper(obj), node);
- } else
- beanToNode(createBeanWrapper(obj), node);
- } catch (RepositoryException e) {
- throw new ArgeoException("Cannot update node " + node + " with "
- + obj, e);
- }
- }
-
- /**
- * if no storage path is given; we use canonical path
- *
- * @see this.storagePath()
- */
- public Node save(Session session, Object obj) {
- return save(session, storagePath(obj), obj);
- }
-
- /**
- * Create a new node to store an object. If the parentNode doesn't exist, it
- * is created
- *
- * the primaryNodeType may be initialized before
- */
- public Node save(Session session, String path, Object obj) {
- try {
- final Node node;
- String parentPath = JcrUtils.parentPath(path);
- // find or create parent node
- Node parentNode;
- if (session.itemExists(path))
- parentNode = (Node) session.getItem(parentPath);
- else {
- parentNode = JcrUtils.mkdirs(session, parentPath, null,
- versioning);
- }
- // create node
-
- if (primaryNodeType != null)
- node = parentNode.addNode(JcrUtils.lastPathElement(path),
- primaryNodeType);
- else
- node = parentNode.addNode(JcrUtils.lastPathElement(path));
-
- // Check specific cases
- if (nodeMapperProvider != null) {
- NodeMapper nodeMapper = nodeMapperProvider.findNodeMapper(node);
- if (nodeMapper != this) {
- nodeMapper.update(node, obj);
- return node;
- }
- }
- update(node, obj);
- return node;
- } catch (ArgeoException e) {
- throw e;
- } catch (Exception e) {
- throw new ArgeoException("Cannot save or update " + obj + " under "
- + path, e);
- }
- }
-
- /**
- * Parse the FQN of a class to string with '/' delimiters Prefix the
- * returned string with "/objects/"
- */
- public String storagePath(Object obj) {
- String clss = obj.getClass().getName();
- StringBuffer buf = new StringBuffer("/objects/");
- StringTokenizer st = new StringTokenizer(clss, ".");
- while (st.hasMoreTokens()) {
- buf.append(st.nextToken()).append('/');
- }
- buf.append(obj.toString());
- return buf.toString();
- }
-
- @SuppressWarnings("unchecked")
- /**
- * Transforms a node into an object of the class defined by classProperty Property
- */
- protected Object nodeToBean(Node node) throws RepositoryException {
- if (log.isTraceEnabled())
- log.trace("Load " + node);
-
- try {
- String clssName = node.getProperty(classProperty).getValue()
- .getString();
-
- BeanWrapper beanWrapper = createBeanWrapper(loadClass(clssName));
-
- // process properties
- PropertyIterator propIt = node.getProperties();
- props: while (propIt.hasNext()) {
- Property prop = propIt.nextProperty();
- if (!beanWrapper.isWritableProperty(prop.getName()))
- continue props;
-
- PropertyDescriptor pd = beanWrapper.getPropertyDescriptor(prop
- .getName());
- Class<?> propClass = pd.getPropertyType();
-
- if (log.isTraceEnabled())
- log.trace("Load " + prop + ", propClass=" + propClass
- + ", property descriptor=" + pd);
-
- // primitive list
- if (propClass != null && List.class.isAssignableFrom(propClass)) {
- List<Object> lst = new ArrayList<Object>();
- Class<?> valuesClass = classFromProperty(prop);
- if (valuesClass != null)
- for (Value value : prop.getValues()) {
- lst.add(asObject(value, valuesClass));
- }
- continue props;
- }
-
- // Case of other type of property accepted by jcr
- // Long, Double, String, Binary, Date, Boolean, Name
- Object value = asObject(prop.getValue(), pd.getPropertyType());
- if (value != null)
- beanWrapper.setPropertyValue(prop.getName(), value);
- }
-
- // process children nodes
- NodeIterator nodeIt = node.getNodes();
- nodes: while (nodeIt.hasNext()) {
- Node childNode = nodeIt.nextNode();
- String name = childNode.getName();
- if (!beanWrapper.isWritableProperty(name))
- continue nodes;
-
- PropertyDescriptor pd = beanWrapper.getPropertyDescriptor(name);
- Class<?> propClass = pd.getPropertyType();
-
- // objects list
- if (propClass != null && List.class.isAssignableFrom(propClass)) {
- String lstClass = childNode.getProperty(classProperty)
- .getString();
- List<Object> lst;
- try {
- lst = (List<Object>) loadClass(lstClass).newInstance();
- } catch (Exception e) {
- lst = new ArrayList<Object>();
- }
-
- if (childNode.hasNodes()) {
- // Look for children nodes
- NodeIterator valuesIt = childNode.getNodes();
- while (valuesIt.hasNext()) {
- Node lstValueNode = valuesIt.nextNode();
- Object lstValue = nodeToBean(lstValueNode);
- lst.add(lstValue);
- }
- } else {
- // look for a property with the same name which will
- // provide
- // primitives
- Property childProp = childNode.getProperty(childNode
- .getName());
- Class<?> valuesClass = classFromProperty(childProp);
- if (valuesClass != null)
- if (childProp.getDefinition().isMultiple())
- for (Value value : childProp.getValues()) {
- lst.add(asObject(value, valuesClass));
- }
- else
- lst.add(asObject(childProp.getValue(),
- valuesClass));
- }
- beanWrapper.setPropertyValue(name, lst);
- continue nodes;
- }
-
- // objects map
- if (propClass != null && Map.class.isAssignableFrom(propClass)) {
- String mapClass = childNode.getProperty(classProperty)
- .getString();
- Map<Object, Object> map;
- try {
- map = (Map<Object, Object>) loadClass(mapClass)
- .newInstance();
- } catch (Exception e) {
- map = new HashMap<Object, Object>();
- }
-
- // properties
- PropertyIterator keysPropIt = childNode.getProperties();
- keyProps: while (keysPropIt.hasNext()) {
- Property keyProp = keysPropIt.nextProperty();
- // FIXME: use property editor
- String key = keyProp.getName();
- if (classProperty.equals(key))
- continue keyProps;
-
- Class<?> keyPropClass = classFromProperty(keyProp);
- if (keyPropClass != null) {
- Object mapValue = asObject(keyProp.getValue(),
- keyPropClass);
- map.put(key, mapValue);
- }
- }
-
- // node
- NodeIterator keysIt = childNode.getNodes();
- while (keysIt.hasNext()) {
- Node mapValueNode = keysIt.nextNode();
- // FIXME: use property editor
- Object key = mapValueNode.getName();
-
- Object mapValue = nodeToBean(mapValueNode);
-
- map.put(key, mapValue);
- }
- beanWrapper.setPropertyValue(name, map);
- continue nodes;
- }
-
- // default
- Object value = nodeToBean(childNode);
- beanWrapper.setPropertyValue(name, value);
-
- }
- return beanWrapper.getWrappedInstance();
- } catch (Exception e) {
- throw new ArgeoException("Cannot map node " + node, e);
- }
- }
-
- /**
- * Transforms an object to the specified jcr Node in order to persist it.
- *
- * @param beanWrapper
- * @param node
- * @throws RepositoryException
- */
- protected void beanToNode(BeanWrapper beanWrapper, Node node)
- throws RepositoryException {
- properties: for (PropertyDescriptor pd : beanWrapper
- .getPropertyDescriptors()) {
- String name = pd.getName();
- if (!beanWrapper.isReadableProperty(name))
- continue properties;// skip
-
- Object value = beanWrapper.getPropertyValue(name);
- if (value == null) {
- // remove values when updating
- if (node.hasProperty(name))
- node.setProperty(name, (Value) null);
- if (node.hasNode(name))
- node.getNode(name).remove();
-
- continue properties;
- }
-
- // if (uuidProperty != null && uuidProperty.equals(name)) {
- // // node.addMixin(ArgeoJcrConstants.MIX_REFERENCEABLE);
- // node.setProperty(ArgeoJcrConstants.JCR_UUID, value.toString());
- // continue properties;
- // }
-
- if ("class".equals(name)) {
- if (classProperty != null) {
- node.setProperty(classProperty, ((Class<?>) value)
- .getName());
- // TODO: store a class hierarchy?
- }
- continue properties;
- }
-
- // Some bean reference other classes. We must deal with this case
- if (value instanceof Class<?>) {
- node.setProperty(name, ((Class<?>) value).getName());
- continue properties;
- }
-
- Value val = asValue(node.getSession(), value);
- if (val != null) {
- node.setProperty(name, val);
- continue properties;
- }
-
- if (value instanceof List<?>) {
- List<?> lst = (List<?>) value;
- addList(node, name, lst);
- continue properties;
- }
-
- if (value instanceof Map<?, ?>) {
- Map<?, ?> map = (Map<?, ?>) value;
- addMap(node, name, map);
- continue properties;
- }
-
- BeanWrapper child = createBeanWrapper(value);
- // TODO: delegate to another mapper
-
- // TODO: deal with references
- // Node childNode = findChildReference(session, child);
- // if (childNode != null) {
- // node.setProperty(name, childNode);
- // continue properties;
- // }
-
- // default case (recursive)
- if (node.hasNode(name)) {// update
- // TODO: optimize
- node.getNode(name).remove();
- }
- Node childNode = node.addNode(name);
- beanToNode(child, childNode);
- }
- }
-
- /**
- * Process specific case of list
- *
- * @param node
- * @param name
- * @param lst
- * @throws RepositoryException
- */
- protected void addList(Node node, String name, List<?> lst)
- throws RepositoryException {
- if (node.hasNode(name)) {// update
- // TODO: optimize
- node.getNode(name).remove();
- }
-
- Node listNode = node.addNode(name);
- listNode.setProperty(classProperty, lst.getClass().getName());
- Value[] values = new Value[lst.size()];
- boolean atLeastOneSet = false;
- for (int i = 0; i < lst.size(); i++) {
- Object lstValue = lst.get(i);
- values[i] = asValue(node.getSession(), lstValue);
- if (values[i] != null) {
- atLeastOneSet = true;
- } else {
- Node childNode = findChildReference(node.getSession(),
- createBeanWrapper(lstValue));
- if (childNode != null) {
- values[i] = node.getSession().getValueFactory()
- .createValue(childNode);
- atLeastOneSet = true;
- }
- }
- }
-
- // will be either properties or nodes, not both
- if (!atLeastOneSet && lst.size() != 0) {
- for (Object lstValue : lst) {
- Node childNode = listNode.addNode(NODE_VALUE);
- beanToNode(createBeanWrapper(lstValue), childNode);
- }
- } else {
- listNode.setProperty(name, values);
- }
- }
-
- /**
- * Process specific case of maps.
- *
- * @param node
- * @param name
- * @param map
- * @throws RepositoryException
- */
- protected void addMap(Node node, String name, Map<?, ?> map)
- throws RepositoryException {
- if (node.hasNode(name)) {// update
- // TODO: optimize
- node.getNode(name).remove();
- }
-
- Node mapNode = node.addNode(name);
- mapNode.setProperty(classProperty, map.getClass().getName());
- for (Object key : map.keySet()) {
- Object mapValue = map.get(key);
- // PropertyEditor pe = beanWrapper.findCustomEditor(key.getClass(),
- // null);
- String keyStr;
- // if (pe == null) {
- if (key instanceof CharSequence)
- keyStr = key.toString();
- else
- throw new ArgeoException(
- "Cannot find property editor for class "
- + key.getClass());
- // } else {
- // pe.setValue(key);
- // keyStr = pe.getAsText();
- // }
- // TODO: check string format
-
- Value mapVal = asValue(node.getSession(), mapValue);
- if (mapVal != null)
- mapNode.setProperty(keyStr, mapVal);
- else {
- Node entryNode = mapNode.addNode(keyStr);
- beanToNode(createBeanWrapper(mapValue), entryNode);
- }
-
- }
-
- }
-
- protected BeanWrapper createBeanWrapper(Object obj) {
- return new BeanWrapperImpl(obj);
- }
-
- protected BeanWrapper createBeanWrapper(Class<?> clss) {
- return new BeanWrapperImpl(clss);
- }
-
- /** Returns null if value cannot be found */
- protected Value asValue(Session session, Object value)
- throws RepositoryException {
- ValueFactory valueFactory = session.getValueFactory();
- if (value instanceof Integer)
- return valueFactory.createValue((Integer) value);
- else if (value instanceof Long)
- return valueFactory.createValue((Long) value);
- else if (value instanceof Float)
- return valueFactory.createValue((Float) value);
- else if (value instanceof Double)
- return valueFactory.createValue((Double) value);
- else if (value instanceof Boolean)
- return valueFactory.createValue((Boolean) value);
- else if (value instanceof Calendar)
- return valueFactory.createValue((Calendar) value);
- else if (value instanceof Date) {
- Calendar cal = new GregorianCalendar();
- cal.setTime((Date) value);
- return valueFactory.createValue(cal);
- } else if (value instanceof CharSequence)
- return valueFactory.createValue(value.toString());
- else if (value instanceof InputStream)
- return valueFactory.createValue((InputStream) value);
- else
- return null;
- }
-
- protected Class<?> classFromProperty(Property property)
- throws RepositoryException {
- switch (property.getType()) {
- case PropertyType.LONG:
- return Long.class;
- case PropertyType.DOUBLE:
- return Double.class;
- case PropertyType.STRING:
- return String.class;
- case PropertyType.BOOLEAN:
- return Boolean.class;
- case PropertyType.DATE:
- return Calendar.class;
- case PropertyType.NAME:
- return null;
- default:
- throw new ArgeoException("Cannot find class for property "
- + property + ", type="
- + PropertyType.nameFromValue(property.getType()));
- }
- }
-
- protected Object asObject(Value value, Class<?> propClass)
- throws RepositoryException {
- if (propClass.equals(Integer.class))
- return (int) value.getLong();
- else if (propClass.equals(Long.class))
- return value.getLong();
- else if (propClass.equals(Float.class))
- return (float) value.getDouble();
- else if (propClass.equals(Double.class))
- return value.getDouble();
- else if (propClass.equals(Boolean.class))
- return value.getBoolean();
- else if (CharSequence.class.isAssignableFrom(propClass))
- return value.getString();
- else if (InputStream.class.isAssignableFrom(propClass))
- return value.getStream();
- else if (Calendar.class.isAssignableFrom(propClass))
- return value.getDate();
- else if (Date.class.isAssignableFrom(propClass))
- return value.getDate().getTime();
- else
- return null;
- }
-
- protected Node findChildReference(Session session, BeanWrapper child)
- throws RepositoryException {
- if (child.isReadableProperty(uuidProperty)) {
- String childUuid = child.getPropertyValue(uuidProperty).toString();
- try {
- return session.getNodeByUUID(childUuid);
- } catch (ItemNotFoundException e) {
- if (strictUuidReference)
- throw new ArgeoException("No node found with uuid "
- + childUuid, e);
- }
- }
- return null;
- }
-
- protected Class<?> loadClass(String name) {
- // log.debug("Class loader: " + classLoader);
- try {
- return classLoader.loadClass(name);
- } catch (ClassNotFoundException e) {
- throw new ArgeoException("Cannot load class " + name, e);
- }
- }
-
- protected String propertyName(String name) {
- return name;
- }
-
- public void setVersioning(Boolean versioning) {
- this.versioning = versioning;
- }
-
- public void setUuidProperty(String uuidProperty) {
- this.uuidProperty = uuidProperty;
- }
-
- public void setClassProperty(String classProperty) {
- this.classProperty = classProperty;
- }
-
- public void setStrictUuidReference(Boolean strictUuidReference) {
- this.strictUuidReference = strictUuidReference;
- }
-
- public void setPrimaryNodeType(String primaryNodeType) {
- this.primaryNodeType = primaryNodeType;
- }
-
- public void setClassLoader(ClassLoader classLoader) {
- this.classLoader = classLoader;
- }
-
- public void setNodeMapperProvider(NodeMapperProvider nodeMapperProvider) {
- this.nodeMapperProvider = nodeMapperProvider;
- }
-
- public String getPrimaryNodeType() {
- return this.primaryNodeType;
- }
-
- public String getClassProperty() {
- return this.classProperty;
- }
-}
package org.argeo.jcr;
-import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
+import javax.jcr.Binary;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
+import javax.jcr.nodetype.NodeType;
import javax.jcr.version.Version;
import javax.jcr.version.VersionHistory;
import javax.jcr.version.VersionIterator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.argeo.ArgeoException;
-import org.springframework.core.io.Resource;
/**
* Bridge Spring resources and JCR folder / files semantics (nt:folder /
}
public void mkdirs(String path) {
- JcrUtils.mkdirs(session(), path, "nt:folder", "nt:folder", versioning);
- }
-
- public void create(String path, Resource file, String mimeType) {
- try {
- create(path, file.getInputStream(), mimeType);
- } catch (IOException e) {
- throw new ArgeoException("Cannot read " + file, e);
- }
+ JcrUtils.mkdirs(session(), path, NodeType.NT_FOLDER,
+ NodeType.NT_FOLDER, versioning);
}
public void create(String path, InputStream in, String mimeType) {
Node folderNode = (Node) session().getItem(parentPath);
Node fileNode = folderNode.addNode(fileName, "nt:file");
- Node contentNode = fileNode.addNode("jcr:content", "nt:resource");
+ Node contentNode = fileNode.addNode(Property.JCR_CONTENT,
+ "nt:resource");
if (mimeType != null)
- contentNode.setProperty("jcr:mimeType", mimeType);
- contentNode.setProperty("jcr:encoding", defaultEncoding);
- contentNode.setProperty("jcr:data", in);
+ contentNode.setProperty(Property.JCR_MIMETYPE, mimeType);
+ contentNode.setProperty(Property.JCR_ENCODING, defaultEncoding);
+ Binary binary = session().getValueFactory().createBinary(in);
+ contentNode.setProperty(Property.JCR_DATA, binary);
+ JcrUtils.closeQuietly(binary);
Calendar lastModified = Calendar.getInstance();
// lastModified.setTimeInMillis(file.lastModified());
- contentNode.setProperty("jcr:lastModified", lastModified);
+ contentNode.setProperty(Property.JCR_LAST_MODIFIED, lastModified);
// resNode.addMixin("mix:referenceable");
if (versioning)
session().save();
if (versioning)
- fileNode.checkin();
+ session().getWorkspace().getVersionManager()
+ .checkin(fileNode.getPath());
if (log.isDebugEnabled())
log.debug("Created " + path);
}
- public void update(String path, Resource file) {
- try {
- update(path, file.getInputStream());
- } catch (IOException e) {
- throw new ArgeoException("Cannot read " + file, e);
- }
- }
-
public void update(String path, InputStream in) {
try {
}
Node fileNode = (Node) session().getItem(path);
- Node contentNode = fileNode.getNode("jcr:content");
+ Node contentNode = fileNode.getNode(Property.JCR_CONTENT);
if (versioning)
- fileNode.checkout();
- contentNode.setProperty("jcr:data", in);
+ session().getWorkspace().getVersionManager()
+ .checkout(fileNode.getPath());
+ Binary binary = session().getValueFactory().createBinary(in);
+ contentNode.setProperty(Property.JCR_DATA, binary);
+ JcrUtils.closeQuietly(binary);
Calendar lastModified = Calendar.getInstance();
// lastModified.setTimeInMillis(file.lastModified());
- contentNode.setProperty("jcr:lastModified", lastModified);
+ contentNode.setProperty(Property.JCR_LAST_MODIFIED, lastModified);
session().save();
if (versioning)
- fileNode.checkin();
+ session().getWorkspace().getVersionManager()
+ .checkin(fileNode.getPath());
if (log.isDebugEnabled())
log.debug("Updated " + path);
try {
List<Calendar> versions = new ArrayList<Calendar>();
Node fileNode = (Node) session().getItem(path);
- VersionHistory history = fileNode.getVersionHistory();
+ VersionHistory history = session().getWorkspace()
+ .getVersionManager().getVersionHistory(fileNode.getPath());
for (VersionIterator it = history.getAllVersions(); it.hasNext();) {
Version version = (Version) it.next();
versions.add(version.getCreated());
public InputStream retrieve(String path) {
try {
- Node node = (Node) session().getItem(path + "/jcr:content");
- Property property = node.getProperty("jcr:data");
- return property.getStream();
+ Node node = (Node) session().getItem(
+ path + "/" + Property.JCR_CONTENT);
+ Property property = node.getProperty(Property.JCR_DATA);
+ return property.getBinary().getStream();
} catch (Exception e) {
throw new ArgeoException("Cannot retrieve " + path, e);
}
try {
Node fileNode = (Node) session().getItem(path);
- VersionHistory history = fileNode.getVersionHistory();
+ VersionHistory history = session().getWorkspace()
+ .getVersionManager().getVersionHistory(fileNode.getPath());
int count = 0;
Version version = null;
for (VersionIterator it = history.getAllVersions(); it.hasNext();) {
protected InputStream fromVersion(Version version)
throws RepositoryException {
Node frozenNode = version.getNode("jcr:frozenNode");
- InputStream in = frozenNode.getNode("jcr:content")
- .getProperty("jcr:data").getStream();
+ InputStream in = frozenNode.getNode(Property.JCR_CONTENT)
+ .getProperty(Property.JCR_DATA).getBinary().getStream();
return in;
}
import java.net.URLConnection;
import java.net.URLStreamHandler;
-import javax.jcr.Binary;
import javax.jcr.Item;
import javax.jcr.Node;
import javax.jcr.Property;
} else {
Property property = (Property) item;
if(property.getType()==PropertyType.BINARY){
- Binary binary = property.getBinary();
+ //Binary binary = property.getBinary();
}
}
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.argeo.ArgeoException;
-import org.springframework.beans.factory.DisposableBean;
-import org.springframework.beans.factory.FactoryBean;
-import org.springframework.beans.factory.InitializingBean;
/** Proxy JCR sessions and attach them to calling threads. */
-public class ThreadBoundJcrSessionFactory implements FactoryBean,
- InitializingBean, DisposableBean {
+public class ThreadBoundJcrSessionFactory {
private final static Log log = LogFactory
.getLog(ThreadBoundJcrSessionFactory.class);
return proxiedSession;
}
- public void afterPropertiesSet() throws Exception {
+ public void init() throws Exception {
monitoringThread = new MonitoringThread();
monitoringThread.start();
}
- public synchronized void destroy() throws Exception {
+ public synchronized void dispose() throws Exception {
if (activeSessions.size() == 0)
return;
package org.argeo.jcr.security;
-import javax.jcr.Session;
public class CaManager {
-private Session session;
+ // private Session session;
}
--- /dev/null
+/*
+ * 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.jcr.spring;
+
+import java.beans.PropertyDescriptor;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import javax.jcr.Binary;
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Value;
+import javax.jcr.ValueFactory;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.ArgeoException;
+import org.argeo.jcr.JcrUtils;
+import org.argeo.jcr.NodeMapper;
+import org.argeo.jcr.NodeMapperProvider;
+import org.springframework.beans.BeanWrapper;
+import org.springframework.beans.BeanWrapperImpl;
+
+public class BeanNodeMapper implements NodeMapper {
+ private final static Log log = LogFactory.getLog(BeanNodeMapper.class);
+
+ private final static String NODE_VALUE = "value";
+
+ // private String keyNode = "bean:key";
+ private String uuidProperty = "uuid";
+ private String classProperty = "class";
+
+ private Boolean versioning = false;
+ private Boolean strictUuidReference = false;
+
+ // TODO define a primaryNodeType Strategy
+ private String primaryNodeType = null;
+
+ private ClassLoader classLoader = getClass().getClassLoader();
+
+ private NodeMapperProvider nodeMapperProvider;
+
+ /**
+ * exposed method to retrieve a bean from a node
+ */
+ public Object load(Node node) {
+ try {
+ if (nodeMapperProvider != null) {
+ NodeMapper nodeMapper = nodeMapperProvider.findNodeMapper(node);
+ if (nodeMapper != this) {
+ return nodeMapper.load(node);
+ }
+ }
+ return nodeToBean(node);
+ } catch (RepositoryException e) {
+ throw new ArgeoException("Cannot load object from node " + node, e);
+ }
+ }
+
+ /** Update an existing node with an object */
+ public void update(Node node, Object obj) {
+ try {
+ if (nodeMapperProvider != null) {
+
+ NodeMapper nodeMapper = nodeMapperProvider.findNodeMapper(node);
+ if (nodeMapper != this) {
+ nodeMapper.update(node, obj);
+ } else
+ beanToNode(createBeanWrapper(obj), node);
+ } else
+ beanToNode(createBeanWrapper(obj), node);
+ } catch (RepositoryException e) {
+ throw new ArgeoException("Cannot update node " + node + " with "
+ + obj, e);
+ }
+ }
+
+ /**
+ * if no storage path is given; we use canonical path
+ *
+ * @see this.storagePath()
+ */
+ public Node save(Session session, Object obj) {
+ return save(session, storagePath(obj), obj);
+ }
+
+ /**
+ * Create a new node to store an object. If the parentNode doesn't exist, it
+ * is created
+ *
+ * the primaryNodeType may be initialized before
+ */
+ public Node save(Session session, String path, Object obj) {
+ try {
+ final Node node;
+ String parentPath = JcrUtils.parentPath(path);
+ // find or create parent node
+ Node parentNode;
+ if (session.itemExists(path))
+ parentNode = (Node) session.getItem(parentPath);
+ else {
+ parentNode = JcrUtils.mkdirs(session, parentPath, null, null,
+ versioning);
+ }
+ // create node
+
+ if (primaryNodeType != null)
+ node = parentNode.addNode(JcrUtils.lastPathElement(path),
+ primaryNodeType);
+ else
+ node = parentNode.addNode(JcrUtils.lastPathElement(path));
+
+ // Check specific cases
+ if (nodeMapperProvider != null) {
+ NodeMapper nodeMapper = nodeMapperProvider.findNodeMapper(node);
+ if (nodeMapper != this) {
+ nodeMapper.update(node, obj);
+ return node;
+ }
+ }
+ update(node, obj);
+ return node;
+ } catch (ArgeoException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new ArgeoException("Cannot save or update " + obj + " under "
+ + path, e);
+ }
+ }
+
+ /**
+ * Parse the FQN of a class to string with '/' delimiters Prefix the
+ * returned string with "/objects/"
+ */
+ public String storagePath(Object obj) {
+ String clss = obj.getClass().getName();
+ StringBuffer buf = new StringBuffer("/objects/");
+ StringTokenizer st = new StringTokenizer(clss, ".");
+ while (st.hasMoreTokens()) {
+ buf.append(st.nextToken()).append('/');
+ }
+ buf.append(obj.toString());
+ return buf.toString();
+ }
+
+ @SuppressWarnings("unchecked")
+ /**
+ * Transforms a node into an object of the class defined by classProperty Property
+ */
+ protected Object nodeToBean(Node node) throws RepositoryException {
+ if (log.isTraceEnabled())
+ log.trace("Load " + node);
+
+ try {
+ String clssName = node.getProperty(classProperty).getValue()
+ .getString();
+
+ BeanWrapper beanWrapper = createBeanWrapper(loadClass(clssName));
+
+ // process properties
+ PropertyIterator propIt = node.getProperties();
+ props: while (propIt.hasNext()) {
+ Property prop = propIt.nextProperty();
+ if (!beanWrapper.isWritableProperty(prop.getName()))
+ continue props;
+
+ PropertyDescriptor pd = beanWrapper.getPropertyDescriptor(prop
+ .getName());
+ Class<?> propClass = pd.getPropertyType();
+
+ if (log.isTraceEnabled())
+ log.trace("Load " + prop + ", propClass=" + propClass
+ + ", property descriptor=" + pd);
+
+ // primitive list
+ if (propClass != null && List.class.isAssignableFrom(propClass)) {
+ List<Object> lst = new ArrayList<Object>();
+ Class<?> valuesClass = classFromProperty(prop);
+ if (valuesClass != null)
+ for (Value value : prop.getValues()) {
+ lst.add(asObject(value, valuesClass));
+ }
+ continue props;
+ }
+
+ // Case of other type of property accepted by jcr
+ // Long, Double, String, Binary, Date, Boolean, Name
+ Object value = asObject(prop.getValue(), pd.getPropertyType());
+ if (value != null)
+ beanWrapper.setPropertyValue(prop.getName(), value);
+ }
+
+ // process children nodes
+ NodeIterator nodeIt = node.getNodes();
+ nodes: while (nodeIt.hasNext()) {
+ Node childNode = nodeIt.nextNode();
+ String name = childNode.getName();
+ if (!beanWrapper.isWritableProperty(name))
+ continue nodes;
+
+ PropertyDescriptor pd = beanWrapper.getPropertyDescriptor(name);
+ Class<?> propClass = pd.getPropertyType();
+
+ // objects list
+ if (propClass != null && List.class.isAssignableFrom(propClass)) {
+ String lstClass = childNode.getProperty(classProperty)
+ .getString();
+ List<Object> lst;
+ try {
+ lst = (List<Object>) loadClass(lstClass).newInstance();
+ } catch (Exception e) {
+ lst = new ArrayList<Object>();
+ }
+
+ if (childNode.hasNodes()) {
+ // Look for children nodes
+ NodeIterator valuesIt = childNode.getNodes();
+ while (valuesIt.hasNext()) {
+ Node lstValueNode = valuesIt.nextNode();
+ Object lstValue = nodeToBean(lstValueNode);
+ lst.add(lstValue);
+ }
+ } else {
+ // look for a property with the same name which will
+ // provide
+ // primitives
+ Property childProp = childNode.getProperty(childNode
+ .getName());
+ Class<?> valuesClass = classFromProperty(childProp);
+ if (valuesClass != null)
+ if (childProp.getDefinition().isMultiple())
+ for (Value value : childProp.getValues()) {
+ lst.add(asObject(value, valuesClass));
+ }
+ else
+ lst.add(asObject(childProp.getValue(),
+ valuesClass));
+ }
+ beanWrapper.setPropertyValue(name, lst);
+ continue nodes;
+ }
+
+ // objects map
+ if (propClass != null && Map.class.isAssignableFrom(propClass)) {
+ String mapClass = childNode.getProperty(classProperty)
+ .getString();
+ Map<Object, Object> map;
+ try {
+ map = (Map<Object, Object>) loadClass(mapClass)
+ .newInstance();
+ } catch (Exception e) {
+ map = new HashMap<Object, Object>();
+ }
+
+ // properties
+ PropertyIterator keysPropIt = childNode.getProperties();
+ keyProps: while (keysPropIt.hasNext()) {
+ Property keyProp = keysPropIt.nextProperty();
+ // FIXME: use property editor
+ String key = keyProp.getName();
+ if (classProperty.equals(key))
+ continue keyProps;
+
+ Class<?> keyPropClass = classFromProperty(keyProp);
+ if (keyPropClass != null) {
+ Object mapValue = asObject(keyProp.getValue(),
+ keyPropClass);
+ map.put(key, mapValue);
+ }
+ }
+
+ // node
+ NodeIterator keysIt = childNode.getNodes();
+ while (keysIt.hasNext()) {
+ Node mapValueNode = keysIt.nextNode();
+ // FIXME: use property editor
+ Object key = mapValueNode.getName();
+
+ Object mapValue = nodeToBean(mapValueNode);
+
+ map.put(key, mapValue);
+ }
+ beanWrapper.setPropertyValue(name, map);
+ continue nodes;
+ }
+
+ // default
+ Object value = nodeToBean(childNode);
+ beanWrapper.setPropertyValue(name, value);
+
+ }
+ return beanWrapper.getWrappedInstance();
+ } catch (Exception e) {
+ throw new ArgeoException("Cannot map node " + node, e);
+ }
+ }
+
+ /**
+ * Transforms an object to the specified jcr Node in order to persist it.
+ *
+ * @param beanWrapper
+ * @param node
+ * @throws RepositoryException
+ */
+ protected void beanToNode(BeanWrapper beanWrapper, Node node)
+ throws RepositoryException {
+ properties: for (PropertyDescriptor pd : beanWrapper
+ .getPropertyDescriptors()) {
+ String name = pd.getName();
+ if (!beanWrapper.isReadableProperty(name))
+ continue properties;// skip
+
+ Object value = beanWrapper.getPropertyValue(name);
+ if (value == null) {
+ // remove values when updating
+ if (node.hasProperty(name))
+ node.setProperty(name, (Value) null);
+ if (node.hasNode(name))
+ node.getNode(name).remove();
+
+ continue properties;
+ }
+
+ // if (uuidProperty != null && uuidProperty.equals(name)) {
+ // // node.addMixin(ArgeoJcrConstants.MIX_REFERENCEABLE);
+ // node.setProperty(ArgeoJcrConstants.JCR_UUID, value.toString());
+ // continue properties;
+ // }
+
+ if ("class".equals(name)) {
+ if (classProperty != null) {
+ node.setProperty(classProperty,
+ ((Class<?>) value).getName());
+ // TODO: store a class hierarchy?
+ }
+ continue properties;
+ }
+
+ // Some bean reference other classes. We must deal with this case
+ if (value instanceof Class<?>) {
+ node.setProperty(name, ((Class<?>) value).getName());
+ continue properties;
+ }
+
+ Value val = asValue(node.getSession(), value);
+ if (val != null) {
+ node.setProperty(name, val);
+ continue properties;
+ }
+
+ if (value instanceof List<?>) {
+ List<?> lst = (List<?>) value;
+ addList(node, name, lst);
+ continue properties;
+ }
+
+ if (value instanceof Map<?, ?>) {
+ Map<?, ?> map = (Map<?, ?>) value;
+ addMap(node, name, map);
+ continue properties;
+ }
+
+ BeanWrapper child = createBeanWrapper(value);
+ // TODO: delegate to another mapper
+
+ // TODO: deal with references
+ // Node childNode = findChildReference(session, child);
+ // if (childNode != null) {
+ // node.setProperty(name, childNode);
+ // continue properties;
+ // }
+
+ // default case (recursive)
+ if (node.hasNode(name)) {// update
+ // TODO: optimize
+ node.getNode(name).remove();
+ }
+ Node childNode = node.addNode(name);
+ beanToNode(child, childNode);
+ }
+ }
+
+ /**
+ * Process specific case of list
+ *
+ * @param node
+ * @param name
+ * @param lst
+ * @throws RepositoryException
+ */
+ protected void addList(Node node, String name, List<?> lst)
+ throws RepositoryException {
+ if (node.hasNode(name)) {// update
+ // TODO: optimize
+ node.getNode(name).remove();
+ }
+
+ Node listNode = node.addNode(name);
+ listNode.setProperty(classProperty, lst.getClass().getName());
+ Value[] values = new Value[lst.size()];
+ boolean atLeastOneSet = false;
+ for (int i = 0; i < lst.size(); i++) {
+ Object lstValue = lst.get(i);
+ values[i] = asValue(node.getSession(), lstValue);
+ if (values[i] != null) {
+ atLeastOneSet = true;
+ } else {
+ Node childNode = findChildReference(node.getSession(),
+ createBeanWrapper(lstValue));
+ if (childNode != null) {
+ values[i] = node.getSession().getValueFactory()
+ .createValue(childNode);
+ atLeastOneSet = true;
+ }
+ }
+ }
+
+ // will be either properties or nodes, not both
+ if (!atLeastOneSet && lst.size() != 0) {
+ for (Object lstValue : lst) {
+ Node childNode = listNode.addNode(NODE_VALUE);
+ beanToNode(createBeanWrapper(lstValue), childNode);
+ }
+ } else {
+ listNode.setProperty(name, values);
+ }
+ }
+
+ /**
+ * Process specific case of maps.
+ *
+ * @param node
+ * @param name
+ * @param map
+ * @throws RepositoryException
+ */
+ protected void addMap(Node node, String name, Map<?, ?> map)
+ throws RepositoryException {
+ if (node.hasNode(name)) {// update
+ // TODO: optimize
+ node.getNode(name).remove();
+ }
+
+ Node mapNode = node.addNode(name);
+ mapNode.setProperty(classProperty, map.getClass().getName());
+ for (Object key : map.keySet()) {
+ Object mapValue = map.get(key);
+ // PropertyEditor pe = beanWrapper.findCustomEditor(key.getClass(),
+ // null);
+ String keyStr;
+ // if (pe == null) {
+ if (key instanceof CharSequence)
+ keyStr = key.toString();
+ else
+ throw new ArgeoException(
+ "Cannot find property editor for class "
+ + key.getClass());
+ // } else {
+ // pe.setValue(key);
+ // keyStr = pe.getAsText();
+ // }
+ // TODO: check string format
+
+ Value mapVal = asValue(node.getSession(), mapValue);
+ if (mapVal != null)
+ mapNode.setProperty(keyStr, mapVal);
+ else {
+ Node entryNode = mapNode.addNode(keyStr);
+ beanToNode(createBeanWrapper(mapValue), entryNode);
+ }
+
+ }
+
+ }
+
+ protected BeanWrapper createBeanWrapper(Object obj) {
+ return new BeanWrapperImpl(obj);
+ }
+
+ protected BeanWrapper createBeanWrapper(Class<?> clss) {
+ return new BeanWrapperImpl(clss);
+ }
+
+ /** Returns null if value cannot be found */
+ protected Value asValue(Session session, Object value)
+ throws RepositoryException {
+ ValueFactory valueFactory = session.getValueFactory();
+ if (value instanceof Integer)
+ return valueFactory.createValue((Integer) value);
+ else if (value instanceof Long)
+ return valueFactory.createValue((Long) value);
+ else if (value instanceof Float)
+ return valueFactory.createValue((Float) value);
+ else if (value instanceof Double)
+ return valueFactory.createValue((Double) value);
+ else if (value instanceof Boolean)
+ return valueFactory.createValue((Boolean) value);
+ else if (value instanceof Calendar)
+ return valueFactory.createValue((Calendar) value);
+ else if (value instanceof Date) {
+ Calendar cal = new GregorianCalendar();
+ cal.setTime((Date) value);
+ return valueFactory.createValue(cal);
+ } else if (value instanceof CharSequence)
+ return valueFactory.createValue(value.toString());
+ else if (value instanceof InputStream) {
+ Binary binary = session.getValueFactory().createBinary(
+ (InputStream) value);
+ return valueFactory.createValue(binary);
+ } else
+ return null;
+ }
+
+ protected Class<?> classFromProperty(Property property)
+ throws RepositoryException {
+ switch (property.getType()) {
+ case PropertyType.LONG:
+ return Long.class;
+ case PropertyType.DOUBLE:
+ return Double.class;
+ case PropertyType.STRING:
+ return String.class;
+ case PropertyType.BOOLEAN:
+ return Boolean.class;
+ case PropertyType.DATE:
+ return Calendar.class;
+ case PropertyType.NAME:
+ return null;
+ default:
+ throw new ArgeoException("Cannot find class for property "
+ + property + ", type="
+ + PropertyType.nameFromValue(property.getType()));
+ }
+ }
+
+ protected Object asObject(Value value, Class<?> propClass)
+ throws RepositoryException {
+ if (propClass.equals(Integer.class))
+ return (int) value.getLong();
+ else if (propClass.equals(Long.class))
+ return value.getLong();
+ else if (propClass.equals(Float.class))
+ return (float) value.getDouble();
+ else if (propClass.equals(Double.class))
+ return value.getDouble();
+ else if (propClass.equals(Boolean.class))
+ return value.getBoolean();
+ else if (CharSequence.class.isAssignableFrom(propClass))
+ return value.getString();
+ else if (InputStream.class.isAssignableFrom(propClass))
+ return value.getBinary().getStream();
+ else if (Calendar.class.isAssignableFrom(propClass))
+ return value.getDate();
+ else if (Date.class.isAssignableFrom(propClass))
+ return value.getDate().getTime();
+ else
+ return null;
+ }
+
+ protected Node findChildReference(Session session, BeanWrapper child)
+ throws RepositoryException {
+ if (child.isReadableProperty(uuidProperty)) {
+ String childUuid = child.getPropertyValue(uuidProperty).toString();
+ try {
+ return session.getNodeByIdentifier(childUuid);
+ } catch (ItemNotFoundException e) {
+ if (strictUuidReference)
+ throw new ArgeoException("No node found with uuid "
+ + childUuid, e);
+ }
+ }
+ return null;
+ }
+
+ protected Class<?> loadClass(String name) {
+ // log.debug("Class loader: " + classLoader);
+ try {
+ return classLoader.loadClass(name);
+ } catch (ClassNotFoundException e) {
+ throw new ArgeoException("Cannot load class " + name, e);
+ }
+ }
+
+ protected String propertyName(String name) {
+ return name;
+ }
+
+ public void setVersioning(Boolean versioning) {
+ this.versioning = versioning;
+ }
+
+ public void setUuidProperty(String uuidProperty) {
+ this.uuidProperty = uuidProperty;
+ }
+
+ public void setClassProperty(String classProperty) {
+ this.classProperty = classProperty;
+ }
+
+ public void setStrictUuidReference(Boolean strictUuidReference) {
+ this.strictUuidReference = strictUuidReference;
+ }
+
+ public void setPrimaryNodeType(String primaryNodeType) {
+ this.primaryNodeType = primaryNodeType;
+ }
+
+ public void setClassLoader(ClassLoader classLoader) {
+ this.classLoader = classLoader;
+ }
+
+ public void setNodeMapperProvider(NodeMapperProvider nodeMapperProvider) {
+ this.nodeMapperProvider = nodeMapperProvider;
+ }
+
+ public String getPrimaryNodeType() {
+ return this.primaryNodeType;
+ }
+
+ public String getClassProperty() {
+ return this.classProperty;
+ }
+}
import javax.jcr.Repository;
import org.apache.jackrabbit.core.TransientRepository;
+import org.argeo.jcr.spring.BeanNodeMapper;
import org.argeo.jcr.unit.AbstractJcrTestCase;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
protected File getRepositoryFile() throws Exception {
Resource res = new ClassPathResource(
- "org/argeo/server/jcr/repository.xml");
+ "org/argeo/server/jcr/repository-h2.xml");
return res.getFile();
}
jra.mkdirs(basePath);
Resource res = new ClassPathResource("org/argeo/server/jcr/dummy00.xls");
String filePath = basePath + "/dummy.xml";
- jra.create(filePath, res, "application/vnd.ms-excel");
+ jra.create(filePath, res.getInputStream(), "application/vnd.ms-excel");
InputStream in = jra.retrieve(filePath);
assertTrue(IOUtils.contentEquals(res.getInputStream(), in));
}
String filePath = basePath + "/dummy.xml";
Resource res00 = new ClassPathResource(
"org/argeo/server/jcr/dummy00.xls");
- jra.create(filePath, res00, "application/vnd.ms-excel");
+ jra.create(filePath, res00.getInputStream(), "application/vnd.ms-excel");
Resource res01 = new ClassPathResource(
"org/argeo/server/jcr/dummy01.xls");
- jra.update(filePath, res01);
+ jra.update(filePath, res01.getInputStream());
Resource res02 = new ClassPathResource(
"org/argeo/server/jcr/dummy02.xls");
- jra.update(filePath, res02);
+ jra.update(filePath, res02.getInputStream());
List<Calendar> versions = jra.listVersions(filePath);
log.debug("Versions of " + filePath);
assertTrue(IOUtils.contentEquals(res02.getInputStream(), in));
Resource res03 = new ClassPathResource(
"org/argeo/server/jcr/dummy03.xls");
- jra.update(filePath, res03);
+ jra.update(filePath, res03.getInputStream());
in = jra.retrieve(filePath, 1);
assertTrue(IOUtils.contentEquals(res01.getInputStream(), in));
}
protected File getRepositoryFile() throws Exception {
Resource res = new ClassPathResource(
- "org/argeo/server/jcr/repository.xml");
+ "org/argeo/server/jcr/repository-h2.xml");
return res.getFile();
}
--- /dev/null
+<?xml version="1.0"?>
+<!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 1.6//EN"
+ "http://jackrabbit.apache.org/dtd/repository-2.0.dtd">
+<Repository>
+ <!-- Shared datasource -->
+ <DataSources>
+ <DataSource name="dataSource">
+ <param name="driver" value="org.h2.Driver" />
+ <param name="url" value="jdbc:h2:mem:jackrabbit" />
+ <param name="user" value="sa" />
+ <param name="password" value="" />
+ <param name="databaseType" value="h2" />
+ <param name="maxPoolSize" value="10" />
+ </DataSource>
+ </DataSources>
+
+ <!-- File system and datastore -->
+ <FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem">
+ <param name="dataSourceName" value="dataSource" />
+ <param name="schema" value="default" />
+ <param name="schemaObjectPrefix" value="fs_" />
+ </FileSystem>
+ <DataStore class="org.apache.jackrabbit.core.data.db.DbDataStore">
+ <param name="dataSourceName" value="dataSource" />
+ <param name="schemaObjectPrefix" value="ds_" />
+ </DataStore>
+
+ <!-- Workspace templates -->
+ <Workspaces rootPath="${rep.home}/workspaces"
+ defaultWorkspace="dev" />
+ <Workspace name="${wsp.name}">
+ <FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem">
+ <param name="dataSourceName" value="dataSource" />
+ <param name="schema" value="default" />
+ <param name="schemaObjectPrefix" value="${wsp.name}_fs_" />
+ </FileSystem>
+ <PersistenceManager
+ class="org.apache.jackrabbit.core.persistence.pool.H2PersistenceManager">
+ <param name="dataSourceName" value="dataSource" />
+ <param name="schemaObjectPrefix" value="${wsp.name}_pm_" />
+ </PersistenceManager>
+ <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
+ <param name="path" value="${wsp.home}/index" />
+ </SearchIndex>
+ </Workspace>
+
+ <!-- Versioning -->
+ <Versioning rootPath="${rep.home}/version">
+ <FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem">
+ <param name="dataSourceName" value="dataSource" />
+ <param name="schema" value="default" />
+ <param name="schemaObjectPrefix" value="fs_ver_" />
+ </FileSystem>
+ <PersistenceManager
+ class="org.apache.jackrabbit.core.persistence.pool.H2PersistenceManager">
+ <param name="dataSourceName" value="dataSource" />
+ <param name="schemaObjectPrefix" value="pm_ver_" />
+ </PersistenceManager>
+ </Versioning>
+
+ <!-- Indexing -->
+ <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
+ <param name="path" value="${rep.home}/repository/index" />
+ <param name="extractorPoolSize" value="2" />
+ <param name="supportHighlighting" value="true" />
+ </SearchIndex>
+
+ <!-- Security -->
+ <Security appName="Jackrabbit">
+ <SecurityManager
+ class="org.apache.jackrabbit.core.security.simple.SimpleSecurityManager"
+ workspaceName="security" />
+ <AccessManager
+ class="org.apache.jackrabbit.core.security.simple.SimpleAccessManager" />
+ <LoginModule
+ class="org.apache.jackrabbit.core.security.simple.SimpleLoginModule">
+ <param name="anonymousId" value="anonymous" />
+ <param name="adminId" value="admin" />
+ </LoginModule>
+ </Security>
+</Repository>
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0"?>
-<!--
-
- 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.
-
--->
-
-<!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 1.6//EN"
- "http://jackrabbit.apache.org/dtd/repository-1.6.dtd">
-<!-- Example Repository Configuration File
- Used by
- - org.apache.jackrabbit.core.config.RepositoryConfigTest.java
- -
--->
-<Repository>
- <!--
- virtual file system where the repository stores global state
- (e.g. registered namespaces, custom node types, etc.)
- -->
- <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
- <param name="path" value="${rep.home}/repository"/>
- </FileSystem>
-
- <!--
- security configuration
- -->
- <Security appName="Jackrabbit">
- <!--
- security manager:
- class: FQN of class implementing the JackrabbitSecurityManager interface
- -->
- <SecurityManager class="org.apache.jackrabbit.core.security.simple.SimpleSecurityManager" workspaceName="security">
- <!--
- workspace access:
- class: FQN of class implementing the WorkspaceAccessManager interface
- -->
- <!-- <WorkspaceAccessManager class="..."/> -->
- <!-- <param name="config" value="${rep.home}/security.xml"/> -->
- </SecurityManager>
-
- <!--
- access manager:
- class: FQN of class implementing the AccessManager interface
- -->
- <AccessManager class="org.apache.jackrabbit.core.security.simple.SimpleAccessManager">
- <!-- <param name="config" value="${rep.home}/access.xml"/> -->
- </AccessManager>
-
- <LoginModule class="org.apache.jackrabbit.core.security.simple.SimpleLoginModule">
- <!--
- anonymous user name ('anonymous' is the default value)
- -->
- <param name="anonymousId" value="anonymous"/>
- <!--
- administrator user id (default value if param is missing is 'admin')
- -->
- <param name="adminId" value="admin"/>
- </LoginModule>
- </Security>
-
- <!--
- location of workspaces root directory and name of default workspace
- -->
- <Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default"/>
- <!--
- workspace configuration template:
- used to create the initial workspace if there's no workspace yet
- -->
- <Workspace name="${wsp.name}">
- <!--
- virtual file system of the workspace:
- class: FQN of class implementing the FileSystem interface
- -->
- <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
- <param name="path" value="${wsp.home}"/>
- </FileSystem>
- <!--
- persistence manager of the workspace:
- class: FQN of class implementing the PersistenceManager interface
- -->
- <PersistenceManager class="org.apache.jackrabbit.core.persistence.bundle.DerbyPersistenceManager">
- <param name="url" value="jdbc:derby:memory:db;create=true"/>
- <param name="schemaObjectPrefix" value="${wsp.name}_"/>
- </PersistenceManager>
- <!--
- Search index and the file system it uses.
- class: FQN of class implementing the QueryHandler interface
- -->
- <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
- <param name="path" value="${wsp.home}/index"/>
- <param name="extractorPoolSize" value="2"/>
- <param name="supportHighlighting" value="true"/>
- </SearchIndex>
- </Workspace>
-
- <!--
- Configures the versioning
- -->
- <Versioning rootPath="${rep.home}/version">
- <!--
- Configures the filesystem to use for versioning for the respective
- persistence manager
- -->
- <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
- <param name="path" value="${rep.home}/version" />
- </FileSystem>
-
- <!--
- Configures the persistence manager to be used for persisting version state.
- Please note that the current versioning implementation is based on
- a 'normal' persistence manager, but this could change in future
- implementations.
- -->
- <PersistenceManager class="org.apache.jackrabbit.core.persistence.bundle.DerbyPersistenceManager">
- <param name="url" value="jdbc:derby:memory:version;create=true"/>
- <param name="schemaObjectPrefix" value="version_"/>
- </PersistenceManager>
- </Versioning>
-
- <!--
- Search index for content that is shared repository wide
- (/jcr:system tree, contains mainly versions)
- -->
- <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
- <param name="path" value="${rep.home}/repository/index"/>
- <param name="extractorPoolSize" value="2"/>
- <param name="supportHighlighting" value="true"/>
- </SearchIndex>
-</Repository>