Java Code Examples for javax.servlet.http.HttpServletRequest.getRemoteUser()

The following are Jave code examples for showing how to use getRemoteUser() of the javax.servlet.http.HttpServletRequest class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: springboot-shiro-cas-mybatis   File: PrincipalFromRequestRemoteUserNonInteractiveCredentialsAction.java   View Source Code Vote up 7 votes
@Override
protected Credential constructCredentialsFromRequest(
        final RequestContext context) {
    final HttpServletRequest request = WebUtils
            .getHttpServletRequest(context);
    final String remoteUser = request.getRemoteUser();

    if (StringUtils.hasText(remoteUser)) {
        logger.debug("Remote  User [{}] found in HttpServletRequest", remoteUser);
        return new PrincipalBearingCredential(this.principalFactory.createPrincipal(remoteUser));
    }

    logger.debug("Remote User not found in HttpServletRequest.");

    return null;
}
 
Example 2
Project: calcite-avatica   File: AbstractAvaticaHandler.java   View Source Code Vote up 6 votes
/**
 * Determines if a request is permitted to be executed. The server may require authentication
 * and the login mechanism might have failed. This check verifies that only authenticated
 * users are permitted through when the server is requiring authentication. When a user
 * is disallowed, a status code and response will be automatically written to the provided
 * <code>response</code> and the caller should return immediately.
 *
 * @param serverConfig The server's configuration
 * @param request The user's request
 * @param response The response to the user's request
 * @return True if request can proceed, false otherwise.
 */
public boolean isUserPermitted(AvaticaServerConfiguration serverConfig, Request baseRequest,
    HttpServletRequest request, HttpServletResponse response) throws IOException {
  // Make sure that we drop any unauthenticated users out first.
  if (null != serverConfig) {
    if (AuthenticationType.SPNEGO == serverConfig.getAuthenticationType()) {
      String remoteUser = request.getRemoteUser();
      if (null == remoteUser) {
        response.setStatus(HttpURLConnection.HTTP_UNAUTHORIZED);
        response.getOutputStream().write(UNAUTHORIZED_ERROR.serialize().toByteArray());
        baseRequest.setHandled(true);
        return false;
      }
    }
  }

  return true;
}
 
Example 3
Project: hadoop-oss   File: StaticUserWebFilter.java   View Source Code Vote up 6 votes
@Override
public void doFilter(ServletRequest request, ServletResponse response,
                     FilterChain chain
                     ) throws IOException, ServletException {
  HttpServletRequest httpRequest = (HttpServletRequest) request;
  // if the user is already authenticated, don't override it
  if (httpRequest.getRemoteUser() != null) {
    chain.doFilter(request, response);
  } else {
    HttpServletRequestWrapper wrapper = 
        new HttpServletRequestWrapper(httpRequest) {
      @Override
      public Principal getUserPrincipal() {
        return user;
      }
      @Override
      public String getRemoteUser() {
        return username;
      }
    };
    chain.doFilter(wrapper, response);
  }
}
 
Example 4
Project: cas4.0.x-server-wechat   File: ClearPassController.java   View Source Code Vote up 6 votes
@Override
public ModelAndView handleRequestInternal(final HttpServletRequest request,
        final HttpServletResponse response) throws Exception {
    final String userName = request.getRemoteUser();

    LOGGER.debug("Handling clearPass request for user [{}]", userName);

    if (StringUtils.isBlank(userName)) {
        return returnError("No username was provided to clearPass.");
    }

    if (!this.credentialsCache.containsKey(userName)) {
        return returnError("Password could not be found in cache for user " + userName);
    }

    final String password = this.credentialsCache.get(userName);
    if (StringUtils.isBlank(password)) {
        return returnError("Password is null or blank");
    }

    LOGGER.debug("Retrieved credentials will be provided to the requesting service.");
    return new ModelAndView(this.successView, MODEL_CLEARPASS, password);
}
 
Example 5
Project: airsonic   File: SubsonicRESTController.java   View Source Code Vote up 6 votes
private String createPlayerIfNecessary(HttpServletRequest request, boolean jukebox) {
    String username = request.getRemoteUser();
    String clientId = request.getParameter("c");
    if (jukebox) {
        clientId += "-jukebox";
    }

    List<Player> players = playerService.getPlayersForUserAndClientId(username, clientId);

    // If not found, create it.
    if (players.isEmpty()) {
        Player player = new Player();
        player.setIpAddress(request.getRemoteAddr());
        player.setUsername(username);
        player.setClientId(clientId);
        player.setName(clientId);
        player.setTechnology(jukebox ? PlayerTechnology.JUKEBOX : PlayerTechnology.EXTERNAL_WITH_PLAYLIST);
        playerService.createPlayer(player);
        players = playerService.getPlayersForUserAndClientId(username, clientId);
    }

    // Return the player ID.
    return !players.isEmpty() ? players.get(0).getId() : null;
}
 
