org.springframework.security.web.access.AccessDeniedHandlerImpl类的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(11.0k)|赞(0)|评价(0)|浏览(254)

本文整理了Java中org.springframework.security.web.access.AccessDeniedHandlerImpl类的一些代码示例,展示了AccessDeniedHandlerImpl类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AccessDeniedHandlerImpl类的具体详情如下:
包路径:org.springframework.security.web.access.AccessDeniedHandlerImpl
类名称:AccessDeniedHandlerImpl

AccessDeniedHandlerImpl介绍

[英]Base implementation of AccessDeniedHandler.

This implementation sends a 403 (SC_FORBIDDEN) HTTP error code. In addition, if an #errorPage is defined, the implementation will perform a request dispatcher "forward" to the specified error page view. Being a "forward", the SecurityContextHolder will remain populated. This is of benefit if the view (or a tag library or macro) wishes to access the SecurityContextHolder. The request scope will also be populated with the exception itself, available from the key WebAttributes#ACCESS_DENIED_403.
[中]AccessDeniedHandler的基本实现。
此实现发送403(SC_禁止)HTTP错误代码。此外,如果定义了#errorPage,则实现将执行请求分派器“转发”到指定的error page视图。作为“远期”SecurityContextHolder将保持填充状态。如果视图(或标记库或宏)希望访问SecurityContextHolder,这将非常有用。请求范围也将填充异常本身,可从关键WebAttributes#ACCESS _DENIED _403获得。

代码示例

代码示例来源:origin: spring-projects/spring-security

/**
 * Shortcut to specify the {@link AccessDeniedHandler} to be used is a specific error
 * page
 *
 * @param accessDeniedUrl the URL to the access denied page (i.e. /errors/401)
 * @return the {@link ExceptionHandlingConfigurer} for further customization
 * @see AccessDeniedHandlerImpl
 * @see #accessDeniedHandler(org.springframework.security.web.access.AccessDeniedHandler)
 */
public ExceptionHandlingConfigurer<H> accessDeniedPage(String accessDeniedUrl) {
  AccessDeniedHandlerImpl accessDeniedHandler = new AccessDeniedHandlerImpl();
  accessDeniedHandler.setErrorPage(accessDeniedUrl);
  return accessDeniedHandler(accessDeniedHandler);
}

代码示例来源:origin: stackoverflow.com

public class MyAccessDeniedHandler implements AccessDeniedHandler {

  private AccessDeniedHandlerImpl accessDeniedHandlerImpl = new AccessDeniedHandlerImpl();

  public void handle(HttpServletRequest request, HttpServletResponse response,
      AccessDeniedException accessDeniedException) throws IOException, ServletException {

    //Some CSRF related code 

    // Then call accessDeniedHandlerImpl.handle to handle request
    accessDeniedHandlerImpl.handle(request, response, accessDeniedException);
  }

  /**
   * The error page to use. Must begin with a "/" and is interpreted relative to the current context root.
   *
   * @param errorPage the dispatcher path to display
   *
   * @throws IllegalArgumentException if the argument doesn't comply with the above limitations
   * @see AccessDeniedHandlerImpl#setErrorPage(String)
   */
  public void setErrorPage(String errorPage) {
    // You can set custom error page here 
    accessDeniedHandlerImpl.setErrorPage(errorPage);
  }
}

代码示例来源:origin: spring-projects/spring-security

private AccessDeniedHandler createDefaultDeniedHandler(H http) {
  if (this.defaultDeniedHandlerMappings.isEmpty()) {
    return new AccessDeniedHandlerImpl();
  }
  if (this.defaultDeniedHandlerMappings.size() == 1) {
    return this.defaultDeniedHandlerMappings.values().iterator().next();
  }
  return new RequestMatcherDelegatingAccessDeniedHandler(
      this.defaultDeniedHandlerMappings,
      new AccessDeniedHandlerImpl());
}

代码示例来源:origin: apache/syncope

@Override
  public void handle(final HttpServletRequest request, final HttpServletResponse response,
      final AccessDeniedException accessDeniedException) throws IOException, ServletException {

    response.addHeader(RESTHeaders.ERROR_INFO, accessDeniedException.getMessage());

    super.handle(request, response, accessDeniedException);
  }
}

代码示例来源:origin: socialsignin/spring-social-security

