Brekeke Forum Index » Brekeke SIP Server Forum

Post new topic   Reply to topic
Sip Server doesn't use Authentication plugins
Author Message
lilipst
Brekeke Junior Member


Joined: 23 Sep 2013
Posts: 8
Location: Jakarta, Indonesia

PostPosted: Thu Sep 26, 2013 1:21 am    Post subject: Sip Server doesn't use Authentication plugins Reply with quote

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/viewtopic.php?t=7364&highlight=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.
Back to top
View user's profile
Harold
Brekeke Master Guru


Joined: 21 Sep 2008
Posts: 286
Location: Japan

PostPosted: Thu Sep 26, 2013 1:54 am    Post subject: Reply with quote

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?
Back to top
View user's profile
lilipst
Brekeke Junior Member


Joined: 23 Sep 2013
Posts: 8
Location: Jakarta, Indonesia

PostPosted: Thu Sep 26, 2013 2:09 am    Post subject: Reply with quote

Yes, already reboot the the windows several times.
Here are the code:
Quote:
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
{
}


}
Back to top
View user's profile
Harold
Brekeke Master Guru


Joined: 21 Sep 2008
Posts: 286
Location: Japan

PostPosted: Thu Sep 26, 2013 11:23 am    Post subject: Reply with quote

Got it work.

Copy TbUserDir.class under com/hitelnet/plugins folder
and execute this
> jar cvf TbUserDir.jar com/hitelnet/plugins/TbUserDir.class
Back to top
View user's profile
lilipst
Brekeke Junior Member


Joined: 23 Sep 2013
Posts: 8
Location: Jakarta, Indonesia

PostPosted: Thu Sep 26, 2013 7:31 pm    Post subject: Reply with quote

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.
Back to top
View user's profile
janP
Brekeke Master Guru


Joined: 25 Nov 2007
Posts: 336

PostPosted: Fri Sep 27, 2013 8:31 am    Post subject: Reply with quote

Nice.
Thank you for sharing the info.
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    Brekeke Forum Index » Brekeke SIP Server Forum All times are GMT - 7 Hours
Page 1 of 1