001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.data.oauth; 003 004import java.util.Objects; 005 006import org.openstreetmap.josm.tools.CheckParameterUtil; 007 008import oauth.signpost.OAuthConsumer; 009 010public class OAuthToken { 011 012 /** 013 * Creates an OAuthToken from the token currently managed by the {@link OAuthConsumer}. 014 * 015 * @param consumer the consumer 016 * @return the token 017 */ 018 public static OAuthToken createToken(OAuthConsumer consumer) { 019 return new OAuthToken(consumer.getToken(), consumer.getTokenSecret()); 020 } 021 022 private final String key; 023 private final String secret; 024 025 /** 026 * Creates a new token 027 * 028 * @param key the token key 029 * @param secret the token secret 030 */ 031 public OAuthToken(String key, String secret) { 032 this.key = key; 033 this.secret = secret; 034 } 035 036 /** 037 * Creates a clone of another token 038 * 039 * @param other the other token. Must not be null. 040 * @throws IllegalArgumentException if other is null 041 */ 042 public OAuthToken(OAuthToken other) { 043 CheckParameterUtil.ensureParameterNotNull(other, "other"); 044 this.key = other.key; 045 this.secret = other.secret; 046 } 047 048 /** 049 * Replies the token key 050 * 051 * @return the token key 052 */ 053 public String getKey() { 054 return key; 055 } 056 057 /** 058 * Replies the token secret 059 * 060 * @return the token secret 061 */ 062 public String getSecret() { 063 return secret; 064 } 065 066 @Override 067 public int hashCode() { 068 return Objects.hash(key, secret); 069 } 070 071 @Override 072 public boolean equals(Object obj) { 073 if (this == obj) return true; 074 if (obj == null || getClass() != obj.getClass()) return false; 075 OAuthToken that = (OAuthToken) obj; 076 return Objects.equals(key, that.key) && 077 Objects.equals(secret, that.secret); 078 } 079}