Sip Server doesn't use Authentication plugins

Discuss any topic about Brekeke SIP Server.

Moderator: Brekeke Support Team

Post Reply
lilipst
Posts: 8
Joined: Mon Sep 23, 2013 2:55 am
Location: Jakarta, Indonesia

Sip Server doesn't use Authentication plugins

Post by lilipst »

1. Brekeke Product Name and Version: 3.2.4.1/366 (eval license)

2. Java version: 1.7.0

3. OS type and the version: Windows 2003 Server

4. UA (phone), gateway or other hardware/software involved: x-lite

5. Your problem:
I'm trying to create my own authentication plugins for brekeke sip server with no luck. I've follow the sip-authentication-plugins.pdf documentation. And I also took the sample code from doc for testing.
I found similar discussion in forum (http://www.brekeke-sip.com/bbs/viewtopi ... ght=plugin) but the information is limited.

It's seems that sip server never use my authentication plugins.

I name my plugins with TbUserDir and the source code is mostly the same as sample code from sip-authentication-plugins.pdf.

I modified the loglevel become:

loglevel = new LogLevel( 255,env.getInt( "net.userdir.loglevel.file", LogLevel.LOG_LEVEL_ALL ) ) ;
(It might somewhat exaggerated but I just want to see the log lines writen by my plugins)

I put the TbUserDir.class into directory c:\plugins and set the parameter in configuration/advance:

net.usrdir.plugins=com.hitelnet.plugins.TbUserDir
net.userdir.loglevel.file=255

( com.hitelnet.plugins is the package name that I use in source code)

And also add c:\plugins in CLASSPATH env variable.

But I suspect that sip server never use (or call) TbUserDir plugins because:

1. In init function, same like sample code, I try to write a log line:
===> this.log.print( "TbUserDir: start\n", loglevel, LogLevel.LOG_LEVEL_ALL ) ;
After sip server restarted, I never found this line in log at directory C:\Program Files\Brekeke\sip\webapps\sip\WEB-INF\work\sv\log\2013\09

2. In lookup function, I intentionally always return null to fail authentication. But X-Lite sipphone always can register to sip server successfully.

I also try jar version by compiling TbUserDir.class into jar:
==> jar cvf TbUserDir.jar TbUserDir.class
And put TbUserDir.jar into directory C:\Program Files\Brekeke\sip\webapps\sip\WEB-INF\lib but no luck.

Did I missed something here.
Thank you.
Harold
Posts: 289
Joined: Sun Sep 21, 2008 10:31 pm
Location: Japan

Post by Harold »

Use .jar file instead of .class file for the plugin.

If you edited OS's "CLASSPATH", you may need to reboot the OS.

Can you put your code here?
lilipst
Posts: 8
Joined: Mon Sep 23, 2013 2:55 am
Location: Jakarta, Indonesia

Post by lilipst »

Yes, already reboot the the windows several times.
Here are the code:
package com.hitelnet.plugins;

import com.brekeke.common.* ;
import com.brekeke.net.usrdir.* ;

public class TbUserDir implements UserDir
{
Envrnmt env = null ;
Logging log = null ;
LogLevel loglevel = null ;


// init
public void init( Envrnmt env, Logging log ) throws Exception
{
this.env = env ;
this.log = log ;

// Log level setting
// It is obtained from the variable net.userdir.loglevel.console
loglevel = new LogLevel( 255,env.getInt( "net.userdir.loglevel.file", LogLevel.LOG_LEVEL_ALL ) ) ;
//loglevel = new LogLevel( 0,255) ;
this.log.print( "TbUserDir: start\n", loglevel, LogLevel.LOG_LEVEL_ALL ) ;

//
// Initialization of database connection, etc.
//
}
// lookup
public UserRecord lookup( String username, String method, String destination, String authinfo ) throws Exception
{
//
// database inquiry for a user information by username key.
//
log.print( "TbUserDir: lookup user\n", loglevel, LogLevel.LOG_LEVEL_ALL );
boolean the_user_info_not_found = false;
boolean the_user_doesnot_have_the_authority_to_execute_the_method = false;

if ( the_user_info_not_found ) {
return ( null ) ;
}

if ( the_user_doesnot_have_the_authority_to_execute_the_method ) {
return ( null ) ;
}

//UserRecord record = new UserRecord() ;
//record.username = username ;
//record.password = "1234567";
//record.bAuthorized = false;

return ( null ) ;
}

public int getCount() throws Exception
{
return 0;
}

public boolean remove( String username ) throws Exception
{
return true;
}

public boolean remove( UserRecord record ) throws Exception
{
return true;
}

public boolean append( UserRecord record ) throws Exception
{
return true;
}

public void close() throws Exception
{
}


}
Harold
Posts: 289
Joined: Sun Sep 21, 2008 10:31 pm
Location: Japan

Post by Harold »

Got it work.

Copy TbUserDir.class under com/hitelnet/plugins folder
and execute this
> jar cvf TbUserDir.jar com/hitelnet/plugins/TbUserDir.class
lilipst
Posts: 8
Joined: Mon Sep 23, 2013 2:55 am
Location: Jakarta, Indonesia

Post by lilipst »

Great, it's work.
Thank you.
So, the complete instruction:
1. compile plugins: javac TbUserDir.java
2. Copy TbUserDir.class to package directory
(example: for package com.hitelnet.plugins, it must be copied to
\com\hitelnet\plugins)
3. Create jar by execute: jar TbUserDir.jar \com\hitelnet\plugins\TbUserDir.class
(here, the complete package directory must be used)
4. copy TbUserDir.jar to \<brekeke install dir>\sip\webapps\sip\WEB-INF\lib
(for example: C:\Program Files\Brekeke\sip\webapps\sip\WEB-INF\lib)
note: if this step is used for modification of existing authentication plugins (plugins is already exists and used by sip server), sip server service must be stop before do the copy.
5. Restart sip server (or start sip server service)

I hope this discussion will be usefull as well for others who want to create their own authentication plugins.

Btw, with this step, its mean no need to add plugins directory to CLASSPATH env variable.
janP
Posts: 336
Joined: Sun Nov 25, 2007 2:55 pm

Post by janP »

Nice.
Thank you for sharing the info.
Post Reply