org.springframework.security.authentication.InternalAuthenticationServiceException类的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(11.6k)|赞(0)|评价(0)|浏览(2007)

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

InternalAuthenticationServiceException介绍

[英]Thrown if an authentication request could not be processed due to a system problem that occurred internally. It differs from AuthenticationServiceException in that it would not be thrown if an external system has an internal error or failure. This ensures that we can handle errors that are within our control distinctly from errors of other systems. The advantage to this distinction is that the untrusted external system should not be able to fill up logs and cause excessive IO. However, an internal system should report errors.

This might be thrown if a backend authentication repository is unavailable, for example. However, it would not be thrown in the event that an error occurred when validating an OpenID response with an OpenID Provider.
[中]如果由于内部发生的系统问题而无法处理身份验证请求,则引发。它与AuthenticationServiceException的不同之处在于,如果外部系统出现内部错误或故障,则不会抛出它。这确保了我们能够处理在我们控制范围内的错误,与其他系统的错误截然不同。这种区别的优点是,不受信任的外部系统不应该能够填充日志并导致过多的IO。但是,内部系统应报告错误。
例如,如果后端身份验证存储库不可用,可能会引发此问题。但是,如果在使用OpenID提供程序验证OpenID响应时发生错误,则不会引发该错误。

代码示例

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

private KeyInfo getActiveKeyInfo() {
  return ofNullable(keyInfoService.getActiveKey())
    .orElseThrow(() -> new InternalAuthenticationServiceException("Unable to sign token, misconfigured JWT signing keys"));
}

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

@Test
public void authenticateWithNamingException() {
  UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(
      "ben", "benspassword");
  LdapAuthenticator mockAuthenticator = mock(LdapAuthenticator.class);
  CommunicationException expectedCause = new CommunicationException(
      new javax.naming.CommunicationException());
  when(mockAuthenticator.authenticate(authRequest)).thenThrow(expectedCause);
  LdapAuthenticationProvider ldapProvider = new LdapAuthenticationProvider(
      mockAuthenticator);
  try {
    ldapProvider.authenticate(authRequest);
    fail("Expected Exception");
  }
  catch (InternalAuthenticationServiceException success) {
    assertThat(success.getCause()).isSameAs(expectedCause);
  }
}

代码示例来源:origin: org.molgenis/molgenis-security

@Override
public boolean isConfiguredForUser() {
 boolean isConfigured = false;
 try {
  UserSecret secret = getSecret();
  if (StringUtils.hasText(secret.getSecret())) {
   isConfigured = true;
  }
 } catch (InternalAuthenticationServiceException err) {
  LOG.warn(err.getMessage());
 }
 return isConfigured;
}

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

private KeyInfo getActiveKeyInfo() {
  return ofNullable(keyInfoService.getActiveKey())
    .orElseThrow(() -> new InternalAuthenticationServiceException("Unable to sign token, misconfigured JWT signing keys"));
}

代码示例来源:origin: org.molgenis/molgenis-security

private String determineErrorMessagesFromInternalAuthenticationExceptions(Object attribute) {
  String errorMessage = "";
  if (attribute instanceof InternalAuthenticationServiceException) {
   Throwable throwable = ((InternalAuthenticationServiceException) attribute).getCause();
   if (throwable.getCause() instanceof UsernameNotFoundException) {
    errorMessage = ERROR_MESSAGE_BAD_CREDENTIALS;
   }
  }
  return errorMessage;
 }
}

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

protected void internalHandle(HttpServletRequest request,
               HttpServletResponse response,
               Exception exception) throws IOException, ServletException {
  AuthenticationException authEx = (exception instanceof AuthenticationException) ?
    (AuthenticationException)exception :
    new InternalAuthenticationServiceException("Access denied.", exception);
  if (wantJson(request)) {
    response.setStatus(HttpServletResponse.SC_FORBIDDEN);
    response.setContentType(MediaType.APPLICATION_JSON_VALUE);
    response.getWriter().append(String.format("{\"error\":\"%s\"}", exception.getMessage()));
  } else {
    LoginUrlAuthenticationEntryPoint entryPoint = getLoginUrlAuthenticationEntryPoint(exception);
    entryPoint.commence(request, response, authEx);
  }
}

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

