Skip to main content
davidsimms
Inspiring
January 14, 2010
Answered

Determine cffunction access method?

  • January 14, 2010
  • 2 replies
  • 1179 views

I have a .cfc which can be called either locally or remotely. When I call it locally, there's no need to determine whether the function should be allowed to run since all local calls can be trusted. However, when called as a web service, I would like to require two paramaters (username and password) so I can determine whether the function can be permitted to execute, or if I should return an "Access denied" message. (The verifyClient attribute of the cffunction tag is not what I'm after. I need to verify the username and password against a collection of account credentials.)

What I really need (in pseudo-code) is something like:

IF (requested_as_a_web_service = "true")

{check username and password against account credentials}

ELSE {stop processing and return an "Access denied" message}

So, is there a way to determine the access method?

David

This topic has been closed for replies.
Correct answer Adam Cameron.

But returning the CFC path doesn't help me determine whether the calling page is local or remote. Now if the CFC could reliably conclude the path of the calling page, that'd help, but I don't see any way that's possible.

Yeah, but think about it... if the path is the CFC, then it's a remote call.  If it's anything else: it's not a remote call.

--

Adam

2 replies

Inspiring
January 14, 2010

My suggestion is to keep that function public so it can't be called as a web service.  Then write another one in the same cfc that can be called as a webservice.  Make sure it has all the same arguments, plus username and password.  This function will process the username and password and if they pass muster, call the public function.

Inspiring
January 14, 2010

When making remote calls, I'd probably have a different function which adds the extra level of access control, which then calls the "actual" function.

However... what does CGI.SCRIPT_NAME contain when a CFC method is called remotely?  I'd guess it'd be the CFC path..?

--
Adam

Message was edited by: A Cameron

davidsimms
Inspiring
January 14, 2010

Thanks Adam, you guess correctly. But returning the CFC path doesn't help me determine whether the calling page is local or remote. Now if the CFC could reliably conclude the path of the calling page, that'd help, but I don't see any way that's possible.

Adam Cameron.Correct answer
Inspiring
January 14, 2010

But returning the CFC path doesn't help me determine whether the calling page is local or remote. Now if the CFC could reliably conclude the path of the calling page, that'd help, but I don't see any way that's possible.

Yeah, but think about it... if the path is the CFC, then it's a remote call.  If it's anything else: it's not a remote call.

--

Adam