minor fixes: added some logs in ContextUserUtil for reading the content of some cookies, added a method to retrieve a user token by scope and userid
git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portal/portal-manager@141363 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
b7ac890f89
commit
40b43f6c8f
|
@ -19,7 +19,7 @@ import com.liferay.util.Encryptor;
|
|||
*
|
||||
*/
|
||||
public class ContextUserUtil {
|
||||
private static final Logger _log = LoggerFactory.getLogger(PortalContext.class);
|
||||
private static final Logger _log = LoggerFactory.getLogger(ContextUserUtil.class);
|
||||
/**
|
||||
*
|
||||
* @param httpServletRequest
|
||||
|
@ -34,13 +34,17 @@ public class ContextUserUtil {
|
|||
if ("COMPANY_ID".equals(c.getName())) {
|
||||
companyId = c.getValue();
|
||||
} else if ("ID".equals(c.getName())) {
|
||||
_log.info("User id before ascii conversion is " + c.getValue());
|
||||
userId = hexStringToStringByAscii(c.getValue());
|
||||
}
|
||||
}
|
||||
if (userId != null && companyId != null) {
|
||||
try {
|
||||
Company company = CompanyLocalServiceUtil.getCompany(Long.parseLong(companyId));
|
||||
_log.info("company is " + company);
|
||||
Key key = company.getKeyObj();
|
||||
_log.info("key is " + company.getKey());
|
||||
_log.info("User id after ascii conversion is " + userId);
|
||||
String userIdPlain = Encryptor.decrypt(key, userId);
|
||||
return Long.valueOf(userIdPlain);
|
||||
|
||||
|
|
|
@ -322,7 +322,40 @@ public class PortalContext {
|
|||
}
|
||||
return userToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Another way to retrieve the user token
|
||||
* @param scope the current scope
|
||||
* @param userId the Liferay's user id
|
||||
* @return the Token for the user in scope
|
||||
*/
|
||||
public String getCurrentUserToken(String scope, long userId) {
|
||||
String userToken = null;
|
||||
if (isWithinPortal()) {
|
||||
String username = null;
|
||||
try {
|
||||
ScopeProvider.instance.set(scope);
|
||||
username = new LiferayUserManager().getUserById(userId).getUsername();
|
||||
userToken = authorizationService().resolveTokenByUserAndContext(username, scope);
|
||||
SecurityTokenProvider.instance.set(userToken);
|
||||
}
|
||||
catch (ObjectNotFound ex) {
|
||||
userToken = generateAuthorizationToken(username, scope);
|
||||
SecurityTokenProvider.instance.set(userToken);
|
||||
_log.debug("generateAuthorizationToken OK for " + username + " in scope " + scope);
|
||||
}
|
||||
catch (Exception e) {
|
||||
_log.error("Error while trying to generate token for user " + username + "in scope " + scope);
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
String toReturn = readTokenPropertyFile();
|
||||
_log.debug("getCurrentToken devMode into IDE detected, returning scope: " + toReturn.toString());
|
||||
_log.debug("The PortalBeanLocatorUtil stacktrace (java.lang.Exception) is acceptable in dev");
|
||||
return toReturn;
|
||||
}
|
||||
return userToken;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param username
|
||||
|
|
Loading…
Reference in New Issue