Example 6
Project: Microservices-with-JHipster-and-Spring-Boot   File: AccountResource.java   View Source Code Vote up 5 votes
/**
 * GET  /authenticate : check if the user is authenticated, and return its login.
 *
 * @param request the HTTP request
 * @return the login if the user is authenticated
 */
@GetMapping("/authenticate")
@Timed
public String isAuthenticated(HttpServletRequest request) {
    log.debug("REST request to check if the current user is authenticated");
    return request.getRemoteUser();
}
 
Example 7
Project: hadoop   File: WebServices.java   View Source Code Vote up 5 votes
protected static UserGroupInformation getUser(HttpServletRequest req) {
  String remoteUser = req.getRemoteUser();
  UserGroupInformation callerUGI = null;
  if (remoteUser != null) {
    callerUGI = UserGroupInformation.createRemoteUser(remoteUser);
  }
  return callerUGI;
}
 
Example 8
Project: jhipster-microservices-example   File: AccountResource.java   View Source Code Vote up 5 votes
/**
 * GET  /authenticate : check if the user is authenticated, and return its login.
 *
 * @param request the HTTP request
 * @return the login if the user is authenticated
 */
@GetMapping("/authenticate")
@Timed
public String isAuthenticated(HttpServletRequest request) {
    log.debug("REST request to check if the current user is authenticated");
    return request.getRemoteUser();
}
 
Example 9
Project: cas-server-4.2.1   File: PrincipalFromRequestRemoteUserNonInteractiveCredentialsAction.java   View Source Code Vote up 5 votes
@Override
protected Credential constructCredentialsFromRequest(final RequestContext context) {
    final HttpServletRequest request = WebUtils.getHttpServletRequest(context);
    final String remoteUser = request.getRemoteUser();

    if (StringUtils.hasText(remoteUser)) {
        logger.debug("Remote User [{}] found in HttpServletRequest", remoteUser);
        return new PrincipalBearingCredential(this.principalFactory.createPrincipal(remoteUser));
    }
    return null;
}
 
Example 10
Project: codemotion-2017-taller-de-jhipster   File: AccountResource.java   View Source Code Vote up 5 votes
/**
* GET  /authenticate : check if the user is authenticated, and return its login.
*
* @param request the HTTP request
* @return the login if the user is authenticated
*/
@GetMapping("/authenticate")
@Timed
public String isAuthenticated(HttpServletRequest request) {
    log.debug("REST request to check if the current user is authenticated");
    return request.getRemoteUser();
}
 
Example 11
Project: springboot-shiro-cas-mybatis   File: PrincipalFromRequestRemoteUserNonInteractiveCredentialsAction.java   View Source Code Vote up 5 votes
@Override
protected Credential constructCredentialsFromRequest(final RequestContext context) {
    final HttpServletRequest request = WebUtils.getHttpServletRequest(context);
    final String remoteUser = request.getRemoteUser();

    if (StringUtils.hasText(remoteUser)) {
        logger.debug("Remote User [{}] found in HttpServletRequest", remoteUser);
        return new PrincipalBearingCredential(this.principalFactory.createPrincipal(remoteUser));
    }
    return null;
}
 
Example 12
Project: hadoop   File: AMWebServices.java   View Source Code Vote up 5 votes
Boolean hasAccess(Job job, HttpServletRequest request) {
  String remoteUser = request.getRemoteUser();
  UserGroupInformation callerUGI = null;
  if (remoteUser != null) {
    callerUGI = UserGroupInformation.createRemoteUser(remoteUser);
  }
  if (callerUGI != null && !job.checkAccess(callerUGI, JobACL.VIEW_JOB)) {
    return false;
  }
  return true;
}
 
Example 13
Project: hadoop-oss   File: HttpServer2.java   View Source Code Vote up 5 votes
/**
 * Does the user sending the HttpServletRequest has the administrator ACLs? If
 * it isn't the case, response will be modified to send an error to the user.
 *
 * @param response used to send the error response if user does not have admin access.
 * @return true if admin-authorized, false otherwise
 * @throws IOException
 */
public static boolean hasAdministratorAccess(
    ServletContext servletContext, HttpServletRequest request,
    HttpServletResponse response) throws IOException {
  Configuration conf =
      (Configuration) servletContext.getAttribute(CONF_CONTEXT_ATTRIBUTE);
  // If there is no authorization, anybody has administrator access.
  if (!conf.getBoolean(
      CommonConfigurationKeys.HADOOP_SECURITY_AUTHORIZATION, false)) {
    return true;
  }

  String remoteUser = request.getRemoteUser();
  if (remoteUser == null) {
    response.sendError(HttpServletResponse.SC_FORBIDDEN,
                       "Unauthenticated users are not " +
                       "authorized to access this page.");
    return false;
  }

  if (servletContext.getAttribute(ADMINS_ACL) != null &&
      !userHasAdministratorAccess(servletContext, remoteUser)) {
    response.sendError(HttpServletResponse.SC_FORBIDDEN, "User "
        + remoteUser + " is unauthorized to access this page.");
    return false;
  }

  return true;
}
 
