Search in sources :

Example 31 with Authentication

use of org.olat.basesecurity.Authentication in project openolat by klemens.

the class RestSecurityBeanImpl method isTokenRegistrated.

@Override
public boolean isTokenRegistrated(String token, HttpSession session) {
    if (!StringHelper.containsNonWhitespace(token))
        return false;
    boolean registrated = tokenToIdentity.containsKey(token);
    if (!registrated) {
        List<Authentication> auths = securityManager.findAuthenticationByToken(REST_AUTH_PROVIDER, token);
        if (auths.size() == 1) {
            Authentication auth = auths.get(0);
            tokenToIdentity.put(token, auth.getIdentity().getKey());
            bindTokenToSession(token, session);
            registrated = true;
        }
    }
    return registrated;
}
Also used : Authentication(org.olat.basesecurity.Authentication)

Example 32 with Authentication

use of org.olat.basesecurity.Authentication in project openolat by klemens.

the class WebDAVPasswordController method toogleChangePassword.

private void toogleChangePassword(UserRequest ureq) {
    boolean visible = newButton.isVisible();
    newButton.setVisible(!visible);
    passwordStaticEl.setVisible(!visible);
    saveButton.setVisible(visible);
    cancelButton.setVisible(visible);
    passwordEl.setVisible(visible);
    confirmPasswordEl.setVisible(visible);
    Authentication auth = securityManager.findAuthentication(ureq.getIdentity(), WebDAVAuthManager.PROVIDER_WEBDAV);
    String passwordPlaceholderKey = auth == null ? "pwdav.password.not_set" : "pwdav.password.set";
    String passwordPlaceholder = getTranslator().translate(passwordPlaceholderKey);
    passwordStaticEl.setValue(passwordPlaceholder);
    String buttonPlaceholderKey = auth == null ? "pwdav.password.new" : "pwdav.password.change";
    newButton.setI18nKey(buttonPlaceholderKey);
    flc.setDirty(true);
}
Also used : Authentication(org.olat.basesecurity.Authentication)

Example 33 with Authentication

use of org.olat.basesecurity.Authentication in project openolat by klemens.

the class WebDAVPasswordController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    setFormTitle("pwdav.title");
    if (formLayout instanceof FormLayoutContainer) {
        FormLayoutContainer layoutContainer = (FormLayoutContainer) formLayout;
        layoutContainer.contextPut("webdavhttp", FolderManager.getWebDAVHttp());
        layoutContainer.contextPut("webdavhttps", FolderManager.getWebDAVHttps());
        accessDataFlc = FormLayoutContainer.createDefaultFormLayout("flc_access_data", getTranslator());
        layoutContainer.add(accessDataFlc);
        StringBuilder sb = new StringBuilder();
        sb.append(getIdentity().getName());
        if (StringHelper.containsNonWhitespace(getIdentity().getUser().getEmail())) {
            sb.append(", ").append(getIdentity().getUser().getEmail());
        }
        if (StringHelper.containsNonWhitespace(getIdentity().getUser().getInstitutionalEmail())) {
            sb.append(", ").append(getIdentity().getUser().getInstitutionalEmail());
        }
        uifactory.addStaticTextElement("pwdav.username", "pwdav.username", sb.toString(), accessDataFlc);
        boolean hasOlatToken = false;
        boolean hasWebDAVToken = false;
        List<Authentication> authentications = securityManager.getAuthentications(ureq.getIdentity());
        for (Authentication auth : authentications) {
            if (BaseSecurityModule.getDefaultAuthProviderIdentifier().equals(auth.getProvider())) {
                hasOlatToken = true;
            } else if (WebDAVAuthManager.PROVIDER_WEBDAV.equals(auth.getProvider())) {
                hasWebDAVToken = true;
            }
        }
        if (hasOlatToken) {
            String passwordPlaceholder = getTranslator().translate("pwdav.password.placeholder");
            uifactory.addStaticTextElement("pwdav.password", "pwdav.password", passwordPlaceholder, accessDataFlc);
        } else {
            String passwordPlaceholderKey = hasWebDAVToken ? "pwdav.password.set" : "pwdav.password.not_set";
            String passwordPlaceholder = getTranslator().translate(passwordPlaceholderKey);
            passwordStaticEl = uifactory.addStaticTextElement("pwdav.password", "pwdav.password", passwordPlaceholder, accessDataFlc);
            passwordEl = uifactory.addPasswordElement("pwdav.password.2", "pwdav.password", 64, "", accessDataFlc);
            passwordEl.setVisible(false);
            passwordEl.setMandatory(true);
            confirmPasswordEl = uifactory.addPasswordElement("pwdav.password.confirm", "pwdav.password.confirm", 64, "", accessDataFlc);
            confirmPasswordEl.setVisible(false);
            confirmPasswordEl.setMandatory(true);
            buttonGroupLayout = FormLayoutContainer.createButtonLayout("buttonGroupLayout", getTranslator());
            buttonGroupLayout.setRootForm(mainForm);
            accessDataFlc.add(buttonGroupLayout);
            if (hasWebDAVToken) {
                newButton = uifactory.addFormLink("pwdav.password.change", buttonGroupLayout, Link.BUTTON);
            } else {
                newButton = uifactory.addFormLink("pwdav.password.new", buttonGroupLayout, Link.BUTTON);
            }
            saveButton = uifactory.addFormSubmitButton("save", buttonGroupLayout);
            saveButton.setVisible(false);
            cancelButton = uifactory.addFormCancelButton("cancel", buttonGroupLayout, ureq, getWindowControl());
            cancelButton.setVisible(false);
        }
        layoutContainer.put("access_data", accessDataFlc.getComponent());
    }
}
Also used : Authentication(org.olat.basesecurity.Authentication) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)

