gpt4 book ai didi

org.springframework.security.oauth2.provider.error.WebResponseExceptionTranslator类的使用及代码示例

转载 作者:知者 更新时间:2024-03-23 06:23:05 27 4
gpt4 key购买 nike

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

WebResponseExceptionTranslator介绍

[英]Translates exceptions into HTTP Responses.
[中]将异常转换为HTTP响应。

代码示例

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

@ExceptionHandler(InvalidTokenException.class)
public ResponseEntity<OAuth2Exception> handleException(Exception e) throws Exception {
  logger.info("Handling error: " + e.getClass().getSimpleName() + ", " + e.getMessage());
  // This isn't an oauth resource, so we don't want to send an
  // unauthorized code here. The client has already authenticated
  // successfully with basic auth and should just
  // get back the invalid token error.
  @SuppressWarnings("serial")
  InvalidTokenException e400 = new InvalidTokenException(e.getMessage()) {
    @Override
    public int getHttpErrorCode() {
      return 400;
    }
  };
  return exceptionTranslator.translate(e400);
}

代码示例来源:origin: mitreid-connect/OpenID-Connect-Java-Spring-Server

@ExceptionHandler(OAuth2Exception.class)
public ResponseEntity<OAuth2Exception> handleException(Exception e) throws Exception {
  logger.info("Handling error: " + e.getClass().getSimpleName() + ", " + e.getMessage());
  return providerExceptionHandler.translate(e);
}

代码示例来源:origin: cloudfoundry/uaa

@ExceptionHandler({ScimResourceNotFoundException.class, NoSuchClientException.class, EmptyResultDataAccessException.class})
public ResponseEntity<OAuth2Exception> handleException(Exception e) throws Exception {
  logger.info("Handling error: " + e.getClass().getSimpleName() + ", " + e.getMessage());
  InvalidTokenException e404 = new InvalidTokenException("Resource not found") {
    @Override
    public int getHttpErrorCode() {
      return 404;
    }
  };
  return exceptionTranslator.translate(e404);
}

代码示例来源:origin: cloudfoundry/uaa

@ExceptionHandler(InvalidScopeException.class)
public ResponseEntity<OAuth2Exception> handleInvalidScopeException(Exception e) throws Exception {
  logger.info("Handling error: " + e.getClass().getSimpleName() + ", " + e.getMessage());
  return exceptionTranslator.translate(e);
}

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

@ExceptionHandler(Exception.class)
public ResponseEntity<OAuth2Exception> handleException(Exception e) throws Exception {
  if (logger.isWarnEnabled()) {
    logger.warn("Handling error: " + e.getClass().getSimpleName() + ", " + e.getMessage());
  }
  return getExceptionTranslator().translate(e);
}

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

@ExceptionHandler(ClientRegistrationException.class)
public ResponseEntity<OAuth2Exception> handleClientRegistrationException(Exception e) throws Exception {
  if (logger.isWarnEnabled()) {
    logger.warn("Handling error: " + e.getClass().getSimpleName() + ", " + e.getMessage());
  }
  return getExceptionTranslator().translate(new BadClientCredentialsException());
}

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

@ExceptionHandler(OAuth2Exception.class)
public ResponseEntity<OAuth2Exception> handleException(OAuth2Exception e) throws Exception {
  if (logger.isWarnEnabled()) {
    logger.warn("Handling error: " + e.getClass().getSimpleName() + ", " + e.getMessage());
  }
  return getExceptionTranslator().translate(e);
}

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

@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
public ResponseEntity<OAuth2Exception> handleHttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e) throws Exception {
  if (logger.isInfoEnabled()) {
    logger.info("Handling error: " + e.getClass().getSimpleName() + ", " + e.getMessage());
  }
  return getExceptionTranslator().translate(e);
}

代码示例来源:origin: cloudfoundry/uaa

