List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64URLSafeString
public static String encodeBase64URLSafeString(final byte[] binaryData)
From source file:org.jahia.modules.userregistration.actions.RecoverPassword.java
private static String generateToken(JCRUserNode user, int passwordRecoveryTimeout) throws RepositoryException { String path = user.getPath(); long timestamp = System.currentTimeMillis(); String authKey = DigestUtils.md5Hex(path + timestamp) + '|' + (timestamp + passwordRecoveryTimeout * 1000L); user.setProperty(PROPERTY_PASSWORD_RECOVERY_TOKEN, authKey); user.getSession().save();/*from ww w.jav a 2 s . c o m*/ try { return Base64.encodeBase64URLSafeString((path + "|" + authKey).getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException(e); } }
From source file:org.jahia.utils.Url.java
/** * Encode facet filter URL parameter//ww w. j a v a 2 s .co m * @param inputString facet filter parameter * @return filter encoded for URL query parameter usage */ public static String encodeUrlParam(String inputString) { if (StringUtils.isEmpty(inputString)) { return inputString; } // Compress the bytes byte[] output = new byte[2048]; Deflater compresser = new Deflater(); try { compresser.setInput(inputString.getBytes("UTF-8")); compresser.finish(); int compressedDataLength = compresser.deflate(output); byte[] copy = new byte[compressedDataLength]; System.arraycopy(output, 0, copy, 0, Math.min(output.length, compressedDataLength)); return Base64.encodeBase64URLSafeString(copy); } catch (UnsupportedEncodingException e) { logger.warn("Not able to encode facet URL: " + inputString, e); } return inputString; }
From source file:org.jasig.resource.aggr.ResourcesAggregatorImpl.java
/** * Aggregate the specified Deque of elements into a single element. The provided MessageDigest is used for * building the file name based on the hash of the file contents. The callback is used for type specific * operations.//from www . j a v a 2 s . c om */ protected <T extends BasicInclude> T aggregateList(final MessageDigest digest, final Deque<T> elements, final List<File> skinDirectories, final File outputRoot, final File alternateOutput, final String extension, final AggregatorCallback<T> callback) throws IOException { if (null == elements || elements.size() == 0) { return null; } // reference to the head of the list final T headElement = elements.getFirst(); if (elements.size() == 1 && this.resourcesDao.isAbsolute(headElement)) { return headElement; } final File tempFile = File.createTempFile("working.", extension); final File aggregateOutputFile; try { //Make sure we're working with a clean MessageDigest digest.reset(); TrimmingWriter trimmingWriter = null; try { final BufferedOutputStream bufferedFileStream = new BufferedOutputStream( new FileOutputStream(tempFile)); final MessageDigestOutputStream digestStream = new MessageDigestOutputStream(bufferedFileStream, digest); final OutputStreamWriter aggregateWriter = new OutputStreamWriter(digestStream, this.encoding); trimmingWriter = new TrimmingWriter(aggregateWriter); for (final T element : elements) { final File resourceFile = this.findFile(skinDirectories, element.getValue()); FileInputStream fis = null; try { fis = new FileInputStream(resourceFile); final BOMInputStream bomIs = new BOMInputStream(new BufferedInputStream(fis)); if (bomIs.hasBOM()) { logger.debug("Stripping UTF-8 BOM from: " + resourceFile); } final Reader resourceIn = new InputStreamReader(bomIs, this.encoding); if (element.isCompressed()) { IOUtils.copy(resourceIn, trimmingWriter); } else { callback.compress(resourceIn, trimmingWriter); } } catch (IOException e) { throw new IOException( "Failed to read '" + resourceFile + "' for skin: " + skinDirectories.get(0), e); } finally { IOUtils.closeQuietly(fis); } trimmingWriter.write(SystemUtils.LINE_SEPARATOR); } } finally { IOUtils.closeQuietly(trimmingWriter); } if (trimmingWriter.getCharCount() == 0) { return null; } // temp file is created, get checksum final String checksum = Base64.encodeBase64URLSafeString(digest.digest()); digest.reset(); // create a new file name final String newFileName = checksum + extension; // Build the new file name and path if (alternateOutput == null) { final String elementRelativePath = FilenameUtils.getFullPath(headElement.getValue()); final File directoryInOutputRoot = new File(outputRoot, elementRelativePath); // create the same directory structure in the output root directoryInOutputRoot.mkdirs(); aggregateOutputFile = new File(directoryInOutputRoot, newFileName).getCanonicalFile(); } else { aggregateOutputFile = new File(alternateOutput, newFileName).getCanonicalFile(); } //Move the aggregate file into the correct location FileUtils.deleteQuietly(aggregateOutputFile); FileUtils.moveFile(tempFile, aggregateOutputFile); } finally { //Make sure the temp file gets deleted FileUtils.deleteQuietly(tempFile); } final String newResultValue = RelativePath.getRelativePath(outputRoot, aggregateOutputFile); this.logAggregation(elements, newResultValue); return callback.getAggregateElement(newResultValue, elements); }
From source file:org.jboss.dashboard.workspace.WorkspacesManager.java
/** * Generate a unique workspace identifier *//*from w w w. jav a 2s. c om*/ public synchronized String generateWorkspaceId() throws Exception { UUID uuid = UUID.randomUUID(); ByteBuffer bb = ByteBuffer.wrap(new byte[16]); bb.putLong(uuid.getMostSignificantBits()); bb.putLong(uuid.getLeastSignificantBits()); return Base64.encodeBase64URLSafeString(bb.array()); }
From source file:org.jbpm.designer.repository.vfs.VFSRepository.java
private String encodeUniqueId(String uniqueId) { try {//from w w w . j av a 2 s . c om return Base64.encodeBase64URLSafeString(UriUtils.decode(uniqueId).getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e.getMessage()); } }
From source file:org.jbpm.designer.server.service.DefaultDesignerAssetService.java
@Override public Map<String, String> getEditorParameters(final Path path, final String editorID, String hostInfo, PlaceRequest place) {//from w w w. ja v a 2 s .c o m List<String> activeNodesList = new ArrayList<String>(); String activeNodesParam = place.getParameter("activeNodes", null); boolean readOnly = place.getParameter("readOnly", null) != null; if (!readOnly) { try { ioService.getFileSystem(URI.create(path.toURI())); } catch (Exception e) { logger.error("Unable to create file system: " + e.getMessage()); throw new FileSystemNotFoundException(e.getMessage()); } } String processId = place.getParameter("processId", ""); String deploymentId = place.getParameter("deploymentId", ""); String encodedProcessSource = ""; try { encodedProcessSource = bpmn2DataServices.iterator().next().getProcessSources(deploymentId, processId); } catch (Exception e) { encodedProcessSource = place.getParameter("encodedProcessSource", ""); } if (activeNodesParam != null) { activeNodesList = Arrays.asList(activeNodesParam.split(",")); } List<String> completedNodesList = new ArrayList<String>(); String completedNodesParam = place.getParameter("completedNodes", null); if (completedNodesParam != null) { completedNodesList = Arrays.asList(completedNodesParam.split(",")); } JSONArray activeNodesArray = new JSONArray(activeNodesList); // String encodedActiveNodesParam; // try { // encodedActiveNodesParam = Base64.encodeBase64URLSafeString( activeNodesArray.toString().getBytes( "UTF-8" ) ); // } catch ( UnsupportedEncodingException e ) { // encodedActiveNodesParam = ""; // } JSONArray completedNodesArray = new JSONArray(completedNodesList); // String encodedCompletedNodesParam; // try { // encodedCompletedNodesParam = Base64.encodeBase64URLSafeString( completedNodesArray.toString().getBytes( "UTF-8" ) ); // } catch ( UnsupportedEncodingException e ) { // encodedCompletedNodesParam = ""; // } Map<String, String> editorParamsMap = new HashMap<String, String>(); editorParamsMap.put("hostinfo", hostInfo); try { editorParamsMap.put("uuid", Base64.encodeBase64URLSafeString(UriUtils.decode(path.toURI()).getBytes("UTF-8"))); } catch (UnsupportedEncodingException e) { } editorParamsMap.put("profile", "jbpm"); editorParamsMap.put("pp", ""); editorParamsMap.put("editorid", editorID); editorParamsMap.put("readonly", String.valueOf(readOnly)); editorParamsMap.put("activenodes", activeNodesArray.toString()); editorParamsMap.put("completednodes", completedNodesArray.toString()); editorParamsMap.put("processsource", encodedProcessSource); //Signal opening to interested parties if we are not in readonly mode if (!readOnly) { resourceOpenedEvent.fire(new ResourceOpenedEvent(path, sessionInfo)); } return editorParamsMap; }
From source file:org.kaaproject.kaa.server.common.admin.AdminClient.java
private static String toUrlSafe(String endpointProfileKeyHash) { return Base64.encodeBase64URLSafeString(Base64.decodeBase64(endpointProfileKeyHash)); }
From source file:org.kaaproject.kaa.server.common.dao.service.SdkTokenGenerator.java
/** * Generates the SDK token.//from ww w. ja v a 2s . c o m * * @param sdkProfileDto SDK profile */ public static void generateSdkToken(SdkProfileDto sdkProfileDto) { if (StringUtils.isEmpty(sdkProfileDto.getToken())) { try { MessageDigest messageDigest = MessageDigest.getInstance(SDK_TOKEN_HASH_ALGORITHM); messageDigest.update(DtoByteMarshaller.toBytes(sdkProfileDto.toSdkTokenDto())); sdkProfileDto.setToken(Base64.encodeBase64URLSafeString(messageDigest.digest())); } catch (NoSuchAlgorithmException ex) { throw new RuntimeException(ex); } } }
From source file:org.kaaproject.kaa.server.common.nosql.cassandra.dao.EndpointProfileCassandraDao.java
private EndpointProfilesPageDto createNextPage(List<EndpointProfileDto> cassandraEndpointProfileList, String endpointGroupId, String limit) { EndpointProfilesPageDto endpointProfilesPageDto = new EndpointProfilesPageDto(); PageLinkDto pageLinkDto = new PageLinkDto(); String next;//w ww . ja va 2 s . co m int lim = Integer.valueOf(limit); if (cassandraEndpointProfileList.size() == (lim + 1)) { pageLinkDto.setEndpointGroupId(endpointGroupId); pageLinkDto.setLimit(limit); pageLinkDto.setOffset( Base64.encodeBase64URLSafeString(cassandraEndpointProfileList.get(lim).getEndpointKeyHash())); cassandraEndpointProfileList.remove(lim); next = null; } else { next = DaoConstants.LAST_PAGE_MESSAGE; } pageLinkDto.setNext(next); endpointProfilesPageDto.setPageLinkDto(pageLinkDto); endpointProfilesPageDto.setEndpointProfiles(cassandraEndpointProfileList); return endpointProfilesPageDto; }
From source file:org.kaaproject.kaa.server.common.nosql.cassandra.dao.EndpointProfileCassandraDao.java
private EndpointProfilesBodyDto createNextBodyPage(List<EndpointProfileBodyDto> profilesBodyDto, String endpointGroupId, String limit) { EndpointProfilesBodyDto endpointProfilesBodyDto = new EndpointProfilesBodyDto(); PageLinkDto pageLinkDto = new PageLinkDto(); String next;/*from w ww . j av a 2 s . c o m*/ int lim = Integer.valueOf(limit); if (profilesBodyDto.size() == (lim + 1)) { pageLinkDto.setEndpointGroupId(endpointGroupId); pageLinkDto.setLimit(limit); pageLinkDto.setOffset(Base64.encodeBase64URLSafeString(profilesBodyDto.get(lim).getEndpointKeyHash())); profilesBodyDto.remove(lim); next = null; } else { next = DaoConstants.LAST_PAGE_MESSAGE; } pageLinkDto.setNext(next); endpointProfilesBodyDto.setPageLinkDto(pageLinkDto); endpointProfilesBodyDto.setEndpointProfilesBody(profilesBodyDto); return endpointProfilesBodyDto; }