package test;

import org.springframework.security.Authentication;
import org.springframework.security.context.SecurityContext;
import org.springframework.security.context.SecurityContextHolder;

public class PingService {

	public String ping() {
		return "pong";
	}
	
	
	public String whoami() {
		SecurityContext context = SecurityContextHolder.getContext();
		if(context == null) throw new SecurityException("Could not get SecurityContext from SecurityContextHolder (null)");
		Authentication authentication = context.getAuthentication();
		if(authentication == null) throw new SecurityException("Could not get Authentication from SecurityContext (null)");
		String name = authentication.getName();
		return name;
	}
}
