use of org.olat.core.util.Encoder.Algorithm 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.core.util.Encoder.Algorithm in project openolat by klemens.
the class BaseSecurityManager method checkCredentials.
@Override
public boolean checkCredentials(Authentication authentication, String password) {
Algorithm algorithm = Algorithm.find(authentication.getAlgorithm());
String hash = Encoder.encrypt(password, authentication.getSalt(), algorithm);
return authentication.getCredential() != null && authentication.getCredential().equals(hash);
}
use of org.olat.core.util.Encoder.Algorithm in project OpenOLAT by OpenOLAT.
the class ForumManager method authenticatePseudonym.
public boolean authenticatePseudonym(Pseudonym pseudonym, String password) {
if (pseudonym.getAlgorithm() != null) {
// check if update is needed
Algorithm algorithm = Algorithm.valueOf(pseudonym.getAlgorithm());
String credentials = Encoder.encrypt(password, pseudonym.getSalt(), algorithm);
return credentials.equals(pseudonym.getCredential());
}
return false;
}
use of org.olat.core.util.Encoder.Algorithm in project OpenOLAT by OpenOLAT.
the class ForumManager method createProtectedPseudonym.
public Pseudonym createProtectedPseudonym(String pseudonym, String password) {
PseudonymImpl pseudo = new PseudonymImpl();
pseudo.setCreationDate(new Date());
pseudo.setPseudonym(pseudonym);
Algorithm algorithm = loginModule.getDefaultHashAlgorithm();
String salt = algorithm.isSalted() ? Encoder.getSalt() : null;
String newCredentials = Encoder.encrypt(password, salt, algorithm);
pseudo.setSalt(salt);
pseudo.setCredential(newCredentials);
pseudo.setAlgorithm(algorithm.name());
dbInstance.getCurrentEntityManager().persist(pseudo);
return pseudo;
}
use of org.olat.core.util.Encoder.Algorithm in project openolat by klemens.
the class ForumManager method authenticatePseudonym.
public boolean authenticatePseudonym(Pseudonym pseudonym, String password) {
if (pseudonym.getAlgorithm() != null) {
// check if update is needed
Algorithm algorithm = Algorithm.valueOf(pseudonym.getAlgorithm());
String credentials = Encoder.encrypt(password, pseudonym.getSalt(), algorithm);
return credentials.equals(pseudonym.getCredential());
}
return false;
}
Aggregations