Example usage for com.liferay.portal.kernel.util Base64 decode

List of usage examples for com.liferay.portal.kernel.util Base64 decode

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util Base64 decode.

Prototype

public static byte[] decode(String base64) 

Source Link

Usage

From source file:com.liferay.ci.http.BaseConnectImpl.java

License:Open Source License

protected InputStream connect(AuthConnectionParams authParams, String urlSuffix, boolean appendUrlPrefix)
        throws IOException {

    if (authParams != null) {
        _connectionParams = authParams;// w w  w .j  a  v  a2 s.  c om
    }

    String user = _connectionParams.getUser();
    String password = _connectionParams.getPassword();

    String connectionURL = "";

    if (appendUrlPrefix) {
        connectionURL += authParams.getBaseApiUrl();
    }

    connectionURL += urlSuffix;

    URL url = new URL(connectionURL);

    URLConnection uc = url.openConnection();

    String userpass = user + " : " + new String(Base64.decode(password));

    String encodedUserPass = new String(Base64.encode(userpass.getBytes()));

    Authenticator.setDefault(new Authenticator() {
        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
            String decodedPassword = new String(Base64.decode(_connectionParams.getPassword()));

            return new PasswordAuthentication(_connectionParams.getUser(), decodedPassword.toCharArray());
        }
    });

    String basicAuth = "Basic " + DatatypeConverter.printBase64Binary(encodedUserPass.getBytes());

    uc.setRequestProperty("Authorization", basicAuth);

    return uc.getInputStream();
}

From source file:com.liferay.document.library.internal.atom.FileEntryAtomCollectionAdapter.java

License:Open Source License

@Override
protected FileEntry doPostEntry(String title, String summary, String content, Date date,
        AtomRequestContext atomRequestContext) throws Exception {

    long folderId = atomRequestContext.getLongParameter("folderId");

    long repositoryId = 0;

    if (folderId != 0) {
        Folder folder = _dlAppService.getFolder(folderId);

        repositoryId = folder.getRepositoryId();
    } else {// w ww.j  av  a  2  s  .co  m
        repositoryId = atomRequestContext.getLongParameter("repositoryId");
    }

    String mimeType = atomRequestContext.getHeader("Media-Content-Type");

    if (mimeType == null) {
        mimeType = MimeTypesUtil.getContentType(title);
    }

    byte[] contentDecoded = Base64.decode(content);

    ByteArrayInputStream contentInputStream = new ByteArrayInputStream(contentDecoded);

    ServiceContext serviceContext = new ServiceContext();

    FileEntry fileEntry = _dlAppService.addFileEntry(repositoryId, folderId, title, mimeType, title, summary,
            null, contentInputStream, contentDecoded.length, serviceContext);

    return fileEntry;
}

From source file:com.liferay.document.library.internal.atom.FileEntryAtomCollectionAdapter.java

License:Open Source License

@Override
protected void doPutEntry(FileEntry fileEntry, String title, String summary, String content, Date date,
        AtomRequestContext atomRequestContext) throws Exception {

    String mimeType = atomRequestContext.getHeader("Media-Content-Type");

    if (mimeType == null) {
        mimeType = MimeTypesUtil.getContentType(title);
    }/*w w w. j  ava 2 s .c  om*/

    byte[] contentDecoded = Base64.decode(content);

    ByteArrayInputStream contentInputStream = new ByteArrayInputStream(contentDecoded);

    ServiceContext serviceContext = new ServiceContext();

    _dlAppService.updateFileEntry(fileEntry.getFileEntryId(), title, mimeType, title, summary, null, true,
            contentInputStream, contentDecoded.length, serviceContext);
}

From source file:com.liferay.events.global.mobile.service.impl.EventContactServiceImpl.java

License:Open Source License

@AccessControlled(guestAccessEnabled = true)
@Override/*from   w  ww.  j  a  va 2  s  .  com*/
public EventContact updateProfilePic(final String eventId, final long contactId, final String mimeType,
        final String extension, final String bytes, String signature) throws Exception {
    Map<String, String> args = new HashMap<String, String>() {
        {
            put("eventId", StringUtil.valueOf(eventId));
            put("extension", StringUtil.valueOf(extension));
            put("contactId", StringUtil.valueOf(contactId));
            put("mimeType", StringUtil.valueOf(mimeType));
            put("bytes", StringUtil.valueOf(bytes));
        }
    };

    if (!Utils.isValidSignature(args, signature)) {
        throw new InvalidSignatureException("invalid signature");

    }

    EventContact contact = EventContactLocalServiceUtil.getEventContact(contactId);

    if (Validator.isNull(contact)) {
        throw new InvalidSignatureException("No such contact");
    }

    final String groupName = GroupConstants.GUEST;
    final long companyId = PortalUtil.getDefaultCompanyId();
    final long guestGroupId = GroupLocalServiceUtil.getGroup(companyId, groupName).getGroupId();
    ServiceContext sc = new ServiceContext();
    sc.setAddGuestPermissions(true);
    sc.setAddGroupPermissions(true);
    sc.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH);

    String[] permissions = { "VIEW" };

    sc.setGuestPermissions(permissions);
    sc.setGroupPermissions(permissions);

    DLFolder folder;
    try {
        folder = DLFolderLocalServiceUtil.getFolder(guestGroupId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
                "profilePics");
    } catch (Exception ex) {

        folder = DLFolderLocalServiceUtil.addFolder(getUserId(), guestGroupId, guestGroupId, true,
                DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, "profilePics", "Profile Pics for Liferay Events",
                false, sc);
    }

    if (Validator.isNull(folder)) {
        throw new Exception("Cannot save picture to profilePics folder");
    }

    try {
        DLFileEntry existingPic = DLFileEntryLocalServiceUtil.getFileEntry(guestGroupId, folder.getFolderId(),
                eventId + "-" + contact.getFullName());
        DLFileEntryLocalServiceUtil.deleteDLFileEntry(existingPic);
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    byte[] imgBytes = Base64.decode(bytes);

    FileEntry newEntry = DLAppLocalServiceUtil.addFileEntry(getUserId(), guestGroupId, folder.getFolderId(),
            eventId + "-" + contact.getEventContactId() + "." + extension, mimeType,
            eventId + "-" + contact.getFullName(), eventId + "-" + contact.getFullName() + " pic", "", imgBytes,
            sc);

    String newPicUrl = PortalUtil.getPathMain() + "/document_library/get_file?uuid=" + newEntry.getUuid()
            + "&groupId=" + guestGroupId;
    contact.setPicUrl(newPicUrl);
    EventContactLocalServiceUtil.updateEventContact(contact);
    return contact;
}

