You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by le...@apache.org on 2010/07/10 10:19:23 UTC
svn commit: r962787 - in /ofbiz/branches/jackrabbit20100709: ./ framework/
framework/base/config/ framework/jackrabbit/ framework/jackrabbit/config/
framework/jackrabbit/src/ framework/jackrabbit/src/org/
framework/jackrabbit/src/org/ofbiz/ framework/j...
Author: lektran
Date: Sat Jul 10 08:19:23 2010
New Revision: 962787
URL: http://svn.apache.org/viewvc?rev=962787&view=rev
Log:
Quick and dirty jackrabbit container and login module, enough to be able to start an embedded jackrabbit repo running on derby and retrieve sessions with a userLogin.
You can gain access to a jcr session in the following manner:
Session session = JackrabbitContainer.getUserSession(userLogin);
// add a content node
Node rootNode = session.getRootNode();
rootNode.addNode("test");
session.save()
// you must always logout or jackrabbit complains in the logs
session.logout();
Added:
ofbiz/branches/jackrabbit20100709/framework/jackrabbit/build.xml (with props)
ofbiz/branches/jackrabbit20100709/framework/jackrabbit/config/
ofbiz/branches/jackrabbit20100709/framework/jackrabbit/config/repository.xml (with props)
ofbiz/branches/jackrabbit20100709/framework/jackrabbit/ofbiz-component.xml (with props)
ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/
ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/
ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/
ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/
ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/JackrabbitContainer.java (with props)
ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/OFBizLoginModule.java (with props)
Modified:
ofbiz/branches/jackrabbit20100709/.classpath
ofbiz/branches/jackrabbit20100709/.gitignore
ofbiz/branches/jackrabbit20100709/framework/base/config/ofbiz-containers.xml
ofbiz/branches/jackrabbit20100709/framework/build.xml
ofbiz/branches/jackrabbit20100709/framework/component-load.xml
Modified: ofbiz/branches/jackrabbit20100709/.classpath
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/.classpath?rev=962787&r1=962786&r2=962787&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/.classpath (original)
+++ ofbiz/branches/jackrabbit20100709/.classpath Sat Jul 10 08:19:23 2010
@@ -230,6 +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/jetty/src"/>
<classpathentry kind="src" path="framework/minilang/src"/>
<classpathentry kind="src" path="framework/security/src"/>
Modified: ofbiz/branches/jackrabbit20100709/.gitignore
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/.gitignore?rev=962787&r1=962786&r2=962787&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/.gitignore (original)
+++ ofbiz/branches/jackrabbit20100709/.gitignore Sat Jul 10 08:19:23 2010
@@ -22,6 +22,7 @@ framework/entityext/build/
framework/example/build/
framework/geronimo/build/
framework/guiapp/build/
+framework/jackrabbit/build/
framework/jetty/build/
framework/minilang/build/
framework/security/build/
@@ -59,6 +60,7 @@ runtime/logs/*.log*
runtime/logs/*.html*
runtime/logs/test-results/*
runtime/data/derby/*
+runtime/data/jackrabbit/*
runtime/catalina/work/*
runtime/tempfiles/*
debian/EncryptPassword.class
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=962787&r1=962786&r2=962787&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/base/config/ofbiz-containers.xml (original)
+++ ofbiz/branches/jackrabbit20100709/framework/base/config/ofbiz-containers.xml Sat Jul 10 08:19:23 2010
@@ -96,6 +96,11 @@ under the License.
<!-- TODO: switch to webslinger, for per-site logging
<container name="catalina-container" class="org.ofbiz.webslinger.WebslingerCatalinaContainer">
-->
+ <container name="jackrabbit" class="org.ofbiz.jackrabbit.JackrabbitContainer">
+ <property name="repHomeDir" value="runtime/data/jackrabbit/"/>
+ <property name="configFilePath" value="framework/jackrabbit/config/repository.xml"/>
+ </container>
+
<container name="catalina-container" class="org.ofbiz.catalina.container.CatalinaContainer">
<!-- static configuration for tomcat -->
<property name="delegator-name" value="default"/>
Modified: ofbiz/branches/jackrabbit20100709/framework/build.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/build.xml?rev=962787&r1=962786&r2=962787&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/build.xml (original)
+++ ofbiz/branches/jackrabbit20100709/framework/build.xml Sat Jul 10 08:19:23 2010
@@ -25,7 +25,7 @@ under the License.
files="start/build.xml,base/build.xml,sql/build.xml,
entity/build.xml,geronimo/build.xml,
catalina/build.xml,jetty/build.xml,
- security/build.xml,service/build.xml,entityext/build.xml,
+ security/build.xml,service/build.xml,jackrabbit/build.xml,entityext/build.xml,
webslinger/build.xml,
bi/build.xml,minilang/build.xml,
webapp/build.xml,guiapp/build.xml,widget/build.xml,
Modified: ofbiz/branches/jackrabbit20100709/framework/component-load.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/component-load.xml?rev=962787&r1=962786&r2=962787&view=diff
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/component-load.xml (original)
+++ ofbiz/branches/jackrabbit20100709/framework/component-load.xml Sat Jul 10 08:19:23 2010
@@ -31,6 +31,7 @@ under the License.
<load-component component-location="common"/>
<load-component component-location="service"/>
<load-component component-location="entityext"/>
+ <load-component component-location="jackrabbit"/>
<load-component component-location="bi"/>
<load-component component-location="birt"/>
<load-component component-location="webapp"/>
Added: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/build.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jackrabbit/build.xml?rev=962787&view=auto
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/jackrabbit/build.xml (added)
+++ ofbiz/branches/jackrabbit20100709/framework/jackrabbit/build.xml Sat Jul 10 08:19:23 2010
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+
+<project name="OFBiz - Jackrabbit" 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="ofbiz.home.dir" value="../.."/>
+
+ <path id="local.class.path">
+ <fileset dir="${lib.dir}" 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"/>
+ <fileset dir="../../framework/service/build/lib" includes="*.jar"/>
+
+ </path>
+
+ <target name="jar" depends="classes">
+ <main-jar/>
+ <test-jar/>
+ </target>
+</project>
Propchange: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/build.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/build.xml
------------------------------------------------------------------------------
svn:keywords = "Date Rev Author URL Id"
Propchange: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/build.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/config/repository.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jackrabbit/config/repository.xml?rev=962787&view=auto
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/jackrabbit/config/repository.xml (added)
+++ ofbiz/branches/jackrabbit20100709/framework/jackrabbit/config/repository.xml Sat Jul 10 08:19:23 2010
@@ -0,0 +1,136 @@
+<?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 2.0//EN"
+ "http://jackrabbit.apache.org/dtd/repository-2.0.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>
+
+ <!--
+ data store configuration
+ -->
+ <DataStore class="org.apache.jackrabbit.core.data.FileDataStore"/>
+
+ <!--
+ 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.ofbiz.jackrabbit.OFBizLoginModule"/>
+ </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.pool.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="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.pool.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="supportHighlighting" value="true"/>
+ </SearchIndex>
+</Repository>
\ No newline at end of file
Propchange: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/config/repository.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/config/repository.xml
------------------------------------------------------------------------------
svn:keywords = "Date Rev Author URL Id"
Propchange: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/config/repository.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/ofbiz-component.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jackrabbit/ofbiz-component.xml?rev=962787&view=auto
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/jackrabbit/ofbiz-component.xml (added)
+++ ofbiz/branches/jackrabbit20100709/framework/jackrabbit/ofbiz-component.xml Sat Jul 10 08:19:23 2010
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+
+<ofbiz-component name="jackrabbit"
+ 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"/>
+ <classpath type="dir" location="config"/>
+ <classpath type="jar" location="build/lib/*"/>
+ <classpath type="jar" location="lib/*"/>
+</ofbiz-component>
+
Propchange: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/ofbiz-component.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/ofbiz-component.xml
------------------------------------------------------------------------------
svn:keywords = "Date Rev Author URL Id"
Propchange: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/ofbiz-component.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/JackrabbitContainer.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/JackrabbitContainer.java?rev=962787&view=auto
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/JackrabbitContainer.java (added)
+++ ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/JackrabbitContainer.java Sat Jul 10 08:19:23 2010
@@ -0,0 +1,107 @@
+/*******************************************************************************
+ * 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.jackrabbit;
+
+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.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+
+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;
+
+// TODO: Add support for remote and jndi based repositories?
+// then use this container to register and start up an embedded instance only
+// repository access for ofbiz should be provided for in a separate class
+
+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 TransientRepository 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/");
+ homeDir = new File(homeDirURL);
+ URL jackrabbitConfigUrl = FlexibleLocation.resolveLocation(ContainerConfig.getPropertyValue(cc, "configFilePath", "framework/jackrabbit/config/repository.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);
+ }
+ return true;
+ }
+
+ @Override
+ public void stop() throws ContainerException {
+ if (session != null) {
+ session.logout();
+ }
+ if (repository != null) {
+ 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);
+ }
+}
Propchange: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/JackrabbitContainer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/JackrabbitContainer.java
------------------------------------------------------------------------------
svn:keywords = "Date Rev Author URL Id"
Propchange: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/JackrabbitContainer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/OFBizLoginModule.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/OFBizLoginModule.java?rev=962787&view=auto
==============================================================================
--- ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/OFBizLoginModule.java (added)
+++ ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/OFBizLoginModule.java Sat Jul 10 08:19:23 2010
@@ -0,0 +1,145 @@
+/*******************************************************************************
+ * 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.jackrabbit;
+
+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");
+ }
+ } catch (GenericServiceException e) {
+ Debug.logError(e, module);
+ throw new LoginException(e.getMessage());
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public boolean logout() throws LoginException {
+ userLogin = null;
+ return true;
+ }
+
+}
Propchange: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/OFBizLoginModule.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/OFBizLoginModule.java
------------------------------------------------------------------------------
svn:keywords = "Date Rev Author URL Id"
Propchange: ofbiz/branches/jackrabbit20100709/framework/jackrabbit/src/org/ofbiz/jackrabbit/OFBizLoginModule.java
------------------------------------------------------------------------------
svn:mime-type = text/plain