<?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: Custom LoginModule in Tomcat</title>
	<atom:link href="http://blog.frankel.ch/custom-loginmodule-in-tomcat/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.frankel.ch/custom-loginmodule-in-tomcat</link>
	<description>Nicolas Fränkel blog</description>
	<lastBuildDate>Wed, 08 Feb 2012 07:06:46 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Gamma</title>
		<link>http://blog.frankel.ch/custom-loginmodule-in-tomcat/comment-page-1#comment-1594</link>
		<dc:creator>Gamma</dc:creator>
		<pubDate>Tue, 09 Aug 2011 15:10:03 +0000</pubDate>
		<guid isPermaLink="false">http://blog.frankel.ch/?p=84#comment-1594</guid>
		<description>This is a great resource that I used for an introduction on JAAS (Tomcat 7 / Mac OS X).
Thanks for the sample,

Gamma</description>
		<content:encoded><![CDATA[<p>This is a great resource that I used for an introduction on JAAS (Tomcat 7 / Mac OS X).<br />
Thanks for the sample,</p>
<p>Gamma</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Quadir Kareemullah</title>
		<link>http://blog.frankel.ch/custom-loginmodule-in-tomcat/comment-page-1#comment-943</link>
		<dc:creator>Quadir Kareemullah</dc:creator>
		<pubDate>Wed, 09 Feb 2011 14:46:18 +0000</pubDate>
		<guid isPermaLink="false">http://blog.frankel.ch/?p=84#comment-943</guid>
		<description>Can you provide more information as to how you are getting the role information and verifying if the user has that role?

Thanks
Quadir</description>
		<content:encoded><![CDATA[<p>Can you provide more information as to how you are getting the role information and verifying if the user has that role?</p>
<p>Thanks<br />
Quadir</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Reza</title>
		<link>http://blog.frankel.ch/custom-loginmodule-in-tomcat/comment-page-1#comment-719</link>
		<dc:creator>Reza</dc:creator>
		<pubDate>Tue, 12 Oct 2010 10:47:59 +0000</pubDate>
		<guid isPermaLink="false">http://blog.frankel.ch/?p=84#comment-719</guid>
		<description>I have tried this in Tomcat 6.0 and it failed. It raise HTTP 403 exception.</description>
		<content:encoded><![CDATA[<p>I have tried this in Tomcat 6.0 and it failed. It raise HTTP 403 exception.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nicolas Frankel</title>
		<link>http://blog.frankel.ch/custom-loginmodule-in-tomcat/comment-page-1#comment-641</link>
		<dc:creator>Nicolas Frankel</dc:creator>
		<pubDate>Wed, 04 Aug 2010 19:50:20 +0000</pubDate>
		<guid isPermaLink="false">http://blog.frankel.ch/?p=84#comment-641</guid>
		<description>Since they are plain, they both are JavaBeans with a name property (and the appropriate getter/setter).</description>
		<content:encoded><![CDATA[<p>Since they are plain, they both are JavaBeans with a name property (and the appropriate getter/setter).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: robin.bakkerus</title>
		<link>http://blog.frankel.ch/custom-loginmodule-in-tomcat/comment-page-1#comment-640</link>
		<dc:creator>robin.bakkerus</dc:creator>
		<pubDate>Wed, 04 Aug 2010 11:57:25 +0000</pubDate>
		<guid isPermaLink="false">http://blog.frankel.ch/?p=84#comment-640</guid>
		<description>Can you publish the code for PlainUserPrincipal and PlainRolePrincipal as well</description>
		<content:encoded><![CDATA[<p>Can you publish the code for PlainUserPrincipal and PlainRolePrincipal as well</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: orbit@websig.com</title>
		<link>http://blog.frankel.ch/custom-loginmodule-in-tomcat/comment-page-1#comment-489</link>
		<dc:creator>orbit@websig.com</dc:creator>
		<pubDate>Fri, 18 Sep 2009 19:15:50 +0000</pubDate>
		<guid isPermaLink="false">http://blog.frankel.ch/?p=84#comment-489</guid>
		<description>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: cubaso</title>
		<link>http://blog.frankel.ch/custom-loginmodule-in-tomcat/comment-page-1#comment-480</link>
		<dc:creator>cubaso</dc:creator>
		<pubDate>Wed, 22 Jul 2009 12:21:13 +0000</pubDate>
		<guid isPermaLink="false">http://blog.frankel.ch/?p=84#comment-480</guid>
		<description>Thanks for useful article!
Just one little fix for your web.xml: replace &lt;code&gt;index.htm&lt;/code&gt; &lt;code&gt;by index.html&lt;/code&gt;.
	</description>
		<content:encoded><![CDATA[<p>Thanks for useful article!<br />
Just one little fix for your web.xml: replace <code>index.htm</code> <code>by index.html</code>.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

