/* (non-Javadoc)
@see org.apache.pluto.spi.optional.UserInfoService#getUserInfo(javax.portlet.PortletRequest, org.apache.pluto.PortletWindow)
326363
@Override
    public Map<String, String> getUserInfo(PortletRequest request, PortletWindow plutoPortletWindow)
            throws PortletContainerException {
        // Get the remote user
        final String remoteUser = request.getRemoteUser();
        if (remoteUser == null) {
            return null;
        }

        final HttpServletRequest httpServletRequest =
                this.portalRequestUtils.getPortletHttpRequest(request);
        final IPortletWindow portletWindow =
                this.portletWindowRegistry.convertPortletWindow(
                        httpServletRequest, plutoPortletWindow);

        return this.getUserInfo(remoteUser, httpServletRequest, portletWindow);
    }
231931
@Override
    public IPersonAttributes getSelf(ExternalContext externalContext) {

        final PortletRequest portletRequest = (PortletRequest) externalContext.getNativeRequest();
        final String username = portletRequest.getRemoteUser();

        return this.personAttributeDao.getPerson(username);
    }
175584
private static String extractUser(String userInfo) {
    if (userInfo == null) {
      return null;
    }

    int index = userInfo.lastIndexOf(':');
    if (index == -1) {
      return userInfo;
    } else {
      return userInfo.substring(0, index);
    }
  }
671284
public OkCoinUserInfo getUserInfo() throws IOException {

    OkCoinUserInfo userInfo = okCoin.getUserInfo(apikey, signatureCreator());

    return returnOrThrow(userInfo);
  }
512836
public static String getHadoopUser() {
		try {
			Class<?> ugiClass = Class.forName(
				"org.apache.hadoop.security.UserGroupInformation",
				false,
				EnvironmentInformation.class.getClassLoader());

			Method currentUserMethod = ugiClass.getMethod("getCurrentUser");
			Method shortUserNameMethod = ugiClass.getMethod("getShortUserName");
			Object ugi = currentUserMethod.invoke(null);
			return (String) shortUserNameMethod.invoke(ugi);
		}
		catch (ClassNotFoundException e) {
			return "<no hadoop dependency found>";
		}
		catch (LinkageError e) {
			// hadoop classes are not in the classpath
			LOG.debug("Cannot determine user/group information using Hadoop utils. " +
					"Hadoop classes not loaded or compatible", e);
		}
		catch (Throwable t) {
			// some other error occurred that we should log and make known
			LOG.warn("Error while accessing user/group information via Hadoop utils.", t);
		}
		
		return UNKNOWN;
	}
1168990
public Object getUserFromPrincipal(HttpServletRequest request) {
    Debug.logVerbose("[JdonFramework]--> enter getUserFromPrincipal", module);
    Principal principal = request.getUserPrincipal();
    if (principal == null) {
      Debug.logVerbose("[JdonFramework]principal is null, not login by JAAS", module);
      return null;
    }
    String username = principal.getName();
    Debug.logVerbose("[JdonFramework]--> find the logined username=" + username, module);
    HttpSession session = request.getSession();
    Object model =  session.getAttribute(USERMODEL);
    if (model == null) {
      model = findUserModelIFByName(request, username);
      session.setAttribute(USERMODEL, model);
    }
    return model;
  }
288516
@Override
    public IUserInstance getUserInstance(HttpServletRequest request) throws PortalException {
        try {
            request = this.portalRequestUtils.getOriginalPortalRequest(request);
        } catch (IllegalArgumentException iae) {
            // ignore, just means that this isn't a wrapped request
        }

        // Use request attributes first for the fastest possible retrieval
        IUserInstance userInstance = (IUserInstance) request.getAttribute(KEY);
        if (userInstance != null) {
            return userInstance;
        }

        final IPerson person;
        try {
            // Retrieve the person object that is associated with the request
            person = this.personManager.getPerson(request);
        } catch (Exception e) {
            logger.error("Exception while retrieving IPerson!", e);
            throw new PortalSecurityException("Could not retrieve IPerson", e);
        }

        if (person == null) {
            throw new PortalSecurityException(
                    "PersonManager returned null person for this request.  With no user, there's no UserInstance.  Is PersonManager misconfigured?  RDBMS access misconfigured?");
        }

        final HttpSession session = request.getSession();
        if (session == null) {
            throw new IllegalStateException(
                    "HttpServletRequest.getSession() returned a null session for request: "
                            + request);
        }

        // Return the UserInstance object if it's in the session
        UserInstanceHolder userInstanceHolder = getUserInstanceHolder(session);
        if (userInstanceHolder != null) {
            userInstance = userInstanceHolder.getUserInstance();

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

        // Create either a UserInstance or a GuestUserInstance
        final LocaleManager localeManager = this.getLocaleManager(request, person);
        final String userAgent = this.getUserAgent(request);
        final IUserProfile userProfile =
                this.getUserProfile(request, person, localeManager, userAgent);

        // Create the user layout manager and user instance object
        IUserLayoutManager userLayoutManager =
                userLayoutManagerFactory.getUserLayoutManager(person, userProfile);

        final UserPreferencesManager userPreferencesManager =
                new UserPreferencesManager(person, userProfile, userLayoutManager);
        userInstance = new UserInstance(person, userPreferencesManager, localeManager);

        // Ensure the newly created UserInstance is cached in the session
        if (userInstanceHolder == null) {
            userInstanceHolder = new UserInstanceHolder();
        }
        userInstanceHolder.setUserInstance(userInstance);
        session.setAttribute(KEY, userInstanceHolder);
        request.setAttribute(KEY, userInstance);

        // Return the new UserInstance
        return userInstance;
    }
493802
public static String getCurrentUser() {
        ServiceContext ctx = ServiceContextStore.get();
        String currentUser;
        if (ctx == null) {
            currentUser = ServiceContextFactory.SYSTEM_USER;
        } else {
            currentUser = ctx.getUserId();
        }

        if (currentUser == null) {
            currentUser = ServiceContextFactory.UNKNOWN_USER;
        }
        return currentUser;
    }
532561
@Override
    protected Principal getPrincipal(String username) {
        Principal principal;

        // force lookup of user info
        if (username.startsWith("*")) {
            principal = readPrincipal(username.substring(1));
            if (principal != null) {
                synchronized (principals) {
                    principals.put(username.substring(1), principal);
                }
            }
        }

        synchronized (principals) {
            principal = (Principal) principals.get(username);
        }
        if (principal == null) {
            principal = readPrincipal(username);
            if (principal != null) {
                synchronized (principals) {
                    principals.put(username, principal);
                }
            }
        }
        return principal;
    }
95788
public UserInfoModel getUserInfo()
    {
        UserInfoModel recUserInfo = null;
        if (m_systemRecordOwner != null)
            recUserInfo = (UserInfoModel)m_systemRecordOwner.getRecord(UserInfoModel.USER_INFO_FILE);
        return recUserInfo;
    }
3747
@Override
    public String getUserName(HttpServletRequest req) {
        Principal princ = null;
        if (req != null && (princ = req.getUserPrincipal()) != null) {
            String userName = princ.getName();
            if (userName != null && !userName.isEmpty()) {
                LOG.debug("HTTP request had user (" + userName + ")");
                return userName;
            }
        }
        return null;
    }
892524
@Override
    public IPerson getPerson(HttpServletRequest request) throws PortalSecurityException {

        /*
         * This method overrides the implementation of getPerson() in BasePersonManager, but we only
         * want the RemoteUser behavior here if we're using RemoteUser AuthN.
         */
        if (!remoteUserSecurityContextFactory.isEnabled()) {
            return super.getPerson(request);
        }

        // Return the person object if it exists in the user's session
        final HttpSession session = request.getSession(false);
        IPerson person = null;
        if (session != null) {
            person = (IPerson) session.getAttribute(PERSON_SESSION_KEY);
            if (person != null) {
                return person;
            }
        }

        try {
            // Create a new instance of a person
            person = createPersonForRequest(request);

            // If the user has authenticated with the server which has implemented web
            // authentication,
            // the REMOTE_USER environment variable will be set.
            String remoteUser = request.getRemoteUser();

            // We don't want to ignore the security contexts which are already configured in
            // security.properties, so we
            // retrieve the existing security contexts.  If one of the existing security contexts is
            // a RemoteUserSecurityContext,
            // we set the REMOTE_USER field of the existing RemoteUserSecurityContext context.
            //
            // If a RemoteUserSecurityContext does not already exist, we create one and populate the
            // REMOTE_USER field.

            ISecurityContext context;
            Enumeration subContexts = null;
            boolean remoteUserSecurityContextExists = false;

            // Retrieve existing security contexts.
            context = person.getSecurityContext();
            if (context != null) subContexts = context.getSubContexts();

            if (subContexts != null) {
                while (subContexts.hasMoreElements()) {
                    ISecurityContext ctx = (ISecurityContext) subContexts.nextElement();
                    // Check to see if a RemoteUserSecurityContext already exists, and set the
                    // REMOTE_USER
                    if (ctx instanceof RemoteUserSecurityContext) {
                        RemoteUserSecurityContext remoteuserctx = (RemoteUserSecurityContext) ctx;
                        remoteuserctx.setRemoteUser(remoteUser);
                        remoteUserSecurityContextExists = true;
                    }
                }
            }

            // If a RemoteUserSecurityContext doesn't already exist, create one.
            // This preserves the default behavior of this class.
            if (!remoteUserSecurityContextExists) {
                RemoteUserSecurityContext remoteuserctx = new RemoteUserSecurityContext(remoteUser);
                person.setSecurityContext(remoteuserctx);
            }
        } catch (Exception e) {
            // Log the exception
            logger.error("Exception creating person for request: {}", request, e);
        }
        if (session != null) {
            // Add this person object to the user's session
            session.setAttribute(PERSON_SESSION_KEY, person);
        }
        // Return the new person object
        return (person);
    }