protected final UserDetails retrieveUser(String username,
    UsernamePasswordAuthenticationToken authentication)
    throws AuthenticationException {
  prepareTimingAttackProtection();
  try {
    UserDetails loadedUser = this.getUserDetailsService().loadUserByUsername(username);
    if (loadedUser == null) {
      throw new InternalAuthenticationServiceException(
          "UserDetailsService returned null, which is an interface contract violation");
    }
    return loadedUser;
  }
  catch (UsernameNotFoundException ex) {
    mitigateAgainstTimingAttack(authentication);
    throw ex;
  }
  catch (InternalAuthenticationServiceException ex) {
    throw ex;
  }
  catch (Exception ex) {
    throw new InternalAuthenticationServiceException(ex.getMessage(), ex);
  }
}

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

protected final UserDetails retrieveUser(String username,
    UsernamePasswordAuthenticationToken authentication)
    throws AuthenticationException {
  prepareTimingAttackProtection();
  try {
    UserDetails loadedUser = this.getUserDetailsService().loadUserByUsername(username);
    if (loadedUser == null) {
      throw new InternalAuthenticationServiceException(
          "UserDetailsService returned null, which is an interface contract violation");
    }
    return loadedUser;
  }
  catch (UsernameNotFoundException ex) {
    mitigateAgainstTimingAttack(authentication);
    throw ex;
  }
  catch (InternalAuthenticationServiceException ex) {
    throw ex;
  }
  catch (Exception ex) {
    throw new InternalAuthenticationServiceException(ex.getMessage(), ex);
  }
}

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

@Test
public void test_when_uaa_exception() throws Exception {
  UaaException e = new UaaException(messageCode);
  InternalAuthenticationServiceException be = new InternalAuthenticationServiceException("", e);
  entryPoint.commence(request, response, be);
  verify(request, times(1)).getRequestDispatcher(eq("/forgot_password"));
  verify(request, times(1)).setAttribute(eq("message_code"), eq("bad_code"));
  verify(requestDispatcher, timeout(1)).forward(any(HttpServletRequest.class), same(response));
  verify(response, times(1)).setStatus(eq(HttpStatus.UNPROCESSABLE_ENTITY.value()));
}

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

entryPoint.commence(request, response, new BadCredentialsException(e.getMessagesAsOneString(), e));
} catch (UaaException e) {
  entryPoint.commence(request, response, new InternalAuthenticationServiceException(e.getMessage(), e));
} catch (PasswordConfirmationException pe) {
  refreshCode(request, expiringCode);

代码示例来源:origin: wuyouzhuguli/SpringAll

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
  SmsAuthenticationToken authenticationToken = (SmsAuthenticationToken) authentication;
  UserDetails userDetails = userDetailService.loadUserByUsername((String) authenticationToken.getPrincipal());
  if (userDetails == null)
    throw new InternalAuthenticationServiceException("未找到与该手机号对应的用户");
  SmsAuthenticationToken authenticationResult = new SmsAuthenticationToken(userDetails, userDetails.getAuthorities());
  authenticationResult.setDetails(authenticationToken.getDetails());
  return authenticationResult;
}

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

@Test
public void providerThrowsInternalAuthenticationServiceException() {
  InternalAuthenticationServiceException expected = new InternalAuthenticationServiceException(
      "Expected");
  ProviderManager mgr = new ProviderManager(Arrays.asList(
      createProviderWhichThrows(expected),
      createProviderWhichThrows(new BadCredentialsException("Oops"))), null);
  final Authentication authReq = mock(Authentication.class);
  try {
    mgr.authenticate(authReq);
    fail("Expected Exception");
  }
  catch (InternalAuthenticationServiceException success) {
  }
}

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

