<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Struts, JAAS, Tomcat: getting acquainted</title>
	<atom:link href="http://technology.amis.nl/2004/11/17/struts-jaas-tomcat-getting-acquainted/feed/" rel="self" type="application/rss+xml" />
	<link>http://technology.amis.nl/2004/11/17/struts-jaas-tomcat-getting-acquainted/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=struts-jaas-tomcat-getting-acquainted</link>
	<description></description>
	<lastBuildDate>Fri, 12 Apr 2013 10:04:09 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
	<item>
		<title>By: orbit</title>
		<link>http://technology.amis.nl/2004/11/17/struts-jaas-tomcat-getting-acquainted/#comment-1113</link>
		<dc:creator>orbit</dc:creator>
		<pubDate>Fri, 18 Sep 2009 18:48:27 +0000</pubDate>
		<guid isPermaLink="false">/?p=259#comment-1113</guid>
		<description><![CDATA[Thought I&#039;d share my experience with getting JAAS/Tomcat 6/Eclipse working.  Not everything in here is crucial to your implementation, but I figured this post will at least put it all together.  Many articles and blogs left me frustrated with just covering pieces of the solution, and not showing me the necessary connections between them.

To begin, I installed Java (say version 6.0 or better), and then Eclipse (or MyEclipse, if you like).  Then I updated Eclipse with the Subversive plug-in, to access my subversion repository to persist and pull my code onto different machines as I travel.
(e.g. https://failship.company.com/repo).

Upon checkout, I created a Dynamic Web Project or whatever name Eclipse provides for a basic web application.  Take your time here and step through each of the wizard screens, because some setting changes are subtle and have major pain-in-the-butt ripple effects.

You&#039;ll have to create the basic LoginModule and Principal implementations to support your custom login code.  That information was provided everywhere on the Web.  My frustration was in putting it all together.  Anyway, out of the scores of resources I used to investigate, I found this one to be pretty concise:

  http://blog.frankel.ch/tech/dev/java/jee/custom-loginmodule-in-tomcat

If you are going to test with Tomcat 6.0, you must add the following tag to the conf/context.xml file.

	&lt;Loader delegate=&quot;true&quot;/&gt;

Otherwise, you might get some

	&quot;java.lang.ClassCastException: org.apache.catalina.util.DefaultAnnotationProcessor  cannot be cast to org.apache.AnnotationProcessor&quot;

exception.

While you have context.xml open, you will have to add a &#039;Realm&#039; for Container Security, to enable our LoginModule secure access.  The 1st step is to enable the JaasRealm, typically by pasting in the existing entry as follows:

	&lt;!-- Inserted to enable MyAccessLoginModule.  You will have to launch tomcat
		with -Djava.security.auth.login.config= pointing to the jaas.config file: --&gt;
	&lt;Realm className=&quot;org.apache.catalina.realm.JAASRealm&quot;
		appName=&quot;MyAccess&quot;
	    	userClassNames=&quot;com.company.myAccess.realm.MyAccessUserPrincipal&quot;
	    	roleClassNames=&quot;com.company.myAccess.realm.MyAccessRolePrincipal&quot;&gt;
	&lt;/Realm&gt;

Next, I had to create a jaas.conf file to declare my LoginModule implementation.  Notice that this has the same name as the &quot;appName&quot; provided in the &lt;realm&gt; definition above.  Here&#039;s the contents of jaas.conf:

	/** Login Configuration for the JAAS Sample Application **/
	MyAccess {
	    com.company.myAccess.realm.MyAccessLoginModule requisite debug=true;
	};

The realm also needs to know how to find the jaas.config file and it does this through the Java system property, set as a JVM argument, for the variable &quot;java.security.auth.login.config&quot;.  You can set this, in eclipse by configuring a &quot;Server&quot;, typically through the Window-&gt;Preference menu (or in MyEclipse under its preferences).  The JVM takes a -D argument, to define the variable, as in:

	-Djava.security.auth.login.config=C:&quot;/Documents and Settings/sandrews/Workspaces/MyEclipse Blue/myAccess-20090902/jaas.config&quot;

While youâ€™re here, you may want to add any custom defined variables for your web application.  My LoginModule read the tomcat-users.xml file as well, so I designated it with the follow arguments:

	-DTomcatUsersXmlFile=C:&quot;/Program Files/Apache Software Foundation/Tomcat 6.0/conf/tomcat-users.xml&quot;

Again, this last argument was custom to my application, so it&#039;s necessary for your web app.

Next, edit the data source for your user authentication, as in conf/tomcat-users.xml, to add the role, say &#039;myAccess&#039;, and the user, like &#039;bsmith&#039; for example:

    &lt;tomcat-users&gt;
        &lt;role rolename=&quot;myAccess&quot;/&gt;
        &lt;user name=&quot;bsmith&quot; password=&quot;123qwe&quot; roles=&quot;myRole&quot;/&gt;
    &lt;/tomcat-users&gt;

Your web application&#039;s WEB-INF/web.xml should set the security restrictions,
as in:

	  &lt;!-- Define a Security Constraint on this Application --&gt;
	  &lt;security-constraint&gt;
	    &lt;web-resource-collection&gt;
	      &lt;web-resource-name&gt;Secured resources&lt;/web-resource-name&gt;
	      &lt;url-pattern&gt;/jsp/*&lt;/url-pattern&gt;
	      &lt;url-pattern&gt;/html/*&lt;/url-pattern&gt;
	      &lt;url-pattern&gt;/index.jsp&lt;/url-pattern&gt;
	    &lt;/web-resource-collection&gt;
	    &lt;auth-constraint&gt;
	      &lt;role-name&gt;myRole&lt;/role-name&gt;
	    &lt;/auth-constraint&gt;
	  &lt;/security-constraint&gt;
	  &lt;security-constraint&gt;
		&lt;web-resource-collection&gt;
		&lt;web-resource-name&gt;Unsecured resources&lt;/web-resource-name&gt;
		&lt;url-pattern&gt;/images/*&lt;/url-pattern&gt;
		&lt;url-pattern&gt;/css/*&lt;/url-pattern&gt;
		&lt;/web-resource-collection&gt;
	  &lt;/security-constraint&gt;
	  &lt;security-role&gt;
		&lt;description&gt;Role required to see admin pages.&lt;/description&gt;
		&lt;role-name&gt;myRole&lt;/role-name&gt;
	  &lt;/security-role&gt;
	  &lt;!-- Define the Login Configuration for this Application --&gt;
	  &lt;login-config&gt;
	    &lt;auth-method&gt;FORM&lt;/auth-method&gt;
	    &lt;realm-name&gt;MyAccess&lt;/realm-name&gt;
	    &lt;form-login-config&gt;
	      &lt;form-login-page&gt;/jsp/userLoginForm.jsp&lt;/form-login-page&gt;
	      &lt;form-error-page&gt;/jsp/userLoginForm.jsp?action=error&lt;/form-error-page&gt;
	    &lt;/form-login-config&gt;
	  &lt;/login-config&gt;

Notice that the &#039;security-constraint&#039; wraps a &#039;auth-constraint&#039; which references a &#039;role-name&#039; which maps to a &#039;security-role&#039;.

Lastly, I had to ensure that when the application server loads (not my web application, but the server), it has access to load my LoginModule implementation and supporting classes.  Hence I used an ANT script to jar up my *.class files and deploy them under tomcat&#039;s lib directory, as in:

	lib/myAccess.jar

This was key, and without it, I was left in the dark, not knowing that the WEB-INF/classes deployment (the default) was not enough.  The realm is loaded before your web app, and needs to be ready with the data source connections open, etc.  Once this was done, I was able to login using my custom LoginModule.

Again, some of my frustrations were eleviated through the information found at:

	http://blog.frankel.ch/tech/dev/java/jee/custom-loginmodule-in-tomcat

So some major Thanks go out to that Nicolas Frankel guy, and Good Luck!]]></description>
		<content:encoded><![CDATA[<p>Thought I&#8217;d share my experience with getting JAAS/Tomcat 6/Eclipse working.  Not everything in here is crucial to your implementation, but I figured this post will at least put it all together.  Many articles and blogs left me frustrated with just covering pieces of the solution, and not showing me the necessary connections between them.</p>
<p>To begin, I installed Java (say version 6.0 or better), and then Eclipse (or MyEclipse, if you like).  Then I updated Eclipse with the Subversive plug-in, to access my subversion repository to persist and pull my code onto different machines as I travel.<br />
(e.g. <a href="https://failship.company.com/repo" rel="nofollow">https://failship.company.com/repo</a>).</p>
<p>Upon checkout, I created a Dynamic Web Project or whatever name Eclipse provides for a basic web application.  Take your time here and step through each of the wizard screens, because some setting changes are subtle and have major pain-in-the-butt ripple effects.</p>
<p>You&#8217;ll have to create the basic LoginModule and Principal implementations to support your custom login code.  That information was provided everywhere on the Web.  My frustration was in putting it all together.  Anyway, out of the scores of resources I used to investigate, I found this one to be pretty concise:</p>
<p>  <a href="http://blog.frankel.ch/tech/dev/java/jee/custom-loginmodule-in-tomcat" rel="nofollow">http://blog.frankel.ch/tech/dev/java/jee/custom-loginmodule-in-tomcat</a></p>
<p>If you are going to test with Tomcat 6.0, you must add the following tag to the conf/context.xml file.</p>
<p>	&lt;Loader delegate=&#8221;true&#8221;/&gt;</p>
<p>Otherwise, you might get some</p>
<p>	&#8220;java.lang.ClassCastException: org.apache.catalina.util.DefaultAnnotationProcessor  cannot be cast to org.apache.AnnotationProcessor&#8221;</p>
<p>exception.</p>
<p>While you have context.xml open, you will have to add a &#8216;Realm&#8217; for Container Security, to enable our LoginModule secure access.  The 1st step is to enable the JaasRealm, typically by pasting in the existing entry as follows:</p>
<p>	&lt;!&#8211; Inserted to enable MyAccessLoginModule.  You will have to launch tomcat<br />
		with -Djava.security.auth.login.config= pointing to the jaas.config file: &#8211;&gt;<br />
	&lt;Realm className=&#8221;org.apache.catalina.realm.JAASRealm&#8221;<br />
		appName=&#8221;MyAccess&#8221;<br />
	    	userClassNames=&#8221;com.company.myAccess.realm.MyAccessUserPrincipal&#8221;<br />
	    	roleClassNames=&#8221;com.company.myAccess.realm.MyAccessRolePrincipal&#8221;&gt;<br />
	&lt;/Realm&gt;</p>
<p>Next, I had to create a jaas.conf file to declare my LoginModule implementation.  Notice that this has the same name as the &#8220;appName&#8221; provided in the &lt;realm&gt; definition above.  Here&#8217;s the contents of jaas.conf:</p>
<p>	/** Login Configuration for the JAAS Sample Application **/<br />
	MyAccess {<br />
	    com.company.myAccess.realm.MyAccessLoginModule requisite debug=true;<br />
	};</p>
<p>The realm also needs to know how to find the jaas.config file and it does this through the Java system property, set as a JVM argument, for the variable &#8220;java.security.auth.login.config&#8221;.  You can set this, in eclipse by configuring a &#8220;Server&#8221;, typically through the Window-&gt;Preference menu (or in MyEclipse under its preferences).  The JVM takes a -D argument, to define the variable, as in:</p>
<p>	-Djava.security.auth.login.config=C:&#8221;/Documents and Settings/sandrews/Workspaces/MyEclipse Blue/myAccess-20090902/jaas.config&#8221;</p>
<p>While youâ€™re here, you may want to add any custom defined variables for your web application.  My LoginModule read the tomcat-users.xml file as well, so I designated it with the follow arguments:</p>
<p>	-DTomcatUsersXmlFile=C:&#8221;/Program Files/Apache Software Foundation/Tomcat 6.0/conf/tomcat-users.xml&#8221;</p>
<p>Again, this last argument was custom to my application, so it&#8217;s necessary for your web app.</p>
<p>Next, edit the data source for your user authentication, as in conf/tomcat-users.xml, to add the role, say &#8216;myAccess&#8217;, and the user, like &#8216;bsmith&#8217; for example:</p>
<p>    &lt;tomcat-users&gt;<br />
        &lt;role rolename=&#8221;myAccess&#8221;/&gt;<br />
        &lt;user name=&#8221;bsmith&#8221; password=&#8221;123qwe&#8221; roles=&#8221;myRole&#8221;/&gt;<br />
    &lt;/tomcat-users&gt;</p>
<p>Your web application&#8217;s WEB-INF/web.xml should set the security restrictions,<br />
as in:</p>
<p>	  &lt;!&#8211; Define a Security Constraint on this Application &#8211;&gt;<br />
	  &lt;security-constraint&gt;<br />
	    &lt;web-resource-collection&gt;<br />
	      &lt;web-resource-name&gt;Secured resources&lt;/web-resource-name&gt;<br />
	      &lt;url-pattern&gt;/jsp/*&lt;/url-pattern&gt;<br />
	      &lt;url-pattern&gt;/html/*&lt;/url-pattern&gt;<br />
	      &lt;url-pattern&gt;/index.jsp&lt;/url-pattern&gt;<br />
	    &lt;/web-resource-collection&gt;<br />
	    &lt;auth-constraint&gt;<br />
	      &lt;role-name&gt;myRole&lt;/role-name&gt;<br />
	    &lt;/auth-constraint&gt;<br />
	  &lt;/security-constraint&gt;<br />
	  &lt;security-constraint&gt;<br />
		&lt;web-resource-collection&gt;<br />
		&lt;web-resource-name&gt;Unsecured resources&lt;/web-resource-name&gt;<br />
		&lt;url-pattern&gt;/images/*&lt;/url-pattern&gt;<br />
		&lt;url-pattern&gt;/css/*&lt;/url-pattern&gt;<br />
		&lt;/web-resource-collection&gt;<br />
	  &lt;/security-constraint&gt;<br />
	  &lt;security-role&gt;<br />
		&lt;description&gt;Role required to see admin pages.&lt;/description&gt;<br />
		&lt;role-name&gt;myRole&lt;/role-name&gt;<br />
	  &lt;/security-role&gt;<br />
	  &lt;!&#8211; Define the Login Configuration for this Application &#8211;&gt;<br />
	  &lt;login-config&gt;<br />
	    &lt;auth-method&gt;FORM&lt;/auth-method&gt;<br />
	    &lt;realm-name&gt;MyAccess&lt;/realm-name&gt;<br />
	    &lt;form-login-config&gt;<br />
	      &lt;form-login-page&gt;/jsp/userLoginForm.jsp&lt;/form-login-page&gt;<br />
	      &lt;form-error-page&gt;/jsp/userLoginForm.jsp?action=error&lt;/form-error-page&gt;<br />
	    &lt;/form-login-config&gt;<br />
	  &lt;/login-config&gt;</p>
<p>Notice that the &#8216;security-constraint&#8217; wraps a &#8216;auth-constraint&#8217; which references a &#8216;role-name&#8217; which maps to a &#8216;security-role&#8217;.</p>
<p>Lastly, I had to ensure that when the application server loads (not my web application, but the server), it has access to load my LoginModule implementation and supporting classes.  Hence I used an ANT script to jar up my *.class files and deploy them under tomcat&#8217;s lib directory, as in:</p>
<p>	lib/myAccess.jar</p>
<p>This was key, and without it, I was left in the dark, not knowing that the WEB-INF/classes deployment (the default) was not enough.  The realm is loaded before your web app, and needs to be ready with the data source connections open, etc.  Once this was done, I was able to login using my custom LoginModule.</p>
<p>Again, some of my frustrations were eleviated through the information found at:</p>
<p>	<a href="http://blog.frankel.ch/tech/dev/java/jee/custom-loginmodule-in-tomcat" rel="nofollow">http://blog.frankel.ch/tech/dev/java/jee/custom-loginmodule-in-tomcat</a></p>
<p>So some major Thanks go out to that Nicolas Frankel guy, and Good Luck!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mark</title>
		<link>http://technology.amis.nl/2004/11/17/struts-jaas-tomcat-getting-acquainted/#comment-1112</link>
		<dc:creator>mark</dc:creator>
		<pubDate>Thu, 19 Jan 2006 22:32:49 +0000</pubDate>
		<guid isPermaLink="false">/?p=259#comment-1112</guid>
		<description><![CDATA[your page works just fine in safari.. it would be nice if it stopped telling me that it
may not work for older versions of mozilla..]]></description>
		<content:encoded><![CDATA[<p>your page works just fine in safari.. it would be nice if it stopped telling me that it<br />
may not work for older versions of mozilla..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fred Thurber</title>
		<link>http://technology.amis.nl/2004/11/17/struts-jaas-tomcat-getting-acquainted/#comment-1111</link>
		<dc:creator>Fred Thurber</dc:creator>
		<pubDate>Thu, 29 Sep 2005 21:02:50 +0000</pubDate>
		<guid isPermaLink="false">/?p=259#comment-1111</guid>
		<description><![CDATA[Where can I see the source code to the AuthenticationBusinessComponent?]]></description>
		<content:encoded><![CDATA[<p>Where can I see the source code to the AuthenticationBusinessComponent?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rami Zanoun</title>
		<link>http://technology.amis.nl/2004/11/17/struts-jaas-tomcat-getting-acquainted/#comment-1110</link>
		<dc:creator>Rami Zanoun</dc:creator>
		<pubDate>Fri, 19 Aug 2005 19:55:39 +0000</pubDate>
		<guid isPermaLink="false">/?p=259#comment-1110</guid>
		<description><![CDATA[Valuable resource! If you could show the source code or at least how you integrated hibernate, that would be much appreciated. :)]]></description>
		<content:encoded><![CDATA[<p>Valuable resource! If you could show the source code or at least how you integrated hibernate, that would be much appreciated. <img src='http://technology.amis.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: source code</title>
		<link>http://technology.amis.nl/2004/11/17/struts-jaas-tomcat-getting-acquainted/#comment-1109</link>
		<dc:creator>source code</dc:creator>
		<pubDate>Wed, 17 Aug 2005 12:53:50 +0000</pubDate>
		<guid isPermaLink="false">/?p=259#comment-1109</guid>
		<description><![CDATA[I would really appreciate seeing your realm implementation source code too :-)]]></description>
		<content:encoded><![CDATA[<p>I would really appreciate seeing your realm implementation source code too <img src='http://technology.amis.nl/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: buetikofer</title>
		<link>http://technology.amis.nl/2004/11/17/struts-jaas-tomcat-getting-acquainted/#comment-1108</link>
		<dc:creator>buetikofer</dc:creator>
		<pubDate>Thu, 04 Aug 2005 15:31:10 +0000</pubDate>
		<guid isPermaLink="false">/?p=259#comment-1108</guid>
		<description><![CDATA[do you provide the source for these examples? thanks!]]></description>
		<content:encoded><![CDATA[<p>do you provide the source for these examples? thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zeger Hendrikse</title>
		<link>http://technology.amis.nl/2004/11/17/struts-jaas-tomcat-getting-acquainted/#comment-1107</link>
		<dc:creator>Zeger Hendrikse</dc:creator>
		<pubDate>Wed, 30 Mar 2005 08:21:31 +0000</pubDate>
		<guid isPermaLink="false">/?p=259#comment-1107</guid>
		<description><![CDATA[Great to know you all appreciate it, thanks!]]></description>
		<content:encoded><![CDATA[<p>Great to know you all appreciate it, thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joao</title>
		<link>http://technology.amis.nl/2004/11/17/struts-jaas-tomcat-getting-acquainted/#comment-1106</link>
		<dc:creator>Joao</dc:creator>
		<pubDate>Tue, 29 Mar 2005 22:54:14 +0000</pubDate>
		<guid isPermaLink="false">/?p=259#comment-1106</guid>
		<description><![CDATA[Searching for this ages ago...
Good stuff.]]></description>
		<content:encoded><![CDATA[<p>Searching for this ages ago&#8230;<br />
Good stuff.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Partha Pal</title>
		<link>http://technology.amis.nl/2004/11/17/struts-jaas-tomcat-getting-acquainted/#comment-1105</link>
		<dc:creator>Partha Pal</dc:creator>
		<pubDate>Thu, 03 Feb 2005 08:37:27 +0000</pubDate>
		<guid isPermaLink="false">/?p=259#comment-1105</guid>
		<description><![CDATA[Good Material]]></description>
		<content:encoded><![CDATA[<p>Good Material</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zeger Hendrikse</title>
		<link>http://technology.amis.nl/2004/11/17/struts-jaas-tomcat-getting-acquainted/#comment-1104</link>
		<dc:creator>Zeger Hendrikse</dc:creator>
		<pubDate>Fri, 19 Nov 2004 13:22:27 +0000</pubDate>
		<guid isPermaLink="false">/?p=259#comment-1104</guid>
		<description><![CDATA[The follow-up that discusses authorization is available &lt;a href=&quot;http://technology.amis.nl/blog/index.php?p=261&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt;.]]></description>
		<content:encoded><![CDATA[<p>The follow-up that discusses authorization is available <a href="http://technology.amis.nl/blog/index.php?p=261" rel="nofollow">here</a>.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
