public Map<String, String> getStoredPasswordsProviders() { Map<String, String> results = new HashMap<String, String>(); results.put(null, user.getUsername()); for (JCRStoreProvider provider : sessionFactory.getProviders().values()) { if ("storedPasswords".equals(provider.getAuthenticationType())) { results.put(provider.getKey(), user.getProperty("storedUsername_" + provider.getKey())); } } return results; }
public JCRNodeWrapper getNodeByUUID(String providerKey, String uuid) throws ItemNotFoundException, RepositoryException { JCRStoreProvider provider = sessionFactory.getProviders().get(providerKey); if (provider == null) { throw new ItemNotFoundException(uuid); } Session session = getProviderSession(provider); Node n = session.getNodeByIdentifier(uuid); return provider.getNodeWrapper(n, this); }
/** {@inheritDoc} */ public JCRNodeWrapper getFrozenVersionAsRegular(Node objectNode, JCRStoreProvider provider) throws RepositoryException { try { VersionHistory vh = objectNode .getSession() .getWorkspace() .getVersionManager() .getVersionHistory(objectNode.getPath()); Version v = null; if (versionLabel != null) { v = JCRVersionService.findVersionByLabel(vh, versionLabel); } if (v == null && versionDate != null) { v = JCRVersionService.findClosestVersion(vh, versionDate); } if (v == null) { throw new PathNotFoundException(); } Node frozen = v.getNode(Constants.JCR_FROZENNODE); return provider.getNodeWrapper(frozen, this); } catch (UnsupportedRepositoryOperationException e) { if (getVersionDate() == null && getVersionLabel() == null) { logger.error("Error while retrieving frozen version", e); } } return null; }
public Session getProviderSession(JCRStoreProvider provider) throws RepositoryException { if (sessions.get(provider) == null) { Session s = null; if (credentials instanceof SimpleCredentials) { SimpleCredentials simpleCredentials = (SimpleCredentials) credentials; JahiaLoginModule.Token t = JahiaLoginModule.getToken( simpleCredentials.getUserID(), new String(simpleCredentials.getPassword())); s = provider.getSession(credentials, workspace.getName()); credentials = JahiaLoginModule.getCredentials( simpleCredentials.getUserID(), t != null ? t.deniedPath : null); } else { s = provider.getSession(credentials, workspace.getName()); } sessions.put(provider, s); for (String token : tokens) { s.addLockToken(token); } NamespaceRegistry namespaceRegistryWrapper = getWorkspace().getNamespaceRegistry(); NamespaceRegistry providerNamespaceRegistry = s.getWorkspace().getNamespaceRegistry(); if (providerNamespaceRegistry != null) { for (String prefix : namespaceRegistryWrapper.getPrefixes()) { try { providerNamespaceRegistry.getURI(prefix); } catch (NamespaceException ne) { providerNamespaceRegistry.registerNamespace( prefix, namespaceRegistryWrapper.getURI(prefix)); } } } for (String prefix : prefixToNs.keySet()) { s.setNamespacePrefix(prefix, prefixToNs.get(prefix)); } } return sessions.get(provider); }
private JCRNodeWrapper dereference(JCRNodeWrapper parent, String refPath) throws RepositoryException { JCRStoreProvider provider = parent.getProvider(); JCRNodeWrapper wrapper; Node referencedNode = parent.getRealNode().getProperty("j:node").getNode(); String fullPath = parent.getPath() + DEREF_SEPARATOR + refPath; if (parent.getPath().startsWith(referencedNode.getPath())) { throw new PathNotFoundException(fullPath); } String refRootName = StringUtils.substringBefore(refPath, "/"); if (!referencedNode.getName().equals(refRootName)) { throw new PathNotFoundException(fullPath); } refPath = StringUtils.substringAfter(refPath, "/"); if (refPath.equals("")) { wrapper = provider.getNodeWrapper(referencedNode, fullPath, parent, this); } else { Node node = referencedNode.getNode(refPath); wrapper = provider.getNodeWrapper(node, fullPath, null, this); } sessionCacheByPath.put(fullPath, wrapper); return wrapper; }
public JCRItemWrapper getItem(String path, final boolean checkVersion) throws PathNotFoundException, RepositoryException { if (sessionCacheByPath.containsKey(path)) { return sessionCacheByPath.get(path); } if (path.contains(DEREF_SEPARATOR)) { JCRNodeWrapper parent = (JCRNodeWrapper) getItem(StringUtils.substringBeforeLast(path, DEREF_SEPARATOR), checkVersion); return dereference(parent, StringUtils.substringAfterLast(path, DEREF_SEPARATOR)); } Map<String, JCRStoreProvider> dynamicMountPoints = sessionFactory.getDynamicMountPoints(); for (Map.Entry<String, JCRStoreProvider> mp : dynamicMountPoints.entrySet()) { if (path.startsWith(mp.getKey() + "/")) { String localPath = path.substring(mp.getKey().length()); JCRStoreProvider provider = mp.getValue(); Item item = getProviderSession(provider).getItem(provider.getRelativeRoot() + localPath); if (item.isNode()) { return provider.getNodeWrapper((Node) item, localPath, null, this); } else { return provider.getPropertyWrapper((Property) item, this); } } } Map<String, JCRStoreProvider> mountPoints = sessionFactory.getMountPoints(); for (Map.Entry<String, JCRStoreProvider> mp : mountPoints.entrySet()) { String key = mp.getKey(); if (key.equals("/") || path.equals(key) || path.startsWith(key + "/")) { String localPath = path; if (!key.equals("/")) { localPath = localPath.substring(key.length()); } JCRStoreProvider provider = mp.getValue(); if (localPath.equals("")) { localPath = "/"; } // Item item = getProviderSession(provider).getItem(localPath); Session session = getProviderSession(provider); if (session instanceof JahiaSessionImpl && getUser() != null && sessionFactory.getCurrentAliasedUser() != null && sessionFactory.getCurrentAliasedUser().equals(getUser())) { ((JahiaSessionImpl) session).toggleThisSessionAsAliased(); } Item item = session.getItem(provider.getRelativeRoot() + localPath); if (item.isNode()) { final Node node = (Node) item; JCRNodeWrapper wrapper = provider.getNodeWrapper(node, localPath, null, this); if (getUser() != null && sessionFactory.getCurrentAliasedUser() != null && !sessionFactory.getCurrentAliasedUser().equals(getUser())) { final JCRNodeWrapper finalWrapper = wrapper; JCRTemplate.getInstance() .doExecuteWithUserSession( sessionFactory.getCurrentAliasedUser().getUsername(), getWorkspace().getName(), getLocale(), new JCRCallback<Object>() { public Object doInJCR(JCRSessionWrapper session) throws RepositoryException { return session.getNodeByUUID(finalWrapper.getIdentifier(), checkVersion); } }); } if (checkVersion && (versionDate != null || versionLabel != null) && node.isNodeType("mix:versionable")) { wrapper = getFrozenVersionAsRegular(node, provider); } sessionCacheByPath.put(path, wrapper); sessionCacheByIdentifier.put(wrapper.getIdentifier(), wrapper); return wrapper; } else { return provider.getPropertyWrapper((Property) item, this); } } } throw new PathNotFoundException(path); }
public JCRNodeWrapper getNodeByUUID(final String uuid, final boolean checkVersion) throws ItemNotFoundException, RepositoryException { if (sessionCacheByIdentifier.containsKey(uuid)) { return sessionCacheByIdentifier.get(uuid); } RepositoryException originalEx = null; for (JCRStoreProvider provider : sessionFactory.getProviderList()) { if (!provider.isInitialized()) { logger.debug( "Provider " + provider.getKey() + " / " + provider.getClass().getName() + " is not yet initialized, skipping..."); continue; } if (provider instanceof JackrabbitStoreProvider && JCRContentUtils.isNotJcrUuid(uuid)) { // not a valid UUID, probably a VFS node continue; } try { Session session = getProviderSession(provider); if (session instanceof JahiaSessionImpl && getUser() != null && sessionFactory.getCurrentAliasedUser() != null && sessionFactory.getCurrentAliasedUser().equals(getUser())) { ((JahiaSessionImpl) session).toggleThisSessionAsAliased(); } Node n = session.getNodeByIdentifier(uuid); JCRNodeWrapper wrapper = provider.getNodeWrapper(n, this); if (getUser() != null && sessionFactory.getCurrentAliasedUser() != null && !sessionFactory.getCurrentAliasedUser().equals(getUser())) { JCRTemplate.getInstance() .doExecuteWithUserSession( sessionFactory.getCurrentAliasedUser().getUsername(), session.getWorkspace().getName(), getLocale(), new JCRCallback<Object>() { public Object doInJCR(JCRSessionWrapper session) throws RepositoryException { return session.getNodeByUUID(uuid, checkVersion); } }); } if (checkVersion && (versionDate != null || versionLabel != null)) { wrapper = getFrozenVersionAsRegular(n, provider); } sessionCacheByIdentifier.put(uuid, wrapper); sessionCacheByPath.put(wrapper.getPath(), wrapper); return wrapper; } catch (ItemNotFoundException ee) { // All good if (originalEx == null) { originalEx = ee; } } catch (UnsupportedRepositoryOperationException uso) { logger.debug( "getNodeByUUID unsupported by : " + provider.getKey() + " / " + provider.getClass().getName()); if (originalEx == null) { originalEx = uso; } } catch (RepositoryException ex) { if (originalEx == null) { originalEx = ex; } logger.warn( "repository exception : " + provider.getKey() + " / " + provider.getClass().getName() + " : " + ex.getMessage()); } } if (originalEx != null) { if (originalEx instanceof ItemNotFoundException) { throw originalEx; } else { throw new ItemNotFoundException(uuid, originalEx); } } throw new ItemNotFoundException(uuid); }
public JCRNodeWrapper getRootNode() throws RepositoryException { JCRStoreProvider provider = sessionFactory.getProvider("/"); return provider.getNodeWrapper(getProviderSession(provider).getRootNode(), "/", null, this); }