A basic JSF application to manage Freeradius-1

Hi again. In this article i will give a detailed explanation about my application. The code for the project will be citated to my github account in some paragraphs(https://github.com/aktasrozerin/jsfapplication). It is something that one can manage the radius server users and clients. It is just the beginning part i am still working around it, when i make changes, i will upload them immediately.

Let’s start from stratch. What we need now is to create a maven project. By the way i will be using intellij-idea but it is similar to Eclipse and NetBeans anyway. After creating a maven project, the rest is about fill the blanks πŸ™‚

Now we need to create our base package. You can name it as you wish. That package will be where you put your objects, beans, data access objects, services, html pages, etc. You need to add the base package information into application-context.xml file like

<context:component-scan base-package="radius"/>

pom.xml is where we put our plugins, repositories and dependencies. You can copy my pom.xml file into yours or you can use other features according to your application. You can find my pom.xml file in the comments below the page.

For now my project has user feature but soon i will also upload client feature. For user feature, i have one adapter class called UserAdapter. You can find this class in jsfapplication/src/main/java/radius/adapters/UserAdapter.

The users also have some roles. Those roles can be added from the web application interface. It is also in jsfapplication/src/main/java/radius/adapters/RoleAdapter. A user may have more than one role, so between a user and role, there is a one-to-many relationship. If you have freeradius installed in your computer, that means you have a database. It’s name doesn’t matter but you will have to add a few tables more for that reason. First of all please add MySQL to your project. At the rightmost of the screen there is a bar called “database“.

-Click on it and press Alt+Insert to choose a database.

-Click data source then MySQL.

-Enter your freeradius database name into database name part. Also add your MySQL username and password and check connection.

Now it is time to introduce the beans. The beans are the objects for html pages. Every html function and data must be defined in those beans. You can define as many beans as you like. As long as it has service connection with @ManagedProperty. You can see my beans in jsfapplication/src/main/java/radius/Beans.

Next, you are going to need converters. If you don’t have converters, you will get errors when you pass bean parameters in your html pages. They will be understood as strings instead of objects. You will pass those converter classes in your html files to prevent that error. You can also find my converters in radius package.

After that we now have data access objects(daos). For now i have three daos but it will be more. In those daos i defined data sources(connections with MySQL), jdbctemplates(objects that executes queries) and methods that will be done in web application such as insert,update and print. See DAO package for daos and their interfaces in radius package.

You have to include every single dao into your application-context.xml file. This is a Spring Config file please don’t get mixed. It’s name can be something else as long as it is included in web.xml. One example for addition is like following;

<bean id="JDBCUserDao" class="radius.DAO.DaoImp.JDBCUserDaoImp">
    <property name="dataSource" ref="dataSource" />
</bean>

And also please add your MySQL connection informations like following after your beans in application-context.xml file.

<bean id="dataSource"
      class="org.springframework.jdbc.datasource.DriverManagerDataSource">
       <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
       <property name="url" value="jdbc:mysql://localhost:3306/radius"/>
       <property name="username" value="root"/>   //you don't have to be a root
       <property name="password" value=""/>   //type your password in here
</bean>

In the next article i will explain xhtml files, other tables and unit tests. Hope to see you there too πŸ™‚

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s