org.springframework.security.authentication.LockedException.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(13.4k)|赞(0)|评价(0)|浏览(123)

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

LockedException.<init>介绍

[英]Constructs a LockedException with the specified message.
[中]使用指定的消息构造一个LockedException

代码示例

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

public AuthenticationException resolveException(LoginException e) {
    return new LockedException("This is just a test!");
  }
});

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

public void check(UserDetails user) {
    if (!user.isAccountNonLocked()) {
      logger.debug("User account is locked");
      throw new LockedException(messages.getMessage(
          "AbstractUserDetailsAuthenticationProvider.locked",
          "User account is locked"));
    }
    if (!user.isEnabled()) {
      logger.debug("User account is disabled");
      throw new DisabledException(messages.getMessage(
          "AbstractUserDetailsAuthenticationProvider.disabled",
          "User is disabled"));
    }
    if (!user.isAccountNonExpired()) {
      logger.debug("User account is expired");
      throw new AccountExpiredException(messages.getMessage(
          "AbstractUserDetailsAuthenticationProvider.expired",
          "User account has expired"));
    }
  }
}

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

@Test
public void authenticateWhenPostAuthenticationChecksFail() {
  when(this.userDetailsService.findByUsername(any())).thenReturn(Mono.just(this.user));
  doThrow(new LockedException("account is locked")).when(this.postAuthenticationChecks).check(any());
  when(this.encoder.matches(any(), any())).thenReturn(true);
  this.manager.setPasswordEncoder(this.encoder);
  this.manager.setPostAuthenticationChecks(this.postAuthenticationChecks);
  assertThatExceptionOfType(LockedException.class)
      .isThrownBy(() -> this.manager.authenticate(new UsernamePasswordAuthenticationToken(this.user, this.user.getPassword())).block())
      .withMessage("account is locked");
  verify(this.postAuthenticationChecks).check(eq(this.user));
}

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

@Test
  public void testLogsEvents() {
    AuthenticationFailureDisabledEvent event = new AuthenticationFailureDisabledEvent(
        getAuthentication(), new LockedException("TEST"));
    LoggerListener listener = new LoggerListener();
    listener.onApplicationEvent(event);

  }
}

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

public void check(UserDetails user) {
    if (!user.isAccountNonLocked()) {
      logger.debug("User account is locked");
      throw new LockedException(messages.getMessage(
          "AbstractUserDetailsAuthenticationProvider.locked",
          "User account is locked"));
    }
    if (!user.isEnabled()) {
      logger.debug("User account is disabled");
      throw new DisabledException(messages.getMessage(
          "AbstractUserDetailsAuthenticationProvider.disabled",
          "User is disabled"));
    }
    if (!user.isAccountNonExpired()) {
      logger.debug("User account is expired");
      throw new AccountExpiredException(messages.getMessage(
          "AbstractUserDetailsAuthenticationProvider.expired",
          "User account has expired"));
    }
  }
}

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

private void raiseExceptionForErrorCode(int code, NamingException exception) {
  String hexString = Integer.toHexString(code);
  Throwable cause = new ActiveDirectoryAuthenticationException(hexString,
      exception.getMessage(), exception);
  switch (code) {
  case PASSWORD_EXPIRED:
    throw new CredentialsExpiredException(messages.getMessage(
        "LdapAuthenticationProvider.credentialsExpired",
        "User credentials have expired"), cause);
  case ACCOUNT_DISABLED:
    throw new DisabledException(messages.getMessage(
        "LdapAuthenticationProvider.disabled", "User is disabled"), cause);
  case ACCOUNT_EXPIRED:
    throw new AccountExpiredException(messages.getMessage(
        "LdapAuthenticationProvider.expired", "User account has expired"),
        cause);
  case ACCOUNT_LOCKED:
    throw new LockedException(messages.getMessage(
        "LdapAuthenticationProvider.locked", "User account is locked"), cause);
  default:
    throw badCredentials(cause);
  }
}

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

@Test
@SuppressWarnings("deprecation")
public void statusExceptionIsPublished() throws Exception {
  AuthenticationManager parent = mock(AuthenticationManager.class);
  final LockedException expected = new LockedException("");
  ProviderManager mgr = new ProviderManager(
      Arrays.asList(createProviderWhichThrows(expected)), parent);
  final Authentication authReq = mock(Authentication.class);
  AuthenticationEventPublisher publisher = mock(AuthenticationEventPublisher.class);
  mgr.setAuthenticationEventPublisher(publisher);
  try {
    mgr.authenticate(authReq);
    fail("Expected exception");
  }
  catch (LockedException e) {
    assertThat(e).isSameAs(expected);
  }
  verify(publisher).publishAuthenticationFailure(expected, authReq);
}

