Returns the level of detail that should be returned by the endpoint.

@param principal Authenticated user
@return The {@link HealthLevelOfDetail}
482679
protected HealthLevelOfDetail levelOfDetail(@Nullable Principal principal) {
        boolean showDetails = false;
        switch (detailsVisible) {
            case AUTHENTICATED:
                showDetails = principal != null;
                break;
            case ANONYMOUS:
                showDetails = true;
            default:
                // no-op
        }
        if (showDetails) {
            return HealthLevelOfDetail.STATUS_DESCRIPTION_DETAILS;
        } else {
            return HealthLevelOfDetail.STATUS;
        }
    }
391009
public String principal() {
        if (getSubject() != null) {
            // Get the principal to print out
            Object principal = getSubject().getPrincipal();
            return principal.toString();
        }
        return "Guest";
    }
769488
public String getLevel() {
        try {
            LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
            return loggerContext.getLogger("root").getLevel().toString();
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }
63178
public java.util.List<PolicyDetail> getUserPolicyList() {
        if (userPolicyList == null) {
            userPolicyList = new com.amazonaws.internal.SdkInternalList<PolicyDetail>();
        }
        return userPolicyList;
    }
321614
public java.security.Principal getUserPrincipal()
    {
        if (WCCustomProperties.CHECK_REQUEST_OBJECT_IN_USE){
            checkRequestObjectInUse();
        }
        IWebAppSecurityCollaborator webAppSec=null;
        if (getDispatchContext()!=null && getDispatchContext().getWebApp() != null) {
            webAppSec = CollaboratorHelperImpl.getCurrentSecurityCollaborator(getDispatchContext().getWebApp());
        } else {
            webAppSec = CollaboratorHelperImpl.getCurrentSecurityCollaborator();           
        } 
            
        if (webAppSec != null) {
            if (TraceComponent.isAnyTracingEnabled()&&logger.isLoggable (Level.FINE)){  //306998.15
                logger.logp(Level.FINE, CLASS_NAME,"getUserPrincipal", "calling getUserPrincipal on " + webAppSec.getClass().getName());
            }
            return webAppSec.getUserPrincipal();
        } else {
            if (TraceComponent.isAnyTracingEnabled()&&logger.isLoggable (Level.FINE)){  //306998.15
                logger.logp(Level.FINE, CLASS_NAME,"getUserPrincipal", "returning null");
            }
            // No IWebAppSecurityCollaborator means no security, so no Principal 
            return null;
        }
    }
1160774
@JsonIgnore
    protected Map<String, List<Object>> getPrincipalAttributes(final Principal principal) {
        if (ignoreResolvedAttributes) {
            return new HashMap<>(0);
        }
        return convertPrincipalAttributesToPersonAttributes(principal.getAttributes());
    }
641529
private HttpServletRequest wrapTheRequest(final ServletRequest request, final AuthPrincipal principal) {
        HttpServletRequestWrapper wrapper = new HttpServletRequestWrapper((HttpServletRequest) request) {
            @Override
            public Principal getUserPrincipal() {
                return principal;
            }

            @Override
            public boolean isUserInRole(String role) {
                return principal.getRoles().contains(role);
            }

            @Override
            public String getRemoteUser() {
                return principal.getName();
            }
        };
        return wrapper;
    }
783381
@GET
    public String showBasicUserSecret(@Context SecurityContext context) {
        User user = (User) context.getUserPrincipal();
        return String.format("Hey there, %s. You seem to be a basic user. %d", user.getName(), user.getId());
    }
657549
@Override
    public Principal getCallerPrincipal() {

        String securityName = null;
        Principal principal = null;
        Subject callerSubject = getCallerSubject();

        if (callerSubject == null) {
            return null;
        }

        SubjectHelper subjectHelper = new SubjectHelper();
        if (subjectHelper.isUnauthenticated(callerSubject)) {
            return null;
        }

        // Here is the order to get the callerPrincipal
        // 1) jsonWebToken in subject
        // 2) From JASPIC property
        // 3) From WSCredential.getSecurityName
        // 4) From WSPrincipal
        // 5) First Principal in Subject

        // 1) From jsonWebToken in subject
        Principal jsonWebToken = MpJwtHelper.getJsonWebTokenPricipal(callerSubject);
        if (jsonWebToken != null) {
            return jsonWebToken;
        }

        WSCredential wscredential = getWSCredential(callerSubject);

        // 2) From JASPIC property
        if (wscredential != null) {
            try {
                principal = (Principal) wscredential.get("com.ibm.wsspi.security.cred.jaspi.principal");
                if (principal != null)
                    return principal;
            } catch (Exception e) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "Internal error getting JASPIC Principal from credential", e);
                }
            }

            // 3) From WSCredential.getSecurityName
            try {
                securityName = wscredential.getSecurityName();
            } catch (Exception e) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "Error getting securityName from WSCredential", e);
                }
            }

            WSPrincipal wsPrincipal = null;
            if (securityName != null) {
                Set<WSPrincipal> principals = callerSubject.getPrincipals(WSPrincipal.class);
                if (!principals.isEmpty()) {
                    wsPrincipal = principals.iterator().next();
                    wsPrincipal = new WSPrincipal(securityName, wsPrincipal.getAccessId(), wsPrincipal.getAuthenticationMethod());
                }

                if (wsPrincipal != null) {
                    return wsPrincipal;
                }
            }

            // 4) From WSPrincipal
            Set<Principal> principals = callerSubject.getPrincipals();
            if (principals.size() > 0) {
                for (Iterator<Principal> iterator = principals.iterator(); iterator.hasNext();) {
                    principal = iterator.next();
                    if (principal instanceof WSPrincipal)
                        return principal;
                }
            }

            // There is no WSPrincipal so just return first one
            // 5) First Principal in Subject
            return principals.iterator().next();
        }

        return null;
    }
