class SecuredMethodInvocationHelper {

    static ExecutionContext getContextAsFirstArgumentOfSecureObject(Object secureObject) {
        Object[] args;

        if (secureObject instanceof MethodInvocation) {
            MethodInvocation invocation = (MethodInvocation) secureObject;
            args = invocation.getArguments();
        } else {
            throw new AuthorizationServiceException("Secure object: " + secureObject + " is not a MethodInvocation");
        }

        // ex context is always the first argument
        ExecutionContext context = null;
        if (isNotEmpty(args) && args[0] instanceof ExecutionContext) {
            context = (ExecutionContext) args[0];
        }
        return context;
    }

}