Tuesday, August 13, 2013

Easy tricks for your needs...

01. Remove duplicate entries (line) from the text file in Ubuntu

       sort random.txt | uniq -u > rand-shorter.txt

02. Change the folder tree rights to 777 in Ubuntu
         
         chmod -R 777 my_folder_name

03. MySQL data export to the database from sql file
      
          mysql -uroot -p -h localhost mydb < mydbbackup.sql
04. Find the running port number for given process in ubuntu
          ps -ax|grep process_name
         example:  ps -ax|grep java will list out all the process having name java

05. Kill running process
        kill -9 12344 (Here 12344 is process number given by "ps -ax|grep myprocess" command)

06. Kill a process for know port
        sudo lsof -t -i:<port-number>
        Example: sudo lsof -t -i:9000
        The result would be the process number. Then use "kill -9 <process-number>" to kill the process. Please see the (05) of the above.
        

Tuesday, March 5, 2013

How to change the splash screen on ubuntu 12.04

Run bellow command on the shell.

sudo update-alternatives --config default.plymouth
Then it will ask you to select the default one from the available list


 Selection    Path                                                       Priority   Status
------------------------------------------------------------
  0            /lib/plymouth/themes/edubuntu-logo/edubuntu-logo.plymouth   150       auto mode
  1            /lib/plymouth/themes/edubuntu-logo/edubuntu-logo.plymouth   150       manual mode
* 2            /lib/plymouth/themes/ubuntu-logo/ubuntu-logo.plymouth       100       manual mode
Press enter to keep the current choice[*], or type selection number: 

You can select appropriate number from the list and enter.  

If your login screen is not graphical on ubuntu 12.04 you can change it back to the normal operation as bellow.

Run command
 sudo gedit /etc/default/grub 

And edit the grup file as bellow.

