Example usage for javax.xml.bind DatatypeConverter parseBase64Binary

List of usage examples for javax.xml.bind DatatypeConverter parseBase64Binary

Introduction

In this page you can find the example usage for javax.xml.bind DatatypeConverter parseBase64Binary.

Prototype

public static byte[] parseBase64Binary(String lexicalXSDBase64Binary) 

Source Link

Document

Converts the string argument into an array of bytes.

Usage

From source file:se.carlengstrom.internetonastick.http.HttpServer.java

private String postAppendLineFile(final Request req, final Response res) throws IOException {
    final String user = req.params("user");
    final String markovName = req.params("markov");
    final String asdasd = req.body();
    final AppendLineFileRequest request = mapper.readValue(req.body(), AppendLineFileRequest.class);

    final String path = "data/" + user + "/" + markovName + "/source.txt";
    final byte[] markovData = DatatypeConverter.parseBase64Binary(request.data());

    final File folder = new File("data/" + user + "/" + markovName + "/");
    folder.mkdirs();/*  ww w. j  av  a 2  s.  c o  m*/

    File source = new File(path);
    if (!source.exists()) {
        source.createNewFile();
    }
    try (FileOutputStream stream = new FileOutputStream(path, true)) {
        stream.write(markovData);
    }

    final File temp = File.createTempFile("markov-input-partial", "txt");
    try (FileOutputStream stream = new FileOutputStream(temp, true)) {
        stream.write(markovData);
    }

    final Markov markov = markovs.get(user).get(markovName);
    final AppendLineFileToMarkovJob job = new AppendLineFileToMarkovJob(markov, folder.getAbsolutePath(),
            Delimiter.LINE);

    runner.scheduleJob(job);

    final String jobName = user + System.currentTimeMillis();
    jobs.put(jobName, job);
    return mapper.writeValueAsString(new CreateMarkovResponseBuilder().jobName(jobName).build());
}

From source file:com.kibana.multitenancy.plugin.KibanaUserReindexFilter.java

private String getUser(RestRequest request) {
    //Sushant:Getting user in case of Basic Authentication
    String username = "";
    //Sushant:Scenario when user Authenticated at Proxy level itself
    String proxyAuthUser = StringUtils.defaultIfBlank(request.header(proxyUserHeader), "");
    //Sushant: Scenario when user Authenticated at Proxy level itself

    String basicAuthorizationHeader = StringUtils.defaultIfBlank(request.header("Authorization"), "");
    if (StringUtils.isNotEmpty(basicAuthorizationHeader)) {
        String decodedBasicHeader = new String(
                DatatypeConverter.parseBase64Binary(basicAuthorizationHeader.split(" ")[1]),
                StandardCharsets.US_ASCII);
        final String[] decodedBasicHeaderParts = decodedBasicHeader.split(":");
        username = decodedBasicHeaderParts[0];
        decodedBasicHeader = null;/*from   w  w  w  .j  a  v a  2s.  co m*/
        basicAuthorizationHeader = null;
        logger.debug("User '{}' is authenticated", username);
    }
    return username;
}

From source file:com.github.stephanarts.cas.ticket.registry.RegistryClient.java

/**
 * Get a ticket from the ticketregistry.
 *
 * @param ticketId       id of ticket-object to get from Registry
 *
 * @return Ticket Object/*from   www . j  ava 2 s  .c  o  m*/
 *
 * @throws JSONRPCException Throws JSONRPCException containing any error.
 */
public final Ticket getTicket(final String ticketId) throws JSONRPCException {

    JSONObject params = new JSONObject();
    JSONObject result;

    Ticket ticket = null;
    String serializedTicket;

    params.put("ticket-id", ticketId);

    result = this.call("cas.getTicket", params);

    if (result.has("ticket")) {
        serializedTicket = result.getString("ticket");

        try {
            ByteArrayInputStream bi = new ByteArrayInputStream(
                    DatatypeConverter.parseBase64Binary(serializedTicket));
            ObjectInputStream si = new ObjectInputStream(bi);

            ticket = (Ticket) si.readObject();
        } catch (final Exception e) {
            throw new JSONRPCException(-32501, "Could not decode Ticket");
        }
    }

    if (ticket == null) {
        logger.debug("Failed to get Ticket: {}", ticketId);
    }

    return ticket;
}

