@@ -0,0 +1,2002 @@
+package net.davidvoid.thor.lightning.service;%0D%0A%0D%0Aimport net.davidvoid.thor.lightning.data.access.UserStore;%0D%0Aimport net.davidvoid.thor.lightning.entity.User;%0D%0Aimport net.davidvoid.thor.lightning.exception.DuplicateUserException;%0D%0Aimport net.davidvoid.thor.lightning.exception.ResourceNotFoundException;%0D%0Aimport net.davidvoid.thor.lightning.exception.UnauthorizedAccessException;%0D%0A%0D%0Aimport org.springframework.beans.factory.annotation.Autowired;%0D%0Aimport org.springframework.stereotype.Component;%0D%0A%0D%0A@Component%0D%0Apublic class Auth %7B%0D%0A    @Autowired%0D%0A    UserStore store = null;%0D%0A%0D%0A    volatile User user = null;%0D%0A    %0D%0A    %0D%0A    public void authenticate(String token) %7B%0D%0A        ensureUserLoaded();%0D%0A%0D%0A        if (user == null %7C%7C !token.equals(this.user.getPassword())) %7B%0D%0A            throw new UnauthorizedAccessException(%22incorrect credential provided%22);%0D%0A        %7D%0D%0A    %7D%0D%0A    %0D%0A    public boolean registered() %7B%0D%0A        ensureUserLoaded();%0D%0A        return user != null;%0D%0A    %7D%0D%0A    %0D%0A    public User getCurrentUser() %7B%0D%0A        return user;%0D%0A    %7D%0D%0A    %0D%0A    synchronized public void register(String name, String token) %7B%0D%0A        ensureUserLoaded();%0D%0A        if (name != null) throw new DuplicateUserException(%22the user already registered%22);%0D%0A        %0D%0A        User user = new User();%0D%0A        user.setName(name);%0D%0A        user.setPassword(token);%0D%0A        store.add(user);%0D%0A        this.user = user;%0D%0A    %7D%0D%0A%0D%0A    private void ensureUserLoaded() %7B%0D%0A        // double checked locking with volatile variable%0D%0A        if (user == null) %7B%0D%0A            synchronized(this) %7B%0D%0A                if (user == null) %7B%0D%0A                    user = retrieve_token();%0D%0A                %7D%0D%0A            %7D%0D%0A            %0D%0A        %7D%0D%0A    %7D%0D%0A    %0D%0A    private User retrieve_token() %7B%0D%0A        try %7B%0D%0A            User user = store.getUser();%0D%0A            return user;%0D%0A        %7D catch (ResourceNotFoundException e) %7B%0D%0A        %7D%0D%0A        %0D%0A        assert false : %22should never reach here%22;%0D%0A        return null;%0D%0A    %7D%0D%0A%7D%0D%0A

add Auth for authenticate users