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