Removed address fields

pull/516/head
Amanda Anganes 2013-09-25 11:19:04 -04:00
parent 78fa5f9b1d
commit 952acccbf3
2 changed files with 16 additions and 14 deletions

View File

@ -45,12 +45,7 @@ public class ScopeClaimTranslationService {
scopesToClaims.put("phone", "phone_number");
scopesToClaims.put("phone", "phone_number_verified");
scopesToClaims.put("address", "address.formatted");
scopesToClaims.put("address", "address.street_address");
scopesToClaims.put("address", "address.locality");
scopesToClaims.put("address", "address.region");
scopesToClaims.put("address", "address.postal_code");
scopesToClaims.put("address", "address.country");
scopesToClaims.put("address", "address");
claimsToFields.put("sub", "sub");
@ -75,13 +70,7 @@ public class ScopeClaimTranslationService {
claimsToFields.put("phone_number", "phoneNumber");
claimsToFields.put("phone_number_verified", "phoneNumberVerified");
//TODO: how to handle compound fields?
claimsToFields.put("address.formatted", "");
claimsToFields.put("address.street_address", "");
claimsToFields.put("address.locality", "");
claimsToFields.put("address.region", "");
claimsToFields.put("address.postal_code", "");
claimsToFields.put("address.country", "");
claimsToFields.put("address", "address");
}

View File

@ -1,14 +1,17 @@
package org.mitre.openid.connect.view;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Map.Entry;
import java.util.Set;
import org.mitre.openid.connect.model.DefaultUserInfo;
import org.mitre.openid.connect.model.UserInfo;
import org.mitre.openid.connect.service.ScopeClaimTranslationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.ReflectionUtils;
import com.google.common.base.CaseFormat;
import com.google.common.collect.Sets;
@ -19,7 +22,7 @@ public class UserInfoSerializer {
private static Logger logger = LoggerFactory.getLogger(UserInfoSerializer.class);
private ScopeClaimTranslationService translator = new ScopeClaimTranslationService();
private static ScopeClaimTranslationService translator = new ScopeClaimTranslationService();
/**
* Build a JSON response according to the request object received.
@ -67,6 +70,8 @@ public class UserInfoSerializer {
//TODO: is there a way to use bean processors to do bean.getfield(name)?
//Method reflection is OK, but need a service to translate scopes into claim names => field names
// TODO: this method is likely to be fragile if the data model changes at all
//For each claim found, add it if not already present
@ -75,6 +80,14 @@ public class UserInfoSerializer {
if (!obj.has(claimName)) {
String value = "";
String fieldName = translator.getFieldNameForClaim(claimName);
Field field = ReflectionUtils.findField(DefaultUserInfo.class, fieldName);
Object val = ReflectionUtils.getField(field, userinfo);
//TODO:how to convert val to a String? Most claims can be converted directly; address is compound
//Process claim names to go from "claim_name" to "ClaimName"
String camelClaimName = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, claimName);
//Now we have "getClaimName"