Problem with logger and Security Interceptor

I am looking at the example in the download sample applications, I have setup the logger and it all works.

Except when I add the line

log.debug(“userValidator entered.”);

I was under the impression as Luis had mentioned it in another post, that the variable log could be used to access the logger in every handler, interceptor and plugin.

This appears to not be the case, as I am getting a variable log is undefined, and yet the interceptor service that calls the userValidator is very much able to use the variable log.

Anyone have any ideas?

Regards,

Andrew Scott

http://www.andyscott.id.au/

I think it's logbox and I think you have to use it like this:

logbox.getLogger( this ).debug( "stuff" );

(but I'm not certain)

That doesn't work either, variable logbox is undefined.

Luis did say in another post, that it should be log, and it is available to
all handlers, interceptors and plugins.

This has me stumped.

Regards,
Andrew Scott
http://www.andyscott.id.au/

Both should exist. Here's the code in the init() of Interceptor:

      variables.logBox = arguments.controller.getLogBox();
      variables.log = variables.logBox.getLogger(this);

Do you have your own init() method? Does it call super.init()? If not,
you won't have those variables.

Yes I know, that is why I don't understand why it is not working.

Regards,
Andrew Scott
http://www.andyscott.id.au/

I sort of see the problem now, and it's because the sample code that comes
with ColdBox "securitySample" doesn't extend the interceptor.

I might be wrong here, but I am thinking if I make it extend the interceptor
it might work.

Now if only ColdFusion Builder would fire break points in these files I
would be able to debug this easier.

Regards,
Andrew Scott
http://www.andyscott.id.au/

I sort of see the problem now, and it's because the sample code that comes
with ColdBox "securitySample" doesn't extend the interceptor.

Yeah, that would do it...

Now if only ColdFusion Builder would fire break points in these files I
would be able to debug this easier.

:slight_smile:

Sean, do you have an example of an interceptor like this?

I can't find any good examples, and they all don't extend anything at all.
Which means that in this example, this is actually a service that is being
masqueraded as an interceptor.

See the thing is if I follow the security sample , and by the fact that it
is a service I tried extending the BaseService. Which has the method
getLogger() but this throws an error as well as it can't find the plugin.

If you ask me, this appears to be legacy style code. And trying to get this
to work in ColdBox 3.0 is driving me a little insane.

Regards,
Andrew Scott
http://www.andyscott.id.au/

Here's one that reports exceptions:

component extends="coldbox.system.Interceptor" {

  // CONSTRUCTOR (called by ColdBox)
  
  public void function configure() {
    variables.exceptionService = getPlugin( 'IOC' ).getBean( 'ExceptionService' );
  }
  
  // PUBLIC API

  // handle exceptions - log them, email them and continue:
  public boolean function onException( any event, struct interceptData ) {

    // report the exception:
    variables.exceptionService.reportException( event, interceptData.exception );

    // continue execution:
    return false;
  }

}

Ok that doesn't look any different to what I am trying to do, the problem I
have is the ColdBox.cfc config file.

This throws an exception saying that properties parameter needs to passed to
the init()

class="coldbox.system.interceptors.security",
        properties={rulesSource='xml',
  
rulesFile='config/securityrules.xml.cfm',
  
validator='system.Services.securityService'
        }

This is where I am getting a little lost at the moment.

Regards,
Andrew Scott
http://www.andyscott.id.au/

Hmm, dunno. I'm still using the XML config.

Andrew and Sean,

Here is the syntax for the Config.cfc to register the security interceptor. See if this helps. It works fine for me. I use it in quite a few applications.

//Register interceptors as an array, we need order

interceptors = [

//Security

{class="core.interceptors.security",

properties={

rulesSource="xml",

rulesFile="config/securityrules.xml.cfm",

debug="true",

validatorModel="user.securityManager"

}

}

];

Also, I use the built in Security Interceptor in my "securityManage" by injecting it. Here is my init() method. I inject it using the interceptor Service since it will init it with all its dependencies. See if that helps

<cffunction name="init" access="public" returnType="securityManager" output="false" hint="Returns an instance of the CFC">

<cfargument name="UserService" type="any" required="false" inject="model:User.UserService" />

<cfargument name="interceptorService" type="any" required="false" inject="coldbox:interceptorService" />

<cfargument name="controller" type="any" required="false" inject="coldbox" />

<cfargument name="messagebox" type="any" required="false" inject="coldbox:plugin:messagebox" />

<cfset variables.UserService = arguments.UserService />

<cfset variables.controller = arguments.controller />

<cfset variables.messagebox = arguments.messagebox />

<cfset variables.SecurityInterceptor = arguments.interceptorService.getInterceptor("security")>

?

<cfreturn this>

</cffunction>

Thanks,
Curt Gratz
Computer Know How