use of com.orientechnologies.orient.core.metadata.security.OUser in project wicket-orientdb by OrienteerBAP.
the class TestModels method testOQueryProvider.
@Test
public void testOQueryProvider() {
OQueryDataProvider<OUser> provider = new OQueryDataProvider<OUser>("select from OUser where name <> :other", OUser.class);
provider.setSort("name", SortOrder.ASCENDING);
provider.setParameter("other", Model.of("blalba"));
Iterator<OUser> it = provider.iterator(0, -1);
List<ODocument> allUsers = wicket.getTester().getMetadata().getSecurity().getAllUsers();
assertTrue(provider.size() == allUsers.size());
while (it.hasNext()) {
OUser oUser = it.next();
assertTrue(allUsers.contains(provider.model(oUser).getObject().getDocument()));
}
provider.detach();
assertTrue(provider.size() == allUsers.size());
}
use of com.orientechnologies.orient.core.metadata.security.OUser in project orientdb by orientechnologies.
the class OTokenHandlerImplTest method testBinartTokenCreationValidation.
@Test
public void testBinartTokenCreationValidation() throws InvalidKeyException, NoSuchAlgorithmException, IOException {
ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:" + OTokenHandlerImplTest.class.getSimpleName());
db.create();
try {
OSecurityUser original = db.getUser();
OTokenHandlerImpl handler = new OTokenHandlerImpl("any key".getBytes(), 60, "HmacSHA256");
ONetworkProtocolData data = new ONetworkProtocolData();
data.driverName = "aa";
data.driverVersion = "aa";
data.serializationImpl = "a";
data.protocolVersion = 2;
byte[] token = handler.getSignedBinaryToken(db, original, data);
OToken tok = handler.parseBinaryToken(token);
assertNotNull(tok);
assertTrue(tok.getIsVerified());
OUser user = tok.getUser(db);
assertEquals(user.getName(), original.getName());
boolean boole = handler.validateBinaryToken(tok);
assertTrue(boole);
assertTrue(tok.getIsValid());
} finally {
db.drop();
}
}
use of com.orientechnologies.orient.core.metadata.security.OUser in project orientdb by orientechnologies.
the class SQLFunctionsTest method queryCountExtendsRestricted.
public void queryCountExtendsRestricted() {
OClass restricted = database.getMetadata().getSchema().getClass("ORestricted");
Assert.assertNotNull(restricted);
database.getMetadata().getSchema().createClass("QueryCountExtendsRestrictedClass", restricted);
OUser admin = database.getMetadata().getSecurity().getUser("admin");
OUser reader = database.getMetadata().getSecurity().getUser("reader");
ORole byPassRestrictedRole = database.getMetadata().getSecurity().createRole("byPassRestrictedRole", ORole.ALLOW_MODES.DENY_ALL_BUT);
byPassRestrictedRole.addRule(ORule.ResourceGeneric.BYPASS_RESTRICTED, null, ORole.PERMISSION_READ);
byPassRestrictedRole.save();
database.getMetadata().getSecurity().createUser("superReader", "superReader", "reader", "byPassRestrictedRole");
ODocument docAdmin = new ODocument("QueryCountExtendsRestrictedClass");
docAdmin.field("_allowRead", new HashSet<OIdentifiable>(Arrays.asList(admin.getDocument().getIdentity())));
docAdmin.save();
ODocument docReader = new ODocument("QueryCountExtendsRestrictedClass");
docReader.field("_allowRead", new HashSet<OIdentifiable>(Arrays.asList(reader.getDocument().getIdentity())));
docReader.save();
List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>("select count(*) from QueryCountExtendsRestrictedClass"));
ODocument count = result.get(0);
Assert.assertEquals(2L, count.field("count"));
database.close();
database.open("admin", "admin");
result = database.query(new OSQLSynchQuery<ODocument>("select count(*) from QueryCountExtendsRestrictedClass"));
count = result.get(0);
Assert.assertEquals(2L, count.field("count"));
database.close();
database.open("reader", "reader");
result = database.query(new OSQLSynchQuery<ODocument>("select count(*) from QueryCountExtendsRestrictedClass"));
count = result.get(0);
Assert.assertEquals(1L, count.field("count"));
database.close();
database.open("superReader", "superReader");
result = database.query(new OSQLSynchQuery<ODocument>("select count(*) from QueryCountExtendsRestrictedClass"));
count = result.get(0);
Assert.assertEquals(2L, count.field("count"));
}
use of com.orientechnologies.orient.core.metadata.security.OUser 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);
}
use of com.orientechnologies.orient.core.metadata.security.OUser in project orientdb by orientechnologies.
the class OServerCommandAuthenticatedDbAbstract method getProfiledDatabaseInstanceToken.
protected ODatabaseDocumentInternal getProfiledDatabaseInstanceToken(final OHttpRequest iRequest) throws InterruptedException {
// after authentication, if current login user is different compare with current DB user, reset DB user to login user
ODatabaseDocumentInternal localDatabase = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
if (localDatabase == null) {
localDatabase = (ODatabaseDocumentTx) server.openDatabase(iRequest.databaseName, iRequest.bearerToken);
} else {
ORID currentUserId = iRequest.bearerToken.getUserId();
if (currentUserId != null && localDatabase != null && localDatabase.getUser() != null) {
if (!currentUserId.equals(localDatabase.getUser().getDocument().getIdentity())) {
ODocument userDoc = localDatabase.load(currentUserId);
localDatabase.setUser(new OUser(userDoc));
}
}
}
iRequest.data.lastDatabase = localDatabase.getName();
iRequest.data.lastUser = localDatabase.getUser() != null ? localDatabase.getUser().getName() : null;
return (ODatabaseDocumentTx) localDatabase.getDatabaseOwner();
}
Aggregations