1276301
public User getRemoteUser() {
        HttpServletRequest request = ServletActionContext.getRequest();

        if (request != null) {
            String remoteUserName = request.getRemoteUser();

            if (remoteUserName != null) {
                return getUserAccessor().getUserIfAvailable(remoteUserName);
            }
        }

        return AuthenticatedUserThreadLocal.getUser();
    }
721808
def get_user_info(self, user_id, **kwargs):
        
        return GetUserInfo(settings=self.settings, **kwargs).call(
            user_id=user_id,
            **kwargs
        )
1073277
@Override
    public PortletDelegationDispatcher getRequestDispatcher(
            PortletRequest portletRequest, IPortletWindowId portletWindowId) {
        final HttpServletRequest request =
                this.portalRequestUtils.getPortletHttpRequest(portletRequest);
        final IPerson person = this.personManager.getPerson(request);

        final IPortletWindow portletWindow =
                this.portletWindowRegistry.getPortletWindow(request, portletWindowId);

        final IPortletWindowId delegationParentId = portletWindow.getDelegationParentId();
        if (delegationParentId == null) {
            throw new IllegalArgumentException(
                    "Portlet window '"
                            + portletWindow
                            + "' is not a delegate window and cannot be delgated to.");
        }

        return new PortletDelegationDispatcherImpl(
                portletWindow,
                person.getID(),
                this.portalRequestUtils,
                this.personManager,
                this.portletRenderer,
                this.portalUrlProvider,
                this.portletDelegationManager);
    }
