You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Tom McCobb <tm...@attglobal.net> on 2004/08/09 16:35:14 UTC

Struts and Websphere security - best practice

I have a struts app that I am deploying in WebSphere 5.1.  Everything works
fine, no issues with WAS per se.  Now I am trying to activate security and I
am running into some bumps in the road.

The security setup is simple:  With global security enabled on WAS,
authenticating against ldap (openldap repository in the test environment), I
only need to designate in my web.xml a security-constraint indicating which
resources are protected, and a login-config which indicates the name of the
login page to use.  The login page must call a WAS servlet called
j_security_check.  When an unauthenticated user tries to navigate to a
protected resource, WAS will redirect the user to the login page designated
in the login-config tag, and process the login from there.  If anyone is
reading this, you probably know all this already.

>From the looks of things, using the above scheme, I do not need to define a
path in struts-config.xml to the login page, as I would normally do.   With
index.jsp as my welcome page, which contains only a redirection to the entry
point path in my struts-config.xml, I expect WAS to kick in and redirect any
user trying to access "sessionStart.do" first to the designated login page
before allowing access to the struts action.  My security-contraint in fact
protects "*.do".  This is how IBM sets up its admin console for WAS, in
fact, although they incorporate everything into a form bean/action class,
and I instead detour out of struts just for the login process.  I am not
having much diffculty with authentication in this manner, although
authorization is another matter.

So my question is, what is the best way to do this?  Should I protected the
static index.jsp instead of any call to the action servlet, or both, or all
resources (I have read through and tried to implement the IBM example of
using SSL for unathenticated access to the login.jsp, and non-secure
authenticated access to everything else)?  Should I make a greater effort to
incorporate the entire procedure into a struts form.action class as IBM has
done (and if so, is there any particular trick to calling j_security_check
from my action class?).

Any suggestions will be appreciated.

T. McCobb

Re: Struts and Websphere security - best practice

Posted by "Ruth, Brice" <br...@fiskars.com>.
Craig McClanahan wrote:

>On Tue, 10 Aug 2004 09:15:49 -0400, Tom McCobb <tm...@attglobal.net> wrote:
>  
>
>>    
>>
>>>One thing to double check is that your welcome page really does do a
>>>*redirect* to sessionStart.do, rather than a <jsp:forward>.  The
>>>latter will not kick in the container managed security, because they
>>>are only applied on the URL that is originally requested from the
>>>client (which will be the one for the welcome page in this scenario).
>>>      
>>>
>>AHA!
>>
>>Any suggestions for poking the username into the session for alter
>>retrieval?  I am trying a javascript function launched from the onSubmit
>>event on the form, and an intermediary jsp/form.  Can I use a struts
>>form.action to store the username/pw and forward directly to the
>>j_security_check servlet?
>>    
>>
>
>You can retrieve the logged-in username by calling
>request.getRemoteUser() in some subsequent request.  For security
>reasons, you cannot retrieve the password, unless your particular app
>server provides some proprietary mechanism.
>
>Craig
>  
>
Tom,

Just as a quick FYI - this isn't WebSphere specific security, per se. My 
understanding is that this is all part of the servlet specification. 
Tomcat supports it, as does any other servlet container. So, if you're 
looking for some documentation on things like getting the username, or 
figuring out what roles the user belongs to - check the servlet 
specification, or any book you have that talks about the servlet spec.

Brice

-- 
Brice Ruth, Sr. IT Analyst
Fiskars Brands Inc
http://www.fiskarsbrands.com/


Re: Struts and Websphere security - best practice

Posted by Craig McClanahan <cr...@gmail.com>.
On Tue, 10 Aug 2004 09:15:49 -0400, Tom McCobb <tm...@attglobal.net> wrote:
> 
> 
> >One thing to double check is that your welcome page really does do a
> >*redirect* to sessionStart.do, rather than a <jsp:forward>.  The
> >latter will not kick in the container managed security, because they
> >are only applied on the URL that is originally requested from the
> >client (which will be the one for the welcome page in this scenario).
> 
> AHA!
> 
> Any suggestions for poking the username into the session for alter
> retrieval?  I am trying a javascript function launched from the onSubmit
> event on the form, and an intermediary jsp/form.  Can I use a struts
> form.action to store the username/pw and forward directly to the
> j_security_check servlet?

