@Test public void matches() throws Exception { Account account = accountWithAuth("pw1", CITIZEN, SYSOP); AccountAccessToken accountAccessToken = new AccountAccessToken(account.getAccountId(), "pw1", EnumSet.of(CITIZEN, SYSOP)); assertTrue(accountAccessToken.matches(account)); accountAccessToken = new AccountAccessToken(account.getAccountId(), "pw1", EnumSet.of(CITIZEN)); assertFalse(accountAccessToken.matches(account)); accountAccessToken = new AccountAccessToken(account.getAccountId(), "pw1", EnumSet.of(SUFFRAGE)); assertFalse(accountAccessToken.matches(account)); accountAccessToken = new AccountAccessToken(account.getAccountId(), "wrongpw1", EnumSet.of(CITIZEN, SYSOP)); assertFalse(accountAccessToken.matches(account)); Account diffAccount = accountWithAuth("ppww", SYSOP); accountAccessToken = new AccountAccessToken(UUID.randomUUID(), "ppww", EnumSet.of(SYSOP)); assertFalse(accountAccessToken.matches(diffAccount)); }
@Override public boolean matches(Account account) { return authenticatedId().equals(account.getAccountId()) && Arrays.equals(this.passwordHashDigest, passwordHashToBytes(account.getPasswordHash())) && this.authoritiesBits == Authority.toBits(account.getAuthorities()); }
AccountAccessToken implements Authorization { @Override public boolean matches(Account account) { return authenticatedId().equals(account.getAccountId()) && Arrays.equals(this.passwordHashDigest, passwordHashToBytes(account.getPasswordHash())) && this.authoritiesBits == Authority.toBits(account.getAuthorities()); } }
AccountAccessToken implements Authorization { @Override public boolean matches(Account account) { return authenticatedId().equals(account.getAccountId()) && Arrays.equals(this.passwordHashDigest, passwordHashToBytes(account.getPasswordHash())) && this.authoritiesBits == Authority.toBits(account.getAuthorities()); } AccountAccessToken(UUID accountId, String passwordHash, Set<Authority> authorities); private  AccountAccessToken(UUID accountId, byte[] passwordHashDigest, long authoritiesBits); }
AccountAccessToken implements Authorization { @Override public boolean matches(Account account) { return authenticatedId().equals(account.getAccountId()) && Arrays.equals(this.passwordHashDigest, passwordHashToBytes(account.getPasswordHash())) && this.authoritiesBits == Authority.toBits(account.getAuthorities()); } AccountAccessToken(UUID accountId, String passwordHash, Set<Authority> authorities); private  AccountAccessToken(UUID accountId, byte[] passwordHashDigest, long authoritiesBits); static Optional<AccountAccessToken> tryDecode(String rawToken, AccountSecret secret); String encode(Instant expireTime, AccountSecret secret); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); @Override UUID authenticatedId(); @Override boolean containsAuthority(Authority authority); @Override boolean matches(Account account); }
AccountAccessToken implements Authorization { @Override public boolean matches(Account account) { return authenticatedId().equals(account.getAccountId()) && Arrays.equals(this.passwordHashDigest, passwordHashToBytes(account.getPasswordHash())) && this.authoritiesBits == Authority.toBits(account.getAuthorities()); } AccountAccessToken(UUID accountId, String passwordHash, Set<Authority> authorities); private  AccountAccessToken(UUID accountId, byte[] passwordHashDigest, long authoritiesBits); static Optional<AccountAccessToken> tryDecode(String rawToken, AccountSecret secret); String encode(Instant expireTime, AccountSecret secret); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); @Override UUID authenticatedId(); @Override boolean containsAuthority(Authority authority); @Override boolean matches(Account account); static final String HEADER_KEY; }