代码示例来源: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: spring-projects/spring-security

publisher.publishAuthenticationFailure(new DisabledException(""), a);
publisher.publishAuthenticationFailure(new DisabledException("", cause), a);
publisher.publishAuthenticationFailure(new LockedException(""), a);
publisher.publishAuthenticationFailure(new LockedException("", cause), a);
publisher.publishAuthenticationFailure(new AuthenticationServiceException(""), a);
publisher.publishAuthenticationFailure(new AuthenticationServiceException("",

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

public void check(UserDetails user) {
    if (!user.isAccountNonLocked()) {
      throw new LockedException(messages.getMessage(
          "AccountStatusUserDetailsChecker.locked", "User account is locked"));
    }

    if (!user.isEnabled()) {
      throw new DisabledException(messages.getMessage(
          "AccountStatusUserDetailsChecker.disabled", "User is disabled"));
    }

    if (!user.isAccountNonExpired()) {
      throw new AccountExpiredException(
          messages.getMessage("AccountStatusUserDetailsChecker.expired",
              "User account has expired"));
    }

    if (!user.isCredentialsNonExpired()) {
      throw new CredentialsExpiredException(messages.getMessage(
          "AccountStatusUserDetailsChecker.credentialsExpired",
          "User credentials have expired"));
    }
  }
}

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

public void check(UserDetails user) {
    if (!user.isAccountNonLocked()) {
      throw new LockedException(messages.getMessage(
          "AccountStatusUserDetailsChecker.locked", "User account is locked"));
    }

    if (!user.isEnabled()) {
      throw new DisabledException(messages.getMessage(
          "AccountStatusUserDetailsChecker.disabled", "User is disabled"));
    }

    if (!user.isAccountNonExpired()) {
      throw new AccountExpiredException(
          messages.getMessage("AccountStatusUserDetailsChecker.expired",
              "User account has expired"));
    }

    if (!user.isCredentialsNonExpired()) {
      throw new CredentialsExpiredException(messages.getMessage(
          "AccountStatusUserDetailsChecker.credentialsExpired",
          "User credentials have expired"));
    }
  }
}

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

else if(user.isLocked()) {
  if(canUnlockUser(user)){
    logger.info("|*|*| Unlocking account. Account Lock Timer Over.. |*|*|*|");
    loginHistoryService.lockUserAccount(user.getUserId(), false);
  } else {
    throw new LockedException("Account is Locked");
  }       
}

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

else if(user.isLocked()) {
  if(canUnlockUser(user)){
    logger.info("|*|*| Unlocking account. Account Lock Timer Over.. |*|*|*|");
    loginHistoryService.lockUserAccount(user.getUserId(), false);
  } else {
    throw new LockedException("Account is Locked");
  }       
}

代码示例来源:origin: osiam/server

private void assertUserNotLocked(String username) {
  if(isLockMechanismDisabled()) {
    return;
  }
  Date logindate = lastFailedLogin.get(username);
  if(logindate != null && isWaitTimeOver(logindate)) {
    accessCounter.remove(username);
    lastFailedLogin.remove(username);
  }
  if (accessCounter.get(username) != null && accessCounter.get(username) >= maxLoginFailures) {
    throw new LockedException("The user '" + username + "' is temporary locked.");
  }
}

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

public void check(UserDetails user) {
    if (!user.isAccountNonLocked()) {
      logger.debug("User account is locked");
      throw new LockedException(messages.getMessage("AbstractUserDetailsAuthenticationProvider.locked",
          "User account is locked"), user);
    }
    if (!user.isEnabled()) {
      logger.debug("User account is disabled");
      throw new DisabledException(messages.getMessage("AbstractUserDetailsAuthenticationProvider.disabled",
          "User is disabled"), user);
    }
    if (!user.isAccountNonExpired()) {
      logger.debug("User account is expired");
      throw new AccountExpiredException(messages.getMessage("AbstractUserDetailsAuthenticationProvider.expired",
          "User account has expired"), user);
    }
  }
}

代码示例来源:origin: com.foreach.across.modules/user-module

