You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Robert Denison <ro...@blim.org> on 2009/11/09 23:33:53 UTC

Secure login only, not rest of app

Hi all,

I am trying to have setup my tomcat webapp to be secure for login  
only. It works as you'd expect if the security-constraint for /* is  
unsecure and if I make it secure (using CONFIDENTIAL) for /*.

However if I try to make it secure only for the login page and  
unsecure elsewhere any attempt to go to a page redirects to the login  
page but unsecure - not using the https and higher port. I've seen  
comments about filters to redirect up to the https port but my  
thoughts are:

1) From what I understand it should be possible with multiple  
constraints for different URLs, and
2) as I only want to do this if the user is not logged in I'm not sure  
how the filter would work.

I have a working https Connector because I can use the service  
configured for /* to be secure.

Any offered help appreciated.

The relevant (I think) web.xml snippet is:

     <security-constraint>
       <web-resource-collection>
         <web-resource-name>Application Login</web-resource-name>
         <url-pattern>/login.jsp</url-pattern>
                 <http-method>GET</http-method>
                 <http-method>POST</http-method>
           </web-resource-collection>
       <auth-constraint>
         <role-name>player</role-name>
       </auth-constraint>
       <user-data-constraint>
         <transport-guarantee>CONFIDENTIAL</transport-guarantee>
       </user-data-constraint>
     </security-constraint>

     <security-constraint>
       <web-resource-collection>
         <web-resource-name>Application</web-resource-name>
         <url-pattern>/*</url-pattern>
       </web-resource-collection>
       <auth-constraint>
         <role-name>player</role-name>
       </auth-constraint>
     </security-constraint>

     <!-- Define the Login Configuration for this Application -->
     <login-config>
       <auth-method>FORM</auth-method>
       <realm-name>Application</realm-name>
           <form-login-config>
         <form-login-page>/jsp/login.jsp</form-login-page>
         <form-error-page>/jsp/error.jsp</form-error-page>
       </form-login-config>
     </login-config>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Secure login only, not rest of app

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Robert,

On 11/10/2009 5:07 AM, Robert Denison wrote:
> if (logged in) {
>   if (https) goto http
> } else {
>   if (http) goto https
> }

I've outlined this in another post, but I'll repeat it, here:

1. Modify your login page to check for HTTPS. If the request isn't
secure, redirect back to yourself in HTTPS mode.

2. Write a filter that checks for secure mode. If you're in secure mode,
do the following:

  a. Check for a JSESSIONID cookie. If one exists and it's in
     secure mode, create a new cookie with the same name, path,
     and value, but make sure it's /not/ in secure mode. Add this
     to the response.

  b. redirect back to yourself in HTTP mode

I believe the above combination will get you what you're looking for.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkr5zE4ACgkQ9CaO5/Lv0PDd3QCgmcskkwkUodIxKKzwI/rdQIR/
WUEAn33AejWyKyk5S8jjK/1QX84qjvj+
=2P/v
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Secure login only, not rest of app

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Robert Denison [mailto:rob@blim.org]
> Subject: Re: Secure login only, not rest of app
> 
> Simple question but can you do one /* constraint and then override that
> with a subsequent /images (and css etc) constraint

Yes, that's required by the servlet spec - longest match wins.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Secure login only, not rest of app

Posted by Oliver Schoett <ol...@capgemini-sdm.com>.
Robert Denison wrote:
> Thanks peter,
>
> Don't suppose anyone can point me to any documentation that talks about getting caching working properly for tomcat and static content can they?
>    

A good caching tutorial is http://www.mnot.net/cache_docs/

The best site for web performance in general is 
http://developer.yahoo.com/performance/rules.html

Tools for checking these rules are YSlow 
(http://developer.yahoo.com/yslow/) and http://www.webpagetest.org/

The most important rules are

    * Reduce number of requests (by consolidating scripts, style sheets
      and images),
    * Reduce data volume (e. g., by compression),
    * Allow re-use by caching,
    * Keep persistent connections,
    * Avoid sending cookies for static objects.

If you have to serve users in a different continent than where your 
servers are, you should also think about using a CDN.

Persistent connections are especially important with SSL, because SSL 
connection setup is expensive.

Regards,

Oliver Schoett



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Secure login only, not rest of app

Posted by Gerwood Stewart <gs...@une.edu.au>.
Pid

Regarding the login. I don't know what architecture you have but what your asking is possible. what Peter indicated below is more likely. 

It doesn't look like you are using spring but you might want to look at some of the ways they do such this. I do know you can enforce the use of https in either paths and/or beans (?a little vague there).

We don't have a https style redirect as we have a CAS server for authentication but we do similar things with url redirects for our extra users. In effect if not authenticated redirect to (as Peter said) to /login/ 

Gerwood
________________________________________
From: Pid [pid@pidster.com]
Sent: Wednesday, 11 November 2009 12:51 AM
To: users@tomcat.apache.org
Subject: Re: Secure login only, not rest of app

On 10/11/2009 13:25, Robert Denison wrote:
> Thanks peter,
>
> Don't suppose anyone can point me to any documentation that talks about getting caching working properly for tomcat and static content can they?

It's not so much a case of Tomcat, unfortunately your app is also
affected by browser type, config, version etc.

Tomcat should handle serving static resources perfectly well, but you
can augment it if needed by employing a Filter that adds headers for
matching files/requests.

Checking the HTTP Headers that are actually being sent & received by the
major browsers is an essential step in tuning your app.  Your access log
will show if files are being returned with HTTP 304 status or not.

Firefox has LiveHTTPHeaders and Firebug, IE has a plugin tool too.



I thought of an alternative, you could only enforce container based
security on a specific path "/login/".

Your Filter could redirect all unauthenticated users to the login app,
the index page (after successful login) just redirects to the app homepage.

  if (logged in) {
    if (https) goto http
  } else {
    redirect to "/login" // tomcat takes care of the HTTPS upgrade
  }




p


> R.
>
> On 10 Nov 2009, at 13:14, Peter Crowther wrote:
>
>> 2009/11/10 Robert Denison<ro...@blim.org>:
>>> I assume that the standard way of dealing with static caching is to have e.g. an images (css etc) directory and have that not secure?
>>
>> No, as on most browsers that will pop up a dialog box with something
>> like "this page contains both secure and insecure items.  Do you want
>> to display the insecure items?"
>>
>> All content referenced from a secure page should be secure to prevent
>> this warning.
>>
>> - Peter
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Secure login only, not rest of app

Posted by Pid <pi...@pidster.com>.
On 10/11/2009 13:25, Robert Denison wrote:
> Thanks peter,
>
> Don't suppose anyone can point me to any documentation that talks about getting caching working properly for tomcat and static content can they?

It's not so much a case of Tomcat, unfortunately your app is also 
affected by browser type, config, version etc.

Tomcat should handle serving static resources perfectly well, but you 
can augment it if needed by employing a Filter that adds headers for 
matching files/requests.

Checking the HTTP Headers that are actually being sent & received by the 
major browsers is an essential step in tuning your app.  Your access log 
will show if files are being returned with HTTP 304 status or not.

Firefox has LiveHTTPHeaders and Firebug, IE has a plugin tool too.



I thought of an alternative, you could only enforce container based 
security on a specific path "/login/".

Your Filter could redirect all unauthenticated users to the login app, 
the index page (after successful login) just redirects to the app homepage.

  if (logged in) {
    if (https) goto http
  } else {
    redirect to "/login" // tomcat takes care of the HTTPS upgrade
  }




p


> R.
>
> On 10 Nov 2009, at 13:14, Peter Crowther wrote:
>
>> 2009/11/10 Robert Denison<ro...@blim.org>:
>>> I assume that the standard way of dealing with static caching is to have e.g. an images (css etc) directory and have that not secure?
>>
>> No, as on most browsers that will pop up a dialog box with something
>> like "this page contains both secure and insecure items.  Do you want
>> to display the insecure items?"
>>
>> All content referenced from a secure page should be secure to prevent
>> this warning.
>>
>> - Peter
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Secure login only, not rest of app

Posted by Robert Denison <ro...@blim.org>.
Thanks peter, 

Don't suppose anyone can point me to any documentation that talks about getting caching working properly for tomcat and static content can they?

R.

On 10 Nov 2009, at 13:14, Peter Crowther wrote:

> 2009/11/10 Robert Denison <ro...@blim.org>:
>> I assume that the standard way of dealing with static caching is to have e.g. an images (css etc) directory and have that not secure?
> 
> No, as on most browsers that will pop up a dialog box with something
> like "this page contains both secure and insecure items.  Do you want
> to display the insecure items?"
> 
> All content referenced from a secure page should be secure to prevent
> this warning.
> 
> - Peter
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Secure login only, not rest of app

Posted by Peter Crowther <pe...@melandra.com>.
2009/11/10 Robert Denison <ro...@blim.org>:
> I assume that the standard way of dealing with static caching is to have e.g. an images (css etc) directory and have that not secure?

No, as on most browsers that will pop up a dialog box with something
like "this page contains both secure and insecure items.  Do you want
to display the insecure items?"

All content referenced from a secure page should be secure to prevent
this warning.

- Peter

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Secure login only, not rest of app

Posted by Robert Denison <ro...@blim.org>.
I assume that the standard way of dealing with static caching is to have e.g. an images (css etc) directory and have that not secure?

Simple question but can you do one /* constraint and then override that with a subsequent /images (and css etc) constraint or is there a different preferred way to do this kind of setup? It would be mildly annoying if I have to have all my main pages under some subdir (lengthening my URLs) just to differentiate, so I assume there is a better way?

R.

On 10 Nov 2009, at 10:42, Pid wrote:

> On 10/11/2009 10:07, Robert Denison wrote:
>> Hi P,
>> 
>> Thanks very much for your reasoned helpful response.
>> 
>> I fancied securing only login because I only want logged in users to see the service and I want the login to be secure (passwords are safe) but the data itself is irrelevant so I figure why spend cpu cycles encrypting/decrypting normal data communication? :)
> 
> Using SSL can interfere with caching of CSS, images etc.  Getting those for each main request could cost the client more time than the encryption takes.
> 
> Paying attention to static resource caching is a good idea.
> 
> 
>> To be honest I'm happy to just encrypt the whole thing if that's just going to save me a lot of hassle.
> 
> Do it, see how it works out.  Then try:
> 
>> My last stab at this is maybe I could use a scenario of filtering all requests and essentially do:
>> 
>> if (logged in) {
>>   if (https) goto http
>> } else {
>>   if (http) goto https
>> }
>> 
>> And then rely on the security constraint only for requiring login and the Valve only for forwarding the request to the login page?
> 
> This would probably work out OK, (just remember that the Filter will work at a level above/after the Valve has a chance to act).
> 
> 
> p
> 
> 
> 
>> R.
>> 
>> On 9 Nov 2009, at 23:05, Pid wrote:
>> 
>>> On 09/11/2009 22:33, Robert Denison wrote:
>>>> Hi all,
>>>> 
>>>> I am trying to have setup my tomcat webapp to be secure for login only.
>>>> It works as you'd expect if the security-constraint for /* is unsecure
>>>> and if I make it secure (using CONFIDENTIAL) for /*.
>>>> 
>>>> However if I try to make it secure only for the login page and unsecure
>>>> elsewhere any attempt to go to a page redirects to the login page but
>>>> unsecure - not using the https and higher port. I've seen comments about
>>>> filters to redirect up to the https port but my thoughts are:
>>>> 
>>>> 1) From what I understand it should be possible with multiple
>>>> constraints for different URLs, and
>>>> 2) as I only want to do this if the user is not logged in I'm not sure
>>>> how the filter would work.
>>>> 
>>>> I have a working https Connector because I can use the service
>>>> configured for /* to be secure.
>>> 
>>> So, to summarise, you want *only* the login page to be sent over SSL?
>>> 
>>> 
>>> The login page isn't ever requested directly, it's forwarded to by the AuthenticationValve.  This means that you can place it out of the way, in, say:
>>> 
>>> WEB-INF/login/form.jsp
>>> WEB-INF/login/error.jsp
>>> 
>>> but it also means that you shouldn't directly request the login page.
>>> 
>>> When you're using Container managed security, you request a secured resource and the Valve forwards to the form.  Once you authenticate the original request is restored.
>>> 
>>> Your config won't enforce SSL for the login page because the container forwards the request to the page after it recognises the /* rule requires a login.
>>> 
>>> 
>>> If you want the whole app to require a login, you can either choose to use SSL, or not, but you can't easily send the login page only over SSL.
>>> 
>>> If only one part of the app required a login, you could employ a Filter to downgrade to non-SSL when the URL didn't match that path.
>>> 
>>> Is there a particular reason why you want to downgrade after login?
>>> 
>>> 
>>> You might look into the Tomcat compatible SecurityFilter project, as it provides very similar functionality to container managed security, but more flexibility.
>>> 
>>> http://securityfilter.sourceforge.net/
>>> 
>>> 
>>> p
>>> 
>>> 
>>>> Any offered help appreciated.
>>>> 
>>>> The relevant (I think) web.xml snippet is:
>>>> 
>>>> <security-constraint>
>>>> <web-resource-collection>
>>>> <web-resource-name>Application Login</web-resource-name>
>>>> <url-pattern>/login.jsp</url-pattern>
>>>> <http-method>GET</http-method>
>>>> <http-method>POST</http-method>
>>>> </web-resource-collection>
>>>> <auth-constraint>
>>>> <role-name>player</role-name>
>>>> </auth-constraint>
>>>> <user-data-constraint>
>>>> <transport-guarantee>CONFIDENTIAL</transport-guarantee>
>>>> </user-data-constraint>
>>>> </security-constraint>
>>>> 
>>>> <security-constraint>
>>>> <web-resource-collection>
>>>> <web-resource-name>Application</web-resource-name>
>>>> <url-pattern>/*</url-pattern>
>>>> </web-resource-collection>
>>>> <auth-constraint>
>>>> <role-name>player</role-name>
>>>> </auth-constraint>
>>>> </security-constraint>
>>>> 
>>>> <!-- Define the Login Configuration for this Application -->
>>>> <login-config>
>>>> <auth-method>FORM</auth-method>
>>>> <realm-name>Application</realm-name>
>>>> <form-login-config>
>>>> <form-login-page>/jsp/login.jsp</form-login-page>
>>>> <form-error-page>/jsp/error.jsp</form-error-page>
>>>> </form-login-config>
>>>> </login-config>
>>>> 
>>>> 
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>> 
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Secure login only, not rest of app

Posted by Robert Denison <ro...@blim.org>.
Ugh, I didn't know about the interference with caching (I am fairly new to this) so it seems that adds weight to the idea of not securing anything but the login process.... I'll give these ideas a try and report back so it's public info.

Thanks again P.

R.

On 10 Nov 2009, at 10:42, Pid wrote:

> On 10/11/2009 10:07, Robert Denison wrote:
>> Hi P,
>> 
>> Thanks very much for your reasoned helpful response.
>> 
>> I fancied securing only login because I only want logged in users to see the service and I want the login to be secure (passwords are safe) but the data itself is irrelevant so I figure why spend cpu cycles encrypting/decrypting normal data communication? :)
> 
> Using SSL can interfere with caching of CSS, images etc.  Getting those for each main request could cost the client more time than the encryption takes.
> 
> Paying attention to static resource caching is a good idea.
> 
> 
>> To be honest I'm happy to just encrypt the whole thing if that's just going to save me a lot of hassle.
> 
> Do it, see how it works out.  Then try:
> 
>> My last stab at this is maybe I could use a scenario of filtering all requests and essentially do:
>> 
>> if (logged in) {
>>   if (https) goto http
>> } else {
>>   if (http) goto https
>> }
>> 
>> And then rely on the security constraint only for requiring login and the Valve only for forwarding the request to the login page?
> 
> This would probably work out OK, (just remember that the Filter will work at a level above/after the Valve has a chance to act).
> 
> 
> p
> 
> 
> 
>> R.
>> 
>> On 9 Nov 2009, at 23:05, Pid wrote:
>> 
>>> On 09/11/2009 22:33, Robert Denison wrote:
>>>> Hi all,
>>>> 
>>>> I am trying to have setup my tomcat webapp to be secure for login only.
>>>> It works as you'd expect if the security-constraint for /* is unsecure
>>>> and if I make it secure (using CONFIDENTIAL) for /*.
>>>> 
>>>> However if I try to make it secure only for the login page and unsecure
>>>> elsewhere any attempt to go to a page redirects to the login page but
>>>> unsecure - not using the https and higher port. I've seen comments about
>>>> filters to redirect up to the https port but my thoughts are:
>>>> 
>>>> 1) From what I understand it should be possible with multiple
>>>> constraints for different URLs, and
>>>> 2) as I only want to do this if the user is not logged in I'm not sure
>>>> how the filter would work.
>>>> 
>>>> I have a working https Connector because I can use the service
>>>> configured for /* to be secure.
>>> 
>>> So, to summarise, you want *only* the login page to be sent over SSL?
>>> 
>>> 
>>> The login page isn't ever requested directly, it's forwarded to by the AuthenticationValve.  This means that you can place it out of the way, in, say:
>>> 
>>> WEB-INF/login/form.jsp
>>> WEB-INF/login/error.jsp
>>> 
>>> but it also means that you shouldn't directly request the login page.
>>> 
>>> When you're using Container managed security, you request a secured resource and the Valve forwards to the form.  Once you authenticate the original request is restored.
>>> 
>>> Your config won't enforce SSL for the login page because the container forwards the request to the page after it recognises the /* rule requires a login.
>>> 
>>> 
>>> If you want the whole app to require a login, you can either choose to use SSL, or not, but you can't easily send the login page only over SSL.
>>> 
>>> If only one part of the app required a login, you could employ a Filter to downgrade to non-SSL when the URL didn't match that path.
>>> 
>>> Is there a particular reason why you want to downgrade after login?
>>> 
>>> 
>>> You might look into the Tomcat compatible SecurityFilter project, as it provides very similar functionality to container managed security, but more flexibility.
>>> 
>>> http://securityfilter.sourceforge.net/
>>> 
>>> 
>>> p
>>> 
>>> 
>>>> Any offered help appreciated.
>>>> 
>>>> The relevant (I think) web.xml snippet is:
>>>> 
>>>> <security-constraint>
>>>> <web-resource-collection>
>>>> <web-resource-name>Application Login</web-resource-name>
>>>> <url-pattern>/login.jsp</url-pattern>
>>>> <http-method>GET</http-method>
>>>> <http-method>POST</http-method>
>>>> </web-resource-collection>
>>>> <auth-constraint>
>>>> <role-name>player</role-name>
>>>> </auth-constraint>
>>>> <user-data-constraint>
>>>> <transport-guarantee>CONFIDENTIAL</transport-guarantee>
>>>> </user-data-constraint>
>>>> </security-constraint>
>>>> 
>>>> <security-constraint>
>>>> <web-resource-collection>
>>>> <web-resource-name>Application</web-resource-name>
>>>> <url-pattern>/*</url-pattern>
>>>> </web-resource-collection>
>>>> <auth-constraint>
>>>> <role-name>player</role-name>
>>>> </auth-constraint>
>>>> </security-constraint>
>>>> 
>>>> <!-- Define the Login Configuration for this Application -->
>>>> <login-config>
>>>> <auth-method>FORM</auth-method>
>>>> <realm-name>Application</realm-name>
>>>> <form-login-config>
>>>> <form-login-page>/jsp/login.jsp</form-login-page>
>>>> <form-error-page>/jsp/error.jsp</form-error-page>
>>>> </form-login-config>
>>>> </login-config>
>>>> 
>>>> 
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>> 
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Secure login only, not rest of app

Posted by Pid <pi...@pidster.com>.
On 10/11/2009 12:48, Robert Denison wrote:
> Just to pick up on the point below.
>
> If the Valve acts before the filter then I would guess my idea can't work because the login will have already happened before I get chance to redirect to https. Therefore meaning the login process will have happened unencrypted...

Ah, yes, indeed.

p


> R.
>
> On 10 Nov 2009, at 10:42, Pid wrote:
>
>>> My last stab at this is maybe I could use a scenario of filtering all requests and essentially do:
>>>
>>> if (logged in) {
>>>    if (https) goto http
>>> } else {
>>>    if (http) goto https
>>> }
>>>
>>> And then rely on the security constraint only for requiring login and the Valve only for forwarding the request to the login page?
>>
>> This would probably work out OK, (just remember that the Filter will work at a level above/after the Valve has a chance to act).
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Secure login only, not rest of app

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Robert,

On 11/11/2009 4:23 AM, Robert Denison wrote:
> Thanks everyone for your help, I'll take a look at this and then let
> everyone know how I get on.
> 
> Christopher, thanks for your patient reply, sorry I missed your
> earlier post, I guess my googling skills aren't what I think they
> are!

No problem. I posted my first(ish) reply before reading your most recent
post, then immediately posted this one. Rather than repeating
everything, I just referenced it.

Good luck with your efforts.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkr7NDAACgkQ9CaO5/Lv0PD/OwCgmShwqOuwUVOaQ49u2B6wMzsS
wDQAoKZkaLYr5lrwO6Hj8rWaV/npX0vN
=r5eW
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Secure login only, not rest of app

Posted by Robert Denison <ro...@blim.org>.
Thanks everyone for your help, I'll take a look at this and then let everyone know how I get on.

Christopher, thanks for your patient reply, sorry I missed your earlier post, I guess my googling skills aren't what I think they are! 

R.

On 10 Nov 2009, at 20:26, Christopher Schultz wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Robert,
> 
> On 11/10/2009 7:48 AM, Robert Denison wrote:
>> If the Valve acts before the filter then I would guess my idea can't
>> work because the login will have already happened before I get chance
>> to redirect to https. Therefore meaning the login process will have
>> happened unencrypted...
> 
> Remember that your login page is allowed to do stuff, too.
> 
> See my other post for details.
> 
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
> 
> iEYEARECAAYFAkr5zHYACgkQ9CaO5/Lv0PD0fACbBRvCADlgHACBQNgeUG+Z7Tcw
> FzkAoJ9zbS3Y2RvGRn0UuTHbDp4VnPc8
> =ld17
> -----END PGP SIGNATURE-----
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Secure login only, not rest of app

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Robert,

On 11/10/2009 7:48 AM, Robert Denison wrote:
> If the Valve acts before the filter then I would guess my idea can't
> work because the login will have already happened before I get chance
> to redirect to https. Therefore meaning the login process will have
> happened unencrypted...

Remember that your login page is allowed to do stuff, too.

See my other post for details.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkr5zHYACgkQ9CaO5/Lv0PD0fACbBRvCADlgHACBQNgeUG+Z7Tcw
FzkAoJ9zbS3Y2RvGRn0UuTHbDp4VnPc8
=ld17
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Secure login only, not rest of app

Posted by Robert Denison <ro...@blim.org>.
Just to pick up on the point below. 

If the Valve acts before the filter then I would guess my idea can't work because the login will have already happened before I get chance to redirect to https. Therefore meaning the login process will have happened unencrypted...

R.

On 10 Nov 2009, at 10:42, Pid wrote:

>> My last stab at this is maybe I could use a scenario of filtering all requests and essentially do:
>> 
>> if (logged in) {
>>   if (https) goto http
>> } else {
>>   if (http) goto https
>> }
>> 
>> And then rely on the security constraint only for requiring login and the Valve only for forwarding the request to the login page?
> 
> This would probably work out OK, (just remember that the Filter will work at a level above/after the Valve has a chance to act).


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Secure login only, not rest of app

Posted by Pid <pi...@pidster.com>.
On 10/11/2009 10:07, Robert Denison wrote:
> Hi P,
>
> Thanks very much for your reasoned helpful response.
>
> I fancied securing only login because I only want logged in users to see the service and I want the login to be secure (passwords are safe) but the data itself is irrelevant so I figure why spend cpu cycles encrypting/decrypting normal data communication? :)

Using SSL can interfere with caching of CSS, images etc.  Getting those 
for each main request could cost the client more time than the 
encryption takes.

Paying attention to static resource caching is a good idea.


> To be honest I'm happy to just encrypt the whole thing if that's just going to save me a lot of hassle.

Do it, see how it works out.  Then try:

> My last stab at this is maybe I could use a scenario of filtering all requests and essentially do:
>
> if (logged in) {
>    if (https) goto http
> } else {
>    if (http) goto https
> }
>
> And then rely on the security constraint only for requiring login and the Valve only for forwarding the request to the login page?

This would probably work out OK, (just remember that the Filter will 
work at a level above/after the Valve has a chance to act).


p



> R.
>
> On 9 Nov 2009, at 23:05, Pid wrote:
>
>> On 09/11/2009 22:33, Robert Denison wrote:
>>> Hi all,
>>>
>>> I am trying to have setup my tomcat webapp to be secure for login only.
>>> It works as you'd expect if the security-constraint for /* is unsecure
>>> and if I make it secure (using CONFIDENTIAL) for /*.
>>>
>>> However if I try to make it secure only for the login page and unsecure
>>> elsewhere any attempt to go to a page redirects to the login page but
>>> unsecure - not using the https and higher port. I've seen comments about
>>> filters to redirect up to the https port but my thoughts are:
>>>
>>> 1) From what I understand it should be possible with multiple
>>> constraints for different URLs, and
>>> 2) as I only want to do this if the user is not logged in I'm not sure
>>> how the filter would work.
>>>
>>> I have a working https Connector because I can use the service
>>> configured for /* to be secure.
>>
>> So, to summarise, you want *only* the login page to be sent over SSL?
>>
>>
>> The login page isn't ever requested directly, it's forwarded to by the AuthenticationValve.  This means that you can place it out of the way, in, say:
>>
>> WEB-INF/login/form.jsp
>> WEB-INF/login/error.jsp
>>
>> but it also means that you shouldn't directly request the login page.
>>
>> When you're using Container managed security, you request a secured resource and the Valve forwards to the form.  Once you authenticate the original request is restored.
>>
>> Your config won't enforce SSL for the login page because the container forwards the request to the page after it recognises the /* rule requires a login.
>>
>>
>> If you want the whole app to require a login, you can either choose to use SSL, or not, but you can't easily send the login page only over SSL.
>>
>> If only one part of the app required a login, you could employ a Filter to downgrade to non-SSL when the URL didn't match that path.
>>
>> Is there a particular reason why you want to downgrade after login?
>>
>>
>> You might look into the Tomcat compatible SecurityFilter project, as it provides very similar functionality to container managed security, but more flexibility.
>>
>> http://securityfilter.sourceforge.net/
>>
>>
>> p
>>
>>
>>> Any offered help appreciated.
>>>
>>> The relevant (I think) web.xml snippet is:
>>>
>>> <security-constraint>
>>> <web-resource-collection>
>>> <web-resource-name>Application Login</web-resource-name>
>>> <url-pattern>/login.jsp</url-pattern>
>>> <http-method>GET</http-method>
>>> <http-method>POST</http-method>
>>> </web-resource-collection>
>>> <auth-constraint>
>>> <role-name>player</role-name>
>>> </auth-constraint>
>>> <user-data-constraint>
>>> <transport-guarantee>CONFIDENTIAL</transport-guarantee>
>>> </user-data-constraint>
>>> </security-constraint>
>>>
>>> <security-constraint>
>>> <web-resource-collection>
>>> <web-resource-name>Application</web-resource-name>
>>> <url-pattern>/*</url-pattern>
>>> </web-resource-collection>
>>> <auth-constraint>
>>> <role-name>player</role-name>
>>> </auth-constraint>
>>> </security-constraint>
>>>
>>> <!-- Define the Login Configuration for this Application -->
>>> <login-config>
>>> <auth-method>FORM</auth-method>
>>> <realm-name>Application</realm-name>
>>> <form-login-config>
>>> <form-login-page>/jsp/login.jsp</form-login-page>
>>> <form-error-page>/jsp/error.jsp</form-error-page>
>>> </form-login-config>
>>> </login-config>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Secure login only, not rest of app

Posted by Robert Denison <ro...@blim.org>.
Hi P,

Thanks very much for your reasoned helpful response.

I fancied securing only login because I only want logged in users to see the service and I want the login to be secure (passwords are safe) but the data itself is irrelevant so I figure why spend cpu cycles encrypting/decrypting normal data communication? :)

To be honest I'm happy to just encrypt the whole thing if that's just going to save me a lot of hassle.

My last stab at this is maybe I could use a scenario of filtering all requests and essentially do:

if (logged in) {
  if (https) goto http
} else {
  if (http) goto https
}

And then rely on the security constraint only for requiring login and the Valve only for forwarding the request to the login page?

R.

On 9 Nov 2009, at 23:05, Pid wrote:

> On 09/11/2009 22:33, Robert Denison wrote:
>> Hi all,
>> 
>> I am trying to have setup my tomcat webapp to be secure for login only.
>> It works as you'd expect if the security-constraint for /* is unsecure
>> and if I make it secure (using CONFIDENTIAL) for /*.
>> 
>> However if I try to make it secure only for the login page and unsecure
>> elsewhere any attempt to go to a page redirects to the login page but
>> unsecure - not using the https and higher port. I've seen comments about
>> filters to redirect up to the https port but my thoughts are:
>> 
>> 1) From what I understand it should be possible with multiple
>> constraints for different URLs, and
>> 2) as I only want to do this if the user is not logged in I'm not sure
>> how the filter would work.
>> 
>> I have a working https Connector because I can use the service
>> configured for /* to be secure.
> 
> So, to summarise, you want *only* the login page to be sent over SSL?
> 
> 
> The login page isn't ever requested directly, it's forwarded to by the AuthenticationValve.  This means that you can place it out of the way, in, say:
> 
> WEB-INF/login/form.jsp
> WEB-INF/login/error.jsp
> 
> but it also means that you shouldn't directly request the login page.
> 
> When you're using Container managed security, you request a secured resource and the Valve forwards to the form.  Once you authenticate the original request is restored.
> 
> Your config won't enforce SSL for the login page because the container forwards the request to the page after it recognises the /* rule requires a login.
> 
> 
> If you want the whole app to require a login, you can either choose to use SSL, or not, but you can't easily send the login page only over SSL.
> 
> If only one part of the app required a login, you could employ a Filter to downgrade to non-SSL when the URL didn't match that path.
> 
> Is there a particular reason why you want to downgrade after login?
> 
> 
> You might look into the Tomcat compatible SecurityFilter project, as it provides very similar functionality to container managed security, but more flexibility.
> 
> http://securityfilter.sourceforge.net/
> 
> 
> p
> 
> 
>> Any offered help appreciated.
>> 
>> The relevant (I think) web.xml snippet is:
>> 
>> <security-constraint>
>> <web-resource-collection>
>> <web-resource-name>Application Login</web-resource-name>
>> <url-pattern>/login.jsp</url-pattern>
>> <http-method>GET</http-method>
>> <http-method>POST</http-method>
>> </web-resource-collection>
>> <auth-constraint>
>> <role-name>player</role-name>
>> </auth-constraint>
>> <user-data-constraint>
>> <transport-guarantee>CONFIDENTIAL</transport-guarantee>
>> </user-data-constraint>
>> </security-constraint>
>> 
>> <security-constraint>
>> <web-resource-collection>
>> <web-resource-name>Application</web-resource-name>
>> <url-pattern>/*</url-pattern>
>> </web-resource-collection>
>> <auth-constraint>
>> <role-name>player</role-name>
>> </auth-constraint>
>> </security-constraint>
>> 
>> <!-- Define the Login Configuration for this Application -->
>> <login-config>
>> <auth-method>FORM</auth-method>
>> <realm-name>Application</realm-name>
>> <form-login-config>
>> <form-login-page>/jsp/login.jsp</form-login-page>
>> <form-error-page>/jsp/error.jsp</form-error-page>
>> </form-login-config>
>> </login-config>
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Secure login only, not rest of app

Posted by Pid <pi...@pidster.com>.
On 09/11/2009 22:33, Robert Denison wrote:
> Hi all,
>
> I am trying to have setup my tomcat webapp to be secure for login only.
> It works as you'd expect if the security-constraint for /* is unsecure
> and if I make it secure (using CONFIDENTIAL) for /*.
>
> However if I try to make it secure only for the login page and unsecure
> elsewhere any attempt to go to a page redirects to the login page but
> unsecure - not using the https and higher port. I've seen comments about
> filters to redirect up to the https port but my thoughts are:
>
> 1) From what I understand it should be possible with multiple
> constraints for different URLs, and
> 2) as I only want to do this if the user is not logged in I'm not sure
> how the filter would work.
>
> I have a working https Connector because I can use the service
> configured for /* to be secure.

So, to summarise, you want *only* the login page to be sent over SSL?


The login page isn't ever requested directly, it's forwarded to by the 
AuthenticationValve.  This means that you can place it out of the way, 
in, say:

  WEB-INF/login/form.jsp
  WEB-INF/login/error.jsp

but it also means that you shouldn't directly request the login page.

When you're using Container managed security, you request a secured 
resource and the Valve forwards to the form.  Once you authenticate the 
original request is restored.

Your config won't enforce SSL for the login page because the container 
forwards the request to the page after it recognises the /* rule 
requires a login.


If you want the whole app to require a login, you can either choose to 
use SSL, or not, but you can't easily send the login page only over SSL.

If only one part of the app required a login, you could employ a Filter 
to downgrade to non-SSL when the URL didn't match that path.

Is there a particular reason why you want to downgrade after login?


You might look into the Tomcat compatible SecurityFilter project, as it 
provides very similar functionality to container managed security, but 
more flexibility.

  http://securityfilter.sourceforge.net/


p


> Any offered help appreciated.
>
> The relevant (I think) web.xml snippet is:
>
> <security-constraint>
> <web-resource-collection>
> <web-resource-name>Application Login</web-resource-name>
> <url-pattern>/login.jsp</url-pattern>
> <http-method>GET</http-method>
> <http-method>POST</http-method>
> </web-resource-collection>
> <auth-constraint>
> <role-name>player</role-name>
> </auth-constraint>
> <user-data-constraint>
> <transport-guarantee>CONFIDENTIAL</transport-guarantee>
> </user-data-constraint>
> </security-constraint>
>
> <security-constraint>
> <web-resource-collection>
> <web-resource-name>Application</web-resource-name>
> <url-pattern>/*</url-pattern>
> </web-resource-collection>
> <auth-constraint>
> <role-name>player</role-name>
> </auth-constraint>
> </security-constraint>
>
> <!-- Define the Login Configuration for this Application -->
> <login-config>
> <auth-method>FORM</auth-method>
> <realm-name>Application</realm-name>
> <form-login-config>
> <form-login-page>/jsp/login.jsp</form-login-page>
> <form-error-page>/jsp/error.jsp</form-error-page>
> </form-login-config>
> </login-config>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org