Search in sources :

Example 6 with Algorithm

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;
}
Also used : Authentication(org.olat.basesecurity.Authentication) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) Algorithm(org.olat.core.util.Encoder.Algorithm)

Example 7 with Algorithm

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);
}
Also used : Algorithm(org.olat.core.util.Encoder.Algorithm)

Example 8 with Algorithm

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;
}
Also used : Algorithm(org.olat.core.util.Encoder.Algorithm)

Example 9 with Algorithm

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;
}
Also used : PseudonymImpl(org.olat.modules.fo.model.PseudonymImpl) Algorithm(org.olat.core.util.Encoder.Algorithm) Date(java.util.Date)

Example 10 with Algorithm

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;
}
Also used : Algorithm(org.olat.core.util.Encoder.Algorithm)

Aggregations

Algorithm (org.olat.core.util.Encoder.Algorithm)10 Authentication (org.olat.basesecurity.Authentication)4 Identity (org.olat.core.id.Identity)4 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 OLATAuthenticationController (org.olat.login.OLATAuthenticationController)2 PseudonymImpl (org.olat.modules.fo.model.PseudonymImpl)2