Search in sources :

Example 6 with ORole

use of com.orientechnologies.orient.core.metadata.security.ORole in project orientdb by orientechnologies.

the class OSystemUserAuthenticator method isAuthorized.

// OSecurityAuthenticator
// If not supported by the authenticator, return false.
// Checks to see if a 
public boolean isAuthorized(final String username, final String resource) {
    if (username == null || resource == null)
        return false;
    try {
        if (getServer() != null) {
            OUser user = getServer().getSecurity().getSystemUser(username, null);
            if (user != null && user.getAccountStatus() == OSecurityUser.STATUSES.ACTIVE) {
                ORole role = null;
                ORule.ResourceGeneric rg = ORule.mapLegacyResourceToGenericResource(resource);
                if (rg != null) {
                    String specificResource = ORule.mapLegacyResourceToSpecificResource(resource);
                    if (specificResource == null || specificResource.equals("*")) {
                        specificResource = null;
                    }
                    role = user.checkIfAllowed(rg, specificResource, ORole.PERMISSION_EXECUTE);
                }
                return role != null;
            }
        }
    } catch (Exception ex) {
        OLogManager.instance().error(this, "isAuthorized() Exception: %s", ex.getMessage());
    }
    return false;
}
Also used : ORole(com.orientechnologies.orient.core.metadata.security.ORole) OUser(com.orientechnologies.orient.core.metadata.security.OUser) ORule(com.orientechnologies.orient.core.metadata.security.ORule)

Example 7 with ORole

use of com.orientechnologies.orient.core.metadata.security.ORole in project orientdb by orientechnologies.

the class RestrictedTest method testReaderRoleDesntInheritsFromWriterRole.

@Test(dependsOnMethods = "testReaderRoleCanSeeInheritedDocument")
public void testReaderRoleDesntInheritsFromWriterRole() throws IOException {
    database.open("admin", "admin");
    ORole reader = database.getMetadata().getSecurity().getRole("reader");
    reader.setParentRole(null);
    reader.save();
}
Also used : ORole(com.orientechnologies.orient.core.metadata.security.ORole) Test(org.testng.annotations.Test)

Example 8 with ORole

use of com.orientechnologies.orient.core.metadata.security.ORole in project orientdb by orientechnologies.

the class RestrictedTest method testReaderRoleInheritsFromWriterRole.

@Test(dependsOnMethods = "testReaderCannotSeeWriterDocumentAgain")
public void testReaderRoleInheritsFromWriterRole() throws IOException {
    database.open("admin", "admin");
    ORole reader = database.getMetadata().getSecurity().getRole("reader");
    reader.setParentRole(database.getMetadata().getSecurity().getRole("writer"));
    reader.save();
}
Also used : ORole(com.orientechnologies.orient.core.metadata.security.ORole) Test(org.testng.annotations.Test)

Aggregations

ORole (com.orientechnologies.orient.core.metadata.security.ORole)8 OUser (com.orientechnologies.orient.core.metadata.security.OUser)4 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)3 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)2 Map (java.util.Map)2 Test (org.testng.annotations.Test)2 OStorageEntryConfiguration (com.orientechnologies.orient.core.config.OStorageEntryConfiguration)1 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)1 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)1 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)1 ODatabaseException (com.orientechnologies.orient.core.exception.ODatabaseException)1 OSecurityAccessException (com.orientechnologies.orient.core.exception.OSecurityAccessException)1 ORule (com.orientechnologies.orient.core.metadata.security.ORule)1 OJSONWriter (com.orientechnologies.orient.core.serialization.serializer.OJSONWriter)1 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)1 OCluster (com.orientechnologies.orient.core.storage.OCluster)1 OObjectDatabaseTx (com.orientechnologies.orient.object.db.OObjectDatabaseTx)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 HashSet (java.util.HashSet)1