Tag: tiny radius

  • Radius, ldap, log4j, sms token

    I’ve already mentioned about that project. We used great library for it it’s called TinyRadius. In the sources you get extra example codes of TestClient and TestServer implementation. That is really helpful. The project is written using Netbeans and Maven tools. That is really comfortable. You just got your pom.xml and it does care about all dependencies. It’s simply download them from the web.

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>pl.johnnyjavago.developement.radiustest</groupId>
        <artifactId>MyWebRadiusServer</artifactId>
        <packaging>war</packaging>
        <version>1.0-SNAPSHOT</version>
        <name>MyWebRadiusServer JEE5 Webapp</name>
        <url>http://maven.apache.org</url>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.0.2</version>
                    <configuration>
                        <source>1.6</source>
                        <target>1.6</target>
                    </configuration>
                </plugin>
            </plugins>
        </build>
        <dependencies>
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
                <version>2.5</version>
                <type>jar</type>
            </dependency>
            <dependency>
                <groupId>javax.servlet.jsp</groupId>
                <artifactId>jsp-api</artifactId>
                <version>2.1</version>
                <scope>provided</scope>
            </dependency>
    
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>3.8.1</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.tinyradius</groupId>
                <artifactId>tinyradius</artifactId>
                <version>0.9.9</version>
                <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
                <version>1.1</version>
            </dependency>
            <dependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>1.2.14</version>
                <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>com.novell.ldap</groupId>
                <artifactId>jldap</artifactId>
                <version>4.3</version>
            </dependency>
            <dependency>
                <groupId>xstream</groupId>
                <artifactId>xstream</artifactId>
                <version>1.2.2</version>
                <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>javaee</groupId>
                <artifactId>javaee-api</artifactId>
                <version>5</version>
                <scope>compile</scope>
            </dependency>
        </dependencies>
    </project>

    That is simply amazing technique. To start and instance of the server I implemented well know ServletContextListener :)

    public class ActivatorServletContextListener implements ServletContextListener {
    
        MyRadiusServer server = new MyRadiusServer();
    
        @Override
        public void contextInitialized(ServletContextEvent arg0) {
            server.start(true, true);
            System.out.println("Server started.");
        }
    
        @Override
        public void contextDestroyed(ServletContextEvent arg0) {
            System.out.println("Stop server");
            server.stop();
        }
    }

    It does a great job too. And for logs we used log4j, it cool also. You can drive your logs wherever you want. Here is log4j.properties file: (from path src/main/resources)

    # #### Use two appenders, one to log to console, another to log to a file
     log4j.rootCategory=debug, R
    #
    # #### First appender writes to console
     log4j.appender.stdout=org.apache.log4j.ConsoleAppender
     log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
    #
    # # Pattern to output the caller's file name and line number.
     log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F%L) - %m%n
    
    log4j.appender.R = org.apache.log4j.DailyRollingFileAppender
    log4j.appender.R.File = logs/my-radius.log
    log4j.appender.R.Append = true
    log4j.appender.R.DatePattern = '.'yyy-MM-dd
    log4j.appender.R.layout = org.apache.log4j.PatternLayout
    log4j.appender.R.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %c{1} [%p] %m%n