= new AccessDeniedHandlerImpl();
request.setAttribute(REQUIRED_PROVIDERS_REQUEST_ATTRIBUTE_NAME, requiredProviderIds);
providerSpecificAccessDeniedHandler.setErrorPage(connectWithProviderUrlPrefix + "/" + requiredProviderIds.iterator().next());
providerSpecificAccessDeniedHandler.handle(request, response, accessDeniedException);
   = new AccessDeniedHandlerImpl();
  defaultAccessDeniedHandler.setErrorPage(defaultAccessDeniedUrl);
  defaultAccessDeniedHandler.handle(request, response, accessDeniedException);
  super.handle(request, response, accessDeniedException);

代码示例来源:origin: spring-projects/spring-security

/**
 * Gets the default {@link AccessDeniedHandler} from the
 * {@link ExceptionHandlingConfigurer#getAccessDeniedHandler()} or create a
 * {@link AccessDeniedHandlerImpl} if not available.
 *
 * @param http the {@link HttpSecurityBuilder}
 * @return the {@link AccessDeniedHandler}
 */
@SuppressWarnings("unchecked")
private AccessDeniedHandler getDefaultAccessDeniedHandler(H http) {
  ExceptionHandlingConfigurer<H> exceptionConfig = http
      .getConfigurer(ExceptionHandlingConfigurer.class);
  AccessDeniedHandler handler = null;
  if (exceptionConfig != null) {
    handler = exceptionConfig.getAccessDeniedHandler();
  }
  if (handler == null) {
    handler = new AccessDeniedHandlerImpl();
  }
  return handler;
}

代码示例来源:origin: org.apache.syncope.core/syncope-core-spring

@Override
public void handle(final HttpServletRequest request, final HttpServletResponse response,
    final AccessDeniedException accessDeniedException) throws IOException, ServletException {
  response.addHeader(RESTHeaders.ERROR_INFO, accessDeniedException.getMessage());
  super.handle(request, response, accessDeniedException);
}

代码示例来源:origin: spring-projects/spring-security-oauth

String failurePage = element.getAttribute("oauth-failure-page");
if (StringUtils.hasText(failurePage)) {
 AccessDeniedHandlerImpl failureHandler = new AccessDeniedHandlerImpl();
 failureHandler.setErrorPage(failurePage);
 consumerContextFilterBean.addPropertyValue("OAuthFailureHandler", failureHandler);

代码示例来源:origin: spring-projects/spring-security

@Override
  protected void configure(HttpSecurity http) throws Exception {
    // @formatter:off
    http
      .authorizeRequests()
        .anyRequest().denyAll()
        .and()
      .exceptionHandling()
        .defaultAccessDeniedHandlerFor(
            this.teapotDeniedHandler,
            new AntPathRequestMatcher("/hello/**"))
        .defaultAccessDeniedHandlerFor(
            new AccessDeniedHandlerImpl(),
            AnyRequestMatcher.INSTANCE);
    // @formatter:on
  }
}

代码示例来源:origin: theotherp/nzbhydra2

@Override
public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
  logger.warn("Access denied to IP {}: {}", SessionStorage.IP.get(), accessDeniedException.getMessage());
  attemptService.accessFailed(SessionStorage.IP.get());
  super.handle(request, response, accessDeniedException);
}

代码示例来源:origin: geoserver/geoserver

ExceptionTranslationFilter filter = new ExceptionTranslationFilter(ep, cache);
AccessDeniedHandlerImpl accessDeniedHandler = new AccessDeniedHandlerImpl();
    accessDeniedHandler.setErrorPage(authConfig.getAccessDeniedErrorPage());
  else LOGGER.warning("Cannot find: " + authConfig.getAccessDeniedErrorPage());

代码示例来源:origin: spring-projects/spring-security

@Override
protected void configure(HttpSecurity http) throws Exception {
  // @formatter:off
  http
    .authorizeRequests()
      .anyRequest().denyAll()
      .and()
    .exceptionHandling()
      .defaultAccessDeniedHandlerFor(new AccessDeniedHandlerImpl(), request -> false)
      .and()
    .httpBasic()
      .and()
    .oauth2ResourceServer()
      .jwt();
  // @formatter:on
}

代码示例来源:origin: com.erudika/para

@Override
public void handle(HttpServletRequest request, HttpServletResponse response,
  AccessDeniedException accessDeniedException) throws IOException, ServletException {
  if (isRestRequest(request)) {
    RestUtils.returnStatusResponse(response, HttpServletResponse.SC_FORBIDDEN, accessDeniedException.getMessage());
  } else {
    super.handle(request, response, accessDeniedException);
  }
}

代码示例来源:origin: org.springframework.security/spring-security-config

/**
 * Shortcut to specify the {@link AccessDeniedHandler} to be used is a specific error
 * page
 *
 * @param accessDeniedUrl the URL to the access denied page (i.e. /errors/401)
 * @return the {@link ExceptionHandlingConfigurer} for further customization
 * @see AccessDeniedHandlerImpl
 * @see #accessDeniedHandler(org.springframework.security.web.access.AccessDeniedHandler)
 */
