Search in sources :

Example 26 with OAuthUser

use of org.olat.login.oauth.model.OAuthUser in project OpenOLAT by OpenOLAT.

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)

Example 27 with OAuthUser

use of org.olat.login.oauth.model.OAuthUser in project OpenOLAT by OpenOLAT.

the class TequilaProvider method parseResponse.

public OAuthUser parseResponse(String body) {
    OAuthUser user = new OAuthUser();
    try {
        JSONObject obj = new JSONObject(body);
        user.setId(getValue(obj, "Sciper"));
        user.setFirstName(getValue(obj, "Firstname"));
        user.setLastName(getValue(obj, "Name"));
        user.setEmail(getValue(obj, "Email"));
        user.setInstitutionalUserIdentifier(getValue(obj, "Sciper"));
    } 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 28 with OAuthUser

use of org.olat.login.oauth.model.OAuthUser in project OpenOLAT by OpenOLAT.

the class OAuthRegistrationController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    OAuthUser oauthUser = registration.getOauthUser();
    usernameEl = uifactory.addTextElement("username", "user.login", 128, "", formLayout);
    usernameEl.setMandatory(true);
    if (StringHelper.containsNonWhitespace(oauthUser.getId())) {
        usernameEl.setValue(oauthUser.getId());
    }
    // Add all available user fields to this form
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
        if (userPropertyHandler != null) {
            FormItem fi = userPropertyHandler.addFormItem(getLocale(), null, USERPROPERTIES_FORM_IDENTIFIER, false, formLayout);
            propFormItems.put(userPropertyHandler.getName(), fi);
            if (fi instanceof TextElement) {
                String value = oauthUser.getProperty(userPropertyHandler.getName());
                if (StringHelper.containsNonWhitespace(value)) {
                    ((TextElement) fi).setValue(value);
                }
            }
        }
    }
    uifactory.addSpacerElement("lang", formLayout, true);
    // second the user language
    Map<String, String> languages = I18nManager.getInstance().getEnabledLanguagesTranslated();
    String[] langKeys = StringHelper.getMapKeysAsStringArray(languages);
    String[] langValues = StringHelper.getMapValuesAsStringArray(languages);
    langEl = uifactory.addDropdownSingleselect("user.language", formLayout, langKeys, langValues, null);
    FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("button_layout", getTranslator());
    formLayout.add(buttonLayout);
    uifactory.addFormSubmitButton("save", buttonLayout);
}
Also used : TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) OAuthUser(org.olat.login.oauth.model.OAuthUser) FormItem(org.olat.core.gui.components.form.flexible.FormItem) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 29 with OAuthUser

use of org.olat.login.oauth.model.OAuthUser in project OpenOLAT by OpenOLAT.

the class ADFSProvider method getUser.

@Override
public OAuthUser getUser(OAuthService service, Token accessToken) {
    OAuthUser user = new OAuthUser();
    try {
        JSONWebToken jwt = JSONWebToken.parse(accessToken);
        JSONObject obj = jwt.getJsonPayload();
        user.setId(getValue(obj, "employeeNumber"));
        user.setFirstName(getValue(obj, "displayNamePrintable"));
        user.setLastName(getValue(obj, "Sn"));
        user.setEmail(getValue(obj, "mail"));
        user.setInstitutionalUserIdentifier(getValue(obj, "SAMAccountName"));
        if (!StringHelper.containsNonWhitespace(user.getId())) {
            user.setId(user.getInstitutionalUserIdentifier());
        }
    } 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 30 with OAuthUser

use of org.olat.login.oauth.model.OAuthUser in project openolat by klemens.

the class OAuthDispatcherTest method parseTequilaUserInfos.

@Test
public void parseTequilaUserInfos() {
    String data = "{ \"Sciper\": \"M02491\", \"authscheme\": \"OAuth2\", \"Firstname\": \"Service\", \"Username\": \"Erecruiting_oAuth2\", \"Name\": \"Erecruiting_oAuth2\", \"scope\": \"Tequila.profile\" }";
    OAuthUser infos = new TequilaProvider().parseResponse(data);
    Assert.assertNotNull(infos);
    Assert.assertEquals("Service", infos.getFirstName());
    Assert.assertEquals("Erecruiting_oAuth2", infos.getLastName());
    Assert.assertEquals("M02491", infos.getId());
}
Also used : TequilaProvider(org.olat.login.oauth.spi.TequilaProvider) OAuthUser(org.olat.login.oauth.model.OAuthUser) Test(org.junit.Test)

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