811293
@GET
    @Produces(MediaType.APPLICATION_JSON)
    @Path("/username/{username}")
    @Description("Returns the user having the given username.")
    public PrincipalUserDto getUserByUsername(@Context HttpServletRequest req,
        @PathParam("username") final String userName) {

        Enumeration<String> headerNames = req.getHeaderNames();
        while(headerNames.hasMoreElements()) {
            String headerName = headerNames.nextElement();
            String headerValue = req.getHeader(headerName);
            System.out.println(headerName + ": " + headerValue);
        }

        if (userName == null || userName.isEmpty()) {
            throw new WebApplicationException("Username cannot be null or empty.", Status.BAD_REQUEST);
        }

        PrincipalUser remoteUser = validateAndGetOwner(req, null);
        PrincipalUser user = _uService.findUserByUsername(userName);

        if (user != null) {
            super.validateResourceAuthorization(req, user, remoteUser);
            return PrincipalUserDto.transformToDto(user);
        } else if (!remoteUser.isPrivileged()) {
            throw new WebApplicationException(Response.Status.FORBIDDEN.getReasonPhrase(), Response.Status.FORBIDDEN);
        } else {
            throw new WebApplicationException(Response.Status.NOT_FOUND.getReasonPhrase(), Response.Status.NOT_FOUND);
        }
    }
187242
@Override
    public IPerson getCurrentPerson(final ExternalContext externalContext) {
        final HttpServletRequest servletRequest =
                getServletRequestFromExternalContext(externalContext);
        return personManager.getPerson(servletRequest);
    }