Brekeke SIP Server Wiki

6. Auth Plug-in Sample Code

Here is a sample code that explains how to implement init and lookup method.

 

package com.domain.proxy.plugins ;

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

public class SampleUserDir 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( 0,
      env.getInt( "net.userdir.loglevel.file", LogLevel.LOG_LEVEL_EXCEPTION ) ) ;

    log.println( "SampleUserDir: start", loglevel, LogLevel.LOG_LEVEL_SYSTEM ) ;

    //
    // 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.
    //

    if ( the user info not found ) {
      return ( null ) ;
    }

    if ( the user doesn’t have the authority to execute the method ) {
      return ( null ) ;
    }

    if ( the user doesn’t have the authority to access the destination SIP-URI ) {
      return ( null ) ;
    }

    UserRecord record = new UserRecord() ;
    record.username = username ;
    record.password = the plain password obtained from the database
    return ( record ) ;
  }

}
Yes No
Suggest Edit