Author: sascharodekamp
Date: Mon Mar 7 10:24:21 2011 New Revision: 1078730 URL: http://svn.apache.org/viewvc?rev=1078730&view=rev Log: Update - Moved the Jackrabbit implementation to a more common folder called "jcr" (JavaContentRepository), updated the Jackrabbit Lib to version 2.2.4 and fixed the build process, there was a reference to the framework/lib folder missing. Added: ofbiz/branches/jackrabbit20100709/framework/jcr/ (props changed) - copied from r1066170, ofbiz/branches/jackrabbit20100709/framework/jackrabbit/ ofbiz/branches/jackrabbit20100709/framework/jcr/lib/jackrabbit-api-2.2.4.jar (with props) ofbiz/branches/jackrabbit20100709/framework/jcr/lib/jackrabbit-core-2.2.4.jar (with props) ofbiz/branches/jackrabbit20100709/framework/jcr/lib/jackrabbit-jca-2.2.4.jar (with props) ofbiz/branches/jackrabbit20100709/framework/jcr/lib/jackrabbit-jcr-commons-2.2.4.jar (with props) ofbiz/branches/jackrabbit20100709/framework/jcr/lib/jackrabbit-spi-2.2.4.jar (with props) ofbiz/branches/jackrabbit20100709/framework/jcr/lib/jackrabbit-spi-commons-2.2.4.jar (with props) ofbiz/branches/jackrabbit20100709/framework/jcr/lib/pdfbox-1.3.1.jar (with props) ofbiz/branches/jackrabbit20100709/framework/jcr/lib/tika-core-0.8.jar (with props) ofbiz/branches/jackrabbit20100709/framework/jcr/lib/tika-parsers-0.8.jar (with props) ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/JackrabbitContainer.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/JcrRepositoryFactory.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/LocalRepositoryFactory.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/OFBizLoginModule.java ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/RepositoryFactory.java Removed: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/ ofbiz/branches/jackrabbit20100709/framework/jcr/lib/jackrabbit-api-2.1.0.jar ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jackrabbit/ Modified: ofbiz/branches/jackrabbit20100709/.classpath ofbiz/branches/jackrabbit20100709/framework/base/config/ofbiz-containers.xml ofbiz/branches/jackrabbit20100709/framework/jcr/build.xml ofbiz/branches/jackrabbit20100709/framework/jcr/ofbiz-component.xml Modified: ofbiz/branches/jackrabbit20100709/.classpath URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/.classpath?rev=1078730&r1=1078729&r2=1078730&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/.classpath (original) +++ ofbiz/branches/jackrabbit20100709/.classpath Mon Mar 7 10:24:21 2011 @@ -125,18 +125,18 @@ <classpathentry kind="lib" path="framework/geronimo/lib/geronimo-transaction-2.1.1.jar"/> <classpathentry kind="lib" path="framework/guiapp/lib/XuiCoreSwing-v3.2rc2b.jar"/> <classpathentry kind="lib" path="framework/guiapp/lib/XuiOptional-v3.2rc2b.jar"/> - <classpathentry kind="lib" path="framework/jackrabbit/lib/concurrent-1.3.4.jar"/> - <classpathentry kind="lib" path="framework/jackrabbit/lib/jackrabbit-api-2.1.0.jar"/> - <classpathentry kind="lib" path="framework/jackrabbit/lib/jackrabbit-core-2.1.0.jar"/> - <classpathentry kind="lib" path="framework/jackrabbit/lib/jackrabbit-jcr-commons-2.1.0.jar"/> - <classpathentry kind="lib" path="framework/jackrabbit/lib/jackrabbit-spi-2.1.0.jar"/> - <classpathentry kind="lib" path="framework/jackrabbit/lib/jackrabbit-spi-commons-2.1.0.jar"/> - <classpathentry kind="lib" path="framework/jackrabbit/lib/jcr-2.0.jar"/> - <classpathentry kind="lib" path="framework/jackrabbit/lib/pdfbox-1.0.0.jar"/> - <classpathentry kind="lib" path="framework/jackrabbit/lib/slf4j-api-1.5.8.jar"/> - <classpathentry kind="lib" path="framework/jackrabbit/lib/slf4j-log4j12-1.5.8.jar"/> - <classpathentry kind="lib" path="framework/jackrabbit/lib/tika-core-0.6.jar"/> - <classpathentry kind="lib" path="framework/jackrabbit/lib/tika-parsers-0.6.jar"/> + <classpathentry kind="lib" path="framework/jcr/lib/concurrent-1.3.4.jar"/> + <classpathentry kind="lib" path="framework/jcr/lib/jackrabbit-api-2.1.0.jar"/> + <classpathentry kind="lib" path="framework/jcr/lib/jackrabbit-core-2.1.0.jar"/> + <classpathentry kind="lib" path="framework/jcr/lib/jackrabbit-jcr-commons-2.1.0.jar"/> + <classpathentry kind="lib" path="framework/jcr/lib/jackrabbit-spi-2.1.0.jar"/> + <classpathentry kind="lib" path="framework/jcr/lib/jackrabbit-spi-commons-2.1.0.jar"/> + <classpathentry kind="lib" path="framework/jcr/lib/jcr-2.0.jar"/> + <classpathentry kind="lib" path="framework/jcr/lib/pdfbox-1.0.0.jar"/> + <classpathentry kind="lib" path="framework/jcr/lib/slf4j-api-1.5.8.jar"/> + <classpathentry kind="lib" path="framework/jcr/lib/slf4j-log4j12-1.5.8.jar"/> + <classpathentry kind="lib" path="framework/jcr/lib/tika-core-0.6.jar"/> + <classpathentry kind="lib" path="framework/jcr/lib/tika-parsers-0.6.jar"/> <classpathentry kind="lib" path="framework/jetty/lib/jasper-compiler-5.5.15.jar"/> <classpathentry kind="lib" path="framework/jetty/lib/jasper-runtime-5.5.15.jar"/> <classpathentry kind="lib" path="framework/jetty/lib/jetty-6.1.11.jar"/> @@ -230,7 +230,7 @@ <classpathentry kind="src" path="framework/example/src"/> <classpathentry kind="src" path="framework/geronimo/src"/> <classpathentry kind="src" path="framework/guiapp/src"/> - <classpathentry kind="src" path="framework/jackrabbit/src"/> + <classpathentry kind="src" path="framework/jcr/src"/> <classpathentry kind="src" path="framework/jetty/src"/> <classpathentry kind="src" path="framework/minilang/src"/> <classpathentry kind="src" path="framework/security/src"/> Modified: ofbiz/branches/jackrabbit20100709/framework/base/config/ofbiz-containers.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/base/config/ofbiz-containers.xml?rev=1078730&r1=1078729&r2=1078730&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/base/config/ofbiz-containers.xml (original) +++ ofbiz/branches/jackrabbit20100709/framework/base/config/ofbiz-containers.xml Mon Mar 7 10:24:21 2011 @@ -99,9 +99,9 @@ under the License. <!-- Load embedded Jackrabbit content repository. Since this container depends upon JNDI, it must be started after the naming-container container.--> - <container name="jackrabbit" class="org.ofbiz.jackrabbit.JackrabbitContainer"> + <container name="jcr-container" class="org.ofbiz.jackrabbit.JackrabbitContainer"> <property name="repHomeDir" value="runtime/data/jackrabbit/"/> - <property name="configFilePath" value="framework/jackrabbit/config/jackrabbit.xml"/> + <property name="configFilePath" value="framework/jcr/config/jackrabbit.xml"/> <property name="jndiName" value="jcr/local"/> </container> @@ -265,7 +265,7 @@ under the License. <property name="ciphers" value=""/> </property> </container> - + <!-- load the BIRT container --> <container name="birt-container" class="org.ofbiz.birt.container.BirtContainer"> <property name="delegator-name" value="default"/> Propchange: ofbiz/branches/jackrabbit20100709/framework/jcr/ ------------------------------------------------------------------------------ --- svn:ignore (added) +++ svn:ignore Mon Mar 7 10:24:21 2011 @@ -0,0 +1 @@ +build Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/build.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/build.xml?rev=1078730&r1=1066170&r2=1078730&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/build.xml (original) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/build.xml Mon Mar 7 10:24:21 2011 @@ -18,19 +18,20 @@ specific language governing permissions under the License. --> -<project name="OFBiz - Jackrabbit" default="jar" basedir="."> +<project name="OFBiz - JCR" default="jar" basedir="."> <import file="../../common.xml"/> <!-- ================================================================== --> <!-- Initialization of all property settings --> <!-- ================================================================== --> - <property name="desc" value="Jackrabbit Component"/> - <property name="name" value="ofbiz-jackrabbit"/> + <property name="desc" value="JCR Component"/> + <property name="name" value="ofbiz-jcr"/> <property name="ofbiz.home.dir" value="../.."/> <path id="local.class.path"> <fileset dir="${lib.dir}" includes="*.jar"/> + <fileset dir="../../framework/base/lib" includes="*.jar"/> <fileset dir="../../framework/base/lib/commons" includes="*.jar"/> <fileset dir="../../framework/base/build/lib" includes="*.jar"/> <fileset dir="../../framework/entity/build/lib" includes="*.jar"/> Added: ofbiz/branches/jackrabbit20100709/framework/jcr/lib/jackrabbit-api-2.2.4.jar URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/lib/jackrabbit-api-2.2.4.jar?rev=1078730&view=auto ============================================================================== Binary file - no diff available. Propchange: ofbiz/branches/jackrabbit20100709/framework/jcr/lib/jackrabbit-api-2.2.4.jar ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: ofbiz/branches/jackrabbit20100709/framework/jcr/lib/jackrabbit-core-2.2.4.jar URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/lib/jackrabbit-core-2.2.4.jar?rev=1078730&view=auto ============================================================================== Binary file - no diff available. Propchange: ofbiz/branches/jackrabbit20100709/framework/jcr/lib/jackrabbit-core-2.2.4.jar ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: ofbiz/branches/jackrabbit20100709/framework/jcr/lib/jackrabbit-jca-2.2.4.jar URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/lib/jackrabbit-jca-2.2.4.jar?rev=1078730&view=auto ============================================================================== Binary file - no diff available. Propchange: ofbiz/branches/jackrabbit20100709/framework/jcr/lib/jackrabbit-jca-2.2.4.jar ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: ofbiz/branches/jackrabbit20100709/framework/jcr/lib/jackrabbit-jcr-commons-2.2.4.jar URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/lib/jackrabbit-jcr-commons-2.2.4.jar?rev=1078730&view=auto ============================================================================== Binary file - no diff available. Propchange: ofbiz/branches/jackrabbit20100709/framework/jcr/lib/jackrabbit-jcr-commons-2.2.4.jar ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: ofbiz/branches/jackrabbit20100709/framework/jcr/lib/jackrabbit-spi-2.2.4.jar URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/lib/jackrabbit-spi-2.2.4.jar?rev=1078730&view=auto ============================================================================== Binary file - no diff available. Propchange: ofbiz/branches/jackrabbit20100709/framework/jcr/lib/jackrabbit-spi-2.2.4.jar ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: ofbiz/branches/jackrabbit20100709/framework/jcr/lib/jackrabbit-spi-commons-2.2.4.jar URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/lib/jackrabbit-spi-commons-2.2.4.jar?rev=1078730&view=auto ============================================================================== Binary file - no diff available. Propchange: ofbiz/branches/jackrabbit20100709/framework/jcr/lib/jackrabbit-spi-commons-2.2.4.jar ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: ofbiz/branches/jackrabbit20100709/framework/jcr/lib/pdfbox-1.3.1.jar URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/lib/pdfbox-1.3.1.jar?rev=1078730&view=auto ============================================================================== Binary file - no diff available. Propchange: ofbiz/branches/jackrabbit20100709/framework/jcr/lib/pdfbox-1.3.1.jar ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: ofbiz/branches/jackrabbit20100709/framework/jcr/lib/tika-core-0.8.jar URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/lib/tika-core-0.8.jar?rev=1078730&view=auto ============================================================================== Binary file - no diff available. Propchange: ofbiz/branches/jackrabbit20100709/framework/jcr/lib/tika-core-0.8.jar ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: ofbiz/branches/jackrabbit20100709/framework/jcr/lib/tika-parsers-0.8.jar URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/lib/tika-parsers-0.8.jar?rev=1078730&view=auto ============================================================================== Binary file - no diff available. Propchange: ofbiz/branches/jackrabbit20100709/framework/jcr/lib/tika-parsers-0.8.jar ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Modified: ofbiz/branches/jackrabbit20100709/framework/jcr/ofbiz-component.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/ofbiz-component.xml?rev=1078730&r1=1066170&r2=1078730&view=diff ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/ofbiz-component.xml (original) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/ofbiz-component.xml Mon Mar 7 10:24:21 2011 @@ -18,7 +18,7 @@ specific language governing permissions under the License. --> -<ofbiz-component name="jackrabbit" +<ofbiz-component name="jcr" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/ofbiz-component.xsd"> <resource-loader name="main" type="component"/> Added: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/JackrabbitContainer.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/JackrabbitContainer.java?rev=1078730&view=auto ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/JackrabbitContainer.java (added) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/JackrabbitContainer.java Mon Mar 7 10:24:21 2011 @@ -0,0 +1,129 @@ +/******************************************************************************* + * 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. + *******************************************************************************/ +package org.ofbiz.jcr; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URISyntaxException; +import java.net.URL; + +import javax.jcr.Credentials; +import javax.jcr.LoginException; +import javax.jcr.Repository; +import javax.jcr.RepositoryException; +import javax.jcr.Session; +import javax.jcr.SimpleCredentials; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.naming.Reference; + +import org.apache.jackrabbit.core.TransientRepository; +import org.ofbiz.base.container.Container; +import org.ofbiz.base.container.ContainerConfig; +import org.ofbiz.base.container.ContainerException; +import org.ofbiz.base.location.FlexibleLocation; +import org.ofbiz.base.util.Debug; +import org.ofbiz.entity.Delegator; +import org.ofbiz.entity.DelegatorFactory; +import org.ofbiz.entity.GenericEntityException; +import org.ofbiz.entity.GenericValue; + +/** + * A container for a local JCR-compliant content repository. The current + * implementation uses Apache Jackrabbit. + */ +public class JackrabbitContainer implements Container { + + public static final String module = JackrabbitContainer.class.getName(); + + private static File homeDir = null; + private static File jackrabbitConfigFile = null; + private static String jndiName; + protected static Repository repository; + private static Session session; + + @Override + public void init(String[] args, String configFile) throws ContainerException { + ContainerConfig.Container cc = ContainerConfig.getContainer("jackrabbit", configFile); + String homeDirURL; + try { + homeDirURL = ContainerConfig.getPropertyValue(cc, "repHomeDir", "runtime/data/jackrabbit/"); + jndiName = ContainerConfig.getPropertyValue(cc, "jndiName", "jcr/local"); + homeDir = new File(homeDirURL); + URL jackrabbitConfigUrl = FlexibleLocation.resolveLocation(ContainerConfig.getPropertyValue(cc, "configFilePath", "framework/jackrabbit/config/jackrabbit.xml")); + jackrabbitConfigFile = new File(jackrabbitConfigUrl.toURI()); + + } catch (MalformedURLException e) { + Debug.logError(e, module); + } catch (URISyntaxException e) { + Debug.logError(e, module); + } + } + + @Override + public boolean start() throws ContainerException { + repository = new TransientRepository(jackrabbitConfigFile, homeDir); + try { + Delegator delegator = DelegatorFactory.getDelegator("default"); + GenericValue userLogin = delegator.findOne("UserLogin", true, "userLoginId", "system"); + // Open a session to get the repo running + session = JackrabbitContainer.getUserSession(userLogin); + } catch (LoginException e) { + Debug.logError(e, module); + } catch (RepositoryException e) { + Debug.logError(e, module); + } catch (GenericEntityException e) { + Debug.logError(e, module); + } + try { + Reference ref = new Reference(Repository.class.getName(), LocalRepositoryFactory.class.getName(), null); + Context context = new InitialContext(); + context.bind(jndiName, ref); + } catch (NamingException e) { + Debug.logError(e, module); + } + // Test JNDI bind + RepositoryFactory.getRepository(); + return true; + } + + @Override + public void stop() throws ContainerException { + try { + Context context = new InitialContext(); + context.unbind(jndiName); + } catch (NamingException e) { + Debug.logError(e, module); + } + if (session != null) { + session.logout(); + } + if (repository != null) { + // Not needed - Jackrabbit shuts down when the session is closed +// repository.shutdown(); + } + } + + public static Session getUserSession(GenericValue userLogin) throws RepositoryException { + String currentPassword = userLogin.getString("currentPassword") == null ? "" : userLogin.getString("currentPassword"); + Credentials creds = new SimpleCredentials(userLogin.getString("userLoginId"), currentPassword.toCharArray()); + return repository.login(creds); + } +} Added: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/JcrRepositoryFactory.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/JcrRepositoryFactory.java?rev=1078730&view=auto ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/JcrRepositoryFactory.java (added) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/JcrRepositoryFactory.java Mon Mar 7 10:24:21 2011 @@ -0,0 +1,30 @@ +/******************************************************************************* + * 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. + *******************************************************************************/ +package org.ofbiz.jcr; + +import javax.jcr.Repository; + +public interface JcrRepositoryFactory { + /** + * + * @param repositoryName The name specified in the <code>jcr-repositories.xml</code> file + * @return + */ + Repository getInstance(String repositoryName); +} Added: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/LocalRepositoryFactory.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/LocalRepositoryFactory.java?rev=1078730&view=auto ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/LocalRepositoryFactory.java (added) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/LocalRepositoryFactory.java Mon Mar 7 10:24:21 2011 @@ -0,0 +1,45 @@ +/******************************************************************************* + * 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. + *******************************************************************************/ +package org.ofbiz.jcr; + +import java.util.Hashtable; + +import javax.jcr.Repository; +import javax.naming.Context; +import javax.naming.Name; +import javax.naming.Reference; +import javax.naming.spi.ObjectFactory; + +/** + * A JNDI <code>ObjectFactory</code> that returns a <code>javax.jcr.Repository</code> + * instance. + */ +public class LocalRepositoryFactory implements ObjectFactory { + + @Override + public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception { + if (obj instanceof Reference) { + Reference ref = (Reference)obj; + if (ref.getClassName().equals(Repository.class.getName())) { + return JackrabbitContainer.repository; + } + } + return null; + } +} Added: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/OFBizLoginModule.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/OFBizLoginModule.java?rev=1078730&view=auto ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/OFBizLoginModule.java (added) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/OFBizLoginModule.java Mon Mar 7 10:24:21 2011 @@ -0,0 +1,146 @@ +/******************************************************************************* + * 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. + *******************************************************************************/ +package org.ofbiz.jcr; + +import java.io.IOException; +import java.util.Map; + +import javax.security.auth.Subject; +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.callback.NameCallback; +import javax.security.auth.callback.PasswordCallback; +import javax.security.auth.callback.UnsupportedCallbackException; +import javax.security.auth.login.LoginException; +import javax.security.auth.spi.LoginModule; + +import javolution.util.FastMap; + +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.entity.Delegator; +import org.ofbiz.entity.DelegatorFactory; +import org.ofbiz.entity.GenericEntityException; +import org.ofbiz.entity.GenericValue; +import org.ofbiz.service.GenericDispatcher; +import org.ofbiz.service.GenericServiceException; +import org.ofbiz.service.LocalDispatcher; +import org.ofbiz.service.ServiceUtil; + +public class OFBizLoginModule implements LoginModule { + + public static final String module = OFBizLoginModule.class.getName(); + + protected Subject subject; + protected CallbackHandler callbackHandler; + protected Map<String, ?> sharedState; + protected Map<String, ?> options; + + private Delegator delegator; + private LocalDispatcher dispatcher; + + private GenericValue userLogin; + + @Override + public boolean abort() throws LoginException { + return logout(); + } + + @Override + public boolean commit() throws LoginException { + if (userLogin != null) { + return true; + } + return false; + } + + @Override + public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> options) { + // get the delegator + delegator = DelegatorFactory.getDelegator("default"); + + // get the dispatcher + dispatcher = GenericDispatcher.getLocalDispatcher("auth-dispatcher", delegator); + + this.subject = subject; + this.callbackHandler = callbackHandler; + this.sharedState = sharedState; + this.options = options; + + if (options != null) { + for (Map.Entry<String, ?> option : options.entrySet()) { + Debug.logWarning("OFBizLoginModule does not support provided option [" + option.getKey() + "] with value [" + option.getValue() + "], ignoring", module); + } + } + } + + @Override + public boolean login() throws LoginException { + NameCallback nameCallback = new NameCallback("userLoginId"); + PasswordCallback passwordCallback = new PasswordCallback("currentPassword", false); + Callback[] callbacks = new Callback[]{nameCallback, passwordCallback}; + try { + callbackHandler.handle(callbacks); + } catch (IOException e) { + Debug.logError(e, module); + throw new LoginException(e.getMessage()); + } catch (UnsupportedCallbackException e) { + Debug.logError(e, module); + throw new LoginException(e.getMessage()); + } + + String userLoginId = nameCallback.getName(); + String password = String.valueOf(passwordCallback.getPassword()); + passwordCallback.clearPassword(); + // try matching against the encrypted password + try { + GenericValue newUserLogin = delegator.findOne("UserLogin", false, "userLoginId", userLoginId); + if (newUserLogin.getString("currentPassword") == null || newUserLogin.getString("currentPassword").equals(password)) { + userLogin = newUserLogin; + return true; + } + } catch (GenericEntityException e) { + Debug.logError(e, module); + } + // plain text password + if (UtilValidate.isNotEmpty(password)) { + Map<String, Object> loginCtx = FastMap.newInstance(); + loginCtx.put("login.username", userLoginId); + loginCtx.put("login.password", password); + try { + Map<String, ? extends Object> result = dispatcher.runSync("userLogin", loginCtx); + if (ServiceUtil.isSuccess(result)) { + userLogin = (GenericValue) result.get("userLogin"); + return true; + } + } catch (GenericServiceException e) { + Debug.logError(e, module); + throw new LoginException(e.getMessage()); + } + } + return false; + } + + @Override + public boolean logout() throws LoginException { + userLogin = null; + return true; + } + +} Added: ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/RepositoryFactory.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/RepositoryFactory.java?rev=1078730&view=auto ============================================================================== --- ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/RepositoryFactory.java (added) +++ ofbiz/branches/jackrabbit20100709/framework/jcr/src/org/ofbiz/jcr/RepositoryFactory.java Mon Mar 7 10:24:21 2011 @@ -0,0 +1,125 @@ +/******************************************************************************* + * 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. + *******************************************************************************/ +package org.ofbiz.jcr; + +import java.io.IOException; +import java.net.URL; +import java.util.Collections; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.jcr.Repository; +import javax.naming.InitialContext; +import javax.naming.NamingException; + +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.UtilXml; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +public class RepositoryFactory { + + public static final String module = RepositoryFactory.class.getName(); + private static final Map<String, Repository> repositoryMap = createRepositoryMap(); + + private static Repository createFromFactory(String repositoryName, ClassLoader loader, String className) throws InstantiationException, IllegalAccessException, ClassNotFoundException { + JcrRepositoryFactory factory = (JcrRepositoryFactory) loader.loadClass(className).newInstance(); + return factory.getInstance(repositoryName); + } + + private static Map<String, Repository> createRepositoryMap() { + Map<String, Repository> result = new HashMap<String, Repository>(); + loadRepositories(result); + Debug.logInfo("Repositories loaded: " + result.size(), module); + return Collections.unmodifiableMap(result); + } + + /** + * Returns the default repository. + * + * @return + */ + public static Repository getRepository() { + return repositoryMap.get("default"); + } + + /** + * Returns the specified repository, or <code>null</code> if the + * specified repository doesn't exist. + * + * @param name + * @return + */ + public static Repository getRepository(String name) { + return repositoryMap.get(name); + } + + private static void loadRepositories(Map<String, Repository> map) { + ClassLoader loader = Thread.currentThread().getContextClassLoader(); + Enumeration<URL> resources; + try { + resources = loader.getResources("jcr-repositories.xml"); + } catch (IOException e) { + Debug.logError(e, "Could not load list of jcr-repositories.xml", module); + return; + } + while (resources.hasMoreElements()) { + URL repositoriesURL = resources.nextElement(); + Debug.logInfo("Loading repositories from: " + repositoriesURL, module); + Document doc = null; + try { + doc = UtilXml.readXmlDocument(repositoriesURL, false); + } catch (Exception e) { + Debug.logError(e, module); + continue; + } + Element resourceElement = doc.getDocumentElement(); + List<? extends Element> repositoryList = UtilXml.childElementList(resourceElement, "repository"); + for (Element element : repositoryList) { + String name = element.getAttribute("name"); + if (UtilValidate.isEmpty(name)) { + continue; + } + String jndiName = element.getAttribute("jndi-name"); + if (UtilValidate.isNotEmpty(jndiName)) { + try { + map.put(name, (Repository) new InitialContext().lookup(jndiName)); + } catch (NamingException e) { + Debug.logError(e, module); + } + continue; + } + String className = element.getAttribute("class-name"); + if (UtilValidate.isNotEmpty(className)) { + try { + map.put(name, createFromFactory(name, loader, className)); + } catch (Exception e) { + Debug.logError(e, module); + } + } + } + } + + } + + private RepositoryFactory() {} +} |
Free forum by Nabble | Edit this page |