@Override
protected DirContextOperations doAuthentication(
    UsernamePasswordAuthenticationToken authentication) {
  try {
    return getAuthenticator().authenticate(authentication);
  }
  catch (PasswordPolicyException ppe) {
    // The only reason a ppolicy exception can occur during a bind is that the
    // account is locked.
    throw new LockedException(this.messages.getMessage(
        ppe.getStatus().getErrorCode(), ppe.getStatus().getDefaultMessage()));
  }
  catch (UsernameNotFoundException notFound) {
    if (this.hideUserNotFoundExceptions) {
      throw new BadCredentialsException(this.messages.getMessage(
          "LdapAuthenticationProvider.badCredentials", "Bad credentials"));
    }
    else {
      throw notFound;
    }
  }
  catch (NamingException ldapAccessFailure) {
    throw new InternalAuthenticationServiceException(
        ldapAccessFailure.getMessage(), ldapAccessFailure);
  }
}

代码示例来源:origin: yidongnan/grpc-spring-boot-starter

/**
 * @deprecated Should never be called
 */
@Override
@Deprecated // Should never be called
public boolean test(final Authentication t) {
  throw new InternalAuthenticationServiceException(
      "Tried to execute the 'permit-all' access predicate. The server's security configuration is broken.");
}

代码示例来源:origin: net.devh/grpc-server-spring-boot-autoconfigure

/**
 * @deprecated Should never be called
 */
@Override
@Deprecated // Should never be called
public boolean test(final Authentication t) {
  throw new InternalAuthenticationServiceException(
      "Tried to execute the 'permit-all' access predicate. The server's security configuration is broken.");
}

代码示例来源:origin: devicehive/devicehive-java-server

private void tryAuthenticate(Authentication requestAuth) {
    Authentication authentication = authenticationManager.authenticate(requestAuth);
    if (authentication == null || !authentication.isAuthenticated()) {
      throw new InternalAuthenticationServiceException("Unable to authenticate user with provided credentials");
    }
    logger.debug("Successfully authenticated");
    SecurityContextHolder.getContext().setAuthentication(authentication);
  }
}

代码示例来源:origin: gustavoorsi/e-learning

private Authentication tryToAuthenticate(Authentication requestAuthentication) {
    Authentication responseAuthentication = authenticationManager.authenticate(requestAuthentication);
    if (responseAuthentication == null || !responseAuthentication.isAuthenticated()) {
      throw new InternalAuthenticationServiceException("Unable to authenticate Domain User for provided credentials");
    }
    logger.debug("User successfully authenticated");
    return responseAuthentication;
  }
}

代码示例来源:origin: gustavoorsi/e-learning

private Authentication tryToAuthenticate(Authentication requestAuthentication) {
    Authentication responseAuthentication = authenticationManager.authenticate(requestAuthentication);
    if (responseAuthentication == null || !responseAuthentication.isAuthenticated()) {
      throw new InternalAuthenticationServiceException("Unable to authenticate Backend Admin for provided credentials");
    }
    logger.debug("Backend Admin successfully authenticated");
    return responseAuthentication;
  }
}

代码示例来源:origin: cloudfoundry-incubator/multiapps-controller

private Pair<String, String> readTokenKey() {
  Map<String, Object> tokenKeyResponse = uaaClient.readTokenKey();
  Object value = tokenKeyResponse.get("value");
  Object alg = tokenKeyResponse.get("alg");
  if (value == null || alg == null) {
    throw new InternalAuthenticationServiceException("Response from /token_key does not contain a key value or an algorithm");
  }
  return new Pair<>(value.toString(), alg.toString());
}

代码示例来源:origin: io.gravitee.management.providers/gravitee-management-api-providers-repository

@Override
protected UserDetails retrieveUser(String username, UsernamePasswordAuthenticationToken authentication) throws AuthenticationException {
  try {
    UserEntity user = userService.findByName(username);
    return mapUserEntityToUserDetails(user);
  } catch (UserNotFoundException notFound) {
    throw new UsernameNotFoundException("User '" + username + "' not found", notFound);
  } catch (Exception repositoryProblem) {
    LOGGER.error("Failed to retrieveUser : {}", username, repositoryProblem);
    throw new InternalAuthenticationServiceException(repositoryProblem.getMessage(), repositoryProblem);
  }
}

相关文章

微信公众号

最新文章

更多