use of org.olat.basesecurity.Authentication in project openolat by klemens.
the class WebDAVAuthManager method updateDigestPassword.
private void updateDigestPassword(Identity doer, Identity identity, String authUsername, String password, String provider, List<Authentication> authentications) {
String digestToken = authUsername + ":" + WebDAVManagerImpl.BASIC_AUTH_REALM + ":" + password;
Authentication authHa1 = getAndRemoveAuthentication(provider, authentications);
if (authHa1 == null) {
// create new authentication for provider OLAT
try {
dbInstance.commit();
Identity reloadedIdentity = securityManager.loadIdentityByKey(identity.getKey());
securityManager.createAndPersistAuthentication(reloadedIdentity, provider, authUsername, digestToken, Encoder.Algorithm.md5_noSalt);
log.audit(doer.getName() + " created new WebDAV (HA1) authentication for identity: " + identity.getKey() + " (" + authUsername + ")");
} catch (DBRuntimeException e) {
log.error("Cannot create digest password with provider " + provider + " for identity:" + identity, e);
dbInstance.commit();
}
} else {
String md5DigestToken = Encoder.encrypt(digestToken, null, Encoder.Algorithm.md5_noSalt);
if (!md5DigestToken.equals(authHa1.getCredential()) || !authHa1.getAuthusername().equals(authUsername)) {
try {
authHa1.setCredential(md5DigestToken);
authHa1.setAuthusername(authUsername);
securityManager.updateAuthentication(authHa1);
log.audit(doer.getName() + " set new WebDAV (HA1) password for identity: " + identity.getKey() + " (" + authUsername + ")");
} catch (DBRuntimeException e) {
log.error("Cannot update digest password with provider " + provider + " for identity:" + identity, e);
dbInstance.commit();
}
}
}
}
use of org.olat.basesecurity.Authentication in project openolat by klemens.
the class WebDAVAuthManager method authenticate.
@Override
public Identity authenticate(Identity identity, String login, String password) {
List<String> providers = new ArrayList<>(3);
providers.add(PROVIDER_WEBDAV);
if (userModule.isEmailUnique()) {
providers.add(PROVIDER_HA1_EMAIL);
providers.add(PROVIDER_HA1_INSTITUTIONAL_EMAIL);
}
List<Authentication> authentications = null;
if (identity != null) {
authentications = securityManager.findAuthentications(identity, providers);
} else {
authentications = securityManager.findAuthenticationByAuthusername(login, providers);
}
if (authentications == null || authentications.isEmpty()) {
// fallback to standard OLAT authentication
return olatAuthenticationSpi.authenticate(identity, login, password);
}
Identity authenticatedIdentity = authentications.get(0).getIdentity();
boolean visible = securityManager.isIdentityVisible(authenticatedIdentity);
if (!visible) {
return null;
}
for (Authentication authentication : authentications) {
if (securityManager.checkCredentials(authentication, password)) {
Algorithm algorithm = Algorithm.find(authentication.getAlgorithm());
if (Algorithm.md5.equals(algorithm)) {
authentication = securityManager.updateCredentials(authentication, password, loginModule.getDefaultHashAlgorithm());
}
return authentication.getIdentity();
}
}
return null;
}
use of org.olat.basesecurity.Authentication in project openolat by klemens.
the class WebDAVAuthManager method updateWebDAVPassword.
private void updateWebDAVPassword(Identity doer, Identity identity, String authUsername, String password, String provider, List<Authentication> authentications) {
Authentication authentication = getAndRemoveAuthentication(provider, authentications);
if (authentication == null) {
// create new authentication for provider OLAT
try {
dbInstance.commit();
Identity reloadedIdentity = securityManager.loadIdentityByKey(identity.getKey());
securityManager.createAndPersistAuthentication(reloadedIdentity, provider, authUsername, password, loginModule.getDefaultHashAlgorithm());
log.audit(doer.getName() + " created new WebDAV authentication for identity: " + identity.getKey() + " (" + authUsername + ")");
} catch (DBRuntimeException e) {
log.error("Cannot create webdav password with provider " + provider + " for identity:" + identity, e);
dbInstance.commit();
}
} else {
try {
dbInstance.commit();
securityManager.updateCredentials(authentication, password, loginModule.getDefaultHashAlgorithm());
log.audit(doer.getName() + " set new WebDAV password for identity: " + identity.getKey() + " (" + authUsername + ")");
} catch (Exception e) {
log.error("Cannot update webdav password with provider " + provider + " for identity:" + identity, e);
dbInstance.commit();
}
}
}
use of org.olat.basesecurity.Authentication in project openolat by klemens.
the class SendTokenToUserForm method sendToken.
private void sendToken(UserRequest ureq, String text) {
// mailer configuration
// We allow creation of password token when user has no password so far or when he as an OpenOLAT Password.
// For other cases such as Shibboleth, LDAP, oAuth etc. we don't allow creation of token as this is most
// likely not a desired action.
List<Authentication> authentications = BaseSecurityManager.getInstance().getAuthentications(user);
boolean isOOpwdAllowed = (authentications.size() == 0);
for (Authentication authentication : authentications) {
if (authentication.getProvider().equals(BaseSecurityModule.getDefaultAuthProviderIdentifier())) {
isOOpwdAllowed = true;
}
}
if (!isOOpwdAllowed) {
showWarning("sendtoken.wrong.auth");
return;
}
Preferences prefs = user.getUser().getPreferences();
Locale locale = i18nManager.getLocaleOrDefault(prefs.getLanguage());
String emailAdress = user.getUser().getProperty(UserConstants.EMAIL, locale);
String ip = ureq.getHttpReq().getRemoteAddr();
TemporaryKey tk = registrationManager.createAndDeleteOldTemporaryKey(user.getKey(), emailAdress, ip, RegistrationManager.PW_CHANGE);
if (text.indexOf(dummyKey) < 0) {
showWarning("changeuserpwd.failed");
logWarn("Can not replace temporary registration token in change pwd mail token dialog, user probably changed temporary token in mai template", null);
return;
}
String body = text.replace(dummyKey, tk.getRegistrationKey());
Translator userTrans = Util.createPackageTranslator(RegistrationManager.class, locale);
MailBundle bundle = new MailBundle();
bundle.setToId(user);
bundle.setContent(userTrans.translate("pwchange.subject"), body);
MailerResult result = mailManager.sendExternMessage(bundle, null, false);
if (result.getReturnCode() == 0) {
showInfo("email.sent");
} else {
showInfo("email.notsent");
}
}
use of org.olat.basesecurity.Authentication in project openolat by klemens.
the class UserAdminController method isPasswordChangesAllowed.
private boolean isPasswordChangesAllowed(Identity identity) {
Boolean canChangePwd = BaseSecurityModule.USERMANAGER_CAN_MODIFY_PWD;
if (canChangePwd.booleanValue() || isOlatAdmin) {
// of a user that has no password yet
if (ldapLoginModule.isLDAPEnabled() && ldapLoginManager.isIdentityInLDAPSecGroup(identity)) {
// it's an ldap-user
return ldapLoginModule.isPropagatePasswordChangedOnLdapServer();
}
Boolean canCreatePwd = BaseSecurityModule.USERMANAGER_CAN_CREATE_PWD;
Authentication olatAuth = securityManager.findAuthentication(identity, BaseSecurityModule.getDefaultAuthProviderIdentifier());
if (olatAuth != null || canCreatePwd.booleanValue() || isOlatAdmin) {
return true;
}
}
return false;
}
Aggregations