Java tutorial
/** * Copyright(C) 2014 * NEC Corporation All rights reserved. * * No permission to use, copy, modify and distribute this software * and its documentation for any purpose is granted. * This software is provided under applicable license agreement only. */ package com.nec.core.context; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; /** * This class will be used to get the current logged in username in Spring * Security Context * * @author sondn * */ public abstract class RootSecurityContext { private RootSecurityContext() { // } /** * Obtains the currently authenticated principal, or an authentication * request token. * * @return the Authentication or null if no authentication information is * available */ public static Object getPrincipal() { final Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication != null) { return authentication.getPrincipal(); } return null; } }