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{
// save host/port and schema
private String schema;
private String host;
private int port;
// These properties are needed to save authentication credentials once.
private HttpClientContext localContext;
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{
this.host = host;
this.port = port;
this.schema = schema;
target = new HttpHost(host, port, schema);
credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
@ -206,9 +215,9 @@ public class LiferayWSUserManager implements UserManager{
}
return null;
}
/**
* Evaluate the user's avatar url path (relative)
* Evaluate the user's avatar url path (absolute!)
* @param userUuid
* @param portraitId
* @return
@ -216,15 +225,17 @@ public class LiferayWSUserManager implements UserManager{
* @throws NoSuchAlgorithmException
*/
private String getUserAvatarAbsoluteURL(String userUuid, long portraitId) throws UnsupportedEncodingException, NoSuchAlgorithmException{
// 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
if(portraitId == 0)
return null;
MessageDigest md = MessageDigest.getInstance("SHA-1");
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;
}
/**