Bellow line should be active (No # at the beggining) and not commented
  GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
Bellow line should be commented (# at the beggining) as bellow.

  #GRUB_TERMINAL=console

Then you should rebuild the grub by using bellow command after saving the above file.
 sudo update-grub  

Thats it. Restart and confirm it.!!!

Monday, March 4, 2013

Webdav example in Spring Security with password encription

You can find few set of link which will guide you to do the spring configuration for the webdav. But, i have reallized that most of the readers getting trouble when implementing those codes as they are not properly explain how to do it basic level.

Here is the clear working guide for the spring webdav integration with encripted password.

01. Setup the spring blank project from your desired developement tool (netbeans, eclipse,intelliJ IDEA). I am using intelliJ on this tutorial. And setup spring security example based on the available sources on the web.
Here is the few links you may try.
http://blog.solidcraft.eu/2011/03/spring-security-by-example-set-up-and.html
http://static.springsource.org/spring-security/site/docs/3.0.x/reference/sample-apps.html

After completing the above steps, you could be able to log in to the web application using form based authontification with encripted password on the database.

Now lets setup for the webdav folder access for the above web project.

02. Modify the web.xml file for the webdav configuration.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
 http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         version="2.5">
    <servlet>
        <servlet-name>webdav</servlet-name>
        <servlet-class>org.apache.catalina.servlets.WebdavServlet</servlet-class>
        <init-param>
            <param-name>debug</param-name>
            <param-value>0</param-value>
        </init-param>
        <init-param>
            <param-name>listings</param-name>
            <param-value>true</param-value>
        </init-param>
        <!-- Read-Write Access Settings -->
        <init-param>
            <param-name>readonly</param-name>
            <param-value>false</param-value>
        </init-param>
    </servlet>
    <!-- URL Mapping -->
    <servlet-mapping>
        <servlet-name>webdav</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/application-security.xml
            /WEB-INF/applicationContext.xml
        </param-value>
    </context-param>
    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
</web-app>
03. As you can see the above web.xml file, following two spring configuration file should be available.

            /WEB-INF/application-security.xml
            /WEB-INF/applicationContext.xml

04. application-security.xml file is use to control the spring security for this example.

<?xml version="1.0" encoding="UTF-8"?>

<beans:beans xmlns="http://www.springframework.org/schema/security"
             xmlns:beans="http://www.springframework.org/schema/beans"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">

    <http>
        <intercept-url pattern="/**" access="ROLE_DESKTOP_USER"/>
        <http-basic/>
        <custom-filter ref="digestFilter" after="BASIC_AUTH_FILTER"/>
    </http>

    <beans:bean id="digestFilter" class="org.springframework.security.web.authentication.www.DigestAuthenticationFilter">
        <beans:property name="userDetailsService" ref="myAuthenticationProvider"/>
        <beans:property name="authenticationEntryPoint" ref="digestEntryPoint"/>
        <beans:property name="passwordAlreadyEncoded" value="true"></beans:property>
    </beans:bean>
     <beans:bean id="digestEntryPoint"
                class="org.springframework.security.web.authentication.www.DigestAuthenticationEntryPoint">
                <beans:property name="realmName" value="my test" />
                <beans:property name="key" value="test" />
                <beans:property name="nonceValiditySeconds" value="10" />
        </beans:bean>


    <authentication-manager>
        <authentication-provider user-service-ref='myAuthenticationProvider'>
             <password-encoder ref="passwordEncoder">
                 <salt-source ref="DigestAuthenticationAwareSaltSource"/>
             </password-encoder>
        </authentication-provider>
    </authentication-manager>

      <beans:bean id="digestAuthenticationProvider"
                class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">
                <beans:property name="userDetailsService" ref="myAuthenticationProvider" />
        </beans:bean>

     <beans:bean id="DigestAuthenticationAwareSaltSource" class="com.indika.service.DigestAwarePasswordEncoder">
         <beans:property name="digestRealm" value="Contacts Realm via Digest Authentication"/>
    </beans:bean>


    <beans:bean class="com.indika.service.DigestAuthenticationAwarePasswordEncoder" id="passwordEncoder"/>

    <beans:bean id="myAuthenticationProvider" class="com.indika.service.UserDetailsServiceImpl">
        <beans:property name="mstuserdao" ref="mstuserdao"/>
        <beans:property name="mstusergroupdao" ref="mstusergroupdao"/>
    </beans:bean>

    <beans:bean id="mstuserdao" class="com.indika.repository.MstUserDAO">
        <beans:property name="hibernateTemplate">
            <beans:ref bean="hibernateTemplate"/>
        </beans:property>
    </beans:bean>

    <beans:bean id="mstusergroupdao" class="com.indika.repository.MstUserGroupDAO">
        <beans:property name="hibernateTemplate">
            <beans:ref bean="hibernateTemplate"/>
        </beans:property>
    </beans:bean>

</beans:beans>


Above red colour classes should be created by you.

05. DigestAuthenticationAwarePasswordEncoder.java

package com.indika.service;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.security.authentication.dao.SaltSource;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.util.Assert;


public class DigestAuthenticationAwarePasswordEncoder implements SaltSource, InitializingBean {

    private String digestRealm;


    public void afterPropertiesSet() throws Exception {
        Assert.hasText(digestRealm, "A Digest Realm must be set");
    }


    public Object getSalt(UserDetails user) {
        return String.format("%s:%s:", user.getUsername(), digestRealm);
    }

    public void setDigestRealm(String digestRealm) {
        this.digestRealm = digestRealm;
    }
}

06. DigestAwarePasswordEncoder.java


package com.indika.service;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.security.authentication.dao.SaltSource;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.util.Assert;


public class DigestAwarePasswordEncoder implements SaltSource, InitializingBean {

    private String digestRealm;


    public void afterPropertiesSet() throws Exception {
        Assert.hasText(digestRealm, "A Digest Realm must be set");
    }


    public Object getSalt(UserDetails user) {
        return String.format("%s:%s:", user.getUsername(), digestRealm);
    }

    public void setDigestRealm(String digestRealm) {
        this.digestRealm = digestRealm;
    }
}




07. UserDetailsServiceImpl.java/MstUserDAO.java/MstUserGroupDAO.java

You can find many sources for the above classes from the web related to the spring security configuration.



08. Once every things were completed, you can login webdav folder using the encripted password.



Friday, April 29, 2011

Open JDK to Sun JAVA JDK on Eclipse

This is how to change the ubuntu open jdk to sun jdk
Step 1. Open Shell
Step 2.

indika@indika-lenovo-3000-g550:~$ java -version
java version "1.6.0_20"
OpenJDK Runtime Environment (IcedTea6 1.9.7) (6b20-1.9.7-0ubuntu1)
OpenJDK Server VM (build 19.0-b09, mixed mode)
Step3.
ndika@indika-lenovo-3000-g550:~$ sudo update-alternatives --config java
[sudo] password for indika: 
There are 3 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                      Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-6-openjdk/jre/bin/java   1061      auto mode
  1            /usr/bin/gij-4.4                           1044      manual mode
  2            /usr/lib/jvm/java-6-openjdk/jre/bin/java   1061      manual mode
  3            /usr/lib/jvm/java-6-sun/jre/bin/java       63        manual mode

Press enter to keep the current choice[*], or type selection number: 3
update-alternatives: using /usr/lib/jvm/java-6-sun/jre/bin/java to provide /usr/bin/java (java) in manual mode.
Step 4.
indika@indika-lenovo-3000-g550:~$ java -version
java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) Server VM (build 19.1-b02, mixed mode)




Monday, November 8, 2010

Java Development with Ubuntu 10.10

This is first step of migration for the software engineers from window platform to linux platform. I am Java Developer and doing my java development in windows platform.  


Here is my window development configurations:

  • OS - windows 7
  • Java version - JDK 6
  • IDE - Netbeans 6.91
  • Application Server - Tomcat 7
  • Database Server - MySQL
  • Version Control - tortoisesvn
Ok. Lets assume you have successfully installed and setup the Ubuntu 10.10 and can access the internet.

Step 1: Install Java

It is obvious that most of linux dis have installed Open JDK at the os installation time. If you are new for java development go this Open JDK.(I never tested open Jdk with netbeans). But when you run your existing code, you might get errors and the only solution for that is use sun java jdk. 

In this step i am going to show you how to install sun jdk for ubuntu 10.10.

Go to Ubuntu Software Center 
Applications –> Ubuntu Software Center.
Then click Edit –> Software Sources..
Next, select ‘Other Software’ tab 
Then Click 'Add..' button to add the software source and paste bellow text for the APT line: text box  
deb http://archive.canonical.com/ubuntu lucid partner                  
Click Add Source button to close the Software Source window.
It will take few second to update the source index for the newly added source. Then search for the keyword sun-java jdk" and will be listed the results. Select required version and click install. 


Step 2: Install Netbeans

Before installing netbeans, make sure that you have installed sun java. Please follow the step 1 to install the sun java on ubuntu 10.10

Download latest version of netbeans from the http://www.netbeans.org web site and download latest stable version.

Once you have downloaded Open a terminal window and navigate to your Download directory (where you downloaded NetBeans installer script). Once you are at your download directory, type the following command to begin the installation.

sudo sh netbeans-6.9rc2-ml-linux.sh                                    

Above command will initialize the installation process which is very much familiarly to you to just clicking next, agreed and finished. (You have to select your desired application servers..etc).

After successfully installed you can open from Application->Programming->netbeans 6.7

Step 3; Tomcat 7

sudo wget http://apache.hoxt.com/tomcat/tomcat-7/v7.0.4-beta/bin/apache-tomcat-7.0.4.tar.gz

tar xvzf apache-tomcat-7.0.4.tar.gz                                                               

sudo mv apache-tomcat-7.0.4 /usr/local/tomcat                                              
(Move tomcat to the permanent location)

Tomcat requires setting the JAVA_HOME variable. The best way to do this is to set it in your .bashrc file. You could also edit your startup.sh file if you so chose.
The better method is editing your .bashrc file and adding the bolded line there. You’ll have to logout of the shell for the change to take effect.
vi ~/.bashrc                                                                                                 

add following line: 

#java_home settings                                                                                    
export JAVA_HOME=/usr/lib/jvm/java-6-sun                                                  

Save vi editor by typing :wq           

Writing auto startup file:

sudo vi /etc/init.d/tomcat                                                                              

Paste following text in the file:

# Tomcat auto-start
#
# description: Auto-starts tomcat
# processname: tomcat
# pidfile: /var/run/tomcat.pid

export JAVA_HOME=/usr/lib/jvm/java-6-sun
case $1 in
start)
sh /usr/local/tomcat/bin/startup.sh
;;
stop)
sh /usr/local/tomcat/bin/shutdown.sh
;;
restart)
sh /usr/local/tomcat/bin/shutdown.sh
sh /usr/local/tomcat/bin/startup.sh
;;
esac
exit 0

