throw new AccountException("Error : sample.jpa.servlet.CreateAccount : Account Number already exists:"+accno);
@PostMapping(path = "/api/register", produces = "application/json") public ResponseEntity<?> register(@RequestBody Account account) { try { account.grantAuthority("ROLE_USER"); return new ResponseEntity<Object>( accountService.register( account ), HttpStatus.OK); } catch (AccountException e) { e.printStackTrace(); return new ResponseEntity<RestError>(new RestError(e.getMessage()),HttpStatus.BAD_REQUEST ); } }
logger.warn("Account failure {}", e.getMessage()); return null; } catch (LoginException e) {
@Bean CommandLineRunner init( AccountService accountService ) { return (evt) -> Arrays.asList( "user,admin,john,robert,ana".split(",")).forEach( username -> { Account acct = new Account(); acct.setUsername(username); if ( username.equals("user")) acct.setPassword("password"); else acct.setPassword(passwordEncoder().encode("password")); acct.setFirstName(username); acct.setLastName("LastName"); acct.grantAuthority("ROLE_USER"); if ( username.equals("admin") ) acct.grantAuthority("ROLE_ADMIN"); try { accountService.register(acct); } catch (AccountException e) { e.printStackTrace(); } } ); } }
logger.warn("Account failure {}", e.getMessage()); return null; } catch (LoginException e) {
public Account register(Account account) throws AccountException { if ( accountRepo.countByUsername( account.getUsername() ) == 0 ) { account.setPassword(passwordEncoder.encode(account.getPassword())); return accountRepo.save( account ); } else { throw new AccountException(String.format("Username[%s] already taken.", account.getUsername())); } }
@Override public void throwSecurityException() throws LoginException { switch (this) { case PASSWORD_EXPIRED: throw new CredentialExpiredException(name()); case ACCOUNT_LOCKED: throw new AccountLockedException(name()); case CHANGE_AFTER_RESET: throw new CredentialExpiredException(name()); case PASSWORD_MOD_NOT_ALLOWED: throw new AccountException(name()); case MUST_SUPPLY_OLD_PASSWORD: throw new AccountException(name()); case INSUFFICIENT_PASSWORD_QUALITY: throw new CredentialException(name()); case PASSWORD_TOO_SHORT: throw new CredentialException(name()); case PASSWORD_TOO_YOUNG: throw new CredentialException(name()); case PASSWORD_IN_HISTORY: throw new CredentialException(name()); default: throw new IllegalStateException("Unknown password policy error: " + this); } }
@Override public void throwSecurityException() throws LoginException { switch (this) { case PASSWORD_EXPIRED: throw new CredentialExpiredException(name()); case ACCOUNT_LOCKED: throw new AccountLockedException(name()); case CHANGE_AFTER_RESET: throw new CredentialExpiredException(name()); case PASSWORD_MOD_NOT_ALLOWED: throw new AccountException(name()); case MUST_SUPPLY_OLD_PASSWORD: throw new AccountException(name()); case INSUFFICIENT_PASSWORD_QUALITY: throw new CredentialException(name()); case PASSWORD_TOO_SHORT: throw new CredentialException(name()); case PASSWORD_TOO_YOUNG: throw new CredentialException(name()); case PASSWORD_IN_HISTORY: throw new CredentialException(name()); default: throw new IllegalStateException("Unknown password policy error: " + this); } }
@Override public void throwSecurityException() throws LoginException { switch (this) { case PASSWORD_EXPIRED: throw new CredentialExpiredException(name()); case ACCOUNT_LOCKED: throw new AccountLockedException(name()); case CHANGE_AFTER_RESET: throw new CredentialExpiredException(name()); case PASSWORD_MOD_NOT_ALLOWED: throw new AccountException(name()); case MUST_SUPPLY_OLD_PASSWORD: throw new AccountException(name()); case INSUFFICIENT_PASSWORD_QUALITY: throw new CredentialException(name()); case PASSWORD_TOO_SHORT: throw new CredentialException(name()); case PASSWORD_TOO_YOUNG: throw new CredentialException(name()); case PASSWORD_IN_HISTORY: throw new CredentialException(name()); default: throw new IllegalStateException("Unknown password policy error: " + this); } }
@Override public void throwSecurityException() throws LoginException { switch (this) { case NO_SUCH_USER: throw new AccountNotFoundException(name()); case LOGON_FAILURE: throw new FailedLoginException(name()); case INVALID_LOGON_HOURS: throw new AccountLockedException(name()); case INVALID_WORKSTATION: throw new AccountException(name()); case PASSWORD_EXPIRED: throw new CredentialExpiredException(name()); case ACCOUNT_DISABLED: throw new AccountLockedException(name()); case ACCOUNT_EXPIRED: throw new AccountExpiredException(name()); case PASSWORD_MUST_CHANGE: throw new CredentialExpiredException(name()); case ACCOUNT_LOCKED_OUT: throw new AccountLockedException(name()); default: throw new IllegalStateException("Unknown active directory error: " + this); } }
@Override public void throwSecurityException() throws LoginException { switch (this) { case NO_SUCH_USER: throw new AccountNotFoundException(name()); case LOGON_FAILURE: throw new FailedLoginException(name()); case INVALID_LOGON_HOURS: throw new AccountLockedException(name()); case INVALID_WORKSTATION: throw new AccountException(name()); case PASSWORD_EXPIRED: throw new CredentialExpiredException(name()); case ACCOUNT_DISABLED: throw new AccountLockedException(name()); case ACCOUNT_EXPIRED: throw new AccountExpiredException(name()); case PASSWORD_MUST_CHANGE: throw new CredentialExpiredException(name()); case ACCOUNT_LOCKED_OUT: throw new AccountLockedException(name()); default: throw new IllegalStateException("Unknown active directory error: " + this); } }
@Override public void throwSecurityException() throws LoginException { switch (this) { case NO_SUCH_USER: throw new AccountNotFoundException(name()); case LOGON_FAILURE: throw new FailedLoginException(name()); case INVALID_LOGON_HOURS: throw new AccountLockedException(name()); case INVALID_WORKSTATION: throw new AccountException(name()); case PASSWORD_EXPIRED: throw new CredentialExpiredException(name()); case ACCOUNT_DISABLED: throw new AccountLockedException(name()); case ACCOUNT_EXPIRED: throw new AccountExpiredException(name()); case PASSWORD_MUST_CHANGE: throw new CredentialExpiredException(name()); case ACCOUNT_LOCKED_OUT: throw new AccountLockedException(name()); default: throw new IllegalStateException("Unknown active directory error: " + this); } }