Tuesday, March 5, 2013

Why Linux is more secure than windows.

Everyone knows Linux is secure and there is no need of anti-virus to be installed. Has anyone wondered what makes Linux so much secure and free from mallicious software ?

Before that, lets see how these mallicious software code affect windows. Program from unknown , untrusted source is downloaded on to your system by some means and it starts executing. Handling this program is not under the control of user. It gets executed automatically and performs tasks harming system environment. In windows, all users are by default administrators and there is very little difference between a normal user and administrator. An open door to access everything on the system.

In Linux, everything is considered as a file i.e Devices, directories etc are all files and default permissions for a file is it can't be executed unless you change permissions using chmod command. So, none of the programs can execute all by itself and damage your computer. It also provides limited access to normal users, thus avoiding damage to system files. Only root user has access to all system files.

Monday, February 11, 2013

Clicking on submit twice while submitting a form in JSF

Assuming the reader of this post has considerate amount of knowledge in JSF (Java Server Faces) Framework.

This peculiar problem occurs while developing web application using JSF Framework. It is really very annoying and makes your application look very dumb and childish. I had got stuck with this problem and finally found out the root cause and solution which i would like to share with fellow programmers.
Suppose, you have a JSF web page which has a form and this form contains SelectOneMenu elements which has ValueChangeListener methods. When, you click on submit button first time, form doesn't get submitted, same page reloads. Second time, when you click on submit button, form submits. This was my case and after digging deep into it, I found that form was getting submitted and it was executing the method specified in action attribute of command button. But, my logic inside that method was returning a value which didn't allow the navigation of page to next page. Reason for the failure of my logic was value of bean property was not getting updated during first submit. I had a checkbox which was checked when clicking on submit, so the corresponding bean value was supposed to be true instead it was false. Bean is not getting updated with proper values when you click on submit first time. This happens due to Value Change Event Listeners.

For a form to submit properly. The same datamodel should be preseved in the subsequent request as it was during initial display. When the page first loads, properties in bean will have some default or null values. SelectOneMenu element in your form will populate a different value to the bean after its loaded and thus same datamodel is not preserved. Since ValueChangeListener methods are registered, it will not update the bean with proper values and there will be problems in form submission. To preserve same datamodel, you can initialize all bean properties to a default value in bean constructor. This resolves the issue.

Other than this, if you have nested form tags also, this problem occurs.

Tuesday, October 2, 2012

Wiki software

     I will try to introduce Wiki software in simple words to those who haven't heard of it. It was invented by Ward Cunningham. It is basically a knowledge sharing website where people can share about things they know and also make changes in things shared by others. It can also be defined as a website which allows to add, modify or delete its own content by users. Other features include search utility to search through all the pages, pages can be grouped under different categories, authentication can be provided so that only authorized users can modify contents, people can discuss on the topic through comments, one can view the revision history on the pages i.e who has modified it and when. A good example for a Wiki software is Wikipedia, everyone would have used wikipedia, it is a collection of pages written by people all over the world and you can even edit the contents, It runs on MediaWiki software.

    Wiki software contains two components 
  • Front-end : It has a common style for all the pages, only the text content changes. It has its own syntax for editing pages, text entered by user will be converted to HTML by wiki software. 
  • Database : Pages and other data about users, revision history, categories, logs are all maintained in database. Some wiki softwares just uses flat files.
