public

extract accountId from User set as "user" property at session scope

  • Download Gist
UserAccountIdExtractor.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
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();
}
 
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.