teintinu / dyuproject

Automatically exported from code.google.com/p/dyuproject
Apache License 2.0
1 stars 0 forks source link

Appengines UserService.getCurrentUser() does not return a user authenticated via dyuproject #22

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. I have successfully integrated'com.dyuproject.openid.OpenIdServletFilter'
2. I can access a valid user object via 
request.getAttribute(OpenIdUser.ATTR_NAME)
3. If I try to access the authenticated user object via 
'com.google.appengine.api.users.UserService.getCurrentUser()' I get 'null'. 

I expect the 'OpenIdServletFilter' to populate the user object to the appengine 
interfaces.

As some other frameworks use the appengines API to access the user object, I 
need to have access to the userobject via 'userService.getCurrentUser()'.
I'm aware, that the object returned by the google API is a different then 
'OpenIdUser' but as 'dyuproject' provides easy appengine integration, I would 
exepect it to ease its full usage.

Is this possible?
How can I do this?

Original issue reported on code.google.com by dominik.bartholdi@gmail.com on 15 Aug 2010 at 5:34

GoogleCodeExporter commented 9 years ago
If you code relies on UserServiceFactory.getUserService (which I'm sure 100% it 
does), you cannot transparently provide a subclass of UserServiceFactory 
because it is marked final.

You can however implement a CustomUserService and wrap the one returned by that 
factory (including the request and response) and delegate the methods to the 
wrapped service except for isUserLoggedIn() and getCurrentUser().

public boolean isUserLoggedIn() {
  // checks the cached OpenIdUser from the request attribute first
  return RelyingParty.getUser(request) != null || wrappedService.isUserLoggedIn();
}

public User getCurrentUser() {
  OpenIdUser user = RelyingParty.getUser(request);
  if(user == null)
    return wrappedService.getCurrentUser();
  // populate the User from the OpenIdUser
  // and return that.
}

Good luck!

Original comment by david.yu...@gmail.com on 16 Aug 2010 at 4:27

GoogleCodeExporter commented 9 years ago
Can't find RelyingParty.getUser(request), has it been removed in the current 
version?

Original comment by hatem.el...@gmail.com on 17 Jun 2011 at 8:43