public ExceptionHandlingConfigurer<H> accessDeniedPage(String accessDeniedUrl) {
  AccessDeniedHandlerImpl accessDeniedHandler = new AccessDeniedHandlerImpl();
  accessDeniedHandler.setErrorPage(accessDeniedUrl);
  return accessDeniedHandler(accessDeniedHandler);
}

代码示例来源:origin: org.springframework.security/spring-security-config

private AccessDeniedHandler createDefaultDeniedHandler(H http) {
  if (this.defaultDeniedHandlerMappings.isEmpty()) {
    return new AccessDeniedHandlerImpl();
  }
  if (this.defaultDeniedHandlerMappings.size() == 1) {
    return this.defaultDeniedHandlerMappings.values().iterator().next();
  }
  return new RequestMatcherDelegatingAccessDeniedHandler(
      this.defaultDeniedHandlerMappings,
      new AccessDeniedHandlerImpl());
}

代码示例来源:origin: Erudika/para

@Override
public void handle(HttpServletRequest request, HttpServletResponse response,
  AccessDeniedException accessDeniedException) throws IOException, ServletException {
  if (isRestRequest(request)) {
    RestUtils.returnStatusResponse(response, HttpServletResponse.SC_FORBIDDEN, accessDeniedException.getMessage());
  } else {
    super.handle(request, response, accessDeniedException);
  }
}

代码示例来源:origin: org.springframework.security/spring-security-javaconfig

/**
 * Shortcut to specify the {@link AccessDeniedHandler} to be used is a specific error page
 *
 * @param accessDeniedUrl the URL to the access denied page (i.e. /errors/401)
 * @return the {@link ExceptionHandlingConfigurer} for further customization
 * @see AccessDeniedHandlerImpl
 * @see {@link #accessDeniedHandler(org.springframework.security.web.access.AccessDeniedHandler)}
 */
public ExceptionHandlingConfigurer<H> accessDeniedPage(String accessDeniedUrl) {
  AccessDeniedHandlerImpl accessDeniedHandler = new AccessDeniedHandlerImpl();
  accessDeniedHandler.setErrorPage(accessDeniedUrl);
  return accessDeniedHandler(accessDeniedHandler);
}

代码示例来源:origin: org.springframework.security/spring-security-config

/**
 * Gets the default {@link AccessDeniedHandler} from the
 * {@link ExceptionHandlingConfigurer#getAccessDeniedHandler()} or create a
 * {@link AccessDeniedHandlerImpl} if not available.
 *
 * @param http the {@link HttpSecurityBuilder}
 * @return the {@link AccessDeniedHandler}
 */
@SuppressWarnings("unchecked")
private AccessDeniedHandler getDefaultAccessDeniedHandler(H http) {
  ExceptionHandlingConfigurer<H> exceptionConfig = http
      .getConfigurer(ExceptionHandlingConfigurer.class);
  AccessDeniedHandler handler = null;
  if (exceptionConfig != null) {
    handler = exceptionConfig.getAccessDeniedHandler();
  }
  if (handler == null) {
    handler = new AccessDeniedHandlerImpl();
  }
  return handler;
}

代码示例来源:origin: com.erudika/para-server

@Override
public void handle(HttpServletRequest request, HttpServletResponse response,
  AccessDeniedException accessDeniedException) throws IOException, ServletException {
  if (isRestRequest(request)) {
    RestUtils.returnStatusResponse(response, HttpServletResponse.SC_FORBIDDEN, accessDeniedException.getMessage());
  } else {
    super.handle(request, response, accessDeniedException);
  }
}

代码示例来源:origin: apache/servicemix-bundles

/**
 * Shortcut to specify the {@link AccessDeniedHandler} to be used is a specific error
 * page
 *
 * @param accessDeniedUrl the URL to the access denied page (i.e. /errors/401)
 * @return the {@link ExceptionHandlingConfigurer} for further customization
 * @see AccessDeniedHandlerImpl
 * @see #accessDeniedHandler(org.springframework.security.web.access.AccessDeniedHandler)
 */
public ExceptionHandlingConfigurer<H> accessDeniedPage(String accessDeniedUrl) {
  AccessDeniedHandlerImpl accessDeniedHandler = new AccessDeniedHandlerImpl();
  accessDeniedHandler.setErrorPage(accessDeniedUrl);
  return accessDeniedHandler(accessDeniedHandler);
}

相关文章

微信公众号

最新文章

更多