diff --git a/src/main/java/org/gcube/smartgears/handlers/application/request/RequestAccounting.java b/src/main/java/org/gcube/smartgears/handlers/application/request/RequestAccounting.java index c8138ff..3cb8dcd 100644 --- a/src/main/java/org/gcube/smartgears/handlers/application/request/RequestAccounting.java +++ b/src/main/java/org/gcube/smartgears/handlers/application/request/RequestAccounting.java @@ -10,6 +10,7 @@ import org.gcube.accounting.persistence.AccountingPersistence; import org.gcube.accounting.persistence.AccountingPersistenceFactory; import org.gcube.common.authorization.library.provider.AuthorizationProvider; import org.gcube.common.authorization.library.provider.CalledMethodProvider; +import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.smartgears.Constants; import org.gcube.smartgears.context.application.ApplicationContext; @@ -35,6 +36,7 @@ public class RequestAccounting extends RequestHandler { @Override public void handleRequest(RequestEvent e) { ApplicationContext context = e.context(); + String calledMethod = e.request().getHeader(called_method_header); if (calledMethod==null){ calledMethod = e.request().getRequestURI().substring(e.request().getContextPath().length()); @@ -47,11 +49,20 @@ public class RequestAccounting extends RequestHandler { log.info("REQUEST START ON {}:{}({}) CALLED FROM {}@{} IN SCOPE {} ", context.configuration().name(),context.configuration().serviceClass(), CalledMethodProvider.instance.get(), caller, e.request().getRemoteHost(), ScopeProvider.instance.get()); + } @Override public void handleResponse(ResponseEvent e) { ApplicationContext context = e.context(); + + boolean resetScope = false; + if (ScopeProvider.instance.get()==null && SecurityTokenProvider.instance.get()==null){ + String infrastructure = e.context().container().configuration().infrastructure(); + ScopeProvider.instance.set("/"+infrastructure); + resetScope = true; + } + String caller = AuthorizationProvider.instance.get()!=null? AuthorizationProvider.instance.get().getClient().getId(): "UNKNOWN"; String callerQualifier = AuthorizationProvider.instance.get()!=null? AuthorizationProvider.instance.get().getTokenQualifier(): "UNKNOWN"; //retieves caller Ip when there is a proxy @@ -66,6 +77,8 @@ public class RequestAccounting extends RequestHandler { caller, callerIp, ScopeProvider.instance.get(), System.currentTimeMillis()-startCallThreadLocal.get()); startCallThreadLocal.remove(); CalledMethodProvider.instance.reset(); + if (resetScope) + ScopeProvider.instance.reset(); } void generateAccounting(String caller, String callerQualifier, String remoteHost, ApplicationContext context){ @@ -92,4 +105,11 @@ public class RequestAccounting extends RequestHandler { } } + @Override + public String toString() { + return getName(); + } + + + } diff --git a/src/main/java/org/gcube/smartgears/handlers/application/request/RequestValidator.java b/src/main/java/org/gcube/smartgears/handlers/application/request/RequestValidator.java index 41e2938..4876cbb 100644 --- a/src/main/java/org/gcube/smartgears/handlers/application/request/RequestValidator.java +++ b/src/main/java/org/gcube/smartgears/handlers/application/request/RequestValidator.java @@ -1,7 +1,6 @@ package org.gcube.smartgears.handlers.application.request; import static org.gcube.common.authorization.client.Constants.authorizationService; -import static org.gcube.smartgears.Constants.request_validation; import static org.gcube.smartgears.Constants.scope_header; import static org.gcube.smartgears.Constants.token_header; import static org.gcube.smartgears.handlers.application.request.RequestError.application_failed_error; @@ -156,7 +155,7 @@ public class RequestValidator extends RequestHandler { @Override public String toString() { - return request_validation; + return getName(); } private ClientInfo retreiveAndSetInfo(String token, RequestEvent call){ @@ -186,5 +185,7 @@ public class RequestValidator extends RequestHandler { SecurityTokenProvider.instance.set(token); return authEntry.getClientInfo(); } + + } diff --git a/src/main/java/org/gcube/smartgears/managers/RequestManager.java b/src/main/java/org/gcube/smartgears/managers/RequestManager.java index b8fc520..c1da931 100644 --- a/src/main/java/org/gcube/smartgears/managers/RequestManager.java +++ b/src/main/java/org/gcube/smartgears/managers/RequestManager.java @@ -65,14 +65,18 @@ public class RequestManager implements Filter { List filterHandlers = getPipelineWithExcluded(httprequest, handlers); - if (filterHandlers.isEmpty()) - + if (filterHandlers.isEmpty()){ + + log.trace("filtered handlers are empty"); + chain.doFilter(request, response); - else { + }else { ApplicationPipeline pipeline = new ApplicationPipeline(filterHandlers); + log.trace("filtered handler for this call are {}", filterHandlers); + // create a per-request context with temporary properties ApplicationContext ctx = new DefaultApplicationContext(context); @@ -135,11 +139,12 @@ public class RequestManager implements Filter { ){ //ALL handler are filtered if (exclude.getHandlers().isEmpty()) return Collections.emptyList(); - + List filteredHandlers = new ArrayList<>(); - for (RequestHandler rh : filteredHandlers) + for (RequestHandler rh : handlersToFilter){ if (!exclude.getHandlers().contains(rh.getName())) filteredHandlers.add(rh); + } return filteredHandlers; } }