ServiceCallInterceptor security = new ServiceCallInterceptor() {
@Override public void onInvoke(String mtd, Object[] args, ServiceContextctx, ctxsvcCall) {
// Check permission before execution of the method.
-> {
if (!CustomSecurityProvider.get().access(mtd, ctx.currentCallContext().attribute("sessionId")))
throw new SecurityException("Method invocation is not permitted");
// Execute remaining interceptors and service }method.
}
return svcCall.call();
};
ServiceCallInterceptor audit = new ServiceCallInterceptor() {
mtd, args, ctx, svcCall) -> {
@OverrideString publicsessionId void onInvoke(String mtd, Object[] args, ServiceContext ctx) {
= ctx.currentCallContext().attribute("sessionId");
AuditProvider prov = AuditProvider.get();
// Record an event before execution of the method.
prov.recordStartEvent(mtd, sessionId);
AuditProvider.get().recordStartEvent(mtd, ctx.currentCallContext().attribute("sessionId"));
try {
}
// Execute service method.
svcCall.call();
@Override public}
void onComplete(String mtd, Object[] args, @Nullable Object res,catch ServiceContext(Exception ctxe) {
// Record error.
AuditProviderprov.getrecordError().recordFinishEvent(mtd, ctx.currentCallContext().attribute("sessionId"sessionId), e.getMessage());
// Re-throw exception to }
initiator.
throw e;
@Override public void}
onError(String mtd, Object[] args, Throwable err, ServiceContext ctx)finally {
// Record finish event after execution AuditProvider.get().recordError(mtd, ctx.currentCallContext().attribute("sessionId"), err.getMessage());of the service method.
} prov.recordFinishEvent(mtd, sessionId);
}
}
ServiceConfiguration svcCfg = new ServiceConfiguration()
.setName("service")
.setService(new MyServiceImpl())
.setMaxPerNodeCount(1)
.setInterceptors(security, audit);
// Deploy service.
ignite.services().deploy(svcCfg);
// Set context parameters for the service proxy.
ServiceCallContext callCtx = ServiceCallContext.builder().put("sessionId", sessionId).build();
// Make service proxy.
MyServiceMyService proxy = ignite.services().serviceProxy("service", MyService.class, false, callCtx, 0);
// AMake businessservice method call to be intercepted.
proxy.placeOrder(order1);
proxy.placeOrder(order2); |