Now avatar file format can be forced to be a specific format (default PNG) if needed (default ON)
This commit is contained in:
parent
335197a072
commit
3fdebddb7e
|
@ -1,10 +1,14 @@
|
|||
package org.gcube.portal.oidc.lr62;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
|
@ -29,6 +33,9 @@ public class OpenIdConnectAutoLogin extends BaseAutoLogin {
|
|||
|
||||
private static final Log log = LogFactoryUtil.getLog(OpenIdConnectAutoLogin.class);
|
||||
|
||||
private static boolean ASSURE_AVATAR_FORMAT = true;
|
||||
private static String DEFAULT_AVATAR_FORMAT = "png";
|
||||
|
||||
@Override
|
||||
public String[] doLogin(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
if (log.isTraceEnabled() && request.getSession(false) != null) {
|
||||
|
@ -119,7 +126,23 @@ public class OpenIdConnectAutoLogin extends BaseAutoLogin {
|
|||
|
||||
try {
|
||||
byte[] userAvatar = OpenIdConnectRESTHelper.getUserAvatar(configuration.getAvatarURL(), token);
|
||||
if (userAvatar != null) {
|
||||
if (userAvatar != null && userAvatar.length > 0) {
|
||||
if (ASSURE_AVATAR_FORMAT) {
|
||||
log.debug("Assuring avatar image format as: " + DEFAULT_AVATAR_FORMAT);
|
||||
log.debug("Reading image stream with length: " + userAvatar.length);
|
||||
BufferedImage bi = ImageIO.read(new ByteArrayInputStream(userAvatar));
|
||||
if (bi != null) {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
log.debug("Converting avatar stream image format to: " + DEFAULT_AVATAR_FORMAT);
|
||||
ImageIO.write(bi, DEFAULT_AVATAR_FORMAT, baos);
|
||||
baos.flush();
|
||||
baos.close();
|
||||
log.debug("Reading converted image from the BAOS");
|
||||
userAvatar = baos.toByteArray();
|
||||
} else {
|
||||
log.warn("Buffered image read is null!");
|
||||
}
|
||||
}
|
||||
log.debug("Saving the retrieved avatar as user's portrait");
|
||||
UserLocalServiceUtil.updatePortrait(user.getUserId(), userAvatar);
|
||||
} else {
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
public class ImageTest {
|
||||
|
||||
public static void main(String[] args) throws FileNotFoundException, IOException {
|
||||
BufferedImage jpg = ImageIO.read(new FileInputStream(args[0]));
|
||||
ImageIO.write(jpg, "png", new FileOutputStream(args[1]));
|
||||
}
|
||||
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 27 KiB |
Loading…
Reference in New Issue