當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。