List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64URLSafeString
public static String encodeBase64URLSafeString(final byte[] binaryData)
From source file:com.mirth.connect.model.ServerEvent.java
public String toExportString() { StringBuilder builder = new StringBuilder(); builder.append(id + ", "); builder.append(new SimpleDateFormat(Exportable.DATE_TIME_FORMAT).format(eventTime.getTime()) + ", "); builder.append(level + ", "); builder.append(outcome + ", "); builder.append(name + ", "); builder.append(userId + ", "); builder.append(ipAddress + ", "); /*// w w w .j ava 2 s.c om * Print out the attributes and Base64 encode them in case there are * newlines. */ ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); MapUtils.verbosePrint(ps, "attributes", attributes); builder.append(Base64.encodeBase64URLSafeString(baos.toByteArray())); builder.append(System.getProperty("line.separator")); IOUtils.closeQuietly(ps); return builder.toString(); }
From source file:com.asual.lesscss.ResourcePackage.java
public String toString() { try {/* w ww. j a v a2 s.c o m*/ if (extension != null && !extensions.contains(extension)) { throw new Exception("Unsupported extension: " + extension); } int mask = 0; if (name != null) { mask = mask | NAME_FLAG; } if (version != null) { mask = mask | VERSION_FLAG; } String key = mask + NEW_LINE + StringUtils.join(resources, NEW_LINE); if (!cache.containsKey(key)) { byte[] bytes = key.getBytes(ENCODING); StringBuilder sb = new StringBuilder(); sb.append("/"); sb.append(name == null ? "" : name + SEPARATOR); sb.append(version == null ? "" : version + SEPARATOR); sb.append(Base64.encodeBase64URLSafeString(bytes.length < DEFLATE ? bytes : deflate(bytes)) .replaceAll("-", "+")); sb.append(extension == null ? "" : "." + extension); cache.put(key, sb.toString()); } return cache.get(key); } catch (Exception e) { logger.error(e.getMessage(), e); } return null; }
From source file:com.smartitengineering.cms.spi.impl.events.EventPublicationListener.java
@Override public void notify(Event event) { final String hexedContentId; final Type eventSourceType = event.getEventSourceType(); try {/* ww w . ja va2 s . c o m*/ ByteArrayOutputStream contentBytes = new ByteArrayOutputStream(); if (eventSourceType.equals(Type.CONTENT)) { ContentId contentId = ((Content) event.getSource()).getContentId(); contentBytes.write(org.apache.commons.codec.binary.StringUtils .getBytesUtf8(contentId.getWorkspaceId().getGlobalNamespace())); contentBytes.write(NEW_LINE); contentBytes.write(org.apache.commons.codec.binary.StringUtils .getBytesUtf8(contentId.getWorkspaceId().getName())); contentBytes.write(NEW_LINE); contentBytes.write(contentId.getId()); } else if (eventSourceType.equals(Type.CONTENT_TYPE)) { ContentTypeId typeId = ((ContentType) event.getSource()).getContentTypeID(); contentBytes.write(org.apache.commons.codec.binary.StringUtils .getBytesUtf8(typeId.getWorkspace().getGlobalNamespace())); contentBytes.write(NEW_LINE); contentBytes.write( org.apache.commons.codec.binary.StringUtils.getBytesUtf8(typeId.getWorkspace().getName())); contentBytes.write(NEW_LINE); contentBytes.write(org.apache.commons.codec.binary.StringUtils.getBytesUtf8(typeId.getNamespace())); contentBytes.write(NEW_LINE); contentBytes.write(org.apache.commons.codec.binary.StringUtils.getBytesUtf8(typeId.getName())); } else if (eventSourceType.equals(Type.SEQUENCE)) { SequenceId seqId = ((Sequence) event.getSource()).getSequenceId(); contentBytes.write(org.apache.commons.codec.binary.StringUtils .getBytesUtf8(seqId.getWorkspaceId().getGlobalNamespace())); contentBytes.write(NEW_LINE); contentBytes.write( org.apache.commons.codec.binary.StringUtils.getBytesUtf8(seqId.getWorkspaceId().getName())); contentBytes.write(NEW_LINE); contentBytes.write(org.apache.commons.codec.binary.StringUtils.getBytesUtf8(seqId.getName())); } else { logger.warn("Unrecognized event source type!"); } hexedContentId = Base64.encodeBase64URLSafeString(contentBytes.toByteArray()); if (logger.isDebugEnabled()) { logger.debug("Content of event message " + hexedContentId); } } catch (Exception ex) { logger.warn("Could not serialize content ID!", ex); return; } if (StringUtils.isNotBlank(hexedContentId)) { String message = new StringBuilder(eventSourceType.name()).append('\n') .append(event.getEventType().name()).append('\n').append(hexedContentId).toString(); if (logger.isDebugEnabled()) { logger.debug("Publishing message " + message); } publisher.publishEvent("text/plain", message); } }
From source file:com.here.account.auth.OAuth1Signer.java
/** * For cases where there is no Content-Type: application/x-www-form-urlencoded, * and no request token, call this method to get the Authorization Header Value * for a single request. //from ww w. j a v a 2 s . c o m * * <p> * Computes the OAuth1 Authorization header value including all required components of the * OAuth type. * See also the OAuth 1.0 * <a href="https://tools.ietf.org/html/rfc5849#section-3.5.1">Authorization Header</a> * Section. * * <p> * Note that the client accessKeySecret, once configured on this object, does not leave this method, * as signatures are used in its place on the wire. * * @param method * @return */ private String getAuthorizationHeaderValue(String method, String url, Map<String, List<String>> formParams) { SignatureCalculator calculator = getSignatureCalculator(); // <a href="https://tools.ietf.org/html/rfc5849#section-3.3">timestamp</no I a>. // the number of seconds since January 1, 1970 00:00:00 GMT long timestamp = clock.currentTimeMillis() / 1000L; // choose the first 6 chars from base64 alphabet byte[] bytes = new byte[NONCE_LENGTH]; nextBytes(bytes); String nonce = Base64.encodeBase64URLSafeString(bytes).substring(0, NONCE_LENGTH); String computedSignature = calculator.calculateSignature(method, url, timestamp, nonce, SignatureMethod.HMACSHA256, formParams, null); return calculator.constructAuthHeader(computedSignature, nonce, timestamp, SignatureMethod.HMACSHA256); }
From source file:io.mapzone.controller.vm.http.LoginProvision.java
protected void registerUser(String userId, @SuppressWarnings("hiding") HttpServletResponse response) { // cookie token byte[] bytes = new byte[8]; rand.nextBytes(bytes);//from w w w .jav a 2 s .co m String token = Base64.encodeBase64URLSafeString(bytes); // FIXME Leak: entries are never removed (allow just one cookie/session per user?) if (loggedIn.putIfAbsent(token, userId) != null) { throw new IllegalStateException("Token already exists: " + token); } // set cookie Cookie newCookie = new Cookie(COOKIE_NAME, token); newCookie.setHttpOnly(true); newCookie.setPath(COOKIE_PATH); newCookie.setSecure(false); // XXX newCookie.setMaxAge(COOKIE_MAX_AGE); response.addCookie(newCookie); }
From source file:de.nx42.maps4cim.map.texture.osm.OsmHash.java
protected static String getQueryHashEntities(List<EntityDef> entities) { Hasher h = hf.newHasher();// w w w. j a va2s . c o m // add query for (EntityDef def : entities) { h.putInt(def.hashCode()); } // get hash, cap length byte[] hash = h.hash().asBytes(); if (hash.length > 4) { hash = Arrays.copyOfRange(hash, 0, 3); } // return hash, max 4 byte (6 chars) return Base64.encodeBase64URLSafeString(hash); }
From source file:com.google.u2f.client.impl.U2FClientReferenceImpl.java
@Override public void authenticate(String origin, String accountName) throws U2FException { U2fSignRequest signRequest = server.getSignRequest(accountName, origin); String serverChallengeBase64 = signRequest.getChallenge(); List<RegisteredKey> registeredKeys = signRequest.getRegisteredKeys(); String version = registeredKeys.get(0).getVersion(); String appId = registeredKeys.get(0).getAppId(); String keyHandleBase64 = registeredKeys.get(0).getKeyHandle(); String sessionId = registeredKeys.get(0).getSessionId(); if (!version.equals(U2FConsts.U2F_V2)) { throw new U2FException(String.format("Unsupported protocol version: %s", version)); }/*from w ww.j a v a2s .c o m*/ appIdVerifier.validateOrigin(appId, origin); JsonObject channelIdJson = channelIdProvider.getJsonChannelId(); String clientData = ClientDataCodec.encodeClientData(ClientDataCodec.REQUEST_TYPE_AUTHENTICATE, serverChallengeBase64, origin, channelIdJson); byte[] clientDataSha256 = crypto.computeSha256(clientData); byte[] appIdSha256 = crypto.computeSha256(appId); byte[] keyHandle = Base64.decodeBase64(keyHandleBase64); AuthenticateResponse authenticateResponse = key.authenticate(new AuthenticateRequest( UserPresenceVerifier.USER_PRESENT_FLAG, clientDataSha256, appIdSha256, keyHandle)); byte[] rawAuthenticateResponse = RawMessageCodec.encodeAuthenticateResponse(authenticateResponse); String rawAuthenticateResponse64 = Base64.encodeBase64URLSafeString(rawAuthenticateResponse); String clientDataBase64 = Base64.encodeBase64URLSafeString(clientData.getBytes()); server.processSignResponse( new SignResponse(keyHandleBase64, rawAuthenticateResponse64, clientDataBase64, sessionId)); }
From source file:com.tremolosecurity.unison.google.u2f.U2FServerUnison.java
@Override public RegistrationRequest getRegistrationRequest(String accountName, String appId) { log.debug(">> getRegistrationRequest " + accountName); byte[] challenge = challengeGenerator.generateChallenge(accountName); EnrollSessionData sessionData = new EnrollSessionData(accountName, appId, challenge); String sessionId = dataStore.storeSessionData(sessionData); String challengeBase64 = Base64.encodeBase64URLSafeString(challenge); if (log.isDebugEnabled()) { log.debug("-- Output --"); log.debug(" sessionId: " + sessionId); log.debug(" challenge: " + Hex.encodeHexString(challenge)); log.debug("<< getRegistrationRequest " + accountName); }//from w w w. java 2 s . co m return new RegistrationRequest(U2FConsts.U2F_V2, challengeBase64, appId, sessionId); }
From source file:com.smartitengineering.cms.spi.impl.events.EventConsumerTest.java
@Test(expected = RuntimeException.class) public void testInvalidType() { mockery.checking(new Expectations() { {/*from ww w . j a va2s .c o m*/ } }); EventConsumer consumer = injector.getInstance(EventConsumer.class); consumer.consume(MSG_TYPE, "MY\nCREATE\n" + Base64.encodeBase64URLSafeString(StringUtils.getBytesUtf8("random string\nfor test"))); mockery.assertIsSatisfied(); }
From source file:de.unirostock.sems.cbarchive.web.dataholder.WorkspaceHistory.java
@JsonIgnore public String toCookieJson() throws JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); String json = mapper.writeValueAsString(recentWorkspaces); json = Base64.encodeBase64URLSafeString(json.getBytes()); return json;// w w w. j a v a2s. c o m }