Example usage for javax.servlet.http HttpServletRequest getRemoteUser

List of usage examples for javax.servlet.http HttpServletRequest getRemoteUser

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getRemoteUser.

Prototype

public String getRemoteUser();

Source Link

Document

Returns the login of the user making this request, if the user has been authenticated, or null if the user has not been authenticated.

Usage

From source file:org.eclipse.orion.internal.server.hosting.HostedStatusDecorator.java

private static UserInfo getWebUser(HttpServletRequest req) {
    String remoteUser = req.getRemoteUser();
    if (remoteUser != null) {
        try {//from   w  w  w . jav a2  s.  c  o  m
            return HostingActivator.getDefault().getMetastore().readUser(remoteUser);
        } catch (CoreException e) {
            //ignore and fall through
        }
    }
    return null;
}

From source file:org.eclipse.orion.internal.server.servlets.task.TaskJobHandler.java

public static final String getUserId(HttpServletRequest req) {
    if (req.getRemoteUser() != null) {
        return req.getRemoteUser();
    } else {/*  w w w .ja  v a 2 s.c  o m*/
        return req.getSession(true).getId();
    }
}

From source file:org.apache.falcon.util.Servlets.java

/**
 * Returns the user of the given request.
 *
 * @param httpRequest    an HTTP servlet request
 * @return the user//from w w  w.jav  a  2 s. com
 */
public static String getUserFromRequest(HttpServletRequest httpRequest) {

    LOG.info("HttpServletRequest RemoteUser is " + httpRequest.getRemoteUser());
    String user = httpRequest.getRemoteUser();
    if (!StringUtils.isEmpty(user)) {
        return user;
    }

    LOG.info("HttpServletRequest user.name param value is " + httpRequest.getParameter("user.name"));
    user = httpRequest.getParameter("user.name"); // available in query-param
    if (!StringUtils.isEmpty(user)) {
        return user;
    }

    LOG.info("HttpServletRequest user.name from remote-header is " + httpRequest.getParameter("user.name"));
    user = httpRequest.getHeader("Remote-User"); // backwards-compatibility
    if (!StringUtils.isEmpty(user)) {
        return user;
    }

    return null;
}

From source file:net.sourceforge.vulcan.web.struts.actions.BaseDispatchAction.java

protected static String getUsername(HttpServletRequest request) {
    String user = request.getRemoteUser();

    if (user == null) {
        user = "(anonymous)";
    }//w  ww .  j a  v  a2  s. co  m

    return user;
}

From source file:org.apache.atlas.web.util.Servlets.java

public static String getUserName(HttpServletRequest httpServletRequest) throws IOException {
    return httpServletRequest.getRemoteUser();
}

From source file:org.apache.atlas.web.util.Servlets.java

/**
 * Returns the user of the given request.
 *
 * @param httpRequest    an HTTP servlet request
 * @return the user/*from   w ww .j  av a 2s.  c  o m*/
 */
public static String getUserFromRequest(HttpServletRequest httpRequest) {
    String user = httpRequest.getRemoteUser();
    if (!StringUtils.isEmpty(user)) {
        return user;
    }

    user = httpRequest.getParameter("user.name"); // available in query-param
    if (!StringUtils.isEmpty(user)) {
        return user;
    }

    user = httpRequest.getHeader("Remote-User"); // backwards-compatibility
    if (!StringUtils.isEmpty(user)) {
        return user;
    }

    user = getDoAsUser(httpRequest);
    if (!StringUtils.isEmpty(user)) {
        return user;
    }

    return null;
}

From source file:nl.nn.adapterframework.http.HttpUtils.java

public static String getCommandIssuedBy(HttpServletRequest request) {
    String commandIssuedBy = " remoteHost [" + request.getRemoteHost() + "]";
    commandIssuedBy += " remoteAddress [" + request.getRemoteAddr() + "]";
    commandIssuedBy += " remoteUser [" + request.getRemoteUser() + "]";
    return commandIssuedBy;
}

From source file:org.eclipse.orion.internal.server.servlets.site.SiteConfigurationResourceHandler.java

/**
 * Obtain and return the user name from the request headers.
 *///w w  w . j a v  a 2s  . c o m
private static String getUserName(HttpServletRequest req) {
    return req.getRemoteUser();
}

From source file:org.apache.hadoop.yarn.server.timeline.webapp.TimelineWebServices.java

private static UserGroupInformation getUser(HttpServletRequest req) {
    String remoteUser = req.getRemoteUser();
    UserGroupInformation callerUGI = null;
    if (remoteUser != null) {
        callerUGI = UserGroupInformation.createRemoteUser(remoteUser);
    }//from w  w w  . j a  va  2 s. com
    return callerUGI;
}

From source file:it.geosolutions.geostore.services.rest.auditing.AuditInfoExtractorTest.java

private static HttpServletRequest getHttpServletRequest() {
    HttpServletRequest httpServletRequest = Mockito.mock(HttpServletRequest.class);
    Mockito.when(httpServletRequest.getRemoteAddr()).thenReturn("127.0.0.1");
    Mockito.when(httpServletRequest.getRemoteHost()).thenReturn("127.0.0.1");
    Mockito.when(httpServletRequest.getRemoteUser())
            .thenReturn("User[id=2, name=admin, group=[UserGroup[id=1, groupName=everyone]], role=ADMIN]");
    Mockito.when(httpServletRequest.getServerName()).thenReturn("localhost");
    UserGroup userGroup = Mockito.mock(UserGroup.class);
    Mockito.when(userGroup.getGroupName()).thenReturn("everyone");
    User user = Mockito.mock(User.class);
    Mockito.when(user.getName()).thenReturn("admin");
    Mockito.when(user.getRole()).thenReturn(Role.ADMIN);
    Mockito.when(user.getGroups()).thenReturn(Collections.singleton(userGroup));
    Authentication authentication = Mockito.mock(Authentication.class);
    Mockito.when(authentication.getPrincipal()).thenReturn(user);
    Mockito.when(httpServletRequest.getUserPrincipal()).thenReturn(authentication);
    return httpServletRequest;
}