use of org.olat.login.oauth.model.OAuthUser in project openolat by klemens.
the class OAuthRegistrationController method formOK.
@Override
protected void formOK(UserRequest ureq) {
String lang = langEl.getSelectedKey();
String username = usernameEl.getValue();
OAuthUser oauthUser = registration.getOauthUser();
User newUser = userManager.createUser(null, null, null);
for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
FormItem propertyItem = this.flc.getFormComponent(userPropertyHandler.getName());
userPropertyHandler.updateUserFromFormItem(newUser, propertyItem);
}
// Init preferences
newUser.getPreferences().setLanguage(lang);
newUser.getPreferences().setInformSessionTimeout(true);
String id;
if (StringHelper.containsNonWhitespace(oauthUser.getId())) {
id = oauthUser.getId();
} else if (StringHelper.containsNonWhitespace(oauthUser.getEmail())) {
id = oauthUser.getEmail();
} else {
id = username;
}
authenticatedIdentity = securityManager.createAndPersistIdentityAndUser(username, null, newUser, registration.getAuthProvider(), id, null);
// Add user to system users group
SecurityGroup olatuserGroup = securityManager.findSecurityGroupByName(Constants.GROUP_OLATUSERS);
securityManager.addIdentityToSecurityGroup(authenticatedIdentity, olatuserGroup);
// open disclaimer
removeAsListenerAndDispose(disclaimerController);
disclaimerController = new DisclaimerController(ureq, getWindowControl());
listenTo(disclaimerController);
cmc = new CloseableModalController(getWindowControl(), translate("close"), disclaimerController.getInitialComponent(), true, translate("disclaimer.title"));
cmc.activate();
listenTo(cmc);
}
use of org.olat.login.oauth.model.OAuthUser in project openolat by klemens.
the class FacebookProvider method parseInfos.
public OAuthUser parseInfos(String body) {
OAuthUser user = new OAuthUser();
try {
JSONObject obj = new JSONObject(body);
user.setId(getValue(obj, "id"));
user.setFirstName(getValue(obj, "first_name"));
user.setLastName(getValue(obj, "last_name"));
user.setLang(getValue(obj, "locale"));
} catch (JSONException e) {
log.error("", e);
}
return user;
}
use of org.olat.login.oauth.model.OAuthUser in project openolat by klemens.
the class LinkedInProvider method parseInfos.
public OAuthUser parseInfos(String body) {
OAuthUser infos = new OAuthUser();
try {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(new InputSource(new StringReader(body)));
NodeList nodes = doc.getElementsByTagName("person");
for (int i = 0; i < nodes.getLength(); i++) {
Element element = (Element) nodes.item(i);
for (Node node = element.getFirstChild(); node != null; node = node.getNextSibling()) {
String localName = node.getNodeName();
if ("first-name".equals(localName)) {
infos.setFirstName(getCharacterDataFromElement(node));
} else if ("last-name".equals(localName)) {
infos.setLastName(getCharacterDataFromElement(node));
} else if ("email-address".equals(localName)) {
infos.setEmail(getCharacterDataFromElement(node));
} else if ("id".equals(localName)) {
infos.setId(getCharacterDataFromElement(node));
}
}
}
} catch (ParserConfigurationException | SAXException | IOException e) {
log.error("", e);
}
return infos;
}
use of org.olat.login.oauth.model.OAuthUser in project openolat by klemens.
the class OpenIdConnectFullConfigurableProvider method parseInfos.
public OAuthUser parseInfos(String body) {
OAuthUser user = new OAuthUser();
try {
JSONObject obj = new JSONObject(body);
user.setId(getValue(obj, "sub"));
user.setEmail(getValue(obj, "sub"));
} catch (JSONException e) {
log.error("", e);
}
return user;
}
use of org.olat.login.oauth.model.OAuthUser in project openolat by klemens.
the class OpenIdConnectProvider method parseInfos.
public OAuthUser parseInfos(String body) {
OAuthUser user = new OAuthUser();
try {
JSONObject obj = new JSONObject(body);
user.setId(getValue(obj, "sub"));
user.setEmail(getValue(obj, "sub"));
} catch (JSONException e) {
log.error("", e);
}
return user;
}
Aggregations