/* * Copyright 2011 gitblit.com. * * Licensed 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 com.gitblit; import java.io.File; import java.io.FileFilter; import java.io.IOException; import java.lang.reflect.Method; import java.net.URL; import java.net.URLClassLoader; import java.security.ProtectionDomain; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; /** * Launch helper class that adds all jars found in the local "lib" & "ext" * folders and then calls the application main. Using this technique we do not * have to specify a classpath and we can dynamically add jars to the * distribution. * * @author James Moger * */ public class Launcher { public static final boolean DEBUG = false; /** * Parameters of the method to add an URL to the System classes. */ private static final Class[] PARAMETERS = new Class[] { URL.class }; public static void main(String[] args) { if (DEBUG) { System.out.println("jcp=" + System.getProperty("java.class.path")); ProtectionDomain protectionDomain = Launcher.class.getProtectionDomain(); System.out.println("launcher=" + protectionDomain.getCodeSource().getLocation().toExternalForm()); } // Load the JARs in the lib and ext folder String[] folders = new String[] { "lib", "ext" }; List jars = new ArrayList(); for (String folder : folders) { if (folder == null) { continue; } File libFolder = new File(folder); if (!libFolder.exists()) { continue; } List found = findJars(libFolder.getAbsoluteFile()); jars.addAll(found); } // sort the jars by name and then reverse the order so the newer version // of the library gets loaded in the event that this is an upgrade Collections.sort(jars); Collections.reverse(jars); if (jars.size() == 0) { for (String folder : folders) { File libFolder = new File(folder); // this is a test of adding a comment // more really interesting things System.err.println("Failed to find any JARs in " + libFolder.getPath()); } System.exit(-1); } else { for (File jar : jars) { try { jar.canRead(); addJarFile(jar); } catch (Throwable t) { t.printStackTrace(); } } } // Start Server GitBlitServer.main(args); } public static List findJars(File folder) { List jars = new ArrayList(); if (folder.exists()) { File[] libs = folder.listFiles(new FileFilter() { @Override public boolean accept(File file) { return !file.isDirectory() && file.getName().toLowerCase().endsWith(".jar"); } }); if (libs != null && libs.length > 0) { jars.addAll(Arrays.asList(libs)); if (DEBUG) { for (File jar : jars) { System.out.println("found " + jar); } } } } return jars; } /** * Adds a file to the classpath * * @param f * the file to be added * @throws IOException */ public static void addJarFile(File f) throws IOException { if (f.getName().indexOf("-sources") > -1 || f.getName().indexOf("-javadoc") > -1) { // don't add source or javadoc jars to runtime classpath return; } URL u = f.toURI().toURL(); if (DEBUG) { System.out.println("load=" + u.toExternalForm()); } URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader(); Class sysclass = URLClassLoader.class; try { Method method = sysclass.getDeclaredMethod("addURL", PARAMETERS); method.setAccessible(true); method.invoke(sysloader, new Object[] { u }); } catch (Throwable t) { throw new IOException(MessageFormat.format( "Error, could not add {0} to system classloader", f.getPath()), t); } } } 'artonge/chore/update_nc_cypress_beta.11'>artonge/chore/update_nc_cypress_beta.11 Nextcloud server, a safe home for all your data: https://github.com/nextcloud/serverwww-data
aboutsummaryrefslogtreecommitdiffstats
blob: 6ae8b79c25886473cf8d7614542f04873cd54471 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php

declare(strict_types=1);

/**
 * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

namespace OCA\Files\Db;

use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\Exception;
use OCP\IDBConnection;

/**
 * @template-extends QBMapper<OpenLocalEditor>
 */
class OpenLocalEditorMapper extends QBMapper {
	public function __construct(IDBConnection $db) {
		parent::__construct($db, 'open_local_editor', OpenLocalEditor::class);
	}

	/**
	 * @throws DoesNotExistException
	 * @throws MultipleObjectsReturnedException
	 * @throws Exception
	 */
	public function verifyToken(string $userId, string $pathHash, string $token): OpenLocalEditor {
		$qb = $this->db->getQueryBuilder();

		$qb->select('*')
			->from($this->getTableName())
			->where($qb->expr()->eq('user_id', $qb->createNamedParameter($userId)))
			->andWhere($qb->expr()->eq('path_hash', $qb->createNamedParameter($pathHash)))
			->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token)));

		return $this->findEntity($qb);
	}

	public function deleteExpiredTokens(int $time): void {
		$qb = $this->db->getQueryBuilder();

		$qb->delete($this->getTableName())
			->where($qb->expr()->lt('expiration_time', $qb->createNamedParameter($time)));

		$qb->executeStatement();
	}
}