@Test public void oauthDirectAuthorizeToken_requireCitizen() throws Exception { Account tourist = savedAccountTourist("badOauthTest"); try { service.createOauthDirectAuthorizeToken(tourist); fail("RequireCitizenException expected"); } catch (RequireCitizenException expected) { } }
@Override public AccountOnceToken createOauthDirectAuthorizeToken(Authorization authorization) throws RequireCitizenException { Optional<Account> verifiedAccount = accountDao.strongVerifyAccount(authorization); if (!verifiedAccount.isPresent()) { throw new AccessDeniedException("invalid access token"); } if (!verifiedAccount.get().containsAuthority(Authority.CITIZEN)) { throw new RequireCitizenException(); } return verifiedAccount.map(account -> accountDao.createOnceToken(account, AccountOnceToken.Type.OAUTH_DIRECT_AUTHORIZE, Instant.now(clock))).get(); }
AccountServiceImpl implements AccountService { @Override public AccountOnceToken createOauthDirectAuthorizeToken(Authorization authorization) throws RequireCitizenException { Optional<Account> verifiedAccount = accountDao.strongVerifyAccount(authorization); if (!verifiedAccount.isPresent()) { throw new AccessDeniedException("invalid access token"); } if (!verifiedAccount.get().containsAuthority(Authority.CITIZEN)) { throw new RequireCitizenException(); } return verifiedAccount.map(account -> accountDao.createOnceToken(account, AccountOnceToken.Type.OAUTH_DIRECT_AUTHORIZE, Instant.now(clock))).get(); } }
AccountServiceImpl implements AccountService { @Override public AccountOnceToken createOauthDirectAuthorizeToken(Authorization authorization) throws RequireCitizenException { Optional<Account> verifiedAccount = accountDao.strongVerifyAccount(authorization); if (!verifiedAccount.isPresent()) { throw new AccessDeniedException("invalid access token"); } if (!verifiedAccount.get().containsAuthority(Authority.CITIZEN)) { throw new RequireCitizenException(); } return verifiedAccount.map(account -> accountDao.createOnceToken(account, AccountOnceToken.Type.OAUTH_DIRECT_AUTHORIZE, Instant.now(clock))).get(); }  }
AccountServiceImpl implements AccountService { @Override public AccountOnceToken createOauthDirectAuthorizeToken(Authorization authorization) throws RequireCitizenException { Optional<Account> verifiedAccount = accountDao.strongVerifyAccount(authorization); if (!verifiedAccount.isPresent()) { throw new AccessDeniedException("invalid access token"); } if (!verifiedAccount.get().containsAuthority(Authority.CITIZEN)) { throw new RequireCitizenException(); } return verifiedAccount.map(account -> accountDao.createOnceToken(account, AccountOnceToken.Type.OAUTH_DIRECT_AUTHORIZE, Instant.now(clock))).get(); }  @Override Account createViaEmail(String username, String email, String password, Locale locale); @Override Optional<Account> findMe(Authorization authorization); @Override Optional<AccountAuth> authenticate(String username, String password); @Override Optional<AccountAccessToken> strongVerifyAccessToken(String rawAccessToken); @Override AccountAuth extendsAccessToken(AccountAccessToken accessToken); @Override boolean isUsernameAvailable(String username); @Override boolean isEmailAvailable(String email); @Override void updateAuthorities(Authorization authorization, EnumSet<Authority> authorities); @Override boolean activate(String inputOnceToken); @Override void resendActivation(Authorization authorization, Locale locale); @Override void sendResetPassword(String username, String email, Locale locale); @Override Optional<AccountOnceToken> findValidResetPasswordToken(String inputOnceToken); @Override void updatePasswordWithOnceToken(String accountOnceToken, String password, Locale locale); @Override AccountAuth updateNewPassword(Authorization authorization,
      String oldPassword,
      String newPassword,
      Locale locale); @Override Optional<AccountAccessToken> tryDecodeAccessToken(String rawAccountAccessToken); @Override AccountStats loadAccountStats(String username); @Override Account loadAccount(String username); @Override String updateDescription(Authorization authorization, String description); @Override String loadEditableDescription(Authorization authorization); @Override void complaintEmail(List<String> emails); @Override void muteEmail(List<String> emails); @Override AccountOnceToken createOauthDirectAuthorizeToken(Authorization authorization); @Override Optional<Account> oauthDirectAuthorize(String inputOnceToken); }
AccountServiceImpl implements AccountService { @Override public AccountOnceToken createOauthDirectAuthorizeToken(Authorization authorization) throws RequireCitizenException { Optional<Account> verifiedAccount = accountDao.strongVerifyAccount(authorization); if (!verifiedAccount.isPresent()) { throw new AccessDeniedException("invalid access token"); } if (!verifiedAccount.get().containsAuthority(Authority.CITIZEN)) { throw new RequireCitizenException(); } return verifiedAccount.map(account -> accountDao.createOnceToken(account, AccountOnceToken.Type.OAUTH_DIRECT_AUTHORIZE, Instant.now(clock))).get(); }  @Override Account createViaEmail(String username, String email, String password, Locale locale); @Override Optional<Account> findMe(Authorization authorization); @Override Optional<AccountAuth> authenticate(String username, String password); @Override Optional<AccountAccessToken> strongVerifyAccessToken(String rawAccessToken); @Override AccountAuth extendsAccessToken(AccountAccessToken accessToken); @Override boolean isUsernameAvailable(String username); @Override boolean isEmailAvailable(String email); @Override void updateAuthorities(Authorization authorization, EnumSet<Authority> authorities); @Override boolean activate(String inputOnceToken); @Override void resendActivation(Authorization authorization, Locale locale); @Override void sendResetPassword(String username, String email, Locale locale); @Override Optional<AccountOnceToken> findValidResetPasswordToken(String inputOnceToken); @Override void updatePasswordWithOnceToken(String accountOnceToken, String password, Locale locale); @Override AccountAuth updateNewPassword(Authorization authorization,
      String oldPassword,
      String newPassword,
      Locale locale); @Override Optional<AccountAccessToken> tryDecodeAccessToken(String rawAccountAccessToken); @Override AccountStats loadAccountStats(String username); @Override Account loadAccount(String username); @Override String updateDescription(Authorization authorization, String description); @Override String loadEditableDescription(Authorization authorization); @Override void complaintEmail(List<String> emails); @Override void muteEmail(List<String> emails); @Override AccountOnceToken createOauthDirectAuthorizeToken(Authorization authorization); @Override Optional<Account> oauthDirectAuthorize(String inputOnceToken);  }