Example 14
Project: xm-gate   File: LoggingFilter.java   View Source Code Vote up 5 votes
@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
throws IOException, ServletException {

    StopWatch stopWatch = StopWatch.createStarted();

    String domain = request.getServerName();
    String remoteAddr = request.getRemoteAddr();
    Long contentLength = request.getContentLengthLong();

    String tenant = tenantMappingService != null ? tenantMappingService.getTenants().get(domain) : null;

    String method = null;
    String userLogin = null;
    String requestUri = null;

    try {

        if (request instanceof HttpServletRequest) {
            HttpServletRequest req = HttpServletRequest.class.cast(request);
            method = req.getMethod();
            userLogin = req.getRemoteUser();
            requestUri = req.getRequestURI();
        }

        MDCUtil.putRid(MDCUtil.generateRid() + ":" + userLogin + ":" + tenant);

        log.info("START {}/{} --> {} {}, contentLength = {} ", remoteAddr, domain, method, requestUri,
                 contentLength);

        chain.doFilter(request, response);

        Integer status = null;

        if (response instanceof HttpServletResponse) {
            HttpServletResponse res = HttpServletResponse.class.cast(response);
            status = res.getStatus();
        }

        log.info("STOP  {}/{} --> {} {}, status = {}, time = {} ms", remoteAddr, domain, method, requestUri,
                 status, stopWatch.getTime());

    } catch (Exception e) {
        log.error("STOP  {}/{} --> {} {}, error = {}, time = {} ms", remoteAddr, domain, method, requestUri,
                  LogObjectPrinter.printException(e), stopWatch.getTime());
        throw e;
    } finally {
        MDCUtil.clear();
    }

}
 
Example 15
Project: qualitoast   File: AccountResource.java   View Source Code Vote up 5 votes
/**
 * GET  /authenticate : check if the user is authenticated, and return its login.
 *
 * @param request the HTTP request
 * @return the login if the user is authenticated
 */
@GetMapping("/authenticate")
@Timed
public String isAuthenticated(HttpServletRequest request) {
    log.debug("REST request to check if the current user is authenticated");
    return request.getRemoteUser();
}
 
Example 16
Project: lams   File: InvocationContextImpl.java   View Source Code Vote up 5 votes
private URL computeEffectiveUrl( HttpServletRequest request, URL requestURL ) {
    if (!_application.requiresAuthorization( requestURL ) || userIsAuthorized( request, requestURL ) ) {
        return requestURL;
    } else if (request.getRemoteUser() != null) {
        throw new AccessDeniedException( requestURL );
    } else if (_application.usesBasicAuthentication()) {
        throw AuthorizationRequiredException.createBasicAuthenticationRequiredException( _application.getAuthenticationRealm() );
    } else if (!_application.usesFormAuthentication()) {
        throw new IllegalStateException( "Authorization required but no authentication method defined" );
    } else {
        ((ServletUnitHttpSession) request.getSession()).setOriginalURL( requestURL );
        return _application.getLoginURL();
    }
}
 
Example 17
Project: devoxxus-jhipster-microservices-demo   File: AccountResource.java   View Source Code Vote up 5 votes
/**
 * GET  /authenticate : check if the user is authenticated, and return its login.
 *
 * @param request the HTTP request
 * @return the login if the user is authenticated
 */
@GetMapping("/authenticate")
@Timed
public String isAuthenticated(HttpServletRequest request) {
    log.debug("REST request to check if the current user is authenticated");
    return request.getRemoteUser();
}
 
Example 18
Project: Code4Health-Platform   File: AccountResource.java   View Source Code Vote up 5 votes
/**
 * GET  /authenticate : check if the user is authenticated, and return its login.
 *
 * @param request the HTTP request
 * @return the login if the user is authenticated
 */
@GetMapping("/authenticate")
@Timed
public String isAuthenticated(HttpServletRequest request) {
    log.debug("REST request to check if the current user is authenticated");
    return request.getRemoteUser();
}
 
Example 19
Project: klask-io   File: AccountResource.java   View Source Code Vote up 5 votes
/**
 * GET  /authenticate : check if the user is authenticated, and return its login.
 *
 * @param request the HTTP request
 * @return the login if the user is authenticated
 */
@RequestMapping(value = "/authenticate",
    method = RequestMethod.GET,
    produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public String isAuthenticated(HttpServletRequest request) {
    log.debug("REST request to check if the current user is authenticated");
    return request.getRemoteUser();
}
 
Example 20
Project: sentry   File: AccountResource.java   View Source Code Vote up 5 votes
/**
 * GET  /authenticate : check if the user is authenticated, and return its login.
 *
 * @param request the HTTP request
 * @return the login if the user is authenticated
 */
@GetMapping("/authenticate")
@Timed
public String isAuthenticated(HttpServletRequest request) {
    log.debug("REST request to check if the current user is authenticated");
    return request.getRemoteUser();
}