Search in sources :

Example 16 with OAuthUser

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);
}
Also used : OAuthUser(org.olat.login.oauth.model.OAuthUser) User(org.olat.core.id.User) DisclaimerController(org.olat.registration.DisclaimerController) OAuthUser(org.olat.login.oauth.model.OAuthUser) FormItem(org.olat.core.gui.components.form.flexible.FormItem) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) SecurityGroup(org.olat.basesecurity.SecurityGroup) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 17 with OAuthUser

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;
}
Also used : JSONObject(org.json.JSONObject) OAuthUser(org.olat.login.oauth.model.OAuthUser) JSONException(org.json.JSONException)

Example 18 with OAuthUser

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;
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) OAuthUser(org.olat.login.oauth.model.OAuthUser) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringReader(java.io.StringReader) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 19 with OAuthUser

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;
}
Also used : JSONObject(org.json.JSONObject) OAuthUser(org.olat.login.oauth.model.OAuthUser) JSONException(org.json.JSONException)

Example 20 with OAuthUser

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;
}
Also used : JSONObject(org.json.JSONObject) OAuthUser(org.olat.login.oauth.model.OAuthUser) JSONException(org.json.JSONException)

Aggregations

OAuthUser (org.olat.login.oauth.model.OAuthUser)36 JSONException (org.json.JSONException)14 JSONObject (org.json.JSONObject)14 Test (org.junit.Test)14 URL (java.net.URL)6 IOException (java.io.IOException)4 FormItem (org.olat.core.gui.components.form.flexible.FormItem)4 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)4 StringReader (java.io.StringReader)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ServletException (javax.servlet.ServletException)2 HttpSession (javax.servlet.http.HttpSession)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 SecurityGroup (org.olat.basesecurity.SecurityGroup)2 UserRequest (org.olat.core.gui.UserRequest)2 UserRequestImpl (org.olat.core.gui.UserRequestImpl)2 TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)2 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)2