added overload method getUserToken for standard servlets

git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portal/portal-manager@135036 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2016-11-29 14:10:57 +00:00
parent 569838c6eb
commit b7ac890f89
1 changed files with 34 additions and 1 deletions

View File

@ -251,7 +251,7 @@ public class PortalContext {
/**
*
* @deprecated use only with AJAX Calls
* @param httpServletRequest the httpServletRequest object
* @return the instance of the user
* @see GCubeUser
@ -289,6 +289,39 @@ public class PortalContext {
}
return userToken;
}
/**
* @param httpServletRequest the httpServletRequest object
* @param scope the infrastructure scope
* @return the instance of the user
* @see GCubeUser
*/
public String getCurrentUserToken(String scope, HttpServletRequest httpServletRequest) {
String userToken = null;
if (isWithinPortal()) {
String username = getCurrentUser(httpServletRequest).getUsername();
try {
ScopeProvider.instance.set(scope);
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;
}
/**
*