Search in sources :

Example 1 with OUserSymmetricKeyConfig

use of com.orientechnologies.orient.core.security.symmetrickey.OUserSymmetricKeyConfig in project orientdb by orientechnologies.

the class OSymmetricKeySecurity method authenticate.

public OUser authenticate(final String username, final String password) {
    if (delegate == null)
        throw new OSecurityAccessException("OSymmetricKeySecurity.authenticate() Delegate is null for username: " + username);
    if (database == null)
        throw new OSecurityAccessException("OSymmetricKeySecurity.authenticate() Database is null for username: " + username);
    final String dbName = database.getName();
    OUser user = delegate.getUser(username);
    if (user == null)
        throw new OSecurityAccessException(dbName, "OSymmetricKeySecurity.authenticate() Username or Key is invalid for username: " + username);
    if (user.getAccountStatus() != OSecurityUser.STATUSES.ACTIVE)
        throw new OSecurityAccessException(dbName, "OSymmetricKeySecurity.authenticate() User '" + username + "' is not active");
    try {
        OUserSymmetricKeyConfig userConfig = new OUserSymmetricKeyConfig(user);
        OSymmetricKey sk = OSymmetricKey.fromConfig(userConfig);
        String decryptedUsername = sk.decryptAsString(password);
        if (OSecurityManager.instance().checkPassword(username, decryptedUsername))
            return user;
    } catch (Exception ex) {
        throw new OSecurityAccessException(dbName, "OSymmetricKeySecurity.authenticate() Exception for database: " + dbName + ", username: " + username + " " + ex.getMessage());
    }
    throw new OSecurityAccessException(dbName, "OSymmetricKeySecurity.authenticate() Username or Key is invalid for database: " + dbName + ", username: " + username);
}
Also used : OSecurityAccessException(com.orientechnologies.orient.core.exception.OSecurityAccessException) OSymmetricKey(com.orientechnologies.orient.core.security.symmetrickey.OSymmetricKey) OUser(com.orientechnologies.orient.core.metadata.security.OUser) OSecurityAccessException(com.orientechnologies.orient.core.exception.OSecurityAccessException) OUserSymmetricKeyConfig(com.orientechnologies.orient.core.security.symmetrickey.OUserSymmetricKeyConfig)

Aggregations

OSecurityAccessException (com.orientechnologies.orient.core.exception.OSecurityAccessException)1 OUser (com.orientechnologies.orient.core.metadata.security.OUser)1 OSymmetricKey (com.orientechnologies.orient.core.security.symmetrickey.OSymmetricKey)1 OUserSymmetricKeyConfig (com.orientechnologies.orient.core.security.symmetrickey.OUserSymmetricKeyConfig)1