type :wq and exit with saving the file.

sudo chmod 755 /etc/init.d/tomcat                                           
(make the script executable)

Creating the symbolic link:

sudo ln -s /etc/init.d/tomcat /etc/rc1.d/K99tomcat                    
sudo ln -s /etc/init.d/tomcat /etc/rc2.d/S99tomcat                    

Thats all. Open your browser and check the URL 'http://locahost:8080/' and you will see tomcat welcome page.


Step 4: MySQL Server

This is again an easy task by opening Ubuntu Software Center and search for the Mysql Server. 

Step 5: Version Control

Since tortisSVN is not available for linux upto date we need to have a alternatives. I have selected RabitVCS instead. (Hope rabit is faster than tortis)

Here is the command to install RabitVCS.

sudo apt-get install rabbitvcs-nautilus rabbitvcs-gedit rabbitvcs-cli              

You need to open nautilus explorer to use the rabitvcs in action.


Ok..thats all about it. Enjoy the java programing with ubuntu 10.10

Thanks for reading....
 

Friday, October 29, 2010

How to copy Copy Protected VCD

Today i bought a nursery rhymes VCD from the market to my daughter. Even though it playing well with the VCD player, I just wanted to have a copy of that VCD in my laptop as it is easy to play it later on without finding the cd in the rack. Also i am pretty sure that those VCDs might not be able to read after 1 to 2 years time as the low quality of them.

I am using Ubuntu 10.04 LTS and i can't play the vcd with the default settings. I tried with VLC and movie player. In movie player it is giving the error massage saying.."Could not read from resource".

With VLC i am getting
"File reading failed:
VLC could not read the file."

These are the step to play/copy the above type of VCDs,
  1. Open linux shell (Application --> Asseseries-->Terminal)
  2. Type "sudo apt-get install vcdimager" and press enter (You need to have internet connection)
  3. Type "vcdxrip". You will get warn massage and wait until it complete the operation and get the cursor on the terminal back to normal.
  4. That's it. Go to the home folder and watch the copied mpg files.


Have fun!!