Securityfilter + JBoss

"Sverker Abrahamsson" <[email protected]> Sun, 25 Apr 2010 22:43:41 +0200
Newsgroups gmane.comp.java.securityfilter.devel
Message-ID <!&!AAAAAAAAAAAYAAAAAAAAAN5fehIZv/BBsQLx9nhfoL3ihQAAEAAAAMLgLe5JrnFHrszto5V7HS4BAAAAAA==@abrahamsson.com>
Hello,
I=92ve been using Securityfilter in a project since long time back, now whe=
n I
was doing some maintenance I thought I=92d change it to use standard form
based login as I never had got Securityfilter to work really well with
JBoss. It has been working more or less but never perfect.

Anyway, I soon remembered why I had been using Securityfilter as it was
impossible =A0to make the standard procedures to work as I wanted. So I went
back to have a new look at Securityfilter, my old version was a modified
1.x. After some research I found out that since JBoss 4.2.3 there is a class
called WebAuthentication which can be used to programmatically authenticate
in the web layer.

I=92ve created a class JBossRealm which can be used to authenticate to JBos=
s.
It make use of WebAuthentication to authenticate to the JBoss security
container. There is a bug which is reported in
https://jira.jboss.org/jira/browse/JBAS-5549 which cause that the
authenticated context is =93forgotten=94 between each request unless there =
is a
security-constraint in web.xml, as described in jira just add a dummy entry
like this:

<security-constraint>
=A0 <web-resource-collection>
=A0 =A0=A0<web-resource-name>dummy</web-resource-name>
=A0 =A0=A0<url-pattern>/dummy/*</url-pattern>
=A0 </web-resource-collection>
</security-constraint>

There were some small changes needed to other classes as described below:

SecurityRequestWrapper
getUserPrincipal was changed to be in line with
org.apache.catalina.connector.Request. If the Pincipal is an instance of
GenericPrincipal then it=92s necessary to call getUserPrincipal on the
Principal to get the UserPrincipal. Also added a getPrincipal method which
is used internally where the full Principall is needed.

FormAuthenticator
Use getPrincipal() on SecurityRequestWrapper instead of getUserPrincipal()

SecurityFilter
Call isUserInRole(String) on the wrapped request instead of directly on the
realm

In addition I removed all compiler warnings and wildcard imports in all
classes.

It=92s also needed to update catalina.jar to version 5.5.10 or newer and add
jboss-web-service.jar (I believe it was named jbossweb-service.jar in 4.2.3
then jboss-web-service.jar from 5.0)

The patch can be found at http://www.abrahamsson.com/securityfilter.patch

Best regards
Sverker


---------------------------------------------------------------------------=
---