2
* Ubuntu Single Sign On Java Client
4
* Copyright (C) 2011 Canonical Ltd.
5
* Author: Michał Karnicki <michal.karnicki@canonical.com>
7
* This file is part of Ubuntu SSO Java Client.
9
* This program is free software: you can redistribute it and/or modify
10
* it under the terms of the GNU Affero General Public License as
11
* published by the Free Software Foundation, either version 3 of the
12
* License, or (at your option) any later version.
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU Affero General Public License for more details.
19
* You should have received a copy of the GNU Affero General Public License
20
* along with this program. If not, see http://www.gnu.org/licenses
23
package com.ubuntu.sso.entry;
25
import java.util.ArrayList;
27
import org.json.JSONException;
28
import org.json.JSONObject;
30
import com.ubuntu.sso.util.JsonUtil;
32
public class AccountResponse extends ServerResponse {
33
protected static final String JSON_DISPLAYNAME_KEY = "displayname";
34
protected static final String JSON_OPENID_IDENTIFIER_KEY = "openid_identifier";
35
protected static final String JSON_PREFERRED_EMAIL_KEY = "preferred_email";
36
protected static final String JSON_VERIFIED_EMAILS = "verified_emails";
37
protected static final String JSON_UNVERIFIED_EMAILS = "unverified_emails";
39
private final String displayname;
40
private final String openidIdentifier;
41
private final String preferredEmail;
42
private final ArrayList<String> verifiedEmails;
43
private final ArrayList<String> unverifiedEmails;
45
public AccountResponse(JSONObject json) throws JSONException {
47
displayname = json.getString(JSON_DISPLAYNAME_KEY);
48
openidIdentifier = json.getString(JSON_OPENID_IDENTIFIER_KEY);
49
preferredEmail = json.getString(JSON_PREFERRED_EMAIL_KEY);
50
verifiedEmails = JsonUtil.jsonArrayToArrayList(
51
json.getJSONArray(JSON_VERIFIED_EMAILS));
52
unverifiedEmails = JsonUtil.jsonArrayToArrayList(
53
json.getJSONArray(JSON_UNVERIFIED_EMAILS));
56
public String getDisplayname() {
60
public String getOpenidIdentifier() {
61
return openidIdentifier;
64
public String getPreferredEmail() {
65
return preferredEmail;
68
public ArrayList<String> getVerifiedEmails() {
69
return verifiedEmails;
72
public ArrayList<String> getUnverifiedEmails() {
73
return unverifiedEmails;
77
public String toString() {
78
StringBuilder builder = new StringBuilder();
79
builder.append("AccountResponse [displayname=");
80
builder.append(displayname);
81
builder.append(", openidIdentifier=");
82
builder.append(openidIdentifier);
83
builder.append(", preferredEmail=");
84
builder.append(preferredEmail);
85
builder.append(", unverifiedEmails=");
86
builder.append(unverifiedEmails);
87
builder.append(", verifiedEmails=");
88
builder.append(verifiedEmails);
89
builder.append(", status=");
90
builder.append(status);
91
builder.append(", message=");
92
builder.append(message);
93
builder.append(", errors=");
94
builder.append(errors);
96
return builder.toString();