@ExceptionHandler(InvalidTokenException.class)
public ResponseEntity<OAuth2Exception> handleException(Exception e) throws Exception {
  logger.info("Handling error: " + e.getClass().getSimpleName() + ", " + e.getMessage());
  // This isn't an oauth resource, so we don't want to send an
  // unauthorized code here.
  // The client has already authenticated successfully with basic auth and
  // should just
  // get back the invalid token error.
  InvalidTokenException e400 = new InvalidTokenException(e.getMessage()) {
    @Override
    public int getHttpErrorCode() {
      return 400;
    }
  };
  return exceptionTranslator.translate(e400);
}

代码示例来源:origin: cloudfoundry/uaa

@ExceptionHandler(Exception.class)
@Override
public ResponseEntity<OAuth2Exception> handleException(Exception e) throws Exception {
  logger.error("Handling error: " + e.getClass().getSimpleName() + ", " + e.getMessage(), e);
  return getExceptionTranslator().translate(e);
}

代码示例来源:origin: cloudfoundry/uaa

@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
public ResponseEntity<OAuth2Exception> handleMethodNotSupportedException(HttpRequestMethodNotSupportedException e) throws Exception {
  logger.info("Handling error: " + e.getClass().getSimpleName() + ", " + e.getMessage());
  ResponseEntity<OAuth2Exception> result =  exceptionTranslator.translate(e);
  if (HttpMethod.POST.matches(e.getMethod())) {
    OAuth2Exception cause = new OAuth2Exception("Parameters must be passed in the body of the request", result.getBody().getCause()) {
      public String getOAuth2ErrorCode() {
        return "query_string_not_allowed";
      }
      public int getHttpErrorCode() {
        return NOT_ACCEPTABLE.value();
      }
    };
    result = new ResponseEntity<>(cause, result.getHeaders(), NOT_ACCEPTABLE);
  }
  return result;
}

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

private ModelAndView handleException(Exception e, ServletWebRequest webRequest) throws Exception {
  ResponseEntity<OAuth2Exception> translate = getExceptionTranslator().translate(e);
  webRequest.getResponse().setStatus(translate.getStatusCode().value());
  if (e instanceof ClientAuthenticationException || e instanceof RedirectMismatchException) {
    return new ModelAndView(errorPage, Collections.singletonMap("error", translate.getBody()));
  }
  AuthorizationRequest authorizationRequest = null;
  try {
    authorizationRequest = getAuthorizationRequestForError(webRequest);
    String requestedRedirectParam = authorizationRequest.getRequestParameters().get(OAuth2Utils.REDIRECT_URI);
    String requestedRedirect = redirectResolver.resolveRedirect(requestedRedirectParam,
        getClientDetailsService().loadClientByClientId(authorizationRequest.getClientId()));
    authorizationRequest.setRedirectUri(requestedRedirect);
    String redirect = getUnsuccessfulRedirect(authorizationRequest, translate.getBody(), authorizationRequest
        .getResponseTypes().contains("token"));
    return new ModelAndView(new RedirectView(redirect, false, true, false));
  }
  catch (OAuth2Exception ex) {
    // If an AuthorizationRequest cannot be created from the incoming parameters it must be
    // an error. OAuth2Exception can be handled this way. Other exceptions will generate a standard 500
    // response.
    return new ModelAndView(errorPage, Collections.singletonMap("error", translate.getBody()));
  }
}

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

