use of com.zimbra.soap.mail.message.ModifyProfileImageRequest in project zm-mailbox by Zimbra.
the class ModifyProfileImageTest method testZCS3545.
@Test
public void testZCS3545() throws Exception {
Account acct = Provisioning.getInstance().getAccountByName("testZCS3545@zimbra.com");
InputStream is = getClass().getResourceAsStream("img.jpg");
FileUploadServlet.Upload up = FileUploadServlet.saveUpload(is, "img.jpg", "image/jpeg", acct.getId());
PowerMockito.stub(PowerMockito.method(MimeDetect.class, "detect", InputStream.class)).toReturn("image/jpeg");
byte[] bytes = IOUtils.toByteArray(up.getInputStream());
PowerMockito.stub(PowerMockito.method(NativeFormatter.class, "getResizedImageData", InputStream.class, String.class, String.class, Integer.class, Integer.class)).toReturn(bytes);
ModifyProfileImageRequest requestJaxb = new ModifyProfileImageRequest();
requestJaxb.setUploadId(up.getId());
Element request = JaxbUtil.jaxbToElement(requestJaxb);
Element response = new ModifyProfileImage().handle(request, ServiceTestUtil.getRequestContext(acct));
ModifyProfileImageResponse responseJaxb = JaxbUtil.elementToJaxb(response);
int profileItemId = responseJaxb.getItemId();
GetInfoRequest getRequestJaxb = new GetInfoRequest();
getRequestJaxb.setSections("mbox");
Element getRequest = JaxbUtil.jaxbToElement(getRequestJaxb);
Element getResponse = new GetInfo().handle(getRequest, ServiceTestUtil.getRequestContext(acct));
GetInfoResponse getResponseJaxb = JaxbUtil.elementToJaxb(getResponse);
Assert.assertEquals(profileItemId, getResponseJaxb.getProfileImageId());
Map<String, Object> attrMap = acct.getAttrs(false, false);
String ldapThumbnailImageData = "/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBwgHBgkIBwgKCgkLDRYPDQwMDRsUFRAWIB0iIiAdHx8kKDQsJCYxJx8fLT0tMTU3Ojo6Iys/RD84QzQ5OjcBCgoKDQwNGg8PGjclHyU3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3N//AABEIAHQAuQMBEQACEQEDEQH/xA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kcZayfwGWDyY035Rsp0/wBRLeYwWAmzQgCCzA8BnaijYTN4Ts55wopvWZsmZaiWrwZdk0HWAveSy4jNwioouJcvrMXFgpoaLVi1ZWyBaxcQ1YnJCHdTNEmZNiyfaUkSxbDMZLFspHlLTJaBAgFFnT43CZzNIG1pFXbOLI2ehiSLRcKJilZs5JCn1YA4MtYzN5Spbqye02jjMZ5RKF7W85bpGa2kzR0un9ZzTmdePHZo1VKB2nNKTO2MEeY+M9ONDr+mdbr+nwbPCtP9pyRn9x+ZcJNxf4LUVdfJ6es1vWrpgqw3A+0h3ZOqQF23EqNmc6MfWbdxnbjujgyVZRcLjymysw6KtmM8TVEMRY2BxLSJFbz6yqQWOVmxJpGY1Hb1ktIabGfV7yeiiQhMLFVjUozIci1Eaulk+oV6YL6X2gsgnjEPpsTRTM3AitCjwk7Qors1dK+FnLNHbjlRN9hxFGI5yKbNkzdI57JrTMTZUUXaVCzCTbOiKSL1LgTCSOmEqLAtxM3E2Uyh1/TjqXRtXpf6nrOw+jDkfuJWNVIbyGV8H9VbVdApFh+un+Gc+nl+0v0+yc89WaN2r47zWOM45ZTJ1WoyTzOrHA5ZztlFrzN1Ax2YBt9ZWorE22S4oLE+KPWXqBpIoxOYvVDkUSWwocAJDKodWokNlpIs1qMTJtmqihwUSbKpAsB6RoTFOi+kpMlxQgoN3aXZnqrGpwOJLNIi7ScRxJkV8zQxHVGRI0iWNxk0aodUx9ZlJGsWO3GRRdsg2MOxhQbM8d8Nk09U6xp6+K1uJA9PqP8AmdDX3v8A72Lzu8MWbVjH1miRwMpXHkzaJjIqvNUZijLARcSBKiNFTcfWaUXR/9k=";
Assert.assertEquals(ldapThumbnailImageData, attrMap.get(ZAttrProvisioning.A_thumbnailPhoto));
}
use of com.zimbra.soap.mail.message.ModifyProfileImageRequest in project zm-mailbox by Zimbra.
the class ModifyProfileImageTest method testZCS3871.
@Test
public void testZCS3871() throws Exception {
Account acct = Provisioning.getInstance().getAccountByName("testZCS3871@zimbra.com");
InputStream is = getClass().getResourceAsStream("img.jpg");
FileUploadServlet.Upload up = FileUploadServlet.saveUpload(is, "img.jpg", "image/jpeg", acct.getId());
PowerMockito.stub(PowerMockito.method(MimeDetect.class, "detect", InputStream.class)).toReturn("image/jpeg");
byte[] bytes = IOUtils.toByteArray(up.getInputStream());
PowerMockito.stub(PowerMockito.method(NativeFormatter.class, "getResizedImageData", InputStream.class, String.class, String.class, Integer.class, Integer.class)).toReturn(bytes);
// Upload an profile image first
ModifyProfileImageRequest requestJaxb = new ModifyProfileImageRequest();
requestJaxb.setUploadId(up.getId());
Element request = JaxbUtil.jaxbToElement(requestJaxb);
Element response = new ModifyProfileImage().handle(request, ServiceTestUtil.getRequestContext(acct));
ModifyProfileImageResponse responseJaxb = JaxbUtil.elementToJaxb(response);
int profileItemId = responseJaxb.getItemId();
GetInfoRequest getRequestJaxb = new GetInfoRequest();
getRequestJaxb.setSections("mbox");
Element getRequest = JaxbUtil.jaxbToElement(getRequestJaxb);
Element getResponse = new GetInfo().handle(getRequest, ServiceTestUtil.getRequestContext(acct));
GetInfoResponse getResponseJaxb = JaxbUtil.elementToJaxb(getResponse);
Assert.assertEquals(profileItemId, getResponseJaxb.getProfileImageId());
Map<String, Object> attrMap = acct.getAttrs(false, false);
String ldapThumbnailImageData = "/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBwgHBgkIBwgKCgkLDRYPDQwMDRsUFRAWIB0iIiAdHx8kKDQsJCYxJx8fLT0tMTU3Ojo6Iys/RD84QzQ5OjcBCgoKDQwNGg8PGjclHyU3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3N//AABEIAHQAuQMBEQACEQEDEQH/xAAbAAACAwEBAQAAAAAAAAAAAAACAwEEBQAGB//EADIQAAICAQMCBAUCBgMBAAAAAAECAAMRBBIhBTETQVFhBhQicYGRoSMyQmLR4TNSwRb/xAAaAQADAQEBAQAAAAA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yfaUkSxbDMZLFspHlLTJaBAgFFnT43CZzNIG1pFXbOLI2ehiSLRcKJilZs5JCn1YA4MtYzN5Spbqye02jjMZ5RKF7W85bpGa2kzR0un9ZzTmdePHZo1VKB2nNKTO2MEeY+M9ONDr+mdbr+nwbPCtP9pyRn9x+ZcJNxf4LUVdfJ6es1vWrpgqw3A+0h3ZOqQF23EqNmc6MfWbdxnbjujgyVZRcLjymysw6KtmM8TVEMRY2BxLSJFbz6yqQWOVmxJpGY1Hb1ktIabGfV7yeiiQhMLFVjUozIci1Eaulk+oV6YL6X2gsgnjEPpsTRTM3AitCjwk7Qors1dK+FnLNHbjlRN9hxFGI5yKbNkzdI57JrTMTZUUXaVCzCTbOiKSL1LgTCSOmEqLAtxM3E2Uyh1/TjqXRtXpf6nrOw+jDkfuJWNVIbyGV8H9VbVdApFh+un+Gc+nl+0v0+yc89WaN2r47zWOM45ZTJ1WoyTzOrHA5ZztlFrzN1Ax2YBt9ZWorE22S4oLE+KPWXqBpIoxOYvVDkUSWwocAJDKodWokNlpIs1qMTJtmqihwUSbKpAsB6RoTFOi+kpMlxQgoN3aXZnqrGpwOJLNIi7ScRxJkV8zQxHVGRI0iWNxk0aodUx9ZlJGsWO3GRRdsg2MOxhQbM8d8Nk09U6xp6+K1uJA9PqP8AmdDX3v8A72Lzu8MWbVjH1miRwMpXHkzaJjIqvNUZijLARcSBKiNFTcfWaUXR/9k=";
Assert.assertEquals(ldapThumbnailImageData, attrMap.get(ZAttrProvisioning.A_thumbnailPhoto));
// remove the uploaded image now
ModifyProfileImageRequest requestJaxb1 = new ModifyProfileImageRequest();
Element request1 = JaxbUtil.jaxbToElement(requestJaxb1);
new ModifyProfileImage().handle(request1, ServiceTestUtil.getRequestContext(acct));
GetInfoRequest getRequestJaxb1 = new GetInfoRequest();
getRequestJaxb1.setSections("mbox");
Element getRequest1 = JaxbUtil.jaxbToElement(getRequestJaxb1);
Element getResponse1 = new GetInfo().handle(getRequest1, ServiceTestUtil.getRequestContext(acct));
// check that the profile image information is not present in GetInfo as well as LDAP
Assert.assertEquals(false, getResponse1.prettyPrint().contains("profileImageId"));
Map<String, Object> attrMap1 = acct.getAttrs(false, false);
Assert.assertEquals(null, attrMap1.get(ZAttrProvisioning.A_thumbnailPhoto));
}
use of com.zimbra.soap.mail.message.ModifyProfileImageRequest in project zm-mailbox by Zimbra.
the class ModifyProfileImage method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Mailbox mbox = getRequestedMailbox(zsc);
OperationContext octxt = getOperationContext(zsc, context);
ModifyProfileImageRequest req = zsc.elementToJaxb(request);
String uploadId = req.getUploadId();
String base64 = req.getImageB64Data().trim();
InputStream thumbnailIn = null;
InputStream in = null;
String contentType = null;
String imageFileName = IMAGE_ITEM_PREFIX + mbox.getAccountId();
String imageFolderName = IMAGE_FOLDER_PREFIX + mbox.getAccountId();
long inputSize = 0l;
int imageItemID = -1;
boolean updateLDAPSuccess = false;
boolean updateDBSuccess = false;
boolean removeFromLDAPSuccess = false;
boolean removeFromDBSuccess = false;
String ldapBackup = null;
boolean removeProfileImage = false;
try {
if (!StringUtil.isNullOrEmpty(base64)) {
byte[] decodedBytes = Base64.decodeBase64(base64);
inputSize = decodedBytes.length;
thumbnailIn = new ByteArrayInputStream(decodedBytes);
in = new ByteArrayInputStream(decodedBytes);
contentType = MimeDetect.getMimeDetect().detect(new ByteArrayInputStream(decodedBytes));
} else if (uploadId != null) {
Upload up = FileUploadServlet.fetchUpload(zsc.getAuthtokenAccountId(), uploadId, zsc.getAuthToken());
in = up.getInputStream();
thumbnailIn = up.getInputStream();
inputSize = up.getSize();
contentType = up.getContentType();
} else {
// remove image
removeProfileImage = true;
ldapBackup = Provisioning.getInstance().A_thumbnailPhoto;
removeFromLDAP(mbox, zsc);
removeFromLDAPSuccess = true;
removeFromDatabase(mbox, octxt, imageFolderName);
removeFromDBSuccess = true;
}
if (!removeProfileImage) {
if (contentType == null || !contentType.matches(MimeConstants.CT_IMAGE_WILD)) {
throw MailServiceException.INVALID_IMAGE("Uploaded image is not a valid image file");
}
if (inputSize > DebugConfig.profileImageMaxSize) {
throw MailServiceException.INVALID_IMAGE("Uploaded image is larger than 2 MB");
}
// Update LDAP with thumbnail image
boolean imageResized = updateLDAP(inputSize, thumbnailIn, contentType, imageFileName, mbox, zsc, true);
if (!imageResized) {
ZimbraLog.mailbox.info("Image not resized. Updating original image to LDAP.");
byte[] byteArray = IOUtils.toByteArray(in);
InputStream originalIn = new ByteArrayInputStream(byteArray);
// update LDAP with actual image
updateLDAP(inputSize, originalIn, contentType, imageFileName, mbox, zsc, false);
}
updateLDAPSuccess = true;
// Update Database with actual image
imageItemID = updateDatabase(mbox, octxt, imageFolderName, contentType, in, imageFileName, zsc);
updateDBSuccess = true;
}
} catch (IOException e) {
throw ServiceException.FAILURE(FAILURE_MESSAGE, e);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
ZimbraLog.mailbox.error("Exception in closing input stream for upload", e);
}
}
if (updateLDAPSuccess && !updateDBSuccess) {
// Databse update failed; revert from LDAP
HashMap<String, Object> prefs = new HashMap<String, Object>();
prefs.put(Provisioning.A_thumbnailPhoto, null);
Provisioning.getInstance().modifyAttrs(mbox.getAccount(), prefs, true, zsc.getAuthToken());
} else if (removeFromLDAPSuccess && !removeFromDBSuccess) {
// Databse removal failed; revert to LDAP
HashMap<String, Object> prefs = new HashMap<String, Object>();
prefs.put(Provisioning.A_thumbnailPhoto, ldapBackup);
Provisioning.getInstance().modifyAttrs(mbox.getAccount(), prefs, true, zsc.getAuthToken());
}
}
Element response = zsc.createElement(MailConstants.MODIFY_PROFILE_IMAGE_RESPONSE);
if (imageItemID != -1) {
response.addAttribute(MailConstants.A_ITEMID, imageItemID);
}
return response;
}
Aggregations