<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Chris Johnston &#187; Articles</title>
	<atom:link href="http://www.fuzzylizard.com/archives/category/articles/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.fuzzylizard.com</link>
	<description>Web development and design with a little VFX thrown in for fun</description>
	<lastBuildDate>Sun, 30 Oct 2011 14:23:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Java 101: MVC model2</title>
		<link>http://www.fuzzylizard.com/archives/2005/10/06/641/</link>
		<comments>http://www.fuzzylizard.com/archives/2005/10/06/641/#comments</comments>
		<pubDate>Thu, 06 Oct 2005 06:18:42 +0000</pubDate>
		<dc:creator>Chris Johnston</dc:creator>
				<category><![CDATA[Application Development]]></category>
		<category><![CDATA[Articles]]></category>
		<category><![CDATA[J2EE]]></category>

		<guid isPermaLink="false">http://www.fuzzylizard.com/?p=641</guid>
		<description><![CDATA[So what exactly is MVC? In short, it stands for Model-View-Controller and it is an implementation of the layered architecture I was talking about in my first Java 101 entry. Overview Here is a very quick rundown on what each term in the MVC pattern means: Model &#8211; this represents the business rules that you [...]]]></description>
			<content:encoded><![CDATA[<p>So what exactly is MVC? In short, it stands for Model-View-Controller and it is an implementation of the layered architecture I was talking about in my <a href="http://www.fuzzylizard.com/archives/2005/10/02/638/">first Java 101 entry</a>.</p>
<h3>Overview</h3>
<p>Here is a very quick rundown on what each term in the MVC pattern means:</p>
<ul>
<li><strong>Model </strong>&#8211; this represents the business rules that you are trying to code. Another way of looking at it is that the Model is what does all the work. It is what performs any and all transformations on the data that your application is required to handle.</li>
<li><strong>View </strong>&#8211; the view represents what the user sees and it is responsible for the collection and display of data for and from the model.</li>
<li><strong>Controller </strong>&#8211; the controller is what ties everything together, it is the link between the view and the model.</li>
</ul>
<p>One way of looking at MVC is that the user views a web page which displays and/or collects data. When the user submits this page, it is submitted to the controller which knows what to do with the data collected by that page. The controller does not know how to transform the data, but it knows which part of the model contains this knowledge and passes the data onto the model. The model then transforms the data. The controller, based on whether the transformation was a success or not, determines which part of the view to call and returns to that view a piece of the model in order for the view to display more data to the user. (Did you follow all of that?).</p>
<h3>An Example</h3>
<p>Here is a quick example: A user login page. </p>
<ol>
<li>The user sees the login page with a form that contains a field for the username and the password.</li>
<li> The user fills in this data and submits it to the User controller with an action of login.</li>
<li> The User controller knows to pass this information on to the <a href="http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html">loginDAO</a> which attempts to verify that user against the database. </li>
<li>If the user exists in the data, the model instantiates a User object and returns that object to the controller.</li>
<li> The controller then tells Tomcat to load the homepage and sends the <a href="http://java.sun.com/blueprints/corej2eepatterns/Patterns/TransferObject.html">user object</a> to the resulting jsp page.</li>
<li> The view then shows a nice little &#8220;Welcome back Sue&#8221; message for the user to see. The name in the message comes from the user object.</li>
<li>If the user does not exist in the database, the model returns an error and the controller instantiates the error page with an appropriate message to the user.</li>
</ol>
<p>The general idea behind the MVC pattern is to abstract and remove as many dependencies as possible from between the layers. If done correctly, the entire web interface could be removed and a Swing ui could be put in its place with no code modifications needed on the part of the model. You may need to code up a few different controllers, but the model should not have to change. Likewise, you should be able to replace the entire model without having to change the view. This is accomplished because the point of dependency is the controller which sits in the middle.</p>
<p>I have listed a few links below for more information.</p>
<h3>Reference</h3>
<ul>
<li><a href="http://www.amazon.com/gp/product/0596005407/002-4770438-4443213?v=glance&#038;n=283155&#038;n=507846&#038;s=books&#038;v=glance">Head First Servlets and JSP: Passing the Sun Certified Web Component Developer Exam (SCWCD)</a> &#8212; this is an excellent book that discusses the MVC pattern and how to implement it using JSPs and Servlets.</li>
<li><a href="http://en.wikipedia.org/wiki/MVC">Model-view-controller</a> &#8212; Wikipedia entry on MVC</li>
<li><a href="http://www.javaworld.com/javaworld/jw-12-1999/jw-12-ssj-jspmvc.html">Understanding JavaServer Pages Model 2 architecture</a> &#8212; a JavaWorld article from a few years ago that discusses the MVC model 2 pattern</li>
<li><a href="http://struts.apache.org/">Struts</a> &#8212; Struts is probably the most popular MVC implementation for Java web development</li>
<li><a href="http://java.sun.com/blueprints/corej2eepatterns/Patterns/DispatcherView.html">Core J2EE Patterns &#8211; Dispatcher View</a> &#8212;  a pattern in Sun&#8217;s Core J2EE Patterns that allows you to implement the MVC design pattern</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.fuzzylizard.com/archives/2005/10/06/641/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java 101: Layered Architecture</title>
		<link>http://www.fuzzylizard.com/archives/2005/10/02/638/</link>
		<comments>http://www.fuzzylizard.com/archives/2005/10/02/638/#comments</comments>
		<pubDate>Sun, 02 Oct 2005 05:38:39 +0000</pubDate>
		<dc:creator>Chris Johnston</dc:creator>
				<category><![CDATA[Application Development]]></category>
		<category><![CDATA[Articles]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.fuzzylizard.com/?p=638</guid>
		<description><![CDATA[I am going to try and start writting a series of very short tutorials on some of the things that I had trouble with when I was learning enterprise Java. The first of these is on what having a Layered Architecture means and why you should implement one. Hopefully this will be the first article [...]]]></description>
			<content:encoded><![CDATA[<p>I am going to try and start writting a series of very short tutorials on some of the things that I had trouble with when I was learning enterprise Java. The first of these is on what having a Layered Architecture means and why you should implement one. Hopefully this will be the first article in a series.</p>
<h3>Layered Architecture</h3>
<p>Layered Architecture is a term that you hear all the time in the world of Java, but what does it mean? In a nutshell, it is about putting code into layers&#8212;one layer for all the presentation code, one layer for the persistence code, one layer for the business rules, one layer for the object model, one layer for services, and other layers. It is a way of organizing your code that carries several benefits when done correctly.</p>
<h3>Organized Code</h3>
<p>Why can&#8217;t I just put all my code in the same place? This works well for a few classes, but once you have a few more classes, and then a few more, and a few 100 more, you need to organize those classes somehow. Layers is one way to do this. In Java, teh word layers translates to packages. So, in order to create these layers, you simply put your code into different packages. As an example, you could create a package called com.foo.presentation and put all your presentation code into it. Here is an example list of packages for a new application:</p>
<ul>
<li>com.foo.presentation</li>
<li>com.foo.business</li>
<li>com.foo.persistence</li>
<li>com.foo.objectmodel</li>
<li>com.foo.services</li>
</ul>
<h3>Abstraction</h3>
<p>The better reason for organizing your code into layers is for abstraction and encapsulation. This allows you to keep dependencies at a minimum and allows you join the layers through abstraction instead of through direct instantiation. Basically this means that you persistence layer can exist independently of any of the layers above. And the layers above call the code in the persistence layer through an interface instead of through concrete classes. In a component diagram, this means that you would have dependency arrows going down through the layers instead of both ways. Below is a diagram showing what I mean.</p>
<p><img src='http://www.fuzzylizard.com/wp-content/LayeredArchitecture.jpg' alt='Component Diagram of a Layered Architecture' /></p>
<p>As you can see from the diagram, all the arrows either travel down through the layers or to the two side layers. These downward arrows represent the direction of dependencies through the application. The advantage of this is that if I build an application correctly, I should be able to swap out any of the layers and replace with entirely different code without breaking any of the other layers. So for example, if I am using Hibernate as my persistence layer, if I set up the correct interfaces I should be able to swap in something like Top Link or iBatis and DAOs and the entire application should continue to work. This is the power that a layered architecture gives you.</p>
<p>This is a very simple introduction to the concept of layered architecture, there are entire books that can be written on the subject. The best of which is probably <em><a href="http://www.amazon.com/exec/obidos/tg/detail/-/0131489062/qid=1128231099/sr=8-1/ref=pd_bbs_1/104-4355390-3185564?v=glance&#038;s=books&#038;n=507846">Applying UML and Patterns : An Introduction to Object-Oriented Analysis and Design and Iterative Development (3rd Edition)</a></em> by Craig Larman. This is one of those books that every software developer should read. It introduces not only Object-Oriented analysis and design using UML, but also design patterns and speaks at length about layered architectures in software development.</p>
<p>Feel free to leave comments on what I have written. If you have questions or issues with/about what I have written, please let me know through the comments section.</p>
<h3>Resources and Links</h3>
<ul>
<li><a href="http://www.awprofessional.com/articles/article.asp?p=167844&#038;rl=1">MVC and Layered Architectures in Java</a></li>
<li><a href="http://en.wikipedia.org/wiki/MVC">Model-View-Controller</a> &#8212; and implementation of a layered architecture</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.fuzzylizard.com/archives/2005/10/02/638/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Securing your Linux box</title>
		<link>http://www.fuzzylizard.com/archives/2004/11/09/392/</link>
		<comments>http://www.fuzzylizard.com/archives/2004/11/09/392/#comments</comments>
		<pubDate>Wed, 10 Nov 2004 04:11:50 +0000</pubDate>
		<dc:creator>Chris Johnston</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.fuzzylizard.com/archives/2004/11/09/392/</guid>
		<description><![CDATA[Tips and tricks to help you secure a Linux machine against unwanted SSH attacks.]]></description>
			<content:encoded><![CDATA[<p>Everyone knows that Linux is secure, but this does not mean that your computer is uncrackable. Even though Linux is more secure than Windows, there are still things you can do to prevent your computer from being attacked and to prevent your computer from being compromised. This article is going to list a few things that you can do to help secure your Linux computer against an SSH attack from the outside.<br />
<span id="more-392"></span></p>
<p>*hosts.allow and hosts.deny*<br />
This is probably your first line of defense. These two files control who can gain access to your computer in the first place. They do this by restricting the people according to their IP address, IP range, or domain name.  In order for them to work correctly, you really need to use them both together. Block everyone using the hosts.deny file and then only let those people in that you trust using the hosts.allow file. Check the man pages for both files, but here are two simple examples to show you how the files work. If you wanted to block everyone from accessing your computer except for those on your internal network, this is how the files would be setup:</p>
<p>hosts.deny</p>
<pre>ALL: ALL</pre>
<p>hosts.allow</p>
<pre>ALL: LOCAL, 192.168.0.</pre>
<p>You will notice that for the internal network IP, I did not specify an entire address. I left the last digit off. This allows you to specify a block of addresses. In this case, anyone trying to access the computer whose IP address begins with 192.168.0 will be allowed. Basically, this allows anyone on your internal network to gain access (assuming that you network uses 192.168.0).</p>
<p>In addition, you can also specify domains and/or outside IP addresses and IP address ranges. For instance, if the company that you work for has a domain called www.foo.com, then you could specify that in the hosts.allow file. This would allow you to connect from work. Or, if your company only uses IP addresses, then you could put that in as well. Here is what the file could look like:</p>
<pre>
ALL: LOCAL, 192.168.0.
ALL: .foo.com, 123.456.789.
</pre>
<p>This establishes where you can connect to your computer from. But what if you don&#8217;t want to restrict the entire world from connecting? Then the next best thing is to restrict how they can connect. For this, we secure SSH.</p>
<p>*Securing SSH*<br />
For this, you will need to edit your sshd_config file. This is usually located in /etc/ssh/sshd_config. There are two key areas that you will want to change. The first will look like this:</p>
<pre>
# Authentication:
#LoginGraceTime 120
#PermitRootLogin no
#StrictModes yes
</pre>
<p>What you want to do here is to uncomment the <code>PermitRootLogin</code>. This will prevent anyone from logging onto your computer over ssh as root. This means that in order to gain root access, someone will have to first login using a regular user account and then su to root.</p>
<p>The second thing you can do to secure SSH is to which users/groups can login and which can not. To do this, you use four commands &#8211; <code>AllowGroups</code>, <code>AllowUsers</code>, <code>DenyGroups</code>, <code>DenyUsers</code>. You use the <code>AllowGroups</code> and <code>AllowUsers</code> to explicitly state which users and which groups can log in through SSH and you use the <code>DenyGroups</code> and <code>DenyUsers</code> to deny all other accounts from logging in.  And these you can place at the end of your sshd_config file. An example might look like this:</p>
<pre>
AllowGroups users foo
AllowUsers foo
DenyGroups root bin postrges mysql nobody apache
DenyUsers root bin postgres mysql nobody apache
</pre>
<p>And that is all that there is to it. Listed above are two simple tricks to securing a Linux computer. However, they are not guaranteed to make your computer completely cracker proof. There are many more things that you will need to do in order to completely secure your computer against attack (proper firewall, secure all open ports, use secure passwords, etc). But the above is a very good start and should be a part of every linux users toolbox when it comes to securing a computer on the Internet.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fuzzylizard.com/archives/2004/11/09/392/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to do: Group Based Authentication and Authorization</title>
		<link>http://www.fuzzylizard.com/archives/2004/07/13/343/</link>
		<comments>http://www.fuzzylizard.com/archives/2004/07/13/343/#comments</comments>
		<pubDate>Tue, 13 Jul 2004 01:59:54 +0000</pubDate>
		<dc:creator>Chris Johnston</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.fuzzylizard.com/archives/2004/07/13/343/</guid>
		<description><![CDATA[Someone on The List asked how to setup what they called &#8220;Multi-level login security&#8221;. Many Content Management Systems these days have this very feature. They will have a few people who are Administrators and can access everything on the site, another group of people who are editors who can only access a few things and [...]]]></description>
			<content:encoded><![CDATA[<p>Someone on <a href="http://www.evolt.org">The List</a> asked how to setup what they called &#8220;Multi-level login security&#8221;. Many Content Management Systems these days have this very feature. They will have a few people who are Administrators and can access everything on the site, another group of people who are editors who can only access a few things and then you have authors who can only submit stories and edit their own stories. In addition, this type of security needs to allow uses to be moved from group to group while keeping this totally transparent to the user. The question is though, how do you set this up on your site? This is actually not that hard to do. It takes three database tables and a little bit of forethought. We will start with the theory behind this simple technique, move on to the database tables, and end with a simple way of implementing this on a web site.<br />
<span id="more-343"></span><br />
To begin with, in order to implement this, you need to put some separation between a user and what they can access. This is done by creating groups and then assigning a user to one or more groups, depending on what you want that user to be able to do on the site. For this article we will use the ones mentioned above, namely Admin, Editor, and Author.</p>
<p>Once you have your groups, you need to decide which parts of your site can be access by each group. Obviously, an administrator can access everything while an author can only submit stories. While an editor can access an authors submitted story before it is published. Each part of your site needs to be assigned to a Group. Just remember this for now, we will discuss how to do it a little later. First, let&#8217;s discuss how to set up our groups and users in a database.</p>
<p>If you remember, the idea behind this is to separate the users from the groups that they belong to. This is done by creating three tables in a database. One table to hold the users, one table to hold the groups, and the last table to assign a user to a group. Here are what the tables might look like:</p>
<pre>User
  +--------+----------+----------+
  | userID | username | password |
  +--------+----------+----------+
  | 1      | foo      | bar      |
  +--------+----------+----------+
</pre>
<pre>Groups
  +---------+----------+-------------+
  | groupID | group    | description |
  +---------+----------+-------------+
  | 1       | admin    |             |
  | 2       | editor   |             |
  | 3       | author   |             |
  +---------+----------+-------------+
</pre>
<pre>User_Groups
  +--------+-------+
  | userID | group |
  +--------+-------+
  | 1      | 2     |
  | 1      | 3     |
  +--------+-------+
</pre>
<p>As you can see from the tables above, this setup allows a user to belong to more than one group. This is what allows a user to progress through positions on the site. A user can start as an author and then move up to an editor while still retaining all the abilities of being an author. In addition, it allow you to isolate a user as an editor. This would mean, in our little example, that that user could access and edit stories, but they would not be able to submit any of their own. For complicated sites, this can be an advantage.</p>
<p>Now that you have your users and groups all setup in the database, how do you translate this to the rest of your site?</p>
<p>First, you need to have your users login to your website. When they login, you check their username and password against the database. If they are a valid user, you then retrieve the list of groups that they belong to. This is the important part. You need to place that list of groups into a session variable that will be accessible from every page on your site. For security reasons, you don&#8217;t really want to store this kind of information in a cookie as it is too accessible to a malicious user. Therefore, to implement this, you need to pick a language that supports user sessions.</p>
<p>Now that you have the list of groups a user belongs to, how do you enforce this against pages on your site? There are many different ways of doing this depending on how your site is setup and what kind of information you need to restrict. I am simply going to illustrate this by making it so that all that needs to be restricted is access to individual pages.</p>
<p>The easiest way to enforce your groups is to assign each page (or group of pages, depending on their functionality) to a group. So for the author, all the pages that work together to allow an author to submit a story would be assigned to the author group. On a praticle level, this can be as simple as setting a variable at the top of your page. This is how you would do this in php:</p>
<p><code>< %php $group = "author" %></code></p>
<p>Once the variable is set, you need to validate your user against that group. How you do this will depend on how you implement your list of groups that a user belongs to. Different languages will have different ways of handling lists and searching for elements in a list. But basically, all you want to see is if the value of the group variable matches an element in the users list of groups. If it does, the user belongs to the same group as the page and is able to access that page. If a match can not be found, then you can redirect the user to an error page or back to the homepage.</p>
<p>This is the most robust method of authentication and authorization that I have come across so far. And it is fairly easy to implement. So if you are looking for a method of restricting different parts of your site to different kinds of users, give this a try. You will quickly see the advantages that it holds.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fuzzylizard.com/archives/2004/07/13/343/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

