Updating ORole from Java API - Giving exceptions

49 views
Skip to first unread message

Melissa Mifsud

unread,
Apr 10, 2013, 9:03:27 PM4/10/13
to orient-...@googlegroups.com
USING: 1.0.4.-SNAPSHOT

I'm trying to create custom database roles and users for my application. I need to be able to do this during a bootstrap process when the database is created.

I have tried both using the ORole and OUser API as well as running direct INSERT/UPDATE statements. In both cases, I'm incurring exception!

Here they are...

CASE 1:

ORole userUpdateRole = new ORole("userUpdateRole", null, ALLOW_MODES.DENY_ALL_BUT);
userUpdateRole.addRule("database.class.User", 6);
userUpdateRole = dbConnection.save(userUpdateRole);
OUser userUpdateUser = new OUser("userUpdateUser", "userUpdateUser");
userUpdateUser.setAccountStatus(STATUSES.ACTIVE);
userUpdateUser.addRole(userUpdateRole);
dbConnection.save(userUpdateUser);


Gives this error:

 com.orientechnologies.orient.core.exception.OSerializationException: Error serializing object of class class com.orientechnologies.orient.core.metadata.security.ORole
at com.orientechnologies.orient.object.enhancement.OObjectEntitySerializer.serializeObject(OObjectEntitySerializer.java:119)
at com.orientechnologies.orient.object.db.OObjectDatabaseTx.save(OObjectDatabaseTx.java:395)
at com.orientechnologies.orient.object.db.OObjectDatabaseTx.save(OObjectDatabaseTx.java:317)
at com.is.jdash.db.OrientDBManager.createDBUsers(OrientDBManager.java:387)
at com.is.jdash.db.OrientDBManager.boostrap(OrientDBManager.java:287)
... 69 more
Caused by: java.lang.NumberFormatException: For input string: "DENY_ALL_BUT"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:492)
at java.lang.Byte.parseByte(Byte.java:148)
at java.lang.Byte.parseByte(Byte.java:174)
at com.orientechnologies.orient.core.metadata.schema.OType.convert(OType.java:295)
at com.orientechnologies.orient.core.record.impl.ODocumentHelper.convertField(ODocumentHelper.java:211)
at com.orientechnologies.orient.core.record.impl.ODocument.field(ODocument.java:737)
at com.orientechnologies.orient.object.enhancement.OObjectEntitySerializer.toStream(OObjectEntitySerializer.java:1044)
at com.orientechnologies.orient.object.enhancement.OObjectEntitySerializer.serializeObject(OObjectEntitySerializer.java:117)


CASE 2:

db.command(new OCommandSQL("UPDATE ORole PUT rules = ?, 1 WHERE name = ?")).execute("database.class.*", "userUpdateRole");

But I am getting the following exception:

FATAL com.is.jdash.db.OrientDBManager.boostrap[294] - Could not boostrap database.
java.lang.ClassCastException: com.orientechnologies.orient.core.sql.filter.OSQLFilterItemField cannot be cast to java.lang.String
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLUpdate.parsePutFields(OCommandExecutorSQLUpdate.java:340)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLUpdate.parse(OCommandExecutorSQLUpdate.java:111)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLUpdate.parse(OCommandExecutorSQLUpdate.java:52)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate.parse(OCommandExecutorSQLDelegate.java:48)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate.parse(OCommandExecutorSQLDelegate.java:33)
at com.orientechnologies.orient.core.storage.OStorageEmbedded.command(OStorageEmbedded.java:82)
at com.orientechnologies.orient.core.command.OCommandRequestTextAbstract.execute(OCommandRequestTextAbstract.java:60)
at com.orientechnologies.orient.object.db.OCommandSQLPojoWrapper.execute(OCommandSQLPojoWrapper.java:45)


I don't think I can change anything for Case 1.
As for Case 2, is there another way to write the update statement?

Melissa

Luca Garulli

unread,
Apr 10, 2013, 9:36:52 PM4/10/13
to orient-database
Hi Melissa,
try using the security class:

db.getMetadata().getSecurity().createRole()

And for SQL the update doesn't support (yet) the dynamic parameters like select. So you can try:

db.command(new OCommandSQL("UPDATE ORole PUT rules = 'database.class.*', 1 WHERE name = 'userUpdateRole'")).execute();


Lvc@




Melissa

--
 
---
You received this message because you are subscribed to the Google Groups "OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to orient-databa...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages