@@ -0,0 +1,1715 @@
+package net.davidvoid.thor.lightning.util;%0D%0A%0D%0A%0D%0Aimport static org.springframework.util.Assert.isTrue;%0D%0Aimport static org.springframework.util.Assert.notNull;%0D%0A%0D%0Aimport java.util.Arrays;%0D%0Aimport java.util.Collection;%0D%0Aimport java.util.List;%0D%0A%0D%0Aimport net.davidvoid.thor.lightning.service.security.ThorAuthentication;%0D%0A%0D%0Aimport org.springframework.security.core.Authentication;%0D%0Aimport org.springframework.security.core.GrantedAuthority;%0D%0Aimport org.springframework.security.core.context.SecurityContextHolder;%0D%0A%0D%0Apublic class SessionUser %7B%0D%0A    private Authentication authentication = null;%0D%0A    private boolean anonymous = true;%0D%0A%0D%0A    public static SessionUser get() %7B%0D%0A        Authentication auth = SecurityContextHolder.getContext().getAuthentication();%0D%0A        notNull(auth);%0D%0A%0D%0A        return new SessionUser(auth);%0D%0A    %7D%0D%0A    %0D%0A    public List%3CString%3E getRoles() %7B%0D%0A        Collection%3C? extends GrantedAuthority%3E it = authentication.getAuthorities();%0D%0A        String%5B%5D roles = (String%5B%5D) it.stream().map((GrantedAuthority a) -%3E %7B return a.toString();%7D).toArray();%0D%0A        return Arrays.asList(roles);%0D%0A    %7D%0D%0A    %0D%0A    public String getName() %7B%0D%0A        return authentication.getName();%0D%0A    %7D%0D%0A    %0D%0A    public boolean isAnonymous() %7B%0D%0A        return anonymous;%0D%0A    %7D%0D%0A    %0D%0A    public long getId() %7B%0D%0A        isTrue(!isAnonymous(), %22getid can only be called on non-anonymous users%22);%0D%0A%0D%0A        return ((ThorAuthentication) authentication).getId();%0D%0A    %7D%0D%0A    %0D%0A    private SessionUser(Authentication auth) %7B%0D%0A        if (auth instanceof ThorAuthentication) %7B%0D%0A            anonymous = false;%0D%0A        %7D else %7B%0D%0A            anonymous = true;%0D%0A        %7D%0D%0A%0D%0A        this.authentication = auth;%0D%0A    %7D%0D%0A%7D%0D%0A

add a helper to get user in the session