From source file:pt.lsts.neptus.comm.iridium.RockBlockIridiumMessenger.java

private String getRockBlockPassword() {
    if (rockBlockPassword == null)
        return "";
    return StringUtils.newStringUtf8(DatatypeConverter.parseBase64Binary(rockBlockPassword));
}

From source file:gov.ca.cwds.rest.util.jni.CmsPKCompressor.java

/**
 * Convenience method. Decompress (inflate) a base64-encoded string of a PK-compressed archive.
 * /*from w ww .  ja  va 2 s  . com*/
 * @param base64Doc base64-encoded, PK-compressed archive
 * @return raw byte array of decompressed document
 * @throws IOException If an I/O error occurs
 */
public byte[] decompressBase64(String base64Doc) throws IOException {
    if (base64Doc == null) {
        throw new IOException("REQUIRED: base64 string to decompress cannot be null");
    }
    final byte[] bytes = decompressBytes(DatatypeConverter.parseBase64Binary(base64Doc.trim()));
    LOGGER.debug("CmsPKCompressor.decompressBase64(String): bytes len={}", bytes.length);
    return bytes;
}

From source file:com.silverpeas.ical.StringUtils.java

/**
 * Decodes a BASE64-encoded string.// w w w  . j  ava  2  s  .  co m
 * @param string BASE64 string
 * @return String the decoded bytes
 * @throws UnsupportedEncodingException
 */
public static String decodeBASE64(String string) {
    return decodeToString(DatatypeConverter.parseBase64Binary(string), CharEncoding.UTF_8);
}

From source file:pt.lsts.neptus.comm.iridium.RockBlockIridiumMessenger.java

private String getGmailPassword() {
    if (gmailPassword == null)
        return "";
    return StringUtils.newStringUtf8(DatatypeConverter.parseBase64Binary(gmailPassword));
}

From source file:io.fabric8.elasticsearch.plugin.auth.FileAuthenticationBackend.java

@Override
public User authenticate(AuthCredentials credentials) throws ElasticsearchSecurityException {
    if (credentials == null) {
        throw new ElasticsearchSecurityException("Creditials are null while trying to authenticate");
    }//from w  w  w  . j a  va 2  s  .  c  om
    Settings settings = loadAuthFile();
    if (exists(settings, credentials.getUsername())) {
        final String hash = settings.get(credentials.getUsername() + PASSWD);
        if (StringUtils.isNotBlank(hash)) {
            final String saved = new String(DatatypeConverter.parseBase64Binary(hash), StandardCharsets.UTF_8)
                    .trim();
            final String presented = new String(credentials.getPassword());
            if (saved.equals(presented)) {
                return new User(credentials.getUsername());
            }
        }
    }
    throw new ElasticsearchSecurityException("Unable to authenticate {}", credentials.getUsername());
}

From source file:com.ocean.common.asserts.Base64Utils.java

/**
 * Base64-decode the given byte array from an UTF-8 String.
 * // w w w.  j a  v a 2 s .  co m
 * @param src
 *            the encoded UTF-8 String (may be {@code null})
 * @return the original byte array (or {@code null} if the input was
 *         {@code null})
 */
public static byte[] decodeFromString(String src) {
    if (src == null) {
        return null;
    }
    if (src.isEmpty()) {
        return new byte[0];
    }

    if (delegate != null) {
        // Full encoder available
        return delegate.decode(src.getBytes(DEFAULT_CHARSET));
    } else {
        // JAXB fallback for String case
        return DatatypeConverter.parseBase64Binary(src);
    }
}