My Quotes


When U were born , you cried and the world rejoiced
Live U'r life in such a way that when you go
THE WORLD SHOULD CRY






Tuesday, December 23, 2014


To empty the Message Queue(IBM MQ). 

  • Pom.xml entries.
    
     
      mycompanygrpid
      parent
      0.0.1
     
     4.0.0
     com.test.mqtest
     mymqpom
     1.0.0
     war
     Test MQ
     Test MQ
             
      UTF-8
                     7.0.0.0
      1.0.0.0
     
            
      
      
       middleware
       com.ibm.mq
       ${webSphereMQVersion}
      
      
       middleware
       com.ibm.mq.jmqi
       ${webSphereMQVersion}
      
      
       middleware
       com.ibm.mq.jmqi.remote
       ${webSphereMQVersion}
      
      
       middleware
       com.ibm.mq.jmqi.system
       ${webSphereMQVersion}
      
      
       middleware
       com.ibm.mqjms
       ${webSphereMQVersion}
      
      
      
       middleware
       com.ibm.msg.client.commonservices
       ${webSphereMQClientVersion}
      
      
       middleware
       com.ibm.msg.client.commonservices.j2se
       ${webSphereMQClientVersion}
      
      
       middleware
       com.ibm.msg.client.jms
       ${webSphereMQClientVersion}
      
      
       middleware
       com.ibm.msg.client.jms.internal
       ${webSphereMQClientVersion}
      
      
       middleware
       com.ibm.msg.client.provider
       ${webSphereMQClientVersion}
      
      
       middleware
       com.ibm.msg.client.wmq
       ${webSphereMQVersion}
      
      
       middleware
       com.ibm.msg.client.wmq.common
       ${webSphereMQVersion}
      
      
       middleware
       com.ibm.msg.client.wmq.factories
       ${webSphereMQVersion}
      
      
       middleware
       dhbcore
       DH610-GOLD
      
      
       org.glassfish
       javax.jms
       10.0-b28
      
    
    

  • Actual code to clean up the queue.
      private void emptyIt()  {
            MQQueueManager _queueManager = null;
            MQQueue queue = null;
           int openOptions = MQC.MQOO_INQUIRE + MQC.MQOO_FAIL_IF_QUIESCING + MQC.MQOO_INPUT_SHARED;
           try{
           _queueManager = new MQQueueManager(qManager);         
           queue = _queueManager.accessQueue(inputQName, openOptions, null, null, null);
           System.out.println("EmptyQ: Opened queue "+inputQName);
    
           int depth = queue.getCurrentDepth();
           System.out.println("EmptyQ: Current depth: " + depth);
    
           MQGetMessageOptions getOptions = new MQGetMessageOptions();
           getOptions.options = MQC.MQGMO_NO_WAIT + MQC.MQGMO_FAIL_IF_QUIESCING + MQC.MQGMO_ACCEPT_TRUNCATED_MSG;
    
           MQMessage message;
           while (loopAgain){
       message = new MQMessage();
       try {
          queue.get(message, getOptions, 1);
       }catch (MQException e){
          if (e.completionCode == 1 && e.reasonCode == MQException.MQRC_TRUNCATED_MSG_ACCEPTED) {
              // Just what we expected!!
          }
          else{
             loopAgain = false;
             if (e.completionCode == 2 && e.reasonCode == MQException.MQRC_NO_MSG_AVAILABLE){
         // Good, we are now done - no error!!
             } else {
         System.err.println("EmptyQ: MQException: " + e.getLocalizedMessage());
             }
          }
       }
           } // close of while loop
          System.out.println("EmptyQ: Queue emptied.");
       }catch (MQException e1){
          System.err.println("EmptyQ: MQException: " + e1.getLocalizedMessage());
       }
       finally {
          if (queue != null){
             queue.close();
          }
    
          if (_queueManager != null){
             _queueManager.disconnect();
          }
       }
      }
     
  • Monday, November 24, 2014

    Configue Sonar with eclipse

    Externalize Named Queries in JPA

    
    Externalize Named Queries in JPA 
    
    
    
    Main XML file 
    
    
    
    
     
      java:/someDS
      
      META-INF/myproject/sample.xml
            
    
    

    
    sample.xml (having named query)
    
    

    
    
     
      
       SELECT 
        website
       FROM 
        Website website
       WHERE
        website.userId = :userId
      
     
     
      
       ...
      
     
    
    
    

    Wednesday, August 6, 2014

    Remove unwanted folders from Maven WAR

    
    When you are using activemq-all.jar file in your maven, you could see that there are lots of folders added to the WAR file especially the bigger ones are
    
    
  • [INFO] Processing overlay [ id org.apache.activemq:activemq-fileserver]
  • [INFO] Processing overlay [ id org.apache.activemq:activemq-web-demo]
  • [INFO] Processing overlay [ id org.apache.activemq:activemq-web-console]
    In order to remove them from your WAR here is an easier technique

  • 
      WarFileName
      
       
        maven-compiler-plugin
        2.2
        
         1.6
         1.6
        
       
       
        org.apache.maven.plugins
        maven-war-plugin
        2.2
         
         
         **
        
        
         
          war
          package
          
           war
          
          
           true
          
         
        
       
      
     
    


    Tuesday, July 8, 2014

    Prevent DNS Injections Apache Web Server

    
    To prevent DNS Injection attacks, 
    
    which are attacks that can inject fake DNS names into your server's cache, you need to add another module to Apache. 
    Follow these steps
    
  • Open a terminal window
  • Issue the command sudo apt-get -y install libapache2-mod-spamhaus
  • After the installation completes, issue the command sudo touch /etc/spamhaus.wl.
  • Issue the command sudo chown -R www-data:root /var/log/apache2/evasive.
  • With the module installed, open the /etc/apache2/apache2.conf file (using sudo and your favorite text editor) and append the following to the bottom of your configuration file:
    
      MS_METHODS POST,PUT,OPTIONS,CONNECT 
      MS_WhiteList /etc/spamhaus.wl 
      MS_CacheSize 256 
    
    
  • Save the apache2.conf file and restart Apache so the new module will take effect
  • Prevent DDOS attacks in Apache Web Server

    DDoS
    There is an Apache module that was created to prevent a DDoS attack, although it's probably not installed by default. Follow these steps to install the module.



  • Open your terminal window.
  • Issue the command sudo apt-get -y install libapache2-mod-evasive.
  • Issue the command sudo mkdir -p /var/log/apache2/evasive.
  • Issue the command sudo chown -R www-data:root /var/log/apache2/evasive.
  • Open the /etc/apache2/mods-available/mod-evasive.load file (using sudo and your favorite text editor) and append the following to the bottom of that file (this is one configuration per line):


    DOSHashTableSize 2048
    DOSPageCount 20  # maximum number of requests for the same page
    DOSSiteCount 300  # total number of requests for any object by the same client IP on the same listener
    DOSPageInterval 1.0 # interval for the page count threshold
    DOSSiteInterval 1.0  # interval for the site count threshold
    DOSBlockingPeriod 10.0 # time that a client IP will be blocked for
    DOSLogDir "/var/log/apache2/evasive"
    DOSEmailNotify admin@domain.com
    
  • Save the apache2.conf file and restart Apache so the new module will take effect
  • Wednesday, June 25, 2014

    Ethical Hack Insufficient Session Destruction

    1. Create a HttpSessionBindingListener

    import javax.servlet.http.HttpSession;
    import javax.servlet.http.HttpSessionEvent;
    import javax.servlet.http.HttpSessionListener;
    
    public class MySessionListener implements HttpSessionListener {
     public void sessionCreated(HttpSessionEvent evt) {
      HttpSession session = evt.getSession();
      session.getServletContext().log(
        "CREATED Session ID: " + session.getId() + "\t time: "
          + new java.util.Date());
     }
    
     public void sessionDestroyed(HttpSessionEvent evt) {
      HttpSession session = evt.getSession();
      session.getServletContext().log(
        "DESTROYED Session ID: " + session.getId() + "\t time: "
          + new java.util.Date());
     }
    }
    

    2. Configure this Session Listener in your web.xml

    
             com.pearson.cat.web.session.MySessionListener
        
    

    3.So all you can do is to copy the method invalidate()from the above code into the logout.jsp and wait and see if the Listener is spilling the messages that the Session has been destroyed or not.

    public void invalidate() {
            if (this.session != null) {
                this.cleanAttributes();
                this.session.invalidate();
            }
        }
    
        public void cleanAttributes() {
           if (this.session != null) {
                Enumeration attributes = session.getAttributeNames();
                while (attributes.hasMoreElements()) {
                    String name = (String) attributes.nextElement();
                    session.removeAttribute(name);
                }
            }
        }