/** * Calculates the local sha1 for a file. * @param file a local file * @return the file's SHA-1 hexadecimal digest */ public String sha1(File file) { ChecksumProviderFactory cpf = new ChecksumProviderFactoryImpl(); return cpf.getProvider(ChecksumType.SHA1).putFile( file.getAbsolutePath()).checksumAsString(); }
protected String passwordDigest(Long userId, String clearText, boolean salt) { if (clearText == null) { throw new ApiUsageException("Value for digesting may not be null"); } byte[] bytes = clearText.getBytes(encoding); // If salting is activated, prepend the salt. if (userId != null && salt) { byte[] saltedBytes = ByteBuffer.allocate(8).putLong(userId).array(); byte[] newValue = new byte[saltedBytes.length+bytes.length]; System.arraycopy(saltedBytes, 0, newValue, 0, saltedBytes.length); System.arraycopy(bytes, 0, newValue, saltedBytes.length, bytes.length); bytes = newValue; } String hashedText = null; ChecksumProviderFactory cpf = new ChecksumProviderFactoryImpl(); try { bytes = cpf.getProvider(ChecksumType.MD5).putBytes(bytes) .checksumAsBytes(); bytes = Base64.encodeBase64(bytes); hashedText = new String(bytes); } catch (Exception e) { log.error("Could not hash password", e); } if (hashedText == null) { throw new InternalException("Failed to obtain digest."); } return hashedText; }
public ManagedRepositoryI(String template, RepositoryDao dao, ProcessContainer processes, ChecksumProviderFactory checksumProviderFactory, String checksumAlgorithmSupported, String pathRules, String rootSessionUuid, Roles roles, Set<String> managedRepoUuids) throws ServerError { super(dao, checksumProviderFactory, checksumAlgorithmSupported, pathRules); this.managedRepoUuids = managedRepoUuids; int splitPoint = template.lastIndexOf("//"); if (splitPoint < 0) { /* without "//" the whole path is user-owned */ splitPoint = 0; } this.templateRoot = new FsFile(template.substring(0, splitPoint)); this.templateUser = new FsFile(template.substring(splitPoint)); if (FsFile.emptyPath.equals(templateUser)) { throw new omero.ApiUsageException(null, null, "no user-owned directories in managed repository template path"); } this.processes = processes; this.rootSessionUuid = rootSessionUuid; this.userGroupId = roles.getUserGroupId(); log.info("Repository template: " + template); }
protected String checksum(String filename, ChecksumAlgorithm checksumAlgorithm) { final ChecksumProviderFactory checksumProviderFactory = new ChecksumProviderFactoryImpl(); final ChecksumProvider cp = checksumProviderFactory.getProvider( ChecksumAlgorithmMapper.getChecksumType(checksumAlgorithm)); cp.putFile(filename); return cp.checksumAsString(); }
public OriginalFileI getFile(ServiceFactory sf) { OriginalFile file = null; ChecksumProviderFactory cpf = new ChecksumProviderFactoryImpl(); try { final byte[] buf = FileUtils.readFileToByteArray(source); final String sha1 = cpf.getProvider(ChecksumType.SHA1) .putBytes(buf).checksumAsString(); log.debug("Loading script: " + sha1); Parameters p = new Parameters(); p.addString("hash", sha1); p.addString("name", getName()); List<OriginalFile> files = loadScripts(sf, p); if (files.size() < 1) { return null; } else { if (files.size() > 1) { log.warn("Multiple scripts found: " + files); } file = files.get(0); } } catch (Exception e) { // pass in order to throw log.warn(e.toString()); // slf4j migration: toString() } if (file == null) { throw new InternalException("Failed to find script"); } else { return new OriginalFileI(file.getId(), false); } }