getUserAvatarAbsoluteURL returns an absolute path (ws service). Returns null if the user doesn't have an image

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/vo-management/usermanagement-core@142258 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2017-02-06 14:11:46 +00:00
parent 4bd0d26d43
commit 6a64ee209c
1 changed files with 18 additions and 7 deletions

View File

@ -51,6 +51,11 @@ import com.liferay.portal.kernel.exception.SystemException;
*/ */
public class LiferayWSUserManager implements UserManager{ public class LiferayWSUserManager implements UserManager{
// save host/port and schema
private String schema;
private String host;
private int port;
// These properties are needed to save authentication credentials once. // These properties are needed to save authentication credentials once.
private HttpClientContext localContext; private HttpClientContext localContext;
private CredentialsProvider credsProvider; private CredentialsProvider credsProvider;
@ -89,6 +94,10 @@ public class LiferayWSUserManager implements UserManager{
*/ */
public LiferayWSUserManager(String user, String password, String host, String schema, int port) throws Exception{ public LiferayWSUserManager(String user, String password, String host, String schema, int port) throws Exception{
this.host = host;
this.port = port;
this.schema = schema;
target = new HttpHost(host, port, schema); target = new HttpHost(host, port, schema);
credsProvider = new BasicCredentialsProvider(); credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials( credsProvider.setCredentials(
@ -208,7 +217,7 @@ public class LiferayWSUserManager implements UserManager{
} }
/** /**
* Evaluate the user's avatar url path (relative) * Evaluate the user's avatar url path (absolute!)
* @param userUuid * @param userUuid
* @param portraitId * @param portraitId
* @return * @return
@ -219,11 +228,13 @@ public class LiferayWSUserManager implements UserManager{
// url looks like LIFERAY_PORTAL/image/user_male_portrait?img_id=21125690&img_id_token=aPduzUQfxcz9kiLzD0yrChPU8k4%3D // url looks like LIFERAY_PORTAL/image/user_male_portrait?img_id=21125690&img_id_token=aPduzUQfxcz9kiLzD0yrChPU8k4%3D
// where img_id_token is the sha-1/base64 encoding, encoded as query parameter, of userUuid // where img_id_token is the sha-1/base64 encoding, encoded as query parameter, of userUuid
if(portraitId == 0)
return null;
MessageDigest md = MessageDigest.getInstance("SHA-1"); MessageDigest md = MessageDigest.getInstance("SHA-1");
String imageId = URLEncoder.encode(Base64.encodeBase64String(md.digest(userUuid.getBytes())), "UTF-8"); String imageId = URLEncoder.encode(Base64.encodeBase64String(md.digest(userUuid.getBytes())), "UTF-8");
return "/image/user_male_portrait?img_id=" + portraitId + "&img_id_token=" + imageId; return schema + "://" + host + ":" + port + "/image/user_male_portrait?img_id=" + portraitId + "&img_id_token=" + imageId;
} }