1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.oauth;
|
---|
3 |
|
---|
4 | import java.util.Objects;
|
---|
5 |
|
---|
6 | import org.openstreetmap.josm.tools.CheckParameterUtil;
|
---|
7 |
|
---|
8 | import oauth.signpost.OAuthConsumer;
|
---|
9 |
|
---|
10 | public class OAuthToken {
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * Creates an OAuthToken from the token currently managed by the {@link OAuthConsumer}.
|
---|
14 | *
|
---|
15 | * @param consumer the consumer
|
---|
16 | * @return the token
|
---|
17 | */
|
---|
18 | public static OAuthToken createToken(OAuthConsumer consumer) {
|
---|
19 | return new OAuthToken(consumer.getToken(), consumer.getTokenSecret());
|
---|
20 | }
|
---|
21 |
|
---|
22 | private final String key;
|
---|
23 | private final String secret;
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Creates a new token
|
---|
27 | *
|
---|
28 | * @param key the token key
|
---|
29 | * @param secret the token secret
|
---|
30 | */
|
---|
31 | public OAuthToken(String key, String secret) {
|
---|
32 | this.key = key;
|
---|
33 | this.secret = secret;
|
---|
34 | }
|
---|
35 |
|
---|
36 | /**
|
---|
37 | * Creates a clone of another token
|
---|
38 | *
|
---|
39 | * @param other the other token. Must not be null.
|
---|
40 | * @throws IllegalArgumentException if other is null
|
---|
41 | */
|
---|
42 | public OAuthToken(OAuthToken other) {
|
---|
43 | CheckParameterUtil.ensureParameterNotNull(other, "other");
|
---|
44 | this.key = other.key;
|
---|
45 | this.secret = other.secret;
|
---|
46 | }
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * Replies the token key
|
---|
50 | *
|
---|
51 | * @return the token key
|
---|
52 | */
|
---|
53 | public String getKey() {
|
---|
54 | return key;
|
---|
55 | }
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * Replies the token secret
|
---|
59 | *
|
---|
60 | * @return the token secret
|
---|
61 | */
|
---|
62 | public String getSecret() {
|
---|
63 | return secret;
|
---|
64 | }
|
---|
65 |
|
---|
66 | @Override
|
---|
67 | public int hashCode() {
|
---|
68 | return Objects.hash(key, secret);
|
---|
69 | }
|
---|
70 |
|
---|
71 | @Override
|
---|
72 | public boolean equals(Object obj) {
|
---|
73 | if (this == obj) return true;
|
---|
74 | if (obj == null || getClass() != obj.getClass()) return false;
|
---|
75 | OAuthToken that = (OAuthToken) obj;
|
---|
76 | return Objects.equals(key, that.key) &&
|
---|
77 | Objects.equals(secret, that.secret);
|
---|
78 | }
|
---|
79 | }
|
---|