-
Notifications
You must be signed in to change notification settings - Fork 159
Expand file tree
/
Copy pathAuthenticationResult.java
More file actions
286 lines (238 loc) · 10.4 KB
/
AuthenticationResult.java
File metadata and controls
286 lines (238 loc) · 10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.microsoft.aad.msal4j;
import java.util.Date;
import java.util.Objects;
final class AuthenticationResult implements IAuthenticationResult {
private static final long serialVersionUID = 1L;
private final String accessToken;
private final long expiresOn;
private final long extExpiresOn;
private final String refreshToken;
private final Long refreshOn;
private final String familyId;
private final String idToken;
private final IdToken idTokenObject;
private final AccountCacheEntity accountCacheEntity;
private final IAccount account;
private final ITenantProfile tenantProfile;
private String environment;
private final Date expiresOnDate;
private final String scopes;
private final AuthenticationResultMetadata metadata;
private final Boolean isPopAuthorization;
AuthenticationResult(String accessToken, long expiresOn, long extExpiresOn, String refreshToken, Long refreshOn, String familyId, String idToken, AccountCacheEntity accountCacheEntity, String environment, String scopes, AuthenticationResultMetadata metadata, Boolean isPopAuthorization) {
this.accessToken = accessToken;
this.expiresOn = expiresOn;
this.extExpiresOn = extExpiresOn;
this.refreshToken = refreshToken;
this.refreshOn = refreshOn;
this.familyId = familyId;
this.idToken = idToken;
this.accountCacheEntity = accountCacheEntity;
this.environment = environment;
this.scopes = scopes;
this.metadata = metadata == null ? AuthenticationResultMetadata.builder().build() : metadata;
this.isPopAuthorization = isPopAuthorization;
this.expiresOnDate = new Date(expiresOn * 1000);
this.idTokenObject = getIdTokenObj();
this.account = getAccount();
this.tenantProfile = getTenantProfile();
}
private IdToken getIdTokenObj() {
if (StringHelper.isBlank(idToken)) {
return null;
}
try {
return JsonHelper.createIdTokenFromEncodedTokenString(idToken);
} catch (Exception e) {
return null;
}
}
private IAccount getAccount() {
if (accountCacheEntity == null) {
return null;
}
return accountCacheEntity.toAccount();
}
private ITenantProfile getTenantProfile() {
if (StringHelper.isBlank(idToken)) {
return null;
}
IAccount acct = getAccount();
if (acct == null) {
return null;
}
try {
return new TenantProfile(JsonHelper.parseJsonToMap(JsonHelper.getTokenPayloadClaims(idToken)), acct.environment());
} catch (Exception e) {
return null;
}
}
public String accessToken() {
return this.accessToken;
}
String refreshToken() {
return this.refreshToken;
}
Long refreshOn() {
return this.refreshOn;
}
public String idToken() {
return this.idToken;
}
public String environment() {
return this.environment;
}
public String scopes() {
return this.scopes;
}
public AuthenticationResultMetadata metadata() {
return this.metadata;
}
long expiresOn() {
return this.expiresOn;
}
long extExpiresOn() {
return this.extExpiresOn;
}
String familyId() {
return this.familyId;
}
IdToken idTokenObject() {
return this.idTokenObject;
}
AccountCacheEntity accountCacheEntity() {
return this.accountCacheEntity;
}
public IAccount account() {
return this.account;
}
public ITenantProfile tenantProfile() {
return this.tenantProfile;
}
public Date expiresOnDate() {
return this.expiresOnDate;
}
Boolean isPopAuthorization() {
return this.isPopAuthorization;
}
static AuthenticationResultBuilder builder() {
return new AuthenticationResultBuilder();
}
static class AuthenticationResultBuilder {
private String accessToken;
private long expiresOn;
private long extExpiresOn;
private String refreshToken;
private Long refreshOn;
private String familyId;
private String idToken;
private AccountCacheEntity accountCacheEntity;
private String environment;
private String scopes;
private AuthenticationResultMetadata metadata;
private Boolean isPopAuthorization;
AuthenticationResultBuilder() {
}
public AuthenticationResultBuilder accessToken(String accessToken) {
this.accessToken = accessToken;
return this;
}
public AuthenticationResultBuilder expiresOn(long expiresOn) {
this.expiresOn = expiresOn;
return this;
}
public AuthenticationResultBuilder extExpiresOn(long extExpiresOn) {
this.extExpiresOn = extExpiresOn;
return this;
}
public AuthenticationResultBuilder refreshToken(String refreshToken) {
this.refreshToken = refreshToken;
return this;
}
public AuthenticationResultBuilder refreshOn(Long refreshOn) {
this.refreshOn = refreshOn;
return this;
}
public AuthenticationResultBuilder familyId(String familyId) {
this.familyId = familyId;
return this;
}
public AuthenticationResultBuilder idToken(String idToken) {
this.idToken = idToken;
return this;
}
public AuthenticationResultBuilder accountCacheEntity(AccountCacheEntity accountCacheEntity) {
this.accountCacheEntity = accountCacheEntity;
return this;
}
public AuthenticationResultBuilder environment(String environment) {
this.environment = environment;
return this;
}
public AuthenticationResultBuilder scopes(String scopes) {
this.scopes = scopes;
return this;
}
public AuthenticationResultBuilder metadata(AuthenticationResultMetadata metadata) {
this.metadata = metadata;
return this;
}
public AuthenticationResultBuilder isPopAuthorization(Boolean isPopAuthorization) {
this.isPopAuthorization = isPopAuthorization;
return this;
}
public AuthenticationResult build() {
return new AuthenticationResult(this.accessToken, this.expiresOn, this.extExpiresOn, this.refreshToken, this.refreshOn, this.familyId, this.idToken, this.accountCacheEntity, this.environment, this.scopes, this.metadata, this.isPopAuthorization);
}
public String toString() {
return "AuthenticationResult.AuthenticationResultBuilder(accessToken=" + this.accessToken + ", expiresOn=" + this.expiresOn + ", extExpiresOn=" + this.extExpiresOn + ", refreshToken=" + this.refreshToken + ", refreshOn=" + this.refreshOn + ", familyId=" + this.familyId + ", idToken=" + this.idToken + ", accountCacheEntity=" + this.accountCacheEntity + ", environment=" + this.environment + ", scopes=" + this.scopes + ", metadata=" + this.metadata + ", isPopAuthorization=" + this.isPopAuthorization + ")";
}
}
//These methods are based on those generated by Lombok's @EqualsAndHashCode annotation.
//They have the same functionality as the generated methods, but were refactored for readability.
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof AuthenticationResult)) return false;
AuthenticationResult other = (AuthenticationResult) o;
if (this.expiresOn() != other.expiresOn()) return false;
if (this.extExpiresOn() != other.extExpiresOn()) return false;
if (!Objects.equals(refreshOn, other.refreshOn)) return false;
if (!Objects.equals(isPopAuthorization, other.isPopAuthorization)) return false;
if (!Objects.equals(accessToken, other.accessToken)) return false;
if (!Objects.equals(refreshToken, other.refreshToken)) return false;
if (!Objects.equals(familyId, other.familyId)) return false;
if (!Objects.equals(idToken, other.idToken)) return false;
if (!Objects.equals(idTokenObject, other.idTokenObject)) return false;
if (!Objects.equals(accountCacheEntity, other.accountCacheEntity)) return false;
if (!Objects.equals(account, other.account)) return false;
if (!Objects.equals(tenantProfile, other.tenantProfile)) return false;
if (!Objects.equals(environment, other.environment)) return false;
if (!Objects.equals(expiresOnDate, other.expiresOnDate)) return false;
if (!Objects.equals(scopes, other.scopes)) return false;
return Objects.equals(metadata, other.metadata);
}
@Override
public int hashCode() {
int result = 1;
result = result * 59 + (int) (this.expiresOn >>> 32 ^ this.expiresOn);
result = result * 59 + (int) (this.extExpiresOn >>> 32 ^ this.extExpiresOn);
result = result * 59 + (this.refreshOn == null ? 43 : this.refreshOn.hashCode());
result = result * 59 + (this.isPopAuthorization == null ? 43 : this.isPopAuthorization.hashCode());
result = result * 59 + (this.accessToken == null ? 43 : this.accessToken.hashCode());
result = result * 59 + (this.refreshToken == null ? 43 : this.refreshToken.hashCode());
result = result * 59 + (this.familyId == null ? 43 : this.familyId.hashCode());
result = result * 59 + (this.idToken == null ? 43 : this.idToken.hashCode());
result = result * 59 + (this.idTokenObject == null ? 43 : this.idTokenObject.hashCode());
result = result * 59 + (this.accountCacheEntity == null ? 43 : this.accountCacheEntity.hashCode());
result = result * 59 + (this.account == null ? 43 : this.account.hashCode());
result = result * 59 + (this.tenantProfile == null ? 43 : this.tenantProfile.hashCode());
result = result * 59 + (this.environment == null ? 43 : this.environment.hashCode());
result = result * 59 + (this.expiresOnDate == null ? 43 : this.expiresOnDate.hashCode());
result = result * 59 + (this.scopes == null ? 43 : this.scopes.hashCode());
result = result * 59 + (this.metadata == null ? 43 : this.metadata.hashCode());
return result;
}
}