From source file:com.liferay.image.editor.hook.action.ActionUtil.java

License:Open Source License

public static File getImageFromBlob(String blob, String formatName) throws Exception {

    blob = blob.substring(blob.indexOf(StringPool.COMMA) + 1);

    byte[] decodedBytes = Base64.decode(blob);

    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(decodedBytes);

    ImageInputStream imageInputStream = ImageIO.createImageInputStream(byteArrayInputStream);

    Iterator<?> readerIterator = ImageIO.getImageReadersByFormatName(formatName);

    ImageReader reader = (ImageReader) readerIterator.next();

    reader.setInput(imageInputStream, true);

    ImageReadParam defaultReadParam = reader.getDefaultReadParam();

    BufferedImage bufferedImage = reader.read(0, defaultReadParam);

    File imageFile = FileUtil.createTempFile();

    ImageIO.write(bufferedImage, formatName, imageFile);

    return imageFile;
}

From source file:com.liferay.mail.util.PasswordUtil.java

License:Open Source License

public static String decrypt(String encryptedPassword) {
    String unencryptedPassword = null;

    try {//w  w w . j a va  2  s  . c  o  m
        if (Validator.isNull(encryptedPassword)) {
            return StringPool.BLANK;
        }

        byte[] bytes = Base64.decode(encryptedPassword);

        unencryptedPassword = new String(bytes, StringPool.UTF8);
    } catch (UnsupportedEncodingException uee) {
        _log.error("Unable to decrypt the password", uee);
    }

    return unencryptedPassword;
}

From source file:com.liferay.petra.encryptor.Encryptor.java

License:Open Source License

public static String decrypt(Key key, String encryptedString) throws EncryptorException {

    byte[] encryptedBytes = Base64.decode(encryptedString);

    return decryptUnencodedAsString(key, encryptedBytes);
}

From source file:com.liferay.petra.encryptor.Encryptor.java

License:Open Source License

public static Key deserializeKey(String base64String) {
    byte[] bytes = Base64.decode(base64String);

    return new SecretKeySpec(bytes, Encryptor.KEY_ALGORITHM);
}

From source file:com.liferay.portlet.documentlibrary.atom.FileEntryAtomCollectionAdapter.java

License:Open Source License

@Override
protected FileEntry doPostEntry(String title, String summary, String content, Date date,
        AtomRequestContext atomRequestContext) throws Exception {

    long folderId = atomRequestContext.getLongParameter("folderId");

    long repositoryId = 0;

    if (folderId != 0) {
        Folder folder = DLAppServiceUtil.getFolder(folderId);

        repositoryId = folder.getRepositoryId();
    } else {/*from w w w  .  jav a2s.c  o m*/
        repositoryId = atomRequestContext.getLongParameter("repositoryId");
    }

    String mimeType = atomRequestContext.getHeader("Media-Content-Type");

    if (mimeType == null) {
        mimeType = MimeTypesUtil.getContentType(title);
    }

    byte[] contentDecoded = Base64.decode(content);

    ByteArrayInputStream contentInputStream = new ByteArrayInputStream(contentDecoded);

    ServiceContext serviceContext = new ServiceContext();

    FileEntry fileEntry = DLAppServiceUtil.addFileEntry(repositoryId, folderId, title, mimeType, title, summary,
            null, contentInputStream, contentDecoded.length, serviceContext);

    return fileEntry;
}

From source file:com.liferay.portlet.documentlibrary.atom.FileEntryAtomCollectionAdapter.java

License:Open Source License

@Override
protected void doPutEntry(FileEntry fileEntry, String title, String summary, String content, Date date,
        AtomRequestContext atomRequestContext) throws Exception {

    String mimeType = atomRequestContext.getHeader("Media-Content-Type");

    if (mimeType == null) {
        mimeType = MimeTypesUtil.getContentType(title);
    }/*  w  w w  .  j  ava2s  . c o m*/

    byte[] contentDecoded = Base64.decode(content);

    ByteArrayInputStream contentInputStream = new ByteArrayInputStream(contentDecoded);

    ServiceContext serviceContext = new ServiceContext();

    DLAppServiceUtil.updateFileEntry(fileEntry.getFileEntryId(), title, mimeType, title, summary, null, true,
            contentInputStream, contentDecoded.length, serviceContext);
}