session
= getThreadLocalRequest().getSession(true);save value in session:
session
.setAttribute("myuser", user); [ myuser-- name of the session ] [user- any object,string]get value from session:
session
.getAttribute("myuser");cheers
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
It does not make sense to have 2 RequestFactory(s) in a single web app. I´d have 2 (or more) RequestContext, and I´d get them having these methods in my AppRequestFactory interface (one of them dealing with the user management):
Ok. Now I´m configuring the application to authenticata against the embedded Jetty server wich comes with GWT. Please, correct me if I´m wrong:
- I have to create a jetty-web.xml in WEB-INF of my gwt application with the following text:
<Configure class="org.mortbay.jetty.webapp.WebAppContext">
<Set name="contextPath">/test</Set>
<Set name="war"><SystemProperty name="jetty.home" default="."/>/webapps/test</Set>
...
<Get name="securityHandler">
<Set name="userRealm">
<New class="org.mortbay.jetty.security.HashUserRealm">
<Set name="name">Test Realm</Set>
<Set name="config"><SystemProperty name="jetty.home" default="."/>/etc/realm.properties</Set>
</New>
You mean how I did implement it? ;-)Using the same pattern as the Expenses sample:
- out HTML host page (the one calling the *.nocache.js) is protected with a simple servlet FORM authentication (<login-config><auth-method>FORM</...> in the web.xml); nothing special here.
- the server returns a known error response for unauthenticated requests (i.e. a 401 status code, I didn't include a WWW-Authenticate header which is in violation of HTTP, but it just works so...), this is done in a servlet Filter, where I simply check for request.getUserPrincipal() != null. This has really nothing specific to RequestFactory, and we use it with other XMLHttpRequest-driven requests too.
- the client handles the known error response in a custom RequestTransport (in our case, for the time being, we simply Window.alert() the user, prompting him to refresh the page to re-authenticate)
(BTW, thank you for the "expert" qualifier ;-) )
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
On 26 January 2011 14:53, Thomas Broyer <t.br...@gmail.com> wrote:You mean how I did implement it? ;-)Using the same pattern as the Expenses sample:
- out HTML host page (the one calling the *.nocache.js) is protected with a simple servlet FORM authentication (<login-config><auth-method>FORM</...> in the web.xml); nothing special here.
- the server returns a known error response for unauthenticated requests (i.e. a 401 status code, I didn't include a WWW-Authenticate header which is in violation of HTTP, but it just works so...), this is done in a servlet Filter, where I simply check for request.getUserPrincipal() != null. This has really nothing specific to RequestFactory, and we use it with other XMLHttpRequest-driven requests too.
I don´t know why this is wrong, but the checking of request.getUserPrincipal() != null seems to be valid only the first time a request is made. The following requests (made by the requestFactory), getUserPrincipal() returns null. Here´s my code in my AuthFilter class:public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {HttpServletRequest request = (HttpServletRequest) servletRequest;HttpServletResponse response = (HttpServletResponse) servletResponse;if(request.getUserPrincipal() == null) {response.setHeader("WWW-Authenticate", "FORM realm=\"userRealm\"");response.sendError(HttpServletResponse.SC_UNAUTHORIZED);return;}What am I doing wrong?
If you want to pass an "authentication token" on each request, then the RequestTransport is the way to go on the client-side.Have a look http://code.google.com/p/google-web-toolkit/source/browse/tags/2.1.1/samples/expenses/src/main/java/com/google/gwt/sample/gaerequest/ which is used in the Expenses sample.
In such a scenario, you'll generally have a "session" maintained by the server through a cookie, which will be enough (yes, cookies are not that secure, but still deemed secure enough that everyone from Google to Facebook, Twitter, Microsoft, Yahoo!, etc. use them).
Of course! I didn't mean to imply that you shouldn't secure your app, but honestly if someone succeeds in hijacking your session, then he could possibly do it before loading the host page, so that your GWT app will run with the hijacked session, and the "auth token in the request payload" won't be of any help.
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
Hi Thomas,On Fri, Feb 25, 2011 at 8:49 AM, Thomas Broyer <t.br...@gmail.com> wrote:Of course! I didn't mean to imply that you shouldn't secure your app, but honestly if someone succeeds in hijacking your session, then he could possibly do it before loading the host page, so that your GWT app will run with the hijacked session, and the "auth token in the request payload" won't be of any help.
First off, the hacker couldn't have access to the local cookie on the user's machine unless the user has been infected with a virus. If the user's computer has been infected with a virus that can some how target local cookies then this user has a lot more to worry about than someone hijacking their session. So let's rule that scenario out.
Secondly, if the hacker could somehow manage to hijack your session - meaning they've some how coerced the request to use a different value for the session id) and do it before loading the host page it wouldn't make a difference if every Servlet method that is called does the following:
1) checks each payload for an auth token (a value equal to the sid stored as a cookie on the client) and
2) compares the auth token's value to the HttpSession's session id value. If they aren't the same then throw a custom exception and catch it on the client and authenticate the user (either form-based auth or some other method such as Google Account, OpenId, et. al)
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
You contradict yourself (compare the HttpSession's ID with the auth token –the HttpSession is maintained by a cookie, whose value generally is the session's ID– vs. do not send the auth token in a cookie), but that's not the problem.
The problem is: how are you initializing the auth token on the client side, and how you associate it with the user on the server-side? The client and server have to share some knowledge at some point, and if you have use "form based" authentication on another web page (i.e. your app's host page is protected and cannot be accessed without being authenticated), then the only way (not accurate, but that's how 99.999% of auth is done, because the alternative comes with a UX penalty) to "transfer" the authentication from the login page to the app's page is to use either a cookie or pass a unique token in the URL, both of which can be hijacked.
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
On Fri, Feb 25, 2011 at 12:30 PM, Thomas Broyer <t.br...@gmail.com> wrote:You contradict yourself (compare the HttpSession's ID with the auth token –the HttpSession is maintained by a cookie, whose value generally is the session's ID– vs. do not send the auth token in a cookie), but that's not the problem.
Actually I am not contradicting myself, Thomas. You just failed to understand!
The problem is: how are you initializing the auth token on the client side, and how you associate it with the user on the server-side? The client and server have to share some knowledge at some point, and if you have use "form based" authentication on another web page (i.e. your app's host page is protected and cannot be accessed without being authenticated), then the only way (not accurate, but that's how 99.999% of auth is done, because the alternative comes with a UX penalty) to "transfer" the authentication from the login page to the app's page is to use either a cookie or pass a unique token in the URL, both of which can be hijacked.
If the user is authenticated the authentication process should then send down the HttpSession id as part of the payload back to the client. The client then stores the session id it receives as part of the payload from the server as a local cookie.
This is where you fail to understand me: you make the assumption that the "authentication process" takes place, while I'm talking about bypassing it with a session-fixation attack.
One possible scenario (easily mitigated through the use of your own domain name):Attacker: authenticates to victim.example.com, grabs the cookies in use, store them at attacker.example.com (note: same domain, different subdomains, much like appspot.com hosted apps)
I think the discussion has become very interesting and I understood a lot about attacks and attackers but I still ponder over the question that if we have to put the auth token on the payload of the RequestFactory, how to do that?And after this how to read the token from the payload to verify it?
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.