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 | /**
|
---|
11 | * An oauth token that has been obtained by JOSM and can be used to authenticate the user on the server.
|
---|
12 | */
|
---|
13 | public class OAuthToken {
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * Creates an OAuthToken from the token currently managed by the {@link OAuthConsumer}.
|
---|
17 | *
|
---|
18 | * @param consumer the consumer
|
---|
19 | * @return the token
|
---|
20 | */
|
---|
21 | public static OAuthToken createToken(OAuthConsumer consumer) {
|
---|
22 | return new OAuthToken(consumer.getToken(), consumer.getTokenSecret());
|
---|
23 | }
|
---|
24 |
|
---|
25 | private final String key;
|
---|
26 | private final String secret;
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * Creates a new token
|
---|
30 | *
|
---|
31 | * @param key the token key
|
---|
32 | * @param secret the token secret
|
---|
33 | */
|
---|
34 | public OAuthToken(String key, String secret) {
|
---|
35 | this.key = key;
|
---|
36 | this.secret = secret;
|
---|
37 | }
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * Creates a clone of another token
|
---|
41 | *
|
---|
42 | * @param other the other token. Must not be null.
|
---|
43 | * @throws IllegalArgumentException if other is null
|
---|
44 | */
|
---|
45 | public OAuthToken(OAuthToken other) {
|
---|
46 | CheckParameterUtil.ensureParameterNotNull(other, "other");
|
---|
47 | this.key = other.key;
|
---|
48 | this.secret = other.secret;
|
---|
49 | }
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * Replies the token key
|
---|
53 | *
|
---|
54 | * @return the token key
|
---|
55 | */
|
---|
56 | public String getKey() {
|
---|
57 | return key;
|
---|
58 | }
|
---|
59 |
|
---|
60 | /**
|
---|
61 | * Replies the token secret
|
---|
62 | *
|
---|
63 | * @return the token secret
|
---|
64 | */
|
---|
65 | public String getSecret() {
|
---|
66 | return secret;
|
---|
67 | }
|
---|
68 |
|
---|
69 | @Override
|
---|
70 | public int hashCode() {
|
---|
71 | return Objects.hash(key, secret);
|
---|
72 | }
|
---|
73 |
|
---|
74 | @Override
|
---|
75 | public boolean equals(Object obj) {
|
---|
76 | if (this == obj) return true;
|
---|
77 | if (obj == null || getClass() != obj.getClass()) return false;
|
---|
78 | OAuthToken that = (OAuthToken) obj;
|
---|
79 | return Objects.equals(key, that.key) &&
|
---|
80 | Objects.equals(secret, that.secret);
|
---|
81 | }
|
---|
82 | }
|
---|