Fix crash got with: 1. try to rename / delete a file with an outdated access token...
[pub/Android/ownCloud.git] / src / com / owncloud / android / network / BearerCredentials.java
1 /* ownCloud Android client application
2 * Copyright (C) 2012 ownCloud Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18
19 package com.owncloud.android.network;
20
21 import org.apache.commons.httpclient.Credentials;
22 import org.apache.commons.httpclient.util.LangUtils;
23
24 /**
25 * Bearer token {@link Credentials}
26 *
27 * @author David A. Velasco
28 */
29 public class BearerCredentials implements Credentials {
30
31
32 private String mAccessToken;
33
34
35 /**
36 * The constructor with the bearer token
37 *
38 * @param token The bearer token
39 */
40 public BearerCredentials(String token) {
41 /*if (token == null) {
42 throw new IllegalArgumentException("Bearer token may not be null");
43 }*/
44 mAccessToken = (token == null) ? "" : token;
45 }
46
47
48 /**
49 * Returns the access token
50 *
51 * @return The access token
52 */
53 public String getAccessToken() {
54 return mAccessToken;
55 }
56
57
58 /**
59 * Get this object string.
60 *
61 * @return The access token
62 */
63 public String toString() {
64 return mAccessToken;
65 }
66
67 /**
68 * Does a hash of the access token.
69 *
70 * @return The hash code of the access token
71 */
72 public int hashCode() {
73 int hash = LangUtils.HASH_SEED;
74 hash = LangUtils.hashCode(hash, mAccessToken);
75 return hash;
76 }
77
78 /**
79 * These credentials are assumed equal if accessToken is the same.
80 *
81 * @param o The other object to compare with.
82 *
83 * @return 'True' if the object is equivalent.
84 */
85 public boolean equals(Object o) {
86 if (o == null) return false;
87 if (this == o) return true;
88 if (this.getClass().equals(o.getClass())) {
89 BearerCredentials that = (BearerCredentials) o;
90 if (LangUtils.equals(mAccessToken, that.mAccessToken)) {
91 return true;
92 }
93 }
94 return false;
95 }
96
97 }
98