This commit is contained in:
Massimiliano Assante 2016-11-15 16:42:45 +00:00
parent dad4c8beb0
commit 7dca141d2f
1 changed files with 15 additions and 14 deletions

View File

@ -30,7 +30,7 @@ import com.liferay.portal.service.UserLocalServiceUtil;
public class SmartGearsPortalValve extends ValveBase {
private static final Logger _log = LoggerFactory.getLogger(SmartGearsPortalValve.class);
private final static String DEFAULT_ROLE = "OrganizationMember";
private final static String LIFERAY_POLLER_CONTEXT = "poller/receive";
@Override
@ -41,19 +41,20 @@ public class SmartGearsPortalValve extends ValveBase {
//_log.trace("SmartGearsPortalValve SecurityTokenProvider and AuthorizationProvider reset OK");
if (req instanceof HttpServletRequest) {
HttpServletRequest request = (HttpServletRequest) req;
PortalContext context = PortalContext.getConfiguration();
String scope = context.getCurrentScope(request);
String username = getCurrentUsername(request);
if (scope != null && username != null) {
try {
String userToken = getAuthorizationToken(username, scope);
SecurityTokenProvider.instance.set(userToken);
} catch (Exception e) {
_log.error("Something went wrong in generating token for " + username + " in scope " + scope);
e.printStackTrace();
if (!req.getRequestURL().toString().endsWith(LIFERAY_POLLER_CONTEXT)) { //avoid calling gCube auth service for liferay internal poller
PortalContext context = PortalContext.getConfiguration();
String scope = context.getCurrentScope(request);
String username = getCurrentUsername(request);
if (scope != null && username != null) {
try {
String userToken = getAuthorizationToken(username, scope);
SecurityTokenProvider.instance.set(userToken);
} catch (Exception e) {
_log.error("Something went wrong in generating token for " + username + " in scope " + scope);
e.printStackTrace();
}
//_log.trace("Security token set OK for " + username + " in scope " + scope);
}
//_log.trace("Security token set OK for " + username + " in scope " + scope);
}
}
getNext().invoke(req, resp);
@ -72,7 +73,7 @@ public class SmartGearsPortalValve extends ValveBase {
String token = authorizationService().generateUserToken(new UserInfo(username, userRoles), scope);
return token;
}
/**
*
* @param httpServletRequest the httpServletRequest object