当前位置: 首页>>代码示例>>Java>>正文


Java HttpServletRequest.getRemoteUser方法代码示例

本文整理汇总了Java中javax.servlet.http.HttpServletRequest.getRemoteUser方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServletRequest.getRemoteUser方法的具体用法?Java HttpServletRequest.getRemoteUser怎么用?Java HttpServletRequest.getRemoteUser使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.servlet.http.HttpServletRequest的用法示例。


在下文中一共展示了HttpServletRequest.getRemoteUser方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: constructCredentialsFromRequest

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@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;
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:17,代码来源:PrincipalFromRequestRemoteUserNonInteractiveCredentialsAction.java

示例2: isUserPermitted

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:30,代码来源:AbstractAvaticaHandler.java

示例3: doFilter

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@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);
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:24,代码来源:StaticUserWebFilter.java

示例4: handleRequestInternal

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@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);
}
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:24,代码来源:ClearPassController.java

示例5: createPlayerIfNecessary

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
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;
}
 
开发者ID:airsonic,项目名称:airsonic,代码行数:25,代码来源:SubsonicRESTController.java

示例6: isAuthenticated

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
 * 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();
}
 
开发者ID:IBM,项目名称:Microservices-with-JHipster-and-Spring-Boot,代码行数:13,代码来源:AccountResource.java

示例7: getUser

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
protected static UserGroupInformation getUser(HttpServletRequest req) {
  String remoteUser = req.getRemoteUser();
  UserGroupInformation callerUGI = null;
  if (remoteUser != null) {
    callerUGI = UserGroupInformation.createRemoteUser(remoteUser);
  }
  return callerUGI;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:9,代码来源:WebServices.java

示例8: constructCredentialsFromRequest

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@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;
}
 
开发者ID:yuweijun,项目名称:cas-server-4.2.1,代码行数:12,代码来源:PrincipalFromRequestRemoteUserNonInteractiveCredentialsAction.java

示例9: isAuthenticated

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
* 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();
}
 
开发者ID:asanzdiego,项目名称:codemotion-2017-taller-de-jhipster,代码行数:13,代码来源:AccountResource.java

示例10: hasAccess

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
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;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:12,代码来源:AMWebServices.java

示例11: hasAdministratorAccess

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:37,代码来源:HttpServer2.java

示例12: doFilter

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@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();
    }

}
 
开发者ID:xm-online,项目名称:xm-gate,代码行数:52,代码来源:LoggingFilter.java

示例13: computeEffectiveUrl

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
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();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:15,代码来源:InvocationContextImpl.java

示例14: isAuthenticated

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
 * 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();
}
 
开发者ID:klask-io,项目名称:klask-io,代码行数:15,代码来源:AccountResource.java


注:本文中的javax.servlet.http.HttpServletRequest.getRemoteUser方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。