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);
}
Aggregations