protected final void doHandle(HttpServletRequest request, HttpServletResponse response, Exception authException)
    throws IOException, ServletException {
  try {
    ResponseEntity<?> result = exceptionTranslator.translate(authException);
    result = enhanceResponse(result, authException);
    exceptionRenderer.handleHttpEntityResponse(result, new ServletWebRequest(request, response));
    response.flushBuffer();
  }
  catch (ServletException e) {
    // Re-use some of the default Spring dispatcher behaviour - the exception came from the filter chain and
    // not from an MVC handler so it won't be caught by the dispatcher (even if there is one)
    if (handlerExceptionResolver.resolveException(request, response, this, e) == null) {
      throw e;
    }
  }
  catch (IOException e) {
    throw e;
  }
  catch (RuntimeException e) {
    throw e;
  }
  catch (Exception e) {
    // Wrap other Exceptions. These are not expected to happen
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: cloudfoundry/uaa

private ModelAndView handleException(Exception e, ServletWebRequest webRequest) throws Exception {
  ResponseEntity<OAuth2Exception> translate = getExceptionTranslator().translate(e);
  webRequest.getResponse().setStatus(translate.getStatusCode().value());
  if (e instanceof ClientAuthenticationException || e instanceof RedirectMismatchException) {
    Map<String, Object> map = new HashMap<>();
    map.put("error", translate.getBody());
    if (e instanceof UnauthorizedClientException) {
      map.put("error_message_code", "login.invalid_idp");
    }
    return new ModelAndView(errorPage, map);
  }
  AuthorizationRequest authorizationRequest = null;
  try {
    authorizationRequest = getAuthorizationRequestForError(webRequest);
    String requestedRedirectParam = authorizationRequest.getRequestParameters().get(OAuth2Utils.REDIRECT_URI);
    String requestedRedirect =
     redirectResolver.resolveRedirect(
      requestedRedirectParam,
      getClientServiceExtention().loadClientByClientId(authorizationRequest.getClientId(), IdentityZoneHolder.get().getId()));
    authorizationRequest.setRedirectUri(requestedRedirect);
    String redirect = getUnsuccessfulRedirect(authorizationRequest, translate.getBody(), authorizationRequest
     .getResponseTypes().contains("token"));
    return new ModelAndView(new RedirectView(redirect, false, true, false));
  } catch (OAuth2Exception ex) {
    // If an AuthorizationRequest cannot be created from the incoming parameters it must be
    // an error. OAuth2Exception can be handled this way. Other exceptions will generate a standard 500
    // response.
    return new ModelAndView(errorPage, Collections.singletonMap("error", translate.getBody()));
  }
}

代码示例来源:origin: org.mitre/openid-connect-server

@ExceptionHandler(OAuth2Exception.class)
public ResponseEntity<OAuth2Exception> handleException(Exception e) throws Exception {
  logger.info("Handling error: " + e.getClass().getSimpleName() + ", " + e.getMessage());
  return providerExceptionHandler.translate(e);
}

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

@ExceptionHandler(Exception.class)
public ResponseEntity<OAuth2Exception> handleException(Exception e) throws Exception {
  if (logger.isWarnEnabled()) {
    logger.warn("Handling error: " + e.getClass().getSimpleName() + ", " + e.getMessage());
  }
  return getExceptionTranslator().translate(e);
}

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

@ExceptionHandler(InvalidTokenException.class)
public ResponseEntity<OAuth2Exception> handleException(Exception e) throws Exception {
  logger.info("Handling error: " + e.getClass().getSimpleName() + ", " + e.getMessage());
  // This isn't an oauth resource, so we don't want to send an
  // unauthorized code here. The client has already authenticated
  // successfully with basic auth and should just
  // get back the invalid token error.
  @SuppressWarnings("serial")
  InvalidTokenException e400 = new InvalidTokenException(e.getMessage()) {
    @Override
    public int getHttpErrorCode() {
      return 400;
    }
  };
  return exceptionTranslator.translate(e400);
}

代码示例来源:origin: com.haulmont.cuba/cuba-rest-api

@ExceptionHandler(ClientAuthenticationException.class)
public ResponseEntity<OAuth2Exception> handleClientAuthenticationException(ClientAuthenticationException e) throws Exception {
  return getExceptionTranslator().translate(e);
}

代码示例来源:origin: com.haulmont.cuba/cuba-rest-api

@ExceptionHandler(BadCredentialsException.class)
public ResponseEntity<OAuth2Exception> handleBadCredentialsException(BadCredentialsException e) throws Exception {
  return getExceptionTranslator().translate(e);
}

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

@ExceptionHandler(ClientRegistrationException.class)
public ResponseEntity<OAuth2Exception> handleClientRegistrationException(Exception e) throws Exception {
  if (logger.isWarnEnabled()) {
    logger.warn("Handling error: " + e.getClass().getSimpleName() + ", " + e.getMessage());
  }
  return getExceptionTranslator().translate(new BadClientCredentialsException());
}

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com