You can retrieve the logged-in username by calling
request.getRemoteUser() in some subsequent request.  For security
reasons, you cannot retrieve the password, unless your particular app
server provides some proprietary mechanism.

Craig

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Struts and Websphere security - best practice

Posted by Tom McCobb <tm...@attglobal.net>.

>One thing to double check is that your welcome page really does do a
>*redirect* to sessionStart.do, rather than a <jsp:forward>.  The
>latter will not kick in the container managed security, because they
>are only applied on the URL that is originally requested from the
>client (which will be the one for the welcome page in this scenario).

AHA!

Any suggestions for poking the username into the session for alter
retrieval?  I am trying a javascript function launched from the onSubmit
event on the form, and an intermediary jsp/form.  Can I use a struts
form.action to store the username/pw and forward directly to the
j_security_check servlet?



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts and Websphere security - best practice

Posted by Craig McClanahan <cr...@gmail.com>.
On Mon, 9 Aug 2004 10:35:14 -0400, Tom McCobb <tm...@attglobal.net> wrote:
> I have a struts app that I am deploying in WebSphere 5.1.  Everything works
> fine, no issues with WAS per se.  Now I am trying to activate security and I
> am running into some bumps in the road.
> 
> The security setup is simple:  With global security enabled on WAS,
> authenticating against ldap (openldap repository in the test environment), I
> only need to designate in my web.xml a security-constraint indicating which
> resources are protected, and a login-config which indicates the name of the
> login page to use.  The login page must call a WAS servlet called
> j_security_check.  When an unauthenticated user tries to navigate to a
> protected resource, WAS will redirect the user to the login page designated
> in the login-config tag, and process the login from there.  If anyone is
> reading this, you probably know all this already.
> 

Yep :-).

> From the looks of things, using the above scheme, I do not need to define a
> path in struts-config.xml to the login page, as I would normally do.

That is correct.

> With index.jsp as my welcome page, which contains only a redirection to the entry
> point path in my struts-config.xml, I expect WAS to kick in and redirect any
> user trying to access "sessionStart.do" first to the designated login page
> before allowing access to the struts action.  My security-contraint in fact
> protects "*.do".  This is how IBM sets up its admin console for WAS, in
> fact, although they incorporate everything into a form bean/action class,
> and I instead detour out of struts just for the login process.  I am not
> having much diffculty with authentication in this manner, although
> authorization is another matter.

One thing to double check is that your welcome page really does do a
*redirect* to sessionStart.do, rather than a <jsp:forward>.  The
latter will not kick in the container managed security, because they
are only applied on the URL that is originally requested from the
client (which will be the one for the welcome page in this scenario).

Using "*.do" is the correct URL pattern for all the rest of the
requests, since that is the URL that the form submit actually uses. 
However, it won't help you deal with fine-grained authorization (i.e.
different people can execute different actions).  For that, you can
either define separate mappings in your security constraints (with
different user roles required for access), or use the "role" attribute
on the <action> element to ask Struts to check for the presence of
that role.

> 
> So my question is, what is the best way to do this?  Should I protected the
> static index.jsp instead of any call to the action servlet, or both, or all
> resources (I have read through and tried to implement the IBM example of
> using SSL for unathenticated access to the login.jsp, and non-secure
> authenticated access to everything else)?  Should I make a greater effort to
> incorporate the entire procedure into a struts form.action class as IBM has
> done (and if so, is there any particular trick to calling j_security_check
> from my action class?).
> 
> Any suggestions will be appreciated.
> 
> T. McCobb
> 

Craig

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org