97367c5f6dc8d2100006e96f3fa6a182eb97c296
[pub/Android/ownCloud.git] / oc_framework / src / com / owncloud / android / oc_framework / network / BearerCredentials.java
1 /* ownCloud Android Library is available under MIT license
2 * Copyright (C) 2014 ownCloud (http://www.owncloud.org/)
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 * THE SOFTWARE.
22 *
23 */
24
25 package com.owncloud.android.oc_framework.network;
26
27 import org.apache.commons.httpclient.Credentials;
28 import org.apache.commons.httpclient.util.LangUtils;
29
30 /**
31 * Bearer token {@link Credentials}
32 *
33 * @author David A. Velasco
34 */
35 public class BearerCredentials implements Credentials {
36
37
38 private String mAccessToken;
39
40
41 /**
42 * The constructor with the bearer token
43 *
44 * @param token The bearer token
45 */
46 public BearerCredentials(String token) {
47 /*if (token == null) {
48 throw new IllegalArgumentException("Bearer token may not be null");
49 }*/
50 mAccessToken = (token == null) ? "" : token;
51 }
52
53
54 /**
55 * Returns the access token
56 *
57 * @return The access token
58 */
59 public String getAccessToken() {
60 return mAccessToken;
61 }
62
63
64 /**
65 * Get this object string.
66 *
67 * @return The access token
68 */
69 public String toString() {
70 return mAccessToken;
71 }
72
73 /**
74 * Does a hash of the access token.
75 *
76 * @return The hash code of the access token
77 */
78 public int hashCode() {
79 int hash = LangUtils.HASH_SEED;
80 hash = LangUtils.hashCode(hash, mAccessToken);
81 return hash;
82 }
83
84 /**
85 * These credentials are assumed equal if accessToken is the same.
86 *
87 * @param o The other object to compare with.
88 *
89 * @return 'True' if the object is equivalent.
90 */
91 public boolean equals(Object o) {
92 if (o == null) return false;
93 if (this == o) return true;
94 if (this.getClass().equals(o.getClass())) {
95 BearerCredentials that = (BearerCredentials) o;
96 if (LangUtils.equals(mAccessToken, that.mAccessToken)) {
97 return true;
98 }
99 }
100 return false;
101 }
102
103 }
104