Skip to content

Instantly share code, notes, and snippets.

@arcseldon
Last active October 24, 2016 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arcseldon/11b4fee1e330241556a2bdc6cd585c03 to your computer and use it in GitHub Desktop.
Save arcseldon/11b4fee1e330241556a2bdc6cd585c03 to your computer and use it in GitHub Desktop.

Own version of com.auth0.SessionUtils with the following two methods overridden in custom impl.

     import org.springframework.beans.BeanUtils;
     ...
     
     
     public static Auth0User getAuth0User(final HttpServletRequest req) {
        System.out.println("GET AUTH0 USER");
        final MyAuth0User myAuth0User = (MyAuth0User) getSession(req).getAttribute(AUTH0_USER);
        final String userId = myAuth0User.getUserId();
        final String name = myAuth0User.getName();
        final String nickname = myAuth0User.getNickname();
        final String picture = myAuth0User.getPicture();
        final String email = myAuth0User.getEmail();
        final String givenName = myAuth0User.getGivenName();
        final String familyName = myAuth0User.getFamilyName();
        final Boolean emailVerified = myAuth0User.isEmailVerified();
        final Date createdAt = myAuth0User.getCreatedAt();
        final List<UserIdentity> identities = myAuth0User.getIdentities();
        final Map<String, Object> userMetadata = myAuth0User.getUserMetadata();
        final Map<String, Object> appMetadata = myAuth0User.getAppMetadata();
        final Map<String, Object> extraInfo = myAuth0User.getExtraInfo();
        final UserProfile userProfile = new UserProfile(userId, name, nickname, picture, email, emailVerified, familyName, createdAt, identities, extraInfo, userMetadata, appMetadata, givenName);
        return new Auth0User(userProfile);
    }

    public static void setAuth0User(final HttpServletRequest req, final Auth0User auth0User) {
        System.out.println("SET AUTH0 USER");
        final MyAuth0User myAuth0User = new MyAuth0User();
        BeanUtils.copyProperties(auth0User, myAuth0User);
        getSession(req).setAttribute(AUTH0_USER, myAuth0User);
    }

and something like this with whatever serialization method you want:

public class MyAuth0User implements Serializable {


   private static final long serialVersionUID = 1474505769852027133L;

   private String userId;
   private String name;
   private String nickname;
   private String picture;
   private String email;
   private boolean emailVerified;
   private String givenName;
   private String familyName;
   private Map<String, Object> userMetadata;
   private Map<String, Object> appMetadata;
   private Date createdAt;
   private List<UserIdentity> identities;
   private Map<String, Object> extraInfo;
   private List<String> roles = new ArrayList();
   private List<String> groups = new ArrayList();

  // default no-arg constructor and getters / setters ...
  
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment