Index: C:/data/jackrabbit/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java =================================================================== --- C:/data/jackrabbit/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java (revision 697694) +++ C:/data/jackrabbit/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java (working copy) @@ -266,6 +266,17 @@ alive = true; this.rep = rep; this.subject = subject; + + if(rep==null && subject==null) { + itemStateMgr = null; + userId = null; + hierMgr = null; + versionMgr = null; + itemMgr = null; + ntMgr = null; + wsp = null; + return; + } userId = retrieveUserId(subject); Index: C:/data/jackrabbit/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransientRepository.java =================================================================== --- C:/data/jackrabbit/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransientRepository.java (revision 697694) +++ C:/data/jackrabbit/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransientRepository.java (working copy) @@ -336,7 +336,7 @@ ((SessionImpl) session).addListener(this); logger.info("Session opened"); - return session; + return new UserSessionImpl((SessionImpl) session); } finally { // Stop the repository if the login failed // and no other sessions are active Index: C:/data/jackrabbit/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/UserSessionImpl.java =================================================================== --- C:/data/jackrabbit/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/UserSessionImpl.java (revision 0) +++ C:/data/jackrabbit/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/UserSessionImpl.java (revision 0) @@ -0,0 +1,248 @@ +/* + * 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.apache.jackrabbit.core; + +import org.apache.jackrabbit.api.JackrabbitSession; +import org.apache.jackrabbit.api.security.principal.PrincipalManager; +import org.apache.jackrabbit.api.security.user.UserManager; +import org.apache.jackrabbit.core.util.Dumpable; +import org.apache.jackrabbit.spi.Name; +import org.apache.jackrabbit.spi.Path; +import org.apache.jackrabbit.spi.commons.conversion.IllegalNameException; +import org.apache.jackrabbit.spi.commons.conversion.MalformedPathException; +import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver; +import org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver; +import org.xml.sax.ContentHandler; +import org.xml.sax.SAXException; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PrintStream; +import java.security.AccessControlException; + +import javax.jcr.AccessDeniedException; +import javax.jcr.Credentials; +import javax.jcr.InvalidItemStateException; +import javax.jcr.InvalidSerializedDataException; +import javax.jcr.Item; +import javax.jcr.ItemExistsException; +import javax.jcr.ItemNotFoundException; +import javax.jcr.LoginException; +import javax.jcr.NamespaceException; +import javax.jcr.Node; +import javax.jcr.PathNotFoundException; +import javax.jcr.Repository; +import javax.jcr.RepositoryException; +import javax.jcr.Session; +import javax.jcr.UnsupportedRepositoryOperationException; +import javax.jcr.ValueFactory; +import javax.jcr.Workspace; +import javax.jcr.lock.LockException; +import javax.jcr.nodetype.ConstraintViolationException; +import javax.jcr.nodetype.NoSuchNodeTypeException; +import javax.jcr.version.VersionException; +import javax.security.auth.Subject; + +/** + * User facing session object. This object is returned by Repository.login. + * Unlike SessionImpl it is not referenced internally in Jackrabbit, and + * therefore can be garbage collection by the JVM if it is no longer used. + * + * Currently it extends SessionImpl because in many places in the Jackrabbit + * code the object is cast to SessionImpl. It would be much better if + * it is cast to JackrabbitSession (or another interface). + */ +public class UserSessionImpl extends SessionImpl + implements JackrabbitSession, NamespaceResolver, NamePathResolver, Dumpable { + + private final SessionImpl session; + private final Exception openStackTrace = new Exception("Stack Trace"); + + UserSessionImpl(SessionImpl session) throws AccessDeniedException, RepositoryException { + super(null, (Subject) null, null); + this.session = session; + } + + public PrincipalManager getPrincipalManager() throws AccessDeniedException, UnsupportedRepositoryOperationException, RepositoryException { + return session.getPrincipalManager(); + } + + public UserManager getUserManager() throws AccessDeniedException, UnsupportedRepositoryOperationException, RepositoryException { + return session.getUserManager(); + } + + public void addLockToken(String lt) { + session.addLockToken(lt); + } + + public void checkPermission(String absPath, String actions) throws AccessControlException, RepositoryException { + session.checkPermission(absPath, actions); + } + + public void exportDocumentView(String absPath, ContentHandler contentHandler, boolean skipBinary, boolean noRecurse) throws PathNotFoundException, SAXException, RepositoryException { + session.exportDocumentView(absPath, contentHandler, skipBinary, noRecurse); + } + + public void exportDocumentView(String absPath, OutputStream out, boolean skipBinary, boolean noRecurse) throws IOException, PathNotFoundException, RepositoryException { + session.exportDocumentView(absPath, out, skipBinary, noRecurse); + } + + public void exportSystemView(String absPath, ContentHandler contentHandler, boolean skipBinary, boolean noRecurse) throws PathNotFoundException, SAXException, RepositoryException { + session.exportSystemView(absPath, contentHandler, skipBinary, noRecurse); + } + + public void exportSystemView(String absPath, OutputStream out, boolean skipBinary, boolean noRecurse) throws IOException, PathNotFoundException, RepositoryException { + session.exportDocumentView(absPath, out, skipBinary, noRecurse); + } + + public Object getAttribute(String name) { + return session.getAttribute(name); + } + + public String[] getAttributeNames() { + return session.getAttributeNames(); + } + + public ContentHandler getImportContentHandler(String parentAbsPath, int uuidBehavior) throws PathNotFoundException, ConstraintViolationException, VersionException, LockException, RepositoryException { + return session.getImportContentHandler(parentAbsPath, uuidBehavior); + } + + public Item getItem(String absPath) throws PathNotFoundException, RepositoryException { + return session.getItem(absPath); + } + + public String[] getLockTokens() { + return session.getLockTokens(); + } + + public String getNamespacePrefix(String uri) throws NamespaceException, RepositoryException { + return session.getNamespacePrefix(uri); + } + + public String[] getNamespacePrefixes() throws RepositoryException { + return session.getNamespacePrefixes(); + } + + public String getNamespaceURI(String prefix) throws NamespaceException, RepositoryException { + return session.getNamespaceURI(prefix); + } + + public Node getNodeByUUID(String uuid) throws ItemNotFoundException, RepositoryException { + return session.getNodeByUUID(uuid); + } + + public Repository getRepository() { + return session.getRepository(); + } + + public Node getRootNode() throws RepositoryException { + return session.getRootNode(); + } + + public String getUserID() { + return session.getUserID(); + } + + public ValueFactory getValueFactory() throws UnsupportedRepositoryOperationException, RepositoryException { + return session.getValueFactory(); + } + + public Workspace getWorkspace() { + return session.getWorkspace(); + } + + public boolean hasPendingChanges() throws RepositoryException { + return session.hasPendingChanges(); + } + + public Session impersonate(Credentials credentials) throws LoginException, RepositoryException { + return session.impersonate(credentials); + } + + public void importXML(String parentAbsPath, InputStream in, int uuidBehavior) throws IOException, PathNotFoundException, ItemExistsException, ConstraintViolationException, VersionException, InvalidSerializedDataException, LockException, RepositoryException { + session.importXML(parentAbsPath, in, uuidBehavior); + } + + public boolean isLive() { + return session.isLive(); + } + + public boolean itemExists(String absPath) throws RepositoryException { + return session.itemExists(absPath); + } + + public void logout() { + session.logout(); + } + + public void move(String srcAbsPath, String destAbsPath) throws ItemExistsException, PathNotFoundException, VersionException, ConstraintViolationException, LockException, RepositoryException { + session.move(srcAbsPath, destAbsPath); + } + + public void refresh(boolean keepChanges) throws RepositoryException { + session.refresh(keepChanges); + } + + public void removeLockToken(String lt) { + session.removeLockToken(lt); + } + + public void save() throws AccessDeniedException, ItemExistsException, ConstraintViolationException, InvalidItemStateException, VersionException, LockException, NoSuchNodeTypeException, RepositoryException { + session.save(); + } + + public void setNamespacePrefix(String prefix, String uri) throws NamespaceException, RepositoryException { + session.getNamespacePrefix(uri); + } + + public String getPrefix(String uri) throws NamespaceException { + return session.getPrefix(uri); + } + + public String getURI(String prefix) throws NamespaceException { + return session.getURI(prefix); + } + + public String getJCRName(Name name) throws NamespaceException { + return session.getJCRName(name); + } + + public Name getQName(String name) throws IllegalNameException, NamespaceException { + return session.getQName(name); + } + + public String getJCRPath(Path path) throws NamespaceException { + return session.getJCRPath(path); + } + + public Path getQPath(String path) throws MalformedPathException, IllegalNameException, NamespaceException { + return session.getQPath(path); + } + + public void dump(PrintStream ps) { + session.dump(ps); + } + + public void finalize() { + if (session.isLive()) { + System.err.println("Session was not closed, it was opened at: "); + openStackTrace.printStackTrace(); + session.logout(); + } + } +} Property changes on: C:\data\jackrabbit\jackrabbit-core\src\main\java\org\apache\jackrabbit\core\UserSessionImpl.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Rev URL Name: svn:eol-style + native