- Incorporate JCR project into Repository project

- Single configuration entry point for JCR and non-JCR clients (i.e. application-context.xml)
- Addition of build-war, incremental-war build targets (no deploy)
- Remove build of JCR TCK war file by default

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2777 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
David Caruana
2006-05-05 16:33:22 +00:00
parent c29f0fd4f1
commit 19e3138e1c
80 changed files with 14665 additions and 3 deletions

View File

@@ -0,0 +1,29 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* 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.alfresco.jcr.repository;
/**
* Factory settings for entry-point Repository implementation
*
* @author David Caruana
*/
public class RepositoryFactory
{
public final static String APPLICATION_CONTEXT = "classpath:alfresco/jcr-context.xml";
public final static String REPOSITORY_BEAN = "JCR.Repository";
}

View File

@@ -0,0 +1,310 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* 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.alfresco.jcr.repository;
import java.util.HashMap;
import java.util.Map;
import javax.jcr.Credentials;
import javax.jcr.LoginException;
import javax.jcr.NoSuchWorkspaceException;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.jcr.dictionary.NamespaceRegistryImpl;
import org.alfresco.jcr.session.SessionImpl;
import org.alfresco.repo.importer.ImporterComponent;
import org.alfresco.repo.security.authentication.AuthenticationException;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.security.AuthenticationService;
import org.alfresco.service.descriptor.Descriptor;
import org.alfresco.service.descriptor.DescriptorService;
/**
* Alfresco implementation of a JCR Repository
*
* @author David Caruana
*/
public class RepositoryImpl implements Repository
{
/** Empty Password, if not supplied */
private final static char[] EMPTY_PASSWORD = "".toCharArray();
/** Repository Descriptors */
private static final Map<String, String> descriptors = new HashMap<String, String>();
/** Thread Local Session */
// Note: For now, we're only allowing one active (i.e. logged in) Session per-thread
private static ThreadLocal<SessionImpl> sessions = new ThreadLocal<SessionImpl>();
// Service dependencies
private ServiceRegistry serviceRegistry;
private ImporterComponent importerComponent;
private String defaultWorkspace = null;
// Services
private NamespaceRegistryImpl namespaceRegistry = null;
//
// Dependency Injection
//
/**
* Set the service registry
*
* @param serviceRegistry
*/
public void setServiceRegistry(ServiceRegistry serviceRegistry)
{
this.serviceRegistry = serviceRegistry;
}
/**
* Set the Importer Component
*
* @param importerComponent
*/
public void setImporterComponent(ImporterComponent importerComponent)
{
this.importerComponent = importerComponent;
}
/**
* Sets the Default Workspace
*
* @param defaultWorkspace default workspace
*/
public void setDefaultWorkspace(String defaultWorkspace)
{
this.defaultWorkspace = defaultWorkspace;
}
/**
* Initialisation
*/
public void init()
{
if (serviceRegistry == null)
{
throw new IllegalStateException("Service Registry has not been specified.");
}
// initialise namespace registry
namespaceRegistry = new NamespaceRegistryImpl(false, serviceRegistry.getNamespaceService());
// initialise descriptors
DescriptorService descriptorService = serviceRegistry.getDescriptorService();
Descriptor descriptor = descriptorService.getServerDescriptor();
String repNameDesc = "Alfresco Content Repository";
String edition = descriptor.getEdition();
if (edition != null && edition.length() > 0)
{
repNameDesc += " (" + edition + ")";
}
String repVersion = descriptor.getVersion();
descriptors.put(Repository.REP_NAME_DESC, repNameDesc);
descriptors.put(Repository.REP_VENDOR_DESC, "Alfresco");
descriptors.put(Repository.REP_VENDOR_URL_DESC, "http://www.alfresco.org");
descriptors.put(Repository.REP_VERSION_DESC, repVersion);
descriptors.put(Repository.SPEC_NAME_DESC, "Content Repository API for Java(TM) Technology Specification");
descriptors.put(Repository.SPEC_VERSION_DESC, "1.0");
descriptors.put(Repository.LEVEL_1_SUPPORTED, "true");
descriptors.put(Repository.LEVEL_2_SUPPORTED, "true");
descriptors.put(Repository.OPTION_TRANSACTIONS_SUPPORTED, "true");
descriptors.put(Repository.QUERY_XPATH_DOC_ORDER, "true");
descriptors.put(Repository.QUERY_XPATH_POS_INDEX, "true");
}
/**
* Get the service registry
*
* @return the service registry
*/
public ServiceRegistry getServiceRegistry()
{
return serviceRegistry;
}
/**
* Get the importer component
*
* @return the importer component
*/
public ImporterComponent getImporterComponent()
{
return importerComponent;
}
/**
* Get the Namespace Registry
*/
public NamespaceRegistryImpl getNamespaceRegistry()
{
return namespaceRegistry;
}
/* (non-Javadoc)
* @see javax.jcr.Repository#getDescriptorKeys()
*/
public String[] getDescriptorKeys()
{
String[] keys = (String[]) descriptors.keySet().toArray(new String[descriptors.keySet().size()]);
return keys;
}
/* (non-Javadoc)
* @see javax.jcr.Repository#getDescriptor(java.lang.String)
*/
public String getDescriptor(String key)
{
return descriptors.get(key);
}
/* (non-Javadoc)
* @see javax.jcr.Repository#login(javax.jcr.Credentials, java.lang.String)
*/
public Session login(Credentials credentials, String workspaceName)
throws LoginException, NoSuchWorkspaceException, RepositoryException
{
// extract username and password
// TODO: determine support for general Credentials
String username = null;
char[] password = EMPTY_PASSWORD;
if (credentials != null && credentials instanceof SimpleCredentials)
{
username = ((SimpleCredentials)credentials).getUserID();
password = ((SimpleCredentials)credentials).getPassword();
}
try
{
// construct the session
SessionImpl sessionImpl = new SessionImpl(this);
registerSession(sessionImpl);
// authenticate user
AuthenticationService authenticationService = getServiceRegistry().getAuthenticationService();
try
{
authenticationService.authenticate(username, password);
}
catch(AuthenticationException e)
{
deregisterSession();
throw new LoginException("Alfresco Repository failed to authenticate credentials", e);
}
// initialise the session
String ticket = authenticationService.getCurrentTicket();
String sessionWorkspace = (workspaceName == null) ? defaultWorkspace : workspaceName;
sessionImpl.init(ticket, sessionWorkspace, getAttributes(credentials));
// session is now ready
Session session = sessionImpl.getProxy();
return session;
}
catch(AlfrescoRuntimeException e)
{
deregisterSession();
throw new RepositoryException(e);
}
}
/* (non-Javadoc)
* @see javax.jcr.Repository#login(javax.jcr.Credentials)
*/
public Session login(Credentials credentials)
throws LoginException, RepositoryException
{
return login(credentials, null);
}
/* (non-Javadoc)
* @see javax.jcr.Repository#login(java.lang.String)
*/
public Session login(String workspaceName)
throws LoginException, NoSuchWorkspaceException, RepositoryException
{
return login(null, workspaceName);
}
/* (non-Javadoc)
* @see javax.jcr.Repository#login()
*/
public Session login()
throws LoginException, RepositoryException
{
return login(null, null);
}
/**
* Get attributes from passed Credentials
*
* @param credentials the credentials to extract attribute from
* @return the attributes
*/
private Map<String, Object> getAttributes(Credentials credentials)
{
Map<String, Object> attributes = null;
if (credentials != null && credentials instanceof SimpleCredentials)
{
SimpleCredentials simpleCredentials = (SimpleCredentials)credentials;
String[] names = simpleCredentials.getAttributeNames();
attributes = new HashMap<String, Object>(names.length);
for (String name : names)
{
attributes.put(name, simpleCredentials.getAttribute(name));
}
}
return attributes;
}
/**
* Register active session
*
* @param session
*/
private void registerSession(SessionImpl session)
throws RepositoryException
{
// only allow one active session
if (sessions.get() != null)
{
throw new RepositoryException("Only one active session is allowed per thread.");
}
// record session in current thread
sessions.set(session);
}
/**
* De-register current active session
*/
public void deregisterSession()
{
// remove session from current thread
sessions.set(null);
}
}