1239728
public String getPrincipal(ContainerRequestContext httpRequest) {
        if (principalCookieName != null && httpRequest.getCookies().size() > 0) {
            Map<String, Cookie> cookies = httpRequest.getCookies();
            for (Cookie cookie : cookies.values()) {
                if (principalCookieName.equals(cookie.getName())) {
                    return cookie.getValue();
                }
            }
        }

        return null;
    }
1270487
@Override
    public Principal getCallerPrincipal() {
        synchronized (this) {
            if ((state == PRE_CREATE) || (state == CREATING) || (!allowRollbackOnly))
                throw new IllegalStateException();
        }

        return super.getCallerPrincipal();

    }
848956
@RequestMapping(value = "/oauth/token_key", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, String> getKey(Principal principal) {
        if ((principal == null || principal instanceof AnonymousAuthenticationToken) && !converter.isPublic()) {
            throw new AccessDeniedException("You need to authenticate to see a shared key");
        }
        Map<String, String> result = converter.getKey();
        return result;
    }
463663
@Override
    public PrincipalUser getUser(String username, String password) {
        requireNotDisposed();
        requireArgument(_isUsernameValid(username), MessageFormat.format("Invalid username: {0}", username));

        PrincipalUser result = null;
        String userDn = _findDNForUser(username);

        if (userDn != null && password != null) {
            result = _findPrincipalUser(userDn, username, password);
        }
        return result;
    }
1373416
protected Map<String, List<Object>> getPrincipalAttributesForPrincipal(final Principal principal, final Map<String, List<Object>> principalAttributes) {
        return principalAttributes;
    }
447200
public Principal getUserPrincipal()
    {
        if (_userPrincipal == __NO_USER) return null;

        if (_userPrincipal == __NOT_CHECKED)
        {
            _userPrincipal = __NO_USER;

            // Try a lazy authentication
            HttpContext context = getHttpResponse().getHttpContext();
            if (context != null)
            {
                Authenticator auth = context.getAuthenticator();
                UserRealm realm = context.getRealm();
                if (realm != null && auth != null)
                {
                    try
                    {
                        // TODO - should not need to recalculate this!
                        String pathInContext = getPath().substring(
                                context.getContextPath().length());
                        auth.authenticate(realm, pathInContext, this, null);
                    }
                    catch (Exception e)
                    {
                        LogSupport.ignore(log, e);
                    }
                }
            }

            if (_userPrincipal == __NO_USER) return null;
        }
        return _userPrincipal;
    }
795215
@Override
	public PrincipalUser getUser(String username, String password) {
		requireNotDisposed();

		PrincipalUser result = _userService.findUserByUsername(username);
		String isPrivileged= _config.getValue(Property.IS_PRIVILEGED.getName(), Property.IS_PRIVILEGED.getDefaultValue());

		if(result == null){
			result = new PrincipalUser(_userService.findAdminUser(), username, username+"@gmail.com");
		}
                DAILY_USERS.put(username, System.currentTimeMillis());
                MONTHLY_USERS.put(username, System.currentTimeMillis());
                _monitorService.updateCounter(MonitorService.Counter.DAILY_USERS, DAILY_USERS.size(), new HashMap<>(0));
                _monitorService.updateCounter(MonitorService.Counter.MONTHLY_USERS, MONTHLY_USERS.size(), new HashMap<>(0));
		_monitorService.updateCounter(MonitorService.Counter.UNIQUE_USERS, _userService.getUniqueUserCount(), new HashMap<String, String>(0));

		try{
			Method method = PrincipalUser.class.getDeclaredMethod("setPrivileged", boolean.class);
			method.setAccessible(true);
			method.invoke(result, Boolean.parseBoolean(isPrivileged));

		} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
			throw new SystemException("Failed to change privileged status.", e);
		}

		result = _userService.updateUser(result);
		return result;
	}
576486
public String getRemoteUser()
    {
        if (WCCustomProperties.CHECK_REQUEST_OBJECT_IN_USE){
            checkRequestObjectInUse();
        }
        String remoteUser = null;
        Principal principal = getUserPrincipal();
        if (principal == null) {
            //remoteUser = null;

            if (_request != null) {
                remoteUser = _request.getRemoteUser();
            }

        } else {
            remoteUser = principal.getName();
            if (TraceComponent.isAnyTracingEnabled()&&logger.isLoggable (Level.FINE)) {
                logger.logp(Level.FINE, CLASS_NAME, "getRemoteUser", "(security enabled)");
            }
        }
        if (TraceComponent.isAnyTracingEnabled()&&logger.isLoggable (Level.FINE)) {  //306998.15
            logger.logp(Level.FINE, CLASS_NAME, "getRemoteUser", "user=" + remoteUser);
        }
        return remoteUser;
    }