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

x33g5p2x  于2022-01-16 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(391)

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

AuthenticationCredentialsNotFoundException介绍

[英]Thrown if an authentication request is rejected because there is no Authentication object in the org.springframework.security.core.context.SecurityContext.
[中]如果由于组织中没有身份验证对象而拒绝身份验证请求,则引发。springframework。安全果心上下文SecurityContext。

代码示例

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

/**
 * Helper method which generates an exception containing the passed reason, and
 * publishes an event to the application context.
 * <p>
 * Always throws an exception.
 *
 * @param reason to be provided in the exception detail
 * @param secureObject that was being called
 * @param configAttribs that were defined for the secureObject
 */
private void credentialsNotFound(String reason, Object secureObject,
    Collection<ConfigAttribute> configAttribs) {
  AuthenticationCredentialsNotFoundException exception = new AuthenticationCredentialsNotFoundException(
      reason);
  AuthenticationCredentialsNotFoundEvent event = new AuthenticationCredentialsNotFoundEvent(
      secureObject, configAttribs, exception);
  publishEvent(event);
  throw exception;
}

代码示例来源:origin: org.springframework.boot/spring-boot-actuator

private void onAuthenticationCredentialsNotFoundEvent(
    AuthenticationCredentialsNotFoundEvent event) {
  Map<String, Object> data = new HashMap<>();
  data.put("type", event.getCredentialsNotFoundException().getClass().getName());
  data.put("message", event.getCredentialsNotFoundException().getMessage());
  publish(new AuditEvent("<unknown>",
      AuthenticationAuditListener.AUTHENTICATION_FAILURE, data));
}

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

/**
 * Helper method which generates an exception containing the passed reason, and
 * publishes an event to the application context.
 * <p>
 * Always throws an exception.
 *
 * @param reason to be provided in the exception detail
 * @param secureObject that was being called
 * @param configAttribs that were defined for the secureObject
 */
private void credentialsNotFound(String reason, Object secureObject,
    Collection<ConfigAttribute> configAttribs) {
  AuthenticationCredentialsNotFoundException exception = new AuthenticationCredentialsNotFoundException(
      reason);
  AuthenticationCredentialsNotFoundEvent event = new AuthenticationCredentialsNotFoundEvent(
      secureObject, configAttribs, exception);
  publishEvent(event);
  throw exception;
}

代码示例来源:origin: yujunhao8831/spring-boot-start-current

@ExceptionHandler( AuthenticationCredentialsNotFoundException.class )
public ResponseEntity serviceErrorHandler ( AuthenticationCredentialsNotFoundException e ) {
  LogUtils.getLogger().error( "error" , e );
  return ResponseEntityPro.unauthorized( e.getMessage() );
}

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

@Test(expected = IllegalArgumentException.class)
public void testRejectsNulls() {
  new AuthenticationCredentialsNotFoundEvent(null,
      SecurityConfig.createList("TEST"),
      new AuthenticationCredentialsNotFoundException("test"));
}

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

@Test(expected = IllegalArgumentException.class)
public void testRejectsNulls2() {
  new AuthenticationCredentialsNotFoundEvent(new SimpleMethodInvocation(), null,
      new AuthenticationCredentialsNotFoundException("test"));
}

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

public DirContextOperations localCompareAuthenticate(DirContextOperations user, String password) {
  boolean match = false;
  try {
    Attributes attributes = user.getAttributes();
    Attribute attr = attributes.get(getPasswordAttributeName());
    if (attr.size()==0) {
      throw new AuthenticationCredentialsNotFoundException("Missing "+getPasswordAttributeName()+" attribute.");
    }
    for (int i = 0; (attr != null) && (!match) && (i < attr.size()); i++) {
      Object valObject = attr.get(i);
      if (valObject != null && valObject instanceof byte[]) {
        if (passwordEncoder instanceof DynamicPasswordComparator) {
          byte[] received = password.getBytes();
          byte[] stored = (byte[]) valObject;
          match = ((DynamicPasswordComparator) passwordEncoder).comparePasswords(received, stored);
        } else {
          String encodedPassword = passwordEncoder.encodePassword(password, null);
          byte[] passwordBytes = Utf8.encode(encodedPassword);
          match = Arrays.equals(passwordBytes, (byte[]) valObject);
        }
      }
    }
  } catch (NamingException e) {
    throw new BadCredentialsException("Bad credentials", e);
  }
  if (!match)
    throw new BadCredentialsException("Bad credentials");
  return user;
}

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

throw new AuthenticationCredentialsNotFoundException("Authentication was null, not authenticated, or not logged in.");

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

throw new AuthenticationCredentialsNotFoundException("No authentication credentials found");

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

