git-svn-id: https://svn.d4science-ii.research-infrastructures.eu/gcube/branches/common/common-smartgears/2.1@135141 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
702a724422
commit
471a08ca64
|
@ -10,6 +10,7 @@ import org.gcube.accounting.persistence.AccountingPersistence;
|
||||||
import org.gcube.accounting.persistence.AccountingPersistenceFactory;
|
import org.gcube.accounting.persistence.AccountingPersistenceFactory;
|
||||||
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
||||||
import org.gcube.common.authorization.library.provider.CalledMethodProvider;
|
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.common.scope.api.ScopeProvider;
|
||||||
import org.gcube.smartgears.Constants;
|
import org.gcube.smartgears.Constants;
|
||||||
import org.gcube.smartgears.context.application.ApplicationContext;
|
import org.gcube.smartgears.context.application.ApplicationContext;
|
||||||
|
@ -35,6 +36,7 @@ public class RequestAccounting extends RequestHandler {
|
||||||
@Override
|
@Override
|
||||||
public void handleRequest(RequestEvent e) {
|
public void handleRequest(RequestEvent e) {
|
||||||
ApplicationContext context = e.context();
|
ApplicationContext context = e.context();
|
||||||
|
|
||||||
String calledMethod = e.request().getHeader(called_method_header);
|
String calledMethod = e.request().getHeader(called_method_header);
|
||||||
if (calledMethod==null){
|
if (calledMethod==null){
|
||||||
calledMethod = e.request().getRequestURI().substring(e.request().getContextPath().length());
|
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 {} ",
|
log.info("REQUEST START ON {}:{}({}) CALLED FROM {}@{} IN SCOPE {} ",
|
||||||
context.configuration().name(),context.configuration().serviceClass(), CalledMethodProvider.instance.get(),
|
context.configuration().name(),context.configuration().serviceClass(), CalledMethodProvider.instance.get(),
|
||||||
caller, e.request().getRemoteHost(), ScopeProvider.instance.get());
|
caller, e.request().getRemoteHost(), ScopeProvider.instance.get());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleResponse(ResponseEvent e) {
|
public void handleResponse(ResponseEvent e) {
|
||||||
ApplicationContext context = e.context();
|
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 caller = AuthorizationProvider.instance.get()!=null? AuthorizationProvider.instance.get().getClient().getId(): "UNKNOWN";
|
||||||
String callerQualifier = AuthorizationProvider.instance.get()!=null? AuthorizationProvider.instance.get().getTokenQualifier(): "UNKNOWN";
|
String callerQualifier = AuthorizationProvider.instance.get()!=null? AuthorizationProvider.instance.get().getTokenQualifier(): "UNKNOWN";
|
||||||
//retieves caller Ip when there is a proxy
|
//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());
|
caller, callerIp, ScopeProvider.instance.get(), System.currentTimeMillis()-startCallThreadLocal.get());
|
||||||
startCallThreadLocal.remove();
|
startCallThreadLocal.remove();
|
||||||
CalledMethodProvider.instance.reset();
|
CalledMethodProvider.instance.reset();
|
||||||
|
if (resetScope)
|
||||||
|
ScopeProvider.instance.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void generateAccounting(String caller, String callerQualifier, String remoteHost, ApplicationContext context){
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package org.gcube.smartgears.handlers.application.request;
|
package org.gcube.smartgears.handlers.application.request;
|
||||||
|
|
||||||
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
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.scope_header;
|
||||||
import static org.gcube.smartgears.Constants.token_header;
|
import static org.gcube.smartgears.Constants.token_header;
|
||||||
import static org.gcube.smartgears.handlers.application.request.RequestError.application_failed_error;
|
import static org.gcube.smartgears.handlers.application.request.RequestError.application_failed_error;
|
||||||
|
@ -156,7 +155,7 @@ public class RequestValidator extends RequestHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return request_validation;
|
return getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ClientInfo retreiveAndSetInfo(String token, RequestEvent call){
|
private ClientInfo retreiveAndSetInfo(String token, RequestEvent call){
|
||||||
|
@ -187,4 +186,6 @@ public class RequestValidator extends RequestHandler {
|
||||||
return authEntry.getClientInfo();
|
return authEntry.getClientInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,14 +65,18 @@ public class RequestManager implements Filter {
|
||||||
|
|
||||||
List<RequestHandler> filterHandlers = getPipelineWithExcluded(httprequest, handlers);
|
List<RequestHandler> filterHandlers = getPipelineWithExcluded(httprequest, handlers);
|
||||||
|
|
||||||
if (filterHandlers.isEmpty())
|
if (filterHandlers.isEmpty()){
|
||||||
|
|
||||||
|
log.trace("filtered handlers are empty");
|
||||||
|
|
||||||
chain.doFilter(request, response);
|
chain.doFilter(request, response);
|
||||||
|
|
||||||
else {
|
}else {
|
||||||
|
|
||||||
ApplicationPipeline<RequestHandler> pipeline = new ApplicationPipeline<RequestHandler>(filterHandlers);
|
ApplicationPipeline<RequestHandler> pipeline = new ApplicationPipeline<RequestHandler>(filterHandlers);
|
||||||
|
|
||||||
|
log.trace("filtered handler for this call are {}", filterHandlers);
|
||||||
|
|
||||||
// create a per-request context with temporary properties
|
// create a per-request context with temporary properties
|
||||||
ApplicationContext ctx = new DefaultApplicationContext(context);
|
ApplicationContext ctx = new DefaultApplicationContext(context);
|
||||||
|
|
||||||
|
@ -137,9 +141,10 @@ public class RequestManager implements Filter {
|
||||||
if (exclude.getHandlers().isEmpty()) return Collections.emptyList();
|
if (exclude.getHandlers().isEmpty()) return Collections.emptyList();
|
||||||
|
|
||||||
List<RequestHandler> filteredHandlers = new ArrayList<>();
|
List<RequestHandler> filteredHandlers = new ArrayList<>();
|
||||||
for (RequestHandler rh : filteredHandlers)
|
for (RequestHandler rh : handlersToFilter){
|
||||||
if (!exclude.getHandlers().contains(rh.getName()))
|
if (!exclude.getHandlers().contains(rh.getName()))
|
||||||
filteredHandlers.add(rh);
|
filteredHandlers.add(rh);
|
||||||
|
}
|
||||||
return filteredHandlers;
|
return filteredHandlers;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue