This commit is contained in:
Lucio Lelii 2016-11-30 16:27:21 +00:00
parent 702a724422
commit 471a08ca64
3 changed files with 33 additions and 7 deletions

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -65,14 +65,18 @@ public class RequestManager implements Filter {
List<RequestHandler> filterHandlers = getPipelineWithExcluded(httprequest, handlers);
if (filterHandlers.isEmpty())
if (filterHandlers.isEmpty()){
log.trace("filtered handlers are empty");
chain.doFilter(request, response);
else {
}else {
ApplicationPipeline<RequestHandler> pipeline = new ApplicationPipeline<RequestHandler>(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<RequestHandler> filteredHandlers = new ArrayList<>();
for (RequestHandler rh : filteredHandlers)
for (RequestHandler rh : handlersToFilter){
if (!exclude.getHandlers().contains(rh.getName()))
filteredHandlers.add(rh);
}
return filteredHandlers;
}
}