public class BasicAuthenticationFilter 
    extends org.springframework.security.web.authentication.www.BasicAuthenticationFilter {

  public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {

    final HttpServletRequest request = (HttpServletRequest) req;
    final HttpServletResponse response = (HttpServletResponse) res;

    String header = request.getHeader("Authorization");

    if ((header != null) && header.startsWith("Basic ")) {
      super.doFilter(req, res, chain);
    } else {
      getAuthenticationEntryPoint().commence(request, response, new AuthenticationCredentialsNotFoundException("Missing credentials"));
    }
  }
}

代码示例来源:origin: yujunhao8831/spring-boot-start-current

/**
 * 得到凭证
 */
private static Authentication getAuthentication () {
  final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
  if ( Objects.isNull( authentication ) ) {
    throw new AuthenticationCredentialsNotFoundException( "未授权" );
  }
  return authentication;
}

代码示例来源:origin: peholmst/vaadin4spring

@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
  SecurityContext securityContext = SecurityContextHolder.getContext();
  Authentication authentication = securityContext.getAuthentication();
  if (authentication == null) {
    throw new AuthenticationCredentialsNotFoundException("No authentication found in current security context");
  }
  return invocation.getMethod().invoke(authentication, invocation.getArguments());
}

代码示例来源:origin: org.vaadin.spring.extensions/vaadin-spring-ext-security

@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
  SecurityContext securityContext = SecurityContextHolder.getContext();
  Authentication authentication = securityContext.getAuthentication();
  if (authentication == null) {
    throw new AuthenticationCredentialsNotFoundException("No authentication found in current security context");
  }
  return invocation.getMethod().invoke(authentication, invocation.getArguments());
}

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

@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
  SecurityContext securityContext = SecurityContextHolder.getContext();
  Authentication authentication = securityContext.getAuthentication();
  if (authentication == null) {
    throw new AuthenticationCredentialsNotFoundException("No authentication found in current security context");
  }
  return invocation.getMethod().invoke(authentication, invocation.getArguments());
}

代码示例来源:origin: anthonyraymond/joal

@SuppressWarnings("TypeMayBeWeakened")
public UsernamePasswordAuthenticationToken getAuthenticatedOrFail(final CharSequence username, final CharSequence authToken) throws AuthenticationException {
  if (StringUtils.isBlank(username)) {
    throw new AuthenticationCredentialsNotFoundException("Username was null or empty.");
  }
  if (StringUtils.isBlank(authToken)) {
    throw new AuthenticationCredentialsNotFoundException("Authentication token was null or empty.");
  }
  if (!appSecretToken.contentEquals(authToken)) {
    throw new BadCredentialsException("Authentication token does not match the expected token");
  }
  // Everything is fine, return an authenticated Authentication. (the constructor with grantedAuthorities auto set authenticated = true)
  // null credentials, we do not pass the password along to prevent security flaw
  return new UsernamePasswordAuthenticationToken(
      username,
      null,
      Collections.singleton((GrantedAuthority) () -> "USER")
  );
}

代码示例来源:origin: yujunhao8831/spring-boot-start-current

/**
 * 未登录
 *
 * @throws ForbiddenException
 */
public static void assertNotLogin () throws ForbiddenException {
  if ( isNotLogin() ) {
    throw new AuthenticationCredentialsNotFoundException( "未登录" );
  }
}

代码示例来源:origin: naturalprogrammer/spring-lemon

/**
   * Default behaviour is to throw error. To be overridden in auth service.
   * 
   * @param username
   * @return
   */
  protected UserDto fetchUserDto(JWTClaimsSet claims) {
    throw new AuthenticationCredentialsNotFoundException(
        LexUtils.getMessage("com.naturalprogrammer.spring.userClaimAbsent"));
  }
}

代码示例来源:origin: jiwhiz/JiwhizBlogWeb

protected UserAccount getCurrentAuthenticatedUser() {
  UserAccount currentUser = this.userAccountService.getCurrentUser();
  if (currentUser == null) {
    throw new AuthenticationCredentialsNotFoundException("User not logged in.");
  }
  return currentUser;
}

代码示例来源:origin: io.macgyver/macgyver-core

@Override
public Authentication authenticate(Authentication auth) throws AuthenticationException {
  try {
    return validateToken(Objects.toString(auth.getCredentials(), null)).orElse(null);
  } catch (RuntimeException e) {
    throw new AuthenticationCredentialsNotFoundException("could not validate token", e);
  }
}

代码示例来源:origin: Evolveum/midpoint

@Override
protected void validateCredentialNotNull(ConnectionEnvironment connEnv, @NotNull MidPointPrincipal principal, PasswordType credential) {
  ProtectedStringType protectedString = credential.getValue();
  if (protectedString == null) {
    recordAuthenticationFailure(principal, connEnv, "no stored password value");
    throw new AuthenticationCredentialsNotFoundException("web.security.provider.password.bad");
  }
}

相关文章

微信公众号

最新文章

更多