List of usage examples for org.apache.commons.codec.digest DigestUtils shaHex
@Deprecated public static String shaHex(String data)
From source file:com.enonic.cms.core.security.user.UserEntity.java
public boolean verifyPassword(String password) { if (password == null) { return this.password == null; }// w ww .java 2 s. c om return DigestUtils.shaHex(password).equals(this.password); }
From source file:com.ebay.pulsar.analytics.metricstore.druid.having.HavingTest.java
public void testGreaterThanHaving() { String aggregate = "Aggregate"; String value = "123"; GreaterThanHaving having = new GreaterThanHaving(aggregate, value); String aggregate1 = having.getAggregation(); String value1 = having.getValue(); assertEquals("Aggregate NOT Equals", aggregate, aggregate1); assertEquals("Value NOT Equals", value, value1); byte[] cacheKey = having.cacheKey(); String hashCacheKeyExpected = "22a85c37b6f950b51f09e5dcb52e2175e898b516"; String hashCacheKeyGot = DigestUtils.shaHex(cacheKey); assertEquals("Hash of cacheKey NOT Equals", hashCacheKeyExpected, hashCacheKeyGot); GreaterThanHaving having1 = new GreaterThanHaving(aggregate, null); byte[] cacheKey1 = having1.cacheKey(); String hashCacheKeyExpected1 = "92d122aadc2a9bab7a85a04be116e9634611befb"; String hashCacheKeyGot1 = DigestUtils.shaHex(cacheKey1); assertEquals("Hash of cacheKey NOT Equals", hashCacheKeyExpected1, hashCacheKeyGot1); HavingType type = having.getType();/*w w w. ja v a 2 s .c o m*/ assertEquals("HavingType NOT Equals", HavingType.greaterThan, type); String aggregate2 = "Aggregate"; String value2 = "123"; GreaterThanHaving having2 = new GreaterThanHaving(null, null); assertTrue(!having2.equals(having)); assertTrue(!having.equals(having2)); having2 = new GreaterThanHaving(aggregate2, null); assertTrue(!having2.equals(having)); assertTrue(!having.equals(having2)); having2 = new GreaterThanHaving(aggregate2, value2); assertTrue(having2.equals(having)); assertTrue(having.equals(having2)); assertTrue(having2.hashCode() == having.hashCode()); assertTrue(having2.equals(having2)); assertTrue(!having2.equals(new NotHaving(having2) { })); }
From source file:com.metamx.druid.merger.common.task.MergeTask.java
private static String computeProcessingID(final String dataSource, final List<DataSegment> segments) { final String segmentIDs = Joiner.on("_").join( Iterables.transform(Ordering.natural().sortedCopy(segments), new Function<DataSegment, String>() { @Override//from www . ja v a2 s . com public String apply(DataSegment x) { return String.format("%s_%s_%s_%s", x.getInterval().getStart(), x.getInterval().getEnd(), x.getVersion(), x.getShardSpec().getPartitionNum()); } })); return String.format("%s_%s", dataSource, DigestUtils.shaHex(segmentIDs).toLowerCase()); }
From source file:eu.optimis.trustedinstance.TrustedInstanceImpl.java
@Override public LicenseTokenSecureDocument getToken(UserTokenAuthorizationDocument userTokenAuthorizationDoc) throws ResourceNotFound, ResourceInvalid, TrustedInstanceException { if (userTokenAuthorizationDoc == null) throw new ResourceInvalid("Resource is null"); // TODO validate timestamps and signature of userTokenAuthorizationDoc? // TODO get tokenID from UserTokenAuthorizationDocument or LicenseDescription? String tokenId = userTokenAuthorizationDoc.getUserTokenAuthorization().getTokenID(); if (tokenId == null || tokenId.equals("")) throw new ResourceInvalid("UserTokenAuthorization is missing TokenID"); DBStorageEntry receivedEntry = null; try {/*w ww. j av a 2s. c om*/ receivedEntry = getStorageEntry(tokenId); } catch (Exception e) { throw new TrustedInstanceException(e.getMessage(), e); } LicenseTokenSecureDocument licenseTokenSecureDocument; try { LicenseTokenDocument licenseToken = receivedEntry.getLicenseToken(); LicenseTokenSecureDocument tokenSecDoc = LicenseTokenSecureDocument.Factory.newInstance(); LicenseTokenSecureType tokenSecType = tokenSecDoc.addNewLicenseTokenSecure(); ByteArrayOutputStream token_bos = new ByteArrayOutputStream(); licenseToken.save(token_bos); byte[] token_encoded = Base64.encode(token_bos.toByteArray()); tokenSecType.setLicenseToken(token_encoded); ProviderInfoType providerInfo = tokenSecType.addNewProviderInfo(); String providerInfoString = getProviderInfo(infoServiceUrl); providerInfo.setName(infoServiceName); ProviderHashType hashType = providerInfo.addNewProviderHash(); hashType.setHashAlgorithm("sha1"); hashType.setStringValue(DigestUtils.shaHex(providerInfoString)); providerInfo.setInfoServiceURL(infoServiceUrl); // server private key PrivateKey tiPrivateKey = (PrivateKey) ti_ks.getKey(ti_keyStoreAlias, ti_keyStorePass); TokenSigner ts_secure = new TokenSigner(ti_certificate, tiPrivateKey); licenseTokenSecureDocument = ts_secure.getSignedToken(tokenSecDoc); if (!licenseTokenSecureDocument.validate()) { throw new ResourceInvalid("invalid trusted instance token authorization."); } } catch (XmlException e) { // TODO add throws TrustedInstanceException? throw new ResourceNotFound("Unable to parse LicenseToken", e); } catch (Exception e) { throw new TrustedInstanceException(e.getMessage(), e); } return licenseTokenSecureDocument; }
From source file:com.ebay.pulsar.analytics.metricstore.druid.aggregator.AggregatorTest.java
public void testFilteredAggregator() { String filteredAggregatorName = "FilteredAggrTest"; String dimension = "columnName"; String value = "columnValue"; BaseFilter filter = new SelectorFilter(dimension, value); String baseAggregatorName = "LongSumAggrTest"; String fieldName = "FieldName"; LongSumAggregator longSumAggr = new LongSumAggregator(baseAggregatorName, fieldName); FilteredAggregator filteredAggr = new FilteredAggregator(filteredAggregatorName, filter, longSumAggr); SelectorFilter filterGot = (SelectorFilter) filteredAggr.getFilter(); String dimensionGot = filterGot.getDimension(); String valueGot = filterGot.getValue(); assertEquals("BaseFilter dimension must be 'columnName'", dimension, dimensionGot); assertEquals("BaseFilter value must be 'columnValue'", value, valueGot); LongSumAggregator longSumAggrGot = (LongSumAggregator) filteredAggr.getAggregator(); longSumAggrGot.getName();//from w ww .ja v a 2 s . c om byte[] cacheKey = filteredAggr.cacheKey(); String hashCacheKeyExpected = "be9b174d517e49eff7c366f4225f72a300ae65b2"; String hashCacheKeyGot = DigestUtils.shaHex(cacheKey); assertEquals("Hash of cacheKey NOT Equals", hashCacheKeyExpected, hashCacheKeyGot); String aggregatorName2 = "DblSumAggrTest2"; //String fieldName2 = "FieldName2"; BaseFilter filter2 = new SelectorFilter(dimension, value); LongSumAggregator long2 = new LongSumAggregator(baseAggregatorName, fieldName); FilteredAggregator agg2 = new FilteredAggregator(aggregatorName2, filter2, long2); FilteredAggregator agg3 = new FilteredAggregator(aggregatorName2, filter2, long2); assertTrue(agg2.hashCode() == agg3.hashCode()); assertTrue(agg2.equals(agg2)); assertTrue(agg2.equals(agg3)); assertTrue(!agg2.equals(null)); FilteredAggregator agg4 = new FilteredAggregator(null, filter2, long2); assertTrue(!agg2.equals(agg4)); assertTrue(!agg4.equals(agg2)); FilteredAggregator agg5 = new FilteredAggregator(aggregatorName2, null, long2); assertTrue(!agg2.equals(agg5)); assertTrue(!agg5.equals(agg2)); FilteredAggregator agg6 = new FilteredAggregator(aggregatorName2, filter2, null); assertTrue(!agg2.equals(agg6)); assertTrue(!agg6.equals(agg2)); assertTrue(!agg2.equals(new CountAggregator(aggregatorName2))); }
From source file:com.enonic.cms.store.resource.FileResourceServiceImpl.java
private String createKey(FileResourceName name) { if (name == null) { return null; }//from www. java 2 s . c o m try { return DigestUtils.shaHex(name.getPath().getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
From source file:com.benfante.jslideshare.SlideShareConnectorImpl.java
public InputStream sendGetMessage(String url, Map<String, String> parameters) throws IOException, SlideShareErrorException { HttpClient client = createHttpClient(); GetMethod method = new GetMethod(url); NameValuePair[] params = new NameValuePair[parameters.size() + 3]; int i = 0;// ww w. j av a 2s. c o m params[i++] = new NameValuePair("api_key", this.apiKey); Iterator<Map.Entry<String, String>> entryIt = parameters.entrySet().iterator(); while (entryIt.hasNext()) { Map.Entry<String, String> entry = entryIt.next(); params[i++] = new NameValuePair(entry.getKey(), entry.getValue()); } Date now = new Date(); String ts = Long.toString(now.getTime() / 1000); String hash = DigestUtils.shaHex(this.sharedSecret + ts).toLowerCase(); params[i++] = new NameValuePair("ts", ts); params[i++] = new NameValuePair("hash", hash); method.setQueryString(params); logger.debug("Sending GET message to " + method.getURI().getURI() + " with parameters " + Arrays.toString(params)); int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { logger.debug("Server replied with a " + statusCode + " HTTP status code (" + HttpStatus.getStatusText(statusCode) + ")"); throw new SlideShareErrorException(statusCode, HttpStatus.getStatusText(statusCode)); } if (logger.isDebugEnabled()) { logger.debug(method.getResponseBodyAsString()); } InputStream result = new ByteArrayInputStream(method.getResponseBody()); method.releaseConnection(); return result; }
From source file:com.ebay.pulsar.analytics.cache.MemcachedCache.java
private static String computeKeyHash(String memcachedPrefix, NamedKey key) { // hash keys to keep things under 250 characters for memcached return memcachedPrefix + ":" + DigestUtils.shaHex(key.namespace) + ":" + DigestUtils.shaHex(key.key); }
From source file:com.ebay.pulsar.analytics.metricstore.druid.filter.FilterTest.java
public void testSelectorFilter() { String dim = "Dimension"; String val = "Value"; SelectorFilter filter = new SelectorFilter(dim, val); byte[] cacheKey = filter.cacheKey(); String hashCacheKeyExpected = "1e3e9d10d888276e16f3565a8950e55b3b29a4ea"; String hashCacheKeyGot = DigestUtils.shaHex(cacheKey); assertEquals("Hash of cacheKey NOT Equals", hashCacheKeyExpected, hashCacheKeyGot); String dim2 = "Dimension2"; String val2 = "Value2"; SelectorFilter filter2 = new SelectorFilter(dim2, val2); SelectorFilter filter1 = new SelectorFilter(null, null); assertTrue(filter2.equals(filter2)); assertTrue(!filter2.equals(filter1)); assertTrue(!filter1.equals(filter2)); filter1 = new SelectorFilter(dim2, null); assertTrue(!filter2.equals(filter1)); assertTrue(!filter1.equals(filter2)); filter1 = new SelectorFilter(dim2, val2); assertTrue(filter2.equals(filter1)); assertTrue(filter2.hashCode() == filter1.hashCode()); assertTrue(!filter2.equals(new NotFilter(filter2) { }));/*from w w w .j a va 2 s .co m*/ }
From source file:ca.licef.lompad.Classification.java
public static File doImportFile(Component parent) { JFileChooser chooser = new JFileChooser(); if (Preferences.getInstance().getPrevClassifDir() != null) chooser.setCurrentDirectory(Preferences.getInstance().getPrevClassifDir()); int returnVal = chooser.showOpenDialog(parent); if (returnVal == JFileChooser.APPROVE_OPTION) { try {//w w w . j a v a 2s .c om Preferences.getInstance().setPrevClassifDir(chooser.getCurrentDirectory()); } catch (Exception e) { e.printStackTrace(); } try { File skosInputFile = chooser.getSelectedFile(); File tmpFile = null; String xml = IOUtil.readStringFromFile(chooser.getSelectedFile()); String rootTagName = XMLUtil.getRootTagName(xml); if (rootTagName != null) { String[] array = StringUtil.split(rootTagName, ':'); rootTagName = array[array.length - 1].toLowerCase(); } boolean isVdexFile = (rootTagName != null && "vdex".equals(rootTagName)); if (isVdexFile) { String xsltFile = "/xslt/convertVDEXToSKOS.xsl"; StreamSource xslt = new StreamSource(Util.class.getResourceAsStream(xsltFile)); StreamSource xmlSource = new StreamSource(new BufferedReader(new StringReader(xml))); Node skosNode = XMLUtil.applyXslToDocument2(xslt, xmlSource, null, null, null); tmpFile = File.createTempFile("lompad", "inputSkos"); Writer tmpFileWriter = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(tmpFile, false), "UTF-8")); try { XMLUtil.serialize(skosNode, false, tmpFileWriter); } finally { if (tmpFileWriter != null) tmpFileWriter.close(); } skosInputFile = tmpFile; } Classification classif = new Classification(skosInputFile); classif.initModel(true); String uri = classif.getConceptSchemeUri(); if (uri == null) throw new Exception("ConceptScheme's URI not found."); String sha1 = DigestUtils.shaHex(uri); File localFile = new File(Util.getClassificationFolder(), sha1 + ".rdf"); classif.dumpModelToRdf(localFile); if (tmpFile != null) tmpFile.delete(); return (localFile); } catch (Exception e) { e.printStackTrace(); String msg = "classifImportFailed"; if ("Classification identifier not found.".equals(e.getMessage())) msg = "classifIdentifierNotFound"; JDialogAlert dialog = new JDialogAlert(Util.getTopJFrame((Container) parent), "titleErr", msg); dialog.setSize(320, 140); dialog.setVisible(true); return (null); } } else return (null); }