Wiki can also be used as stand-alone application on a single computer without a web server. They are increasingly adopted in enterprise as collaborative software. common uses include project communication, intranets, and documentation, initially for technical users. It is implemented using many technolgies, list of wiki softwares available are
  • Java-based

    • JAMWiki is a J2EE application, It is a Java clone of the MediaWiki software and uses the same wiki syntax.
    • XWiki is a Java wiki engine with a complete wiki feature set (version control, attachments, etc.) and a database engine and programming language which allows database driven applications to be created using the wiki interface
  • JavaScript-based

    • TiddlyWiki is a HTML/JavaScript-based server-less wiki in which the entire site/wiki is contained in a single file.
    • Lively Wiki is based on Lively Kernel and combines features of wikis and development environments. Users can create and edit application behavior as well as other content.
  • .NET-based

    • FlexWiki was written in C#, uses the .NET Framework, and stores data in files or Microsoft SQL Server. The development stopped in 2009, but FlexWiki can still be downloaded.
    • Roadkill is written in C# using .NET 4, NHibernate and ASP.NET MVC 3 and is currently (July 2012) being actively developed. It can run using SQL Server, mySQL, SQLite and a number of other database engines. 
  • Perl-based

    • WikiWikiWeb, the first wiki and its associated software
    • Foswiki is a structured wiki, which enables users to create wiki applications.
    • ikiwiki, a "wiki compiler" - can use Subversion or git as the backend storage mechanism.
    • TWiki is a structured wiki, typically used to run a project development space, a document management system, a knowledge base, or any other groupware tool. Also available as a VMware appliance.
  • PHP-based

    • DokuWiki is aimed at the documentation needs of a small company. It uses plain text files and has a simple but powerful syntax which ensures the data files remain readable outside the wiki.
    • MediaWiki was custom-designed for the high-volume Wikipedia encyclopedia website; it is also used for all other projects run by the Wikimedia Foundation, which operates Wikipedia. It is also publicly available for use in other wikis, and has widespread popularity among smaller, non-Wikimedia wikis.
    • PhpWiki is a WikiWikiWeb clone in PHP.
    • PmWiki is a PHP-based wiki. Features include: easy installation/customization, designed for collaborative authoring and maintenance of web sites, and support for internationalization. Does not require a database.
    • TigerWiki is a minimalist and simple wiki framework, that has been discontinued. It spawned a number of forks, all of which have been discontinued as well.
    • WakkaWiki is a now-defunct PHP/MySQL-based lightweight wiki engine, that notably spawned a large number of forks, including WackoWiki and WikkaWiki.
    • MindTouch is an open-source application that began as a fork of MediaWiki; it has a C# back-end and a PHP front-end.
    • Banana Dance is open-source wiki software that combines CMS and Wiki features.
  • Python-based

    • MoinMoin is a wiki engine written in Python. Offers good access control based on user groups.
    • Zwiki is a Zope-based GPL wiki engine. It can integrate with the content management framework Plone, and supports several kinds of markup as well as WYSIWYG HTML editing
  • Other languages

    • ProjectForum is a self-contained wiki server for Windows, Mac OS X and Linux, written in Tcl, C and C++.
    • Swiki is written in Squeak. It runs on common platforms, including Mac, Windows, Linux, as well as others.
    • Wiki Server is proprietary software distributed with Mac OS X Server.
Reference for list of wiki softwares : Wikipedia

Sunday, September 4, 2011

Silverlight Introduction

My previous post explained about COM objects access in Silverlight application, since many doesn't know Silverlight, i will give small introduction to silverlight in this post.

Silverlight is a Browser-plugin which provides rich internet applications !, Its a client-side web technology, If you know Applets in java, this is something very similar to it but its based on Dot Net.

Silverlight is embedded in HTML, It can access client computer's resources (which i have explained as accessing COM objects in previous post), It provides rich user-interface. It supports media and graphics.

To make your web application more interactive, attractive you need silverlight, its works on any browser and any OS.

You must have browsed many web-sites and seen a box still loading with java symbol, thats Applet, similar to that Silverlight also loads parallel to web page. Silverlight runtime should be installed on client-system just like Java-runtime.

Silverlight uses XAML (Extensible Application Mark-up Language) for designing user-interface. Its simple and very easy to learn, It looks like XML + HTML. Operations to be performed in result of the interaction by user is programmed in C#.
eg: A button is placed and designed using XAML. What operations have to be performed for the click of that button is programmed using C#.

Visual studio can be used for developing a silverlight application. Choose New project-> silverlight application.
Interface should be designed in .xaml file, you can use drag-drop option of visual studio IDE and easily design interface without typing any XAML code or you can type code yourself.
Event handlers for these interface elements should be in .cs file i.e. C# code.