View File

@@ -0,0 +1,127 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* 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.alfresco.jcr.repository;
import javax.jcr.LoginException;
import javax.jcr.NoSuchWorkspaceException;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import org.alfresco.jcr.test.BaseJCRTest;
/**
* Test JCR Repository Implementation
*
* @author David Caruana
*/
public class RepositoryImplTest extends BaseJCRTest
{
public void testDescriptors()
{
String[] keys = repository.getDescriptorKeys();
assertEquals(11, keys.length);
for (String key : keys)
{
String value = repository.getDescriptor(key);
assertNotNull(value);
}
assertNotNull(repository.getDescriptor(Repository.REP_NAME_DESC));
System.out.println(repository.getDescriptor(Repository.REP_NAME_DESC));
assertNotNull(repository.getDescriptor(Repository.REP_VENDOR_DESC));
assertNotNull(repository.getDescriptor(Repository.REP_VENDOR_URL_DESC));
assertNotNull(repository.getDescriptor(Repository.REP_VERSION_DESC));
System.out.println(repository.getDescriptor(Repository.REP_VERSION_DESC));
assertNotNull(repository.getDescriptor(Repository.SPEC_NAME_DESC));
assertNotNull(repository.getDescriptor(Repository.SPEC_VERSION_DESC));
assertEquals("true", repository.getDescriptor(Repository.LEVEL_1_SUPPORTED));
assertEquals("true", repository.getDescriptor(Repository.LEVEL_2_SUPPORTED));
assertEquals("true", repository.getDescriptor(Repository.OPTION_TRANSACTIONS_SUPPORTED));
assertEquals("true", repository.getDescriptor(Repository.QUERY_XPATH_DOC_ORDER));
assertEquals("true", repository.getDescriptor(Repository.QUERY_XPATH_POS_INDEX));
}
public void testBadUsernameLogin() throws Exception
{
SimpleCredentials badUser = new SimpleCredentials("baduser", "".toCharArray());
try
{
repository.login(badUser);
fail("Failed to catch bad username - username should not exist.");
}
catch (LoginException e)
{
}
}
public void testBadPwdLogin() throws Exception
{
SimpleCredentials badPwd = new SimpleCredentials("superuser", "badpwd".toCharArray());
try
{
repository.login(badPwd);
fail("Failed to catch bad password - password is invalid.");
}
catch (LoginException e)
{
}
}
public void testNoCredentialsLogin() throws Exception
{
try
{
repository.login();
fail("Failed to catch no credentials.");
}
catch (LoginException e)
{
}
}
public void testLogin()
throws RepositoryException
{
SimpleCredentials good = new SimpleCredentials("superuser", "".toCharArray());
try
{
Session session = repository.login(good, getWorkspace());
assertNotNull(session);
session.logout();
}
catch (LoginException e)
{
fail("Failed to login.");
}
try
{
Session session = repository.login(good, null);
session.logout();
}
catch (NoSuchWorkspaceException e)
{
fail("Failed to detect default workspace");
}
}
}