001/* 002 * (C) Copyright 2014 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Arnaud Kervern 018 */ 019package org.nuxeo.ecm.platform.oauth2.openid.auth.googleplus; 020 021import java.util.Date; 022import java.util.List; 023 024import org.nuxeo.ecm.platform.oauth2.openid.auth.OpenIDUserInfo; 025 026import com.google.api.client.json.GenericJson; 027import com.google.api.client.util.ArrayMap; 028import com.google.api.client.util.Key; 029 030/** 031 * GooglePlus user info 032 * 033 * @author <a href="mailto:ak@nuxeo.com">Arnaud Kervern</a> 034 * @since 5.9.5 035 */ 036public class GooglePlusUserInfo extends GenericJson implements OpenIDUserInfo { 037 @Key("id") 038 protected String id; 039 040 @Key("displayName") 041 protected String name; 042 043 @Key("verified") 044 protected boolean verified; 045 046 @Key("gender") 047 protected String gender; 048 049 @Override 050 public String getSubject() { 051 return id; 052 } 053 054 @Override 055 public String getName() { 056 return name; 057 } 058 059 @Override 060 public String getGivenName() { 061 ArrayMap<String, Object> nameObject = getNameObject(); 062 return nameObject == null ? "" : String.valueOf(nameObject.get("givenName")); 063 } 064 065 @Override 066 public String getFamilyName() { 067 ArrayMap<String, Object> nameObject = getNameObject(); 068 return nameObject == null ? "" : String.valueOf(nameObject.get("familyName")); 069 } 070 071 @Override 072 public String getMiddleName() { 073 return null; 074 } 075 076 @Override 077 public String getNickname() { 078 return null; 079 } 080 081 @Override 082 public String getPreferredUsername() { 083 return getGivenName(); 084 } 085 086 @Override 087 public String getProfile() { 088 return null; 089 } 090 091 @Override 092 public String getPicture() { 093 return null; 094 } 095 096 @Override 097 public String getWebsite() { 098 return null; 099 } 100 101 @Override 102 public String getEmail() { 103 return String.valueOf(getEmailsObject().get(0).get("value")); 104 } 105 106 @Override 107 public boolean isEmailVerified() { 108 return verified; 109 } 110 111 @Override 112 public String getGender() { 113 return gender; 114 } 115 116 @Override 117 public Date getBirthdate() { 118 return null; 119 } 120 121 @Override 122 public String getZoneInfo() { 123 return null; 124 } 125 126 @Override 127 public String getLocale() { 128 return null; 129 } 130 131 @Override 132 public String getPhoneNumber() { 133 return null; 134 } 135 136 @Override 137 public String getAddress() { 138 return null; 139 } 140 141 @Override 142 public Date getUpdatedTime() { 143 return null; 144 } 145 146 protected ArrayMap<String, Object> getNameObject() { 147 return (ArrayMap<String, Object>) get("name"); 148 } 149 150 protected List<ArrayMap<String, Object>> getEmailsObject() { 151 return (List<ArrayMap<String, Object>>) get("emails"); 152 } 153}