Naren Cool Geek - Tips on .NET and Java development.
This is page 4 of the discussion. Read the opening post
After Hours
This is page 4 of the discussion. Read the opening post
by narendrn
This is one of the most common and trivial challenges that developers face in any enterprise application development ? How to store passwords in database in a safe and secure manner?
It?s common sense to reconcile that passwords should not be stored as plain text as it would be possible for anyone to hack the passwords if he has access to the database table.
One option is to encrypt the passwords using a symmetric key and decrypting it for comparison during password authentication. But then we have the problem of securely storing the secret symmetric key, because if the key were compromised all the passwords would become accessible.
The most common and simple solution to this problem is to ?hash? the passwords before storing it in database. MD5 or SHA-1 hash algorithms can be used to perform a one-way hash of the password. To compare passwords for authentication, you retrieve the password entered by the user and hash it; then you compare the hashed value with the hashed value in the database. This method is quite foolproof and safe as it?s impossible to convert a hashed entry into its original value.
But still it possible for a hacker to perform a brute-force dictionary attack on the passwords and guess some passwords. More info on this here.
To hinder the risk of a dictionary attack, it is important that password contain special characters that are difficult to guess. Another option is to ?salt? the password before hashing it. Salting the password means adding some padding data in front or back of the password to create a new string that is hashed and put inside the database table. This padding data could be a random generated number or the userID of the user itself. This makes the dictionary attack much difficult to succeed.
Recently there was a lot of furor over the security of MD5 algorithm. The problem is that of MD5 hash collisions. The problem that arises is the following:
Since what we did is take the characters in some text, however many they are, and producing 128 characters out of them somehow, there will be lots of texts that give the same set of 128 characters, and hence have the same MD5 value. I.e. the hash-function is not 1-1 as we say. So how do we know that the file we received is not one of those other millions of files that have the same MD5 value? The simple answer is, we don?t. But what we believe is that the chance that this other file will be meaningful is miniscule. In other words, we believe that even if someone were to tamper with our file on its way to us, they would not be able to produce a file that has the same MD5 value and can harm u.
But the site below shows how two different postscript files end up having the same MD5 hash. http://www.cits.rub.de/MD5Collisions/
So, what are the other options? Tiger and SHA-2 are still considered to be safe hash functions to use. One could possibly also apply a number of hash-functions to the same file, as secondary checks.
by hcabral00
Better subject line would be "Naive windows developers".
Every platform has its own design decisions. Anyone trying to
develop for a platform without knowing the basics is going to be in
trouble.
To answer your "quirks":
1) ports below 1024 are special ports reserved to trusted
servers. Remember that Unix machines are multi-user, it's not
only you who may use the machine. Therefore, you don't anybody
able to start a trojan horse passing as a web server in port 80.
2) Design decision, for better or for worse. You protect against
deletion by using the acess control facilities Unix provides you
as a multi-user system.
4) This is so your environment doesn't get "polluted" by spurious
scripts. You run a script, it gets its own environment, mess it
up at its own will and when it finishes you have your environment as it
was before. Neat, isn't it?
5) Yeah, for some reason windows decided to go for the \r\n. Why? Beats me...
by narendrn
Recently, I started using Rational Software Modeller for UML modelling. The UML diagram files that the tool creates have a *.emx extension. I was expecting it to be some proprietary binary format, but when I opened the file in Notepad, I was suprised to see a XML format!!!. It looks like even IBM has decided to make its UML models XMI compatible.So what exactly is XMI?
The XML Metadata Interchange (XMI) is an OMG standard for exchanging metadata information via Extensible Markup Language (XML). It can be used for any metadata whose metamodel can be expressed in Meta-Object Facility (MOF). The most common use of XMI is as an interchange format for UML models, although it can also be used for serialization of models of other languages (metamodels).
Here's an excerpt from Wikipedia : http://en.wikipedia.org/wiki/XMI
XMI can be used to transfer UML diagrams between various modeling tools.At the moment there are severe incompatibilities between different modeling tool vendor implementations of XMI, even between interchange of abstract model data. The usage of Diagram Interchange is almost nonexistent. Unfortunately this means exchanging files between UML modeling tools using XMI is rarely possible.
by narendrn
An aggregation is a special form of association between classes that represents the concept of "WHOLE -PART". Each object of one of the classes that belong to the aggregation (the composed class) is composed of objects of the other class of the aggregation (the component class). The composed class is often called "whole" andthe component classes are often called "parts".
A simple aggregation is an aggregation where each part can be part of more than one whole.
Composition is a special kind of aggregation in which the parts are physically linked to the whole. So, a composition defines restrictions with regard the aggregation concept:
- A part can not simultaneously belong to more than one whole.
- Once a part has been created it lives and dies with its whole.
by narendrn
In one of my recent projects, there was a business requirement to identify the language of a text document automatically and segregate them.
I tried to do some research on the internet and came up with some open-source tools that can help in identifying a language. One such popular tool is "Lingua" - open source and written in Pearl.
Language identification happens by searching for common patterns of that language. Those patterns can be prefixes, suffixes, common words, ngrams or even sequences of words. More information about n-grams can be found here.
Other interesting links on the same subject:
http://staff.science.uva.nl/~jvgemert/mia_page/LangTools.html
http://odur.let.rug.nl/~vannoord/TextCat/Demo/
http://staff.science.uva.nl/~jvgemert/mia_page/demo.html#Lid
by narendrn
Recently some of the developers in my team were struggling with a javascript issue.
The problem was very simple. There were 2 textfields on the screen - one after the other. Both of which have an OnBlur call to a routine that simply validates that the fields are not left blank.
Now when the first field is left blank and a 'tab' is pressed, then the javascript goes into a recursive loop !!! The loop is started because we used the focus method in the javascript function: tabbing out of field one fires onblur and sets focus to field two. The function focusses back to field one, "taking focus off field two", which fires a new onblur, which makes your function put focus back on field two firing onblur for field one. This goes on forever.
The solution to this is very simple - Just keep a global variable that points to the current object being validated and check that inside the function. Here is the script for doing so:
var currentObjectName='';
function NoBlank(object, label)
{
if (currentObjectName!='' && currentObjectName!= object.name) return;
currentObjectName=object.name;
if (object.value == "")
{
lc_name = label;
alert(lc_name + " input field cannot be blank!")
object.focus();
return false;
}
currentObjectName='';
return true;
}
by narendrn
During the good old days of WinNT, MTS used to provide the middle layer for distributed computing using MS technologies. The MTS (Microsoft Transaction Service) environment used to sit in between the client and database and provide distributed transaction services, object pooling, security and other services.
With Windows 2000, MTS was upgraded to COM+. While MTS was actually an add-on to Windows NT, COM+ was natively supported by Windows 2000. This simplified the programming model quite a bit. It was often said that MTS + COM = COM+.
Thus MTS/COM+ is the equivalent of EJB in the J2EE world.
In .NET, COM+ components can be written as .NET component services. The "System.EnterpriseServices" namespace provides us with classes that enable us to deploy a .NET component as a COM+ component. Existing COM+ components can be accessed using .NET remoting and COM-Interop.
by narendrn
Generally developers are used to deploy J2EE applications by dropping the war file or the application folder directly into the webapps directory of Tomcat.
But it is possible for the application to be deployed in a separate location also - even on a separate logical drive.
We just have to create a XML fragment file and place it in the following folder:
$CATALINA_HOME/conf/[enginename]/[hostname]/[applicationName].xml
If one opens this folder, then we can see the context XML descriptors of all applications deployed on Tomcat.
The files typically contain the docBase attribute that points to the physical location on the hard-disk and the web logical path.
<context path="/ASGPortal" docbase="ASGPortal">
So, if want to deploy the above webapp on a separate path, say d:/myApps/ASGPortal, I copy my webapp folder there and change the docBase attribute in Context. Zimple...... :)
Note: This comes really handy when we are using a Source-control tool and the check-in/check-out folders are not under Tomcat.
by martinfitzg
Does any one know is it possible to do this with
jboss application server version 4.* ?
by jim-mn
And if I'm on Linux, so can't use Windows-style drive mappings, what does the path to the physical location look like? What if it's not on the same box; maybe on a Samba share?
Jim
by jchapple
To see what the path would look like on a xNIX server:
find the location of where your would like to put your files and issue the command pwd.
In UNIX (and Windows too) you mount remote file stores via NFS (older Windows you just map a drive, newer windows you can map external stores to a directory as well) and the O/S makes it look local to you. So, create a common share, mount it up and path out to it. Although you can share the Tomcat container with all the servers, it will become a pain. It would be best to create one for each server by using the command $hostname in the xNIX path. The reason, temp files, log files, work dirs, etc tend to collide, and itis just easier to separate them out. You still gain a common location to view all the files though, which is better than logging into many servers to see the Tomcat apps.
by narendrn
A recent developer asked me why should one use ForwardAction, when one can directly give a link to a separate JSP directly.
The reason is: When we use ForwardAction, the ActionServlet in Struts intercepts the request and provides appropriate attributes such as Message Resource Bundles and also FormBeans.
If we directly give a reference to a JSP page, then the behavior of the Struts tags may become unpredictable.
Another reason when ForwardAction would be necessary is when direct access to JSP files are prevented from direct access by using the "security-constraint" tag in web.xml.
by narendrn
In quite a few projects in the past, I have directly accessed the DAO methods from the Struts Action classes. This strategy makes a lot of sense when we are only retrieving data from the database and populating beans that would be binded to the JSP page.
But there are many who consider including any persistance code or business logic code in the Action classes as 'sacrilege'. Many prefer having a business service layer (aka business delegate) layer that encapsulates all persistance and business-logic.
But for simple CRUD operations, the service layer just becomes a thin layer around the DAO layer. But nevertheless, there are advantages of adding this business service layer.
Another reason this extra layer can be helpful is in a real-life scenario- For e.g. A more complex application there are often other business operations you might want to perform besides just calling you DAO. For example, maybe when an "update" is done you need to call some process that sends out an e-mail or some kind of notification. If you don't use a Service class you are stuck now between coding this business logic either in your Action class or in the DAO. Neither of those places is really a good place for that kind of logic - hence we provide an extra service class to handle business rules that shouldn't be in the Action and don't belong in a DAO. Of course for rapid development, you could possibly skip the Service classes and just use the DAOs directly within your Action.
But there is no absolute right or wrong answer. This reminds me of a quote:
"I'm always wary of absolutes. Know the rules, know the reasons behind the rules, know when and why to break the rules, proceed accordingly."
Accessing DAO directly from the Action classes usally make sense for read only kind of data. Infact, Fast Lane Reader Pattern advocates the same thing.
Any data which potentially might have business logic or might participate in transactions should not be directly accessed from the Action class.
~munish
Tech Spot
by zaidatheer
Bypassing the Business Delegate layer (Business service layer) can save some time, HOWEVER, adding a small chunk of business logic might enforce you to RE-design the project architecture and include the business logic service layer. Even the simple CRUD operations require some business logic sometimes, I will state 2 simple examples:
1. Editing & updating user email : In this case we need to make sure that the submitted email has not been used by other user but it might be already assigned to the same user, in that case we need a business process to validate this condition, then we can throw EmailHasBeenUsedException from the Business layer to the struts action.
2. Deleting an Item which has spareparts children (parent-child relationship): this is a delete operation, and we need to make sure that the deleted item has no children dependant on it, in that case the Business logic layer can fit in this simple daily-used requirement.
Conculsion: Adding a business service layer is, in my opinion, a very good practice. Using the Refractor menu (which is available in most of the IDEs such Eclipse and NetBeans) can simplify the process of adding this layer.
Regards,
Zaid Omar
by narendrn
In quite a few design brainstorming sessions, the debate between Spring and EJB results in a deadlock. There are developers who are damn passionate about Spring and hate EJBs. Let?s have a look at the main important differences between the two:
1) Distributed Computing ? If components in your web-container need to access remote components, then EJB provides in-build support for remote method calls. The EJB container manages all RMI-IIOP connections. Spring provides support for proxying remote calls via RMI, JAX-RPC etc.
2) Transaction Support ? EJB by default uses the JTA manager provided by the EJB container and hence can support XA or distributed transactions. Spring does not have default support for distributed transactions, but it can plug in a JTA Transaction manager. Both EJB and Spring allows for declarative transaction demarcation. EJB uses deployment descriptor and Spring uses AOP.
3) Persistance ? Entity Beans provide CMP and BMP strategies, but my personal experience with these options has been devastating. Entity Beans are too slow!!!..They just suck..
Spring integrates with Hibernate, IBatis and also has good JDBC wrapper components (JdbcTemplate).
4) Security ? EJB provides support for declarative security through the deployment descriptor. But again, this incurs a heavy performance penalty and I have rarely seen projects using EJB-container managed security.
by pkrouse
by ivank2139
I find that Spring makes it much easier to use POJO's and to test more
of the application with JUnit. Our Junit tests have been a big
selling point for our project when compared to other projects.
And the unit testing allows us to confront some problems earlier.
In general, Spring has allowed us to write slightly more verbose but
simpler code. This is important since many of our developers are
junior level.
2 years ago when we started the J2EE hosting service at Florida
Department of Environmental Protection I specifically discouraged the
use of EJB's in favor of simpler JDBC methods. This had its own
problems, namely the proliferation of varieties of DAO's in use.
Now that EJB3 is out we are considering it again. Along the way
though, since this is an Oracle shop, TopLink has become our preferred
persistence layer. It works fine, is simple to use, test, and
easy to understand.
Ivan S Kirkpatrick
System Architect FDEP
by jitrc
As touched upon above, many of the objections against EJBs (e.g., Entity Beans, slow/difficult Unit Testing, etc ...)have been addressed in EJB 3. Now, I guess Agile practices like Test Driven Development can also be used with EJBs more effectively (without any need for in-container testing). So, I would say EJBs still remain viable.
This discussion is closed to new replies.
Sort by Trending