1 /*
2 * Copyright (C) 2010 Atlassian
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.atlassian.jira.rest.client.api.domain;
18
19 import com.google.common.base.Objects;
20
21 /**
22 * Basic Authentication information of the current user session (if the connection maintains the session)
23 * or just authentication info from the last remote call (when the connection is stateless - usually
24 * recommended for really RESTful designs).
25 *
26 * @since v0.1
27 */
28 public class Authentication {
29 private final LoginInfo loginInfo;
30 private final SessionCookie sessionCookie;
31
32 public Authentication(LoginInfo loginInfo, SessionCookie sessionCookie) {
33 this.loginInfo = loginInfo;
34 this.sessionCookie = sessionCookie;
35 }
36
37 public LoginInfo getLoginInfo() {
38 return loginInfo;
39 }
40
41 public SessionCookie getSession() {
42 return sessionCookie;
43 }
44
45 @Override
46 public String toString() {
47 return Objects.toStringHelper(this).addValue(super.toString()).
48 add("loginInfo", loginInfo).
49 add("sessionCookie", sessionCookie).
50 toString();
51 }
52
53 @Override
54 public boolean equals(Object obj) {
55 if (obj instanceof Authentication) {
56 Authentication that = (Authentication) obj;
57 return Objects.equal(this.loginInfo, that.loginInfo)
58 && Objects.equal(this.sessionCookie, that.sessionCookie);
59 }
60 return false;
61 }
62
63 @Override
64 public int hashCode() {
65 return Objects.hashCode(loginInfo, sessionCookie);
66 }
67
68 }