When you execute, it will dynamically create an HTML page and embed this silverlight application in it, but if you want to have your own HTML file, you can embed it this way.

<object height="90%"
type="application/x-silverlight-2"
data="data:application/x-silverlight-2,"
style="width: 85%; position:relative;left:5%;top:5%" >
<param name="source" value="Bin/Debug/Weighing machine.xap"/>
<param name="onerror" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="5.0.60401.0" />
<param name="autoUpgrade" value="true" />
a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.60310.0"
style="text-decoration: none;">
<img
src="http://go.microsoft.com/fwlink/?LinkId=161376"
alt="Get Microsoft Silverlight"
style="border-style: none"/>
</a>
<object>


anchor tag here comes as an alternate if your application is not loaded onto web page for some problem just like alternate text for an image tag.

Any doubts, can ask in comments.
Will try my level best to clarify.




Saturday, September 3, 2011

Silverlight 5 : In browser application for accessing COM objects

I have been working on Silverlight for some time now and particulary silverlight 5, elevated trust in "In-browser" applications. So trying to spread whatever knowledge I have on it

There are 2 ways of achieving COM objects access in your silverlight application
1. If you host your silverlight application on a website, you will get that access automatically.
you should select "host on a website" option while creating silverlight application in Visual studio.

2. If you are not planning to host it on a website and just want an HTML file or just silverlight application running in browser, following are the steps

  • Create a silverlight 5 project without selecting host on a website option
  • Type "regedit" in windows->run , registry editor opens, navigate to HKEY_LOCAL_MACHINE->Software->Microsoft->silverlight Double click on silverlight. You should create a new registry variable now right click and select new->DWORD(32-bit value) . Give name as "AllowElevatedTrustAppsInBrowser" and set value as 1
  • In project->properties, navigate to silverlight tab, check "Enable running application out of browser". Click on out of browser settings, in that check "Require elevated trust when running outside the browser".
  • Project->properties, navigate to Debug tab and select Dynamically create a web page or specific page and choose your HTML file which embeds silverlight application.
  • Project->properties, navigate to Signing, check Sign the XAP file, click on Create test certificate, you will be asked to enter password. After that, click on more details, install the certificate in Trusted publishers and Trusted root certification authorities stores.
Now you can design your interface with XAML and give functionality with C#, Code to access COM objects are as follows.

A reference to Microsoft.Csharp should be added.

using System.Runtime.InteropServices.Automation;

dynamic com=com = AutomationFactory.CreateObject("Word.Application");

word.Visible = true;

dynamic doc = word.Documents.Add();

string insertText = "Hello World from Silverlight 5!";
dynamic range = doc.Range(0, 0);
range.Text = insertText;

This code opens Microsoft word, creates new document and inserts "hello world from silverlight 5!" text.

Now when you run this application, it runs in-browser and performs the operation.

After developing the application, you would like to deploy it in some client system, how do you do it.

1. same step as explained above for "regedit", add that registry value.
2. You should also install certificate, but while developing Visual studio has done certificate creation and signing XAP file just by click of buttons, you have to do this step manually for deploying it to other system.
Steps to create certificate and signing XAP file.

Run Visual studio command line tools as administrator and type the following commands.
  • makecert -r -pe -n "CN=sampleapplication" -ss bharath -sr CurrentUser -a sha1 -sky signature -sv sample.pvk sample.cer
  • pvk2pfx -pvk sample.pvk -spc sample.cer -pfx sample.pfx
  • signtool sign /v /f sample.pfx C:\Users\bharath\Desktop\sample.xap
you will find sample.cer and sample.pfx certificate files C:\windows\system32 folder.
copy those 2 files along with XAP + HTML file to the client system where you would like to run it.

double click on sample.cer file to install it in Trusted root certification authorities store
and double click on sample.pfx file to install it in Trusted Publishers store.

now you can open HTML file in-browser and your application will run fine.