Example 34 with Authentication

use of org.olat.basesecurity.Authentication in project openolat by klemens.

the class UserModule method isPwdChangeAllowed.

/**
 * checks whether the given identity is allowed to change it's own password.
 * default settings (olat.properties) :
 * <ul>
 *  <li>LDAP-user are not allowed to change their pw</li>
 *  <li>other users are allowed to change their pw</li>
 * </ul>
 *
 * @param id
 * @return
 */
public boolean isPwdChangeAllowed(Identity id) {
    if (id == null) {
        return isAnyPasswordChangeAllowed();
    }
    // if this is set to false, nobody can change their password
    if (!pwdchangeallowed) {
        return false;
    }
    // call to CoreSpringFactory to break dependencies cycles
    // (the method will only be called with a running application)
    // check if the user has an OLAT provider token, otherwise a password change makes no sense
    Authentication auth = CoreSpringFactory.getImpl(BaseSecurity.class).findAuthentication(id, BaseSecurityModule.getDefaultAuthProviderIdentifier());
    if (auth == null && !pwdChangeWithoutAuthenticationAllowed) {
        return false;
    }
    LDAPLoginManager ldapLoginManager = CoreSpringFactory.getImpl(LDAPLoginManager.class);
    if (ldapLoginManager.isIdentityInLDAPSecGroup(id)) {
        // it's an ldap-user
        return CoreSpringFactory.getImpl(LDAPLoginModule.class).isPropagatePasswordChangedOnLdapServer();
    }
    return pwdchangeallowed;
}
Also used : LDAPLoginManager(org.olat.ldap.LDAPLoginManager) Authentication(org.olat.basesecurity.Authentication) LDAPLoginModule(org.olat.ldap.LDAPLoginModule) BaseSecurity(org.olat.basesecurity.BaseSecurity)

Example 35 with Authentication

use of org.olat.basesecurity.Authentication in project openolat by klemens.

the class ChangePasswordController method event.

@Override
public void event(UserRequest ureq, Controller source, Event event) {
    if (source == chPwdForm) {
        if (event == Event.DONE_EVENT) {
            String oldPwd = chPwdForm.getOldPasswordValue();
            Identity provenIdent = null;
            Authentication ldapAuthentication = securityManager.findAuthentication(ureq.getIdentity(), LDAPAuthenticationController.PROVIDER_LDAP);
            if (ldapAuthentication != null) {
                LDAPError ldapError = new LDAPError();
                // fallback to OLAT if enabled happen automatically in LDAPAuthenticationController
                String userName = ldapAuthentication.getAuthusername();
                provenIdent = ldapLoginManager.authenticate(userName, oldPwd, ldapError);
            } else if (securityManager.findAuthentication(ureq.getIdentity(), BaseSecurityModule.getDefaultAuthProviderIdentifier()) != null) {
                provenIdent = olatAuthenticationSpi.authenticate(ureq.getIdentity(), ureq.getIdentity().getName(), oldPwd);
            }
            if (provenIdent == null) {
                showError("error.password.noauth");
            } else {
                String newPwd = chPwdForm.getNewPasswordValue();
                if (olatAuthenticationSpi.changePassword(ureq.getIdentity(), provenIdent, newPwd)) {
                    fireEvent(ureq, Event.DONE_EVENT);
                    getLogger().audit("Changed password for identity." + provenIdent.getName());
                    showInfo("password.successful");
                } else {
                    showError("password.failed");
                }
            }
        } else if (event == Event.CANCELLED_EVENT) {
            removeAsListenerAndDispose(chPwdForm);
            chPwdForm = new ChangePasswordForm(ureq, getWindowControl());
            listenTo(chPwdForm);
            myContent.put("chpwdform", chPwdForm.getInitialComponent());
        }
    }
}
Also used : Authentication(org.olat.basesecurity.Authentication) LDAPError(org.olat.ldap.LDAPError) Identity(org.olat.core.id.Identity)

Aggregations

Authentication (org.olat.basesecurity.Authentication)82 Identity (org.olat.core.id.Identity)46 BaseSecurity (org.olat.basesecurity.BaseSecurity)16 Test (org.junit.Test)10 RestSecurityHelper.getIdentity (org.olat.restapi.security.RestSecurityHelper.getIdentity)8 AuthenticationVO (org.olat.restapi.support.vo.AuthenticationVO)8 URI (java.net.URI)6 ArrayList (java.util.ArrayList)6 Produces (javax.ws.rs.Produces)6 HttpResponse (org.apache.http.HttpResponse)6 SecurityGroup (org.olat.basesecurity.SecurityGroup)6 Locale (java.util.Locale)4 GET (javax.ws.rs.GET)4 HttpPut (org.apache.http.client.methods.HttpPut)4 AssertException (org.olat.core.logging.AssertException)4 DBRuntimeException (org.olat.core.logging.DBRuntimeException)4 Algorithm (org.olat.core.util.Encoder.Algorithm)4 TemporaryKey (org.olat.registration.TemporaryKey)4 ErrorVO (org.olat.restapi.support.vo.ErrorVO)4 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)4