Skip to content

Instantly share code, notes, and snippets.

@sfussenegger
Created March 24, 2011 08:29
Show Gist options
  • Save sfussenegger/884744 to your computer and use it in GitHub Desktop.
Save sfussenegger/884744 to your computer and use it in GitHub Desktop.
extract accountId from User set as "user" property at session scope
package org.example;
import java.io.Serializable;
import org.springframework.social.web.connect.AccountIdExtractor;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.WebRequest;
// your own User class
import org.example.User;
/**
* extract accountId from User set as "user" property at session scope
*/
public class UserAccountIdExtractor implements AccountIdExtractor {
@Override
public Serializable extractAccountId(final WebRequest request) {
User user = (User) request.getAttribute("user", RequestAttributes.SCOPE_SESSION);
return user == null ? null : user.getId();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment