use of org.pac4j.oauth.profile.generic.GenericOAuth20ProfileDefinition in project pac4j by pac4j.
the class GenericOAuth20ClientTest method setProfileAttrs.
@Test
public void setProfileAttrs() throws Exception {
GenericOAuth20Client client = new GenericOAuth20Client();
Map map = new HashMap();
map.put(AGE, "Integer|age");
// map.put("creation_time", "Date:|creation_time");
map.put(IS_ADMIN, "Boolean|is_admin");
map.put(BG_COLOR, "Color|bg_color");
map.put(GENDER, "Gender|gender");
map.put(BIRTHDAY, "Locale|birthday");
map.put(ID, "Long|id");
map.put(BLOG, "URI|blog");
client.setProfileAttrs(map);
client.setCallbackUrl(CALLBACK_URL);
client.init();
Field configurationField = OAuth20Client.class.getDeclaredField("configuration");
configurationField.setAccessible(true);
OAuth20Configuration configuration = (OAuth20Configuration) configurationField.get(client);
GenericOAuth20ProfileDefinition profileDefinition = (GenericOAuth20ProfileDefinition) configuration.getProfileDefinition();
Method getConverters = ProfileDefinition.class.getDeclaredMethod("getConverters");
getConverters.setAccessible(true);
Map<String, AttributeConverter<?>> converters = (Map<String, AttributeConverter<?>>) getConverters.invoke(profileDefinition);
assertTrue(converters.get(AGE) instanceof IntegerConverter);
assertTrue(converters.get(IS_ADMIN) instanceof BooleanConverter);
assertTrue(converters.get(BG_COLOR) instanceof ColorConverter);
assertTrue(converters.get(GENDER) instanceof GenderConverter);
assertTrue(converters.get(BIRTHDAY) instanceof LocaleConverter);
assertTrue(converters.get(ID) instanceof LongConverter);
assertTrue(converters.get(BLOG) instanceof UrlConverter);
}
use of org.pac4j.oauth.profile.generic.GenericOAuth20ProfileDefinition in project pac4j by pac4j.
the class GenericOAuth20Client method clientInit.
@Override
protected void clientInit() {
LOG.info("InternalInit");
GenericApi20 genApi = new GenericApi20(authUrl, tokenUrl);
configuration.setApi(genApi);
configuration.setCustomParams(customParams);
GenericOAuth20ProfileDefinition profileDefinition = new GenericOAuth20ProfileDefinition();
profileDefinition.setFirstNodePath(profilePath);
profileDefinition.setProfileVerb(profileVerb);
profileDefinition.setProfileUrl(profileUrl);
if (profileAttrs != null) {
for (Map.Entry<String, String> entry : profileAttrs.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
String[] tokens = value.split("\\|");
if (tokens.length == 2) {
profileDefinition.profileAttribute(key, tokens[1], getConverter(tokens[0]));
} else if (tokens.length == 1) {
profileDefinition.profileAttribute(key, value, null);
} else {
LOG.warning("Ignored incorrect attribute value expressions:" + value);
}
}
}
configuration.setProfileDefinition(profileDefinition);
super.clientInit();
}
Aggregations