public void check( UserDetails user ) {
    if ( !user.isAccountNonLocked() ) {
      LOG.debug( "User account is locked" );
      throw new LockedException( messages.getMessage( "AbstractUserInDirectoryAuthenticationProvider.locked",
                              "User account is locked" ) );
    }
    if ( !user.isEnabled() ) {
      LOG.debug( "User account is disabled" );
      throw new DisabledException(
          messages.getMessage( "AbstractUserInDirectoryAuthenticationProvider.disabled",
                     "User is disabled" ) );
    }
    if ( !user.isAccountNonExpired() ) {
      LOG.debug( "User account is expired" );
      throw new AccountExpiredException(
          messages.getMessage( "AbstractUserInDirectoryAuthenticationProvider.expired",
                     "User account has expired" ) );
    }
  }
}

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

private class Demo implements UserDetailsChecker {
  public void check(UserDetails user) {
    if (!user.isAccountNonLocked())
      throw new LockedException("User account is locked");
    if (!user.isEnabled())
      throw new DisabledException("User is disabled"));
    if (!user.isAccountNonExpired())
      throw new AccountExpiredException("User account has expired");
    //And here comes you!
  }
}

代码示例来源:origin: pl.edu.icm.synat/synat-console-core

@Override
protected UserDetails retrieveUser(String userId, UsernamePasswordAuthenticationToken token) {
  try {
    if (!userService.authenticate(token.getPrincipal().toString(), token.getCredentials().toString())) {
      throw new BadCredentialsException(messages.getMessage(MessageConstants.MESSAGE_LOGIN_FAIL));
    }
    PortalUserDetails portalUserData = userService.getUserData(userId);
    if (!portalUserData.isAccountNonLocked()) {
      throw new LockedException(messages.getMessage(MessageConstants.MESSAGE_LOGIN_LOCKED));
    }
    return portalUserData;
  } catch (AuthenticationException e) {
    throw e;
  } catch (Exception e) {
    throw new AuthenticationServiceException(messages.getMessage(MessageConstants.MESSAGE_LOGIN_SERVICE_EXCEPTION), e);
  }
}

代码示例来源:origin: pl.edu.icm.synat/synat-portal-core

protected AuthenticationException getException(String errorCodeString) {
  CasLoginErrorCode errorCode = CasLoginErrorCode.valueOf(errorCodeString);
  
  switch (errorCode) {
  case INVALID_EMIAL:
    return new NoCredentialsException(messages.getMessage(MessageConstants.MESSAGE_LOGIN_NO_CREDENTIALS_PREFIX
        + NoCredentialsException.Reason.INVALID_LOGIN), NoCredentialsException.Reason.INVALID_LOGIN);
  case EMPTY_USERNAME:
    return new NoCredentialsException(messages.getMessage(MessageConstants.MESSAGE_LOGIN_NO_CREDENTIALS_PREFIX
        + NoCredentialsException.Reason.NO_LOGIN), NoCredentialsException.Reason.NO_LOGIN);
  case EMPTY_PASSWORD:
    return new NoCredentialsException(messages.getMessage(MessageConstants.MESSAGE_LOGIN_NO_CREDENTIALS_PREFIX
        + NoCredentialsException.Reason.NO_PASSWORD), NoCredentialsException.Reason.NO_PASSWORD);
  case USER_LOCKED:
    return new LockedException(messages.getMessage(MessageConstants.MESSAGE_LOGIN_LOCKED));
  case BAD_CREDENTIALS:
    return new BadCredentialsException(messages.getMessage(MessageConstants.MESSAGE_LOGIN_FAIL));
  }
  
  throw new IllegalStateException("Login error '" + errorCode + "' is not supported by login controller");
}

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

public void check(UserDetails user) {
    if (!user.isAccountNonLocked()) {
      throw new LockedException(messages.getMessage("AccountStatusUserDetailsChecker.locked", "User account is locked"), user);
    }

    if (!user.isEnabled()) {
      throw new DisabledException(messages.getMessage("AccountStatusUserDetailsChecker.disabled", "User is disabled"), user);
    }

    if (!user.isAccountNonExpired()) {
      throw new AccountExpiredException(messages.getMessage("AccountStatusUserDetailsChecker.expired",
          "User account has expired"), user);
    }

    if (!user.isCredentialsNonExpired()) {
      throw new CredentialsExpiredException(messages.getMessage("AccountStatusUserDetailsChecker.credentialsExpired",
          "User credentials have expired"), user);
    }
  }
}

相关文章

微信公众号

最新文章

更多