package com.orionplatform.web.core.session.tasks;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.UserDetails;
import com.orionplatform.core.abstraction.Orion;

public class ExtractUsernameFromAuthenticationObjectTask extends Orion
{
    public static String run(Authentication authentication)
    {
        Object principal = authentication.getPrincipal();

        if(principal instanceof UserDetails)
        {
            return ((UserDetails)principal).getUsername();
        }
        else
        {
            return principal.toString();
        }
    }
}