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