sessionimpl.java
来自「jsr170接口的java实现。是个apache的开源项目。」· Java 代码 · 共 1,456 行 · 第 1/4 页
JAVA
1,456 行
/* * 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.commons.collections.IteratorUtils;import org.apache.commons.collections.map.ReferenceMap;import org.apache.jackrabbit.core.config.AccessManagerConfig;import org.apache.jackrabbit.core.config.WorkspaceConfig;import org.apache.jackrabbit.core.nodetype.NodeDefinitionImpl;import org.apache.jackrabbit.core.nodetype.NodeTypeImpl;import org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl;import org.apache.jackrabbit.core.security.AMContext;import org.apache.jackrabbit.core.security.AccessManager;import org.apache.jackrabbit.core.security.AuthContext;import org.apache.jackrabbit.core.security.SecurityConstants;import org.apache.jackrabbit.core.state.NodeState;import org.apache.jackrabbit.core.state.SessionItemStateManager;import org.apache.jackrabbit.core.state.SharedItemStateManager;import org.apache.jackrabbit.core.state.LocalItemStateManager;import org.apache.jackrabbit.value.ValueFactoryImpl;import org.apache.jackrabbit.core.version.VersionManager;import org.apache.jackrabbit.core.xml.DocViewSAXEventGenerator;import org.apache.jackrabbit.core.xml.ImportHandler;import org.apache.jackrabbit.core.xml.SessionImporter;import org.apache.jackrabbit.core.xml.SysViewSAXEventGenerator;import org.apache.jackrabbit.core.util.Dumpable;import org.apache.jackrabbit.core.lock.LockManager;import org.apache.jackrabbit.name.NameException;import org.apache.jackrabbit.name.NamePathResolver;import org.apache.jackrabbit.name.NamespaceResolver;import org.apache.jackrabbit.name.Path;import org.apache.jackrabbit.name.QName;import org.apache.jackrabbit.uuid.UUID;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.xml.sax.ContentHandler;import org.xml.sax.InputSource;import org.xml.sax.SAXException;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.NoSuchWorkspaceException;import javax.jcr.Node;import javax.jcr.PathNotFoundException;import javax.jcr.Repository;import javax.jcr.RepositoryException;import javax.jcr.Session;import javax.jcr.SimpleCredentials;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.observation.EventListener;import javax.jcr.observation.EventListenerIterator;import javax.jcr.observation.ObservationManager;import javax.jcr.version.VersionException;import javax.security.auth.Subject;import javax.xml.parsers.ParserConfigurationException;import javax.xml.parsers.SAXParser;import javax.xml.parsers.SAXParserFactory;import javax.xml.transform.OutputKeys;import javax.xml.transform.TransformerException;import javax.xml.transform.sax.SAXTransformerFactory;import javax.xml.transform.sax.TransformerHandler;import javax.xml.transform.stream.StreamResult;import java.io.File;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.io.PrintStream;import java.security.AccessControlException;import java.security.Principal;import java.util.ArrayList;import java.util.Collection;import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;import java.util.Map;import java.util.Set;/** * A <code>SessionImpl</code> ... */public class SessionImpl implements Session, NamePathResolver, Dumpable { private static Logger log = LoggerFactory.getLogger(SessionImpl.class); /** * prededfined action constants in checkPermission */ public static final String READ_ACTION = "read"; public static final String REMOVE_ACTION = "remove"; public static final String ADD_NODE_ACTION = "add_node"; public static final String SET_PROPERTY_ACTION = "set_property"; /** * flag indicating whether this session is alive */ protected boolean alive; /** * the repository that issued this session */ protected final RepositoryImpl rep; /** * the AuthContext of this session (can be null if this * session was not instantiated through a login process) */ protected AuthContext loginContext; /** * the Subject of this session */ protected final Subject subject; /** * the user ID that was used to acquire this session */ protected final String userId; /** * the attributes of this session */ protected final HashMap attributes = new HashMap(); /** * the node type manager */ protected final NodeTypeManagerImpl ntMgr; /** * the AccessManager associated with this session */ protected AccessManager accessMgr; /** * the item state mgr associated with this session */ protected final SessionItemStateManager itemStateMgr; /** * the HierarchyManager associated with this session */ protected final HierarchyManager hierMgr; /** * the item mgr associated with this session */ protected final ItemManager itemMgr; /** * the Workspace associated with this session */ protected final WorkspaceImpl wsp; /** * the transient prefix/namespace mappings with session scope */ protected final LocalNamespaceMappings nsMappings; /** * The version manager for this session */ protected final VersionManager versionMgr; /** * Listeners (weak references) */ protected final Map listeners = new ReferenceMap(ReferenceMap.WEAK, ReferenceMap.WEAK); /** * Lock tokens */ protected final Set lockTokens = new HashSet(); /** * value factory */ protected ValueFactory valueFactory; /** * Protected constructor. * * @param rep * @param loginContext * @param wspConfig * @throws AccessDeniedException if the subject of the given login context * is not granted access to the specified * workspace * @throws RepositoryException if another error occurs */ protected SessionImpl(RepositoryImpl rep, AuthContext loginContext, WorkspaceConfig wspConfig) throws AccessDeniedException, RepositoryException { this(rep, loginContext.getSubject(), wspConfig); this.loginContext = loginContext; } /** * Protected constructor. * * @param rep * @param subject * @param wspConfig * @throws AccessDeniedException if the given subject is not granted access * to the specified workspace * @throws RepositoryException if another error occurs */ protected SessionImpl(RepositoryImpl rep, Subject subject, WorkspaceConfig wspConfig) throws AccessDeniedException, RepositoryException { alive = true; this.rep = rep; Set principals = subject.getPrincipals(); if (principals.isEmpty()) { String msg = "unable to instantiate Session: no principals found"; log.error(msg); throw new RepositoryException(msg); } else { // use 1st principal in case there are more that one Principal principal = (Principal) principals.iterator().next(); userId = principal.getName(); } this.subject = subject; nsMappings = new LocalNamespaceMappings(rep.getNamespaceRegistry()); ntMgr = new NodeTypeManagerImpl(rep.getNodeTypeRegistry(), rep.getNamespaceRegistry(), getNamespaceResolver()); String wspName = wspConfig.getName(); wsp = createWorkspaceInstance(wspConfig, rep.getWorkspaceStateManager(wspName), rep, this); itemStateMgr = createSessionItemStateManager(wsp.getItemStateManager()); hierMgr = itemStateMgr.getHierarchyMgr(); itemMgr = createItemManager(itemStateMgr, hierMgr); accessMgr = createAccessManager(subject, itemStateMgr.getAtticAwareHierarchyMgr()); versionMgr = createVersionManager(rep); } /** * Create the session item state manager. * * @return session item state manager */ protected SessionItemStateManager createSessionItemStateManager(LocalItemStateManager manager) { return new SessionItemStateManager(rep.getRootNodeId(), manager, this); } /** * Creates the workspace instance backing this session. * * @param wspConfig The workspace configuration * @param stateMgr The shared item state manager * @param rep The repository * @param session The session * @return An instance of the {@link WorkspaceImpl} class or an extension * thereof. */ protected WorkspaceImpl createWorkspaceInstance(WorkspaceConfig wspConfig, SharedItemStateManager stateMgr, RepositoryImpl rep, SessionImpl session) { return new WorkspaceImpl(wspConfig, stateMgr, rep, session); } /** * Create the item manager. * @return item manager */ protected ItemManager createItemManager(SessionItemStateManager itemStateMgr, HierarchyManager hierMgr) { return new ItemManager(itemStateMgr, hierMgr, this, ntMgr.getRootNodeDefinition(), rep.getRootNodeId()); } /** * Create the version manager. If we are not using XA, we may safely use * the repository version manager. * @return version manager */ protected VersionManager createVersionManager(RepositoryImpl rep) throws RepositoryException { return rep.getVersionManager(); } /** * Create the access manager. * * @return access manager * @throws AccessDeniedException if the current subject is not granted access * to the current workspace * @throws RepositoryException if the access manager cannot be instantiated */ protected AccessManager createAccessManager(Subject subject, HierarchyManager hierMgr) throws AccessDeniedException, RepositoryException { AccessManagerConfig amConfig = rep.getConfig().getAccessManagerConfig(); try { AMContext ctx = new AMContext(new File(rep.getConfig().getHomeDir()), rep.getFileSystem(), subject, hierMgr, rep.getNamespaceRegistry(), wsp.getName()); AccessManager accessMgr = (AccessManager) amConfig.newInstance(); accessMgr.init(ctx); return accessMgr; } catch (AccessDeniedException ade) { // re-throw throw ade; } catch (Exception e) { // wrap in RepositoryException String msg = "failed to instantiate AccessManager implementation: " + amConfig.getClassName(); log.error(msg, e); throw new RepositoryException(msg, e); } } /** * Performs a sanity check on this session. * * @throws RepositoryException if this session has been rendered invalid * for some reason (e.g. if this session has * been closed explicitly or if it has expired) */ protected void sanityCheck() throws RepositoryException { // check session status if (!alive) { throw new RepositoryException("this session has been closed"); } } /** * Returns the <code>Subject</code> associated with this session. * * @return the <code>Subject</code> associated with this session */ protected Subject getSubject() { return subject; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?