@Test public void validate() throws Exception { Account account = accountCitizen("user1"); UUID accountId = account.getAccountId(); ClientAppUserAccessToken token = new ClientAppUserAccessToken(accountId, EnumSet.of(Authority.CITIZEN, Authority.TOURIST), EnumSet.of(ClientAppScope.FEED, ClientAppScope.PUBLIC), "client-id-bar", "secret-123"); ClientAppUser clientAppUser = ClientAppUser.create("client-id-bar", "secret-123", accountId, EnumSet.of(ClientAppScope.FEED), Instant.now()); assertTrue(token.validate(clientAppUser)); ClientAppUser diffClientId = ClientAppUser.create("client-id-diff", "secret-123", accountId, EnumSet.of(ClientAppScope.FEED), Instant.now()); ClientAppUser diffClientSecret = ClientAppUser.create("client-id-bar", "secret-diff", accountId, EnumSet.of(ClientAppScope.FEED), Instant.now()); ClientAppUser diffAccount = ClientAppUser.create("client-id-bar", "secret-123", UUID.randomUUID(), EnumSet.of(ClientAppScope.FEED), Instant.now()); assertFalse(token.validate(diffClientId)); assertFalse(token.validate(diffClientSecret)); assertFalse(token.validate(diffAccount)); assertFalse(token.validate(null)); }
@Override public boolean validate(@Nullable ClientAppUser clientAppUser) { return Optional.ofNullable(clientAppUser) .filter(user -> authenticatedId().equals(user.getAccountId())) .filter(user -> clientId().equals(user.getClientId())) .filter(user -> clientSecret.equals(user.getCurrentClientSecret())) .isPresent(); }
ClientAppUserAccessToken implements Authorization, ClientAppAuthorization { @Override public boolean validate(@Nullable ClientAppUser clientAppUser) { return Optional.ofNullable(clientAppUser) .filter(user -> authenticatedId().equals(user.getAccountId())) .filter(user -> clientId().equals(user.getClientId())) .filter(user -> clientSecret.equals(user.getCurrentClientSecret())) .isPresent(); } }
ClientAppUserAccessToken implements Authorization, ClientAppAuthorization { @Override public boolean validate(@Nullable ClientAppUser clientAppUser) { return Optional.ofNullable(clientAppUser) .filter(user -> authenticatedId().equals(user.getAccountId())) .filter(user -> clientId().equals(user.getClientId())) .filter(user -> clientSecret.equals(user.getCurrentClientSecret())) .isPresent(); } ClientAppUserAccessToken(UUID accountId,
      Set<Authority> authorities,
      Set<ClientAppScope> tokenScopes,
      String clientId,
      String clientSecret); private  ClientAppUserAccessToken(UUID accountId,
      long authoritiesBits,
      Set<ClientAppScope> tokenScopes,
      String clientId,
      String clientSecret); }
ClientAppUserAccessToken implements Authorization, ClientAppAuthorization { @Override public boolean validate(@Nullable ClientAppUser clientAppUser) { return Optional.ofNullable(clientAppUser) .filter(user -> authenticatedId().equals(user.getAccountId())) .filter(user -> clientId().equals(user.getClientId())) .filter(user -> clientSecret.equals(user.getCurrentClientSecret())) .isPresent(); } ClientAppUserAccessToken(UUID accountId,
      Set<Authority> authorities,
      Set<ClientAppScope> tokenScopes,
      String clientId,
      String clientSecret); private  ClientAppUserAccessToken(UUID accountId,
      long authoritiesBits,
      Set<ClientAppScope> tokenScopes,
      String clientId,
      String clientSecret); static Optional<ClientAppUserAccessToken> tryDecode(String rawToken, OauthSecret secret); @Override String toString(); String encode(Instant expireTime, OauthSecret secret); @Override UUID authenticatedId(); @Override boolean containsAuthority(Authority authority); @Override boolean matches(Account account); @Override boolean equals(Object o); @Override int hashCode(); @Override boolean validate(@Nullable ClientAppUser clientAppUser); @Override boolean containsScope(ClientAppScope scope); @Override String clientId(); String getCanonicalScope(); }
ClientAppUserAccessToken implements Authorization, ClientAppAuthorization { @Override public boolean validate(@Nullable ClientAppUser clientAppUser) { return Optional.ofNullable(clientAppUser) .filter(user -> authenticatedId().equals(user.getAccountId())) .filter(user -> clientId().equals(user.getClientId())) .filter(user -> clientSecret.equals(user.getCurrentClientSecret())) .isPresent(); } ClientAppUserAccessToken(UUID accountId,
      Set<Authority> authorities,
      Set<ClientAppScope> tokenScopes,
      String clientId,
      String clientSecret); private  ClientAppUserAccessToken(UUID accountId,
      long authoritiesBits,
      Set<ClientAppScope> tokenScopes,
      String clientId,
      String clientSecret); static Optional<ClientAppUserAccessToken> tryDecode(String rawToken, OauthSecret secret); @Override String toString(); String encode(Instant expireTime, OauthSecret secret); @Override UUID authenticatedId(); @Override boolean containsAuthority(Authority authority); @Override boolean matches(Account account); @Override boolean equals(Object o); @Override int hashCode(); @Override boolean validate(@Nullable ClientAppUser clientAppUser); @Override boolean containsScope(ClientAppScope scope); @Override String clientId(); String getCanonicalScope();  }