Pages

Monday, October 27, 2014

Springs Security


Springs Security is a flexible and powerful authentication and access control framework to secure Spring-based Java web application.

Spring Security provides security services for J2EE-based enterprise software applications.

Application Security Areas:

There are two main areas for application securities.
  1. Authentication: Process of checking the user, who they claim to be.
  2. Authorization: Process of deciding whether an user is allowed to perform an activity within the application.

Spring Security Modules

Spring security code has been divided in different JARs(Can be considers as modules)
  1. Core (spring-security-core.jar) : Required. Contains core authentication and access-contol classes and interfaces, remoting support and basic provisioning APIs.
  2. Web (spring-security-web.jar): Required* if web authentication services and URL-based access-control is required.Contains filters and related web-security infrastructure code.

 Types or Levels:

1) URL
2) Method
3) ACL object level security.

more coming soon.......

Wednesday, May 30, 2012

Difference between two times in javascript


var secondsPerMinute = 60;
var minutesPerHour = 60;

function convertSecondsToHHMMSS(intSecondsToConvert) {
var hours = convertHours(intSecondsToConvert);
var minutes = getRemainingMinutes(intSecondsToConvert);
minutes = (minutes == 60) ? "00" : minutes;
var seconds = getRemainingSeconds(intSecondsToConvert);
return hours+":"+minutes;
}

function convertHours(intSeconds) {
var minutes = convertMinutes(intSeconds);
var hours = Math.floor(minutes/minutesPerHour);
return hours;
}
function convertMinutes(intSeconds) {
return Math.floor(intSeconds/secondsPerMinute);
}
function getRemainingSeconds(intTotalSeconds) {
return (intTotalSeconds%secondsPerMinute);
}
function getRemainingMinutes(intSeconds) {
var intTotalMinutes = convertMinutes(intSeconds);
return (intTotalMinutes%minutesPerHour);
}

function HMStoSec1(T) { // h:m:s
  var A = T.split(/\D+/) ; return (A[0]*60 + +A[1])*60 + +A[2] }
 
Sample code to get difference between two times using javascript 
var time1 = HMStoSec1("10:00:00");
var time2 = HMStoSec1("12:05:00");
var diff = time2 - time1;
document.write(convertSecondsToHHMMSS(diff));

Tuesday, January 31, 2012

Get the process id in java

Each application is treated as Process in our JVM. So how to get our running application in runtime. In java in lang package we are having a class called ManagementFactory. Which will help us to trace out process id of our running application.

     ManagementFactory.getRuntimeMXBean().getName()

It will returns the id in String format.
We need to use this command after each process or thread.
 
For Eg see the below examples: 
  
To Get the process id.  
import java.awt.BorderLayout;
import java.awt.Color;
import java.lang.management.ManagementFactory;

import javax.swing.JFrame;
import javax.swing.JTextArea;

public class SwingDemo {
     public static void main(String[] args) {
         try {
                JFrame f = new JFrame(System.nanoTime()+"");
                f.setSize(450, 450);
                f.setLocation(300,200);
                f.getContentPane().add(BorderLayout.CENTER, new JTextArea(10, 40));
                f.setVisible(true);
                f.setForeground(Color.BLUE);
              
                    //Process process = Runtime.getRuntime().exec("notepad.exe");
                    System.out.println("P id::=>" +
                                ManagementFactory.getRuntimeMXBean().getName()
                    );           
                    System.out.println("T id::=>" );
                    //    process.destroy();
            
             } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
          
          }
}

To Kill the process id       

  // serviceName should be the process id  which we got from the above application.
  // taskkill /IM command will work on windows only. Check out in web for OS dependent commands.
  public static void killProcess(String serviceName) throws Exception {

          Runtime.getRuntime().exec("taskkill /IM " + serviceName);  
  }


To check whether Process is running or not.

  public static boolean isProcessRunning(String serviceName) throws Exception {

         Process p = Runtime.getRuntime().exec(TASKLIST);
         Thread.sleep(1000);
         BufferedReader reader = new BufferedReader(new InputStreamReader(
           p.getInputStream()));
         String line;
         while ((line = reader.readLine()) != null) {

          System.out.println("om ::"+ line);
          if (line.contains(serviceName)) {
           return true;
          }
         }

         return false;
}

So i hope with the help of above sample code you can achieve process id of your applications.