package eu.dnetlib.loginservice.services; import eu.dnetlib.loginservice.entities.User; import eu.dnetlib.loginservice.exception.ResourceNotFoundException; import org.mitre.openid.connect.model.OIDCAuthenticationToken; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Service; @Service public class UserInfoService { public User getUserInfo() throws ResourceNotFoundException { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if(authentication instanceof OIDCAuthenticationToken) { return new User((OIDCAuthenticationToken) authentication); } throw new ResourceNotFoundException("No Session has been found"); } }