Skip to content

Instantly share code, notes, and snippets.

@Dimanaux
Created June 18, 2019 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dimanaux/7cf4d1c4e6e3a3a856b0c2cf4c40eebc to your computer and use it in GitHub Desktop.
Save Dimanaux/7cf4d1c4e6e3a3a856b0c2cf4c40eebc to your computer and use it in GitHub Desktop.
May be it is an OOP solution
class Account {
private String email;
private String password;
// single method
public UserDetails asDetails() {
return new AccountDetails() {
@Override public String getPassword() {
return Account.this.password;
}
@Override public String getUsername() {
return Account.this.email;
}
};
}
}
abstract class AccountDetails implements UserDetails {
public final Account account;
public AccountDetails(Account account) { this.account = account; }
// template code vvv
@Override public Collection<? extends GrantedAuthority> getAuthorities() { return null; }
@Override public boolean isAccountNonExpired() { return true; }
@Override public boolean isAccountNonLocked() { return true; }
@Override public boolean isCredentialsNonExpired() { return true; }